Create JPEG from RGB array

How can I create a JPEG image from a int array of value RGB?thanks
[80 byte] By [paolo_cucchia] at [2007-10-3 1:00:29]
# 1

First create an Image from the RGB array (make sure the color components are in the right order in the int, which is ARGB). You can do this with the BufferedImage class.

BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

bi.setRGB(yourpixelarray);

Of course your int array must be width * height in size.

Next, use the ImageIO class to write this BufferedImage to a jpeg file. Something like:

ImageIO.write(bi, "jpg", new File("thefile.jpg"));

That should do it.

gimbal2a at 2007-7-14 17:56:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

bi.setRGB(yourpixelarray);doesn't exists.

There is bi.setRGB(0,0,mp4.getWidth(), mp4.getHeight(),dataRGB,0,1);

and then I write it on an output stream but I received a black image.

response.setContentType("image/jpg");

OutputStream out = response.getOutputStream();

ImageIO.write(bi, "jpg", out);

out.close();

paolo_cucchia at 2007-7-14 17:56:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Sorry, my mistake. The actual call should be:bi.setRGB(0,0,mp4.getWidth(), mp4.getHeight(),dataRGB,0,mp4.getWidth());Your scansize parameter is not correct, it should be the width of the image.
gimbal2a at 2007-7-14 17:56:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
How can I resize this image?
paolo_cucchia at 2007-7-14 17:56:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...