Why does Java imageio smooth JPEG colors

When I see some JPG files, the color becomes flat This is a simple example. It reads a JPG and writes the same image to another file

import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;

public class JPegReadTest {
    public static void main(String[] args) {
        if (args.length == 2) {
            try {
                BufferedImage src = ImageIO.read(new File(args[0]));
                ImageIO.write(src,"jpg",new File(args[1]));
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            System.err.println("Usage: java JPegReadTest src dest");
        }
    }
}

If you try to use, for example http://www.flickr.com/photos/visualpanic/233508614/sizes/l/ , the color of the target image is different from that of the source file Why? How to solve it?

You also try to save the image as PNG, but the color is also flat (so it is assumed that the color information is not read correctly)

Solution

This may be for several reasons

>JPEG color data is usually stored as YCrCb instead of RGB, although the conversion should be mostly unobtrusive. > JPEG usually has an embedded color profile, but many applications don't understand this and just ignore it (in this case, your output file may lack a color profile). > Java can reset or lose gamma values

I didn't really try your example... Can you post it before and after the document? Without the ability to actually check the result file, it is difficult to say whether this additional data exists

Edit: Yes, obviously, your original and converted images have different color profiles Java stripped the original color configuration file and used the general sRGB They are the same as Firefox and various programs on windows because they do not use color profiles when rendering However, on the Mac, the MAC actually supports these color profiles (graphical prompts on the Mac, etc.), so they render differently I don't have the convenience of MAC, but I doubt if you open files in Photoshop on any platform, you will see the difference

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>