Save BufferedImage

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() );
} 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.
How can I change this to get my real pictures saved?

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.

both ways work well.

urg, that sounds worthy of a bug parade entry!