tags:

views:

48

answers:

2

i has a BufferedImage instance: (only a example)

BufferedImage image = ImageIO.read(new URL("http://www.google.com/intl/en_ALL/images/srpr/logo1w.png"));

now,i only know use

ImageIO.write(image,"jpg", file); //or ImageIO.write(image,"png", file);

to save this BufferedImage to a file, but this file is ZIPed,not equal original image size.

can I get original image ByteArray or OutputStream from BufferedImage instance?

A: 
public static Image toImage(BufferedImage bufferedImage) { 
    return Toolkit.getDefaultToolkit().createImage(bufferedImage.getSource()); 
} 
denis_k
but how to save a Image to file? like also use `ImageIO.write` http://snipplr.com/view/9891/store-image-to-file/
Zenofo
Well there is no way of using `Image` with `ImageIO.write`. Instead of `ImageIO` you can use Peter Tillemans' suggestion
denis_k
+2  A: 

In short : no.

Java converts the images to an internal representation and converts the files on reading and writing.

Your best bet will be to read the files in a byte array (or to a temporary file), create the image from there. and when saving the file, go back to the original bytearray or tempfile.

Peter Tillemans
really? so sad :(
Zenofo