I\'m trying to read, rescale and save images within a Servlet. That\'s the relevant code:
BufferedImage image = ImageIO.read(file);
BufferedImage after = ne
ImageIO.read
ignores all embedded metadata, including an embedded color profile, which defines how RBG values map to physical devices such as screens or printers.
You could read the metadata separately and pass it to ImageIO.write
, but it's easier to just convert the image to the (default) sRGB color space and ignore the metadata.
If you don't mind losing the metadata, replace
after = scaleOp.filter(image, null);
with
after = scaleOp.filter(image, after);
From the documentation of AffineTransformOp.filter:
If the color models for the two images do not match, a color conversion
into the destination color model is performed.