本文介绍了读取JPEG:ImageIO.read()会弄乱色彩空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Servlet中读取,重新缩放和保存图像。这是相关的代码:

I'm trying to read, rescale and save images within a Servlet. That's the relevant code:

BufferedImage image = ImageIO.read(file);

BufferedImage after = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
AffineTransform at = AffineTransform.getScaleInstance(factor, factor);
AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
after = scaleOp.filter(image, null);

ImageIO.write(after, "JPG", file));

原始文件是纯RGB-Jpeg,但是当我打开并保存文件时它出来了作为CMYK-Jpeg。即使我没有重新缩放图像,只是打开和关闭图像会导致问题。

The original file is a plain RGB-Jpeg, but when I open and save the file it comes out as a CMYK-Jpeg. That happens even if i don't rescale the image, just opening and closing the image causes the problem.

当我打开PNG或GIF时,一切都很好。有人知道该怎么做吗?我希望ImageIO的read-Method能够保留原始的色彩空间。

When I open PNGs or GIFs everything is fine. Does anybody know what to do here? I would expect ImageIO's read-Method to retain the original colorspace.

如果还有其他方式可以轻松阅读jpeg?

If there's another way comfortable way of reading jpeg's?

感谢您的任何建议!

推荐答案

您在之后创建并且然后用 scaleOp.filter 覆盖它。它是否正确?所以你的之后的图像可能不是RGB,即使你认为它是?如果你想在之后成为RGB,那么你可能需要在之后绘制图像在进行转换之前

You create after and then overwrite it with scaleOp.filter. Is this correct? So your after image may not be RGB even though you think it is? If you want after to be RGB then you may need to 'draw' image onto after before you do the transform.

这篇关于读取JPEG:ImageIO.read()会弄乱色彩空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-21 02:16