Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

public static Image toImage(BufferedImage bufferedImage) { 
    return Toolkit.getDefaultToolkit().createImage(bufferedImage.getSource()); 
} 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top