Image changes color when saved with java

Viewed 2645

When I save this image:

Holiday Doodle

with this method:

private final static Path ROOT_PATH = Paths.getPath("C:/images");

private static void saveImageFromWebSimple(final String url) {
    URL u = null;
    try {
        u = new URL(url);
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    String file = url.substring(url.indexOf("//") + 2);
    Path filePath = ROOT_PATH.resolve(file);
    try {
        Files.createDirectories(filePath.getParent());
        BufferedImage img = ImageIO.read(u);
        ImageIO.write(img, "jpg", filePath.toFile());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

this is my result:

Result

This doesn't happen with all pictures though.

Can you tell me why?

1 Answers
Related