Save BufferedImage

Hi.
I have a program that creates some BufferedImage with

offscreen = new BufferedImage (2000,2000,BufferedImage.TYPE_INT_ARGB);

I draw something to it and draw a filter with a Color f.e. (new Color(0,0,50,100))
afterwards so that the hole image looks a bit blue with a transparent color.

When I save this Image with the following method something happens that shouldn´t.

This is the method:

try {
ByteArrayOutputStream out = new ByteArrayOutputStream( 0xfff );
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder( out );
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(foto);
param.setQuality(1.0f, true );
encoder.encode(Foto, param );
FileOutputStream fos = new FileOutputStream(f);
fos.write( out.toByteArray() );
fos.close();
out.close();
} catch (Exception e) {
}

It should save my Image foto with the maximum of quality and it does,
but what happens is that the colors of my saved JPG don´t match the ones I see when I draw this Image
to the screen.
Why?
How can I change this to get my real pictures saved?

http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/com/sun/media/jai/codec/JPEGEncodeParam.html#setQuality(float)

Choose the right tool for the right job; if you want an image saved losslessly, don’t use jpeg - use png.

Actually, the problem is somewhere else. I had this problem, all my images that went through ImageIO.write() turned out a bit pink/redish.

The problem whas that I was writing 4 color-channels (RGBA) to a format that doesn’t handle the alpha at all. Copy your ARGB image to a RGB buffered image, and save that, and the redness will be gone.

Thanks,
both ways work well.
:slight_smile:

urg, that sounds worthy of a bug parade entry!

http://www.java-gaming.org/forums/index.php?topic=12032.0