Java Code Examples for java.awt.image.BufferedImage.setData()

The following are Jave code examples for showing how to use setData() of the java.awt.image.BufferedImage class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: pdi   File: ProcessadorImagem.java   View Source Code Vote up 9 votes
public BufferedImage processaAlgoritmo(BufferedImage img, PosicoesDTO posicoes) {
	WritableRaster raster = img.getRaster();
	BufferedImage newImage = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
	int pixels[] = new int[4];
	for (int i = posicoes.getX1(); i < posicoes.getY1() - 1; i++) {
		for (int j = posicoes.getX2(); j < posicoes.getY2() - 1; j++) {
			raster.getPixel(i, j, pixels);
			int[] novosPixels = calculaPixeis(img, i, j);
			pixels[0] = novosPixels[0];
			pixels[1] = novosPixels[1];
			pixels[2] = novosPixels[2];

			raster.setPixel(i, j, pixels);
		}
	}

	newImage.setData(raster);

	return newImage;

}
 
Example 2
Project: rekit-game   File: ImageManagement.java   View Source Code Vote up 8 votes
/**
 * Convert {@link AbstractImage} to {@link Image}.
 *
 * @param in
 *            the input image
 * @return the converted image
 */
public static Image toImage(AbstractImage in) {
	if (in == null) {
		return null;
	}
	BufferedImage res = new BufferedImage(in.width, in.height, BufferedImage.TYPE_INT_ARGB);
	int[] pixels = new int[in.pixels.length];
	for (int i = 0; i < pixels.length; i += 1) {
		pixels[i] = in.pixels[i] & 0xFF;
	}
	WritableRaster raster = Raster.createWritableRaster(res.getSampleModel(), null);
	raster.setPixels(0, 0, in.width, in.height, pixels);
	res.setData(raster);
	res.flush();
	return res;

}
 
Example 3
Project: pdi   File: GiraImagem.java   View Source Code Vote up 7 votes
public BufferedImage girar(BufferedImage img, PosicoesDTO posicoes) {
	WritableRaster raster = img.getRaster();
	BufferedImage newImage = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
	WritableRaster rasterNewImage = newImage.getRaster();
	int pixels[] = new int[4];
	for (int i = posicoes.getX1(); i < posicoes.getX2(); i++) {
		for (int j = posicoes.getY1(); j < posicoes.getY2(); j++) {
			raster.getPixel(i, j, pixels);
			rasterNewImage.setPixel(i, img.getHeight() - j, pixels);
		}
	}

	newImage.setData(rasterNewImage);

	return newImage;

}
 
Example 4
Project: pdi   File: GiraImagemParcial.java   View Source Code Vote up 7 votes
public BufferedImage girar(BufferedImage img, PosicoesDTO posicoes) {
	WritableRaster raster = img.getRaster();
	BufferedImage newImage = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
	WritableRaster rasterNewImage = newImage.getRaster();
	int pixels[] = new int[4];
	for (int i = 1; i < img.getWidth() - 1; i++) {
		for (int j = 1; j < img.getHeight() - 1; j++) {
			raster.getPixel(i, j, pixels);
			rasterNewImage.setPixel(i, j, pixels);
		}
	}

	for (int i = posicoes.getX1(); i < posicoes.getX2(); i++) {
		int pixeisInvertidos = 0;
		for (int j = posicoes.getY1(); j < posicoes.getY2(); j++) {
			raster.getPixel(i, j, pixels);
			rasterNewImage.setPixel(i, posicoes.getY2() - pixeisInvertidos, pixels);
			pixeisInvertidos++;
		}
	}

	newImage.setData(rasterNewImage);

	return newImage;

}
 
Example 5
Project: BHBot   File: MarvinImage.java   View Source Code Vote up 4 votes
/**
 * Return a new instance of the BufferedImage
 * @return BufferedImage
 */
public BufferedImage getNewImageInstance(){
	BufferedImage buf = new BufferedImage(image.getWidth(),image.getHeight(), image.getType());
	buf.setData(image.getData());
	return buf;
}