I have been using ImageIO.read() and ImageIO.write() methods in javax.imageio.ImageIO for reading and writing images, and I found that some images' color gets changed weirdly.

Even if I change my code to do nothing but just read images and write them (with jpeg, png, gif), all those new images have the same issue.

Do I need to add any other code before/after ImageIO.read/write methods?

Here is the code I used:

    File f = new File("obw.jpg");
    BufferedImage bi = ImageIO.read(f);
    FileOutputStream fos2 = new FileOutputStream("obw2.jpg");
    ImageIO.write(bi, "JPG", fos2);
    FileOutputStream fos3 = new FileOutputStream("obw3.gif");
    ImageIO.write(bi, "GIF", fos3);
    FileOutputStream fos4 = new FileOutputStream("obw4.png");
    ImageIO.write(bi, "PNG", fos4);

My environment:

    java version "1.6.0_35"
    MacOSX 10.8.2

Original Image: enter image description here

One of images after read and write:

enter image description here

Edit
Report