This question already has an answer here:
- JPEG image with wrong colors 7 answers
When I save this image:
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:
This doesn't happen with all pictures though.
Can you tell me why?