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:
One of images after read and write:
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…