本文介绍了读取 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?

感谢您的任何建议!

推荐答案

你创建 after 然后用 scaleOp.filter 覆盖它.这样对吗?所以你的 after 图像可能不是 RGB,即使你认为它是?如果您希望 after 成为 RGB,那么您可能需要在进行转换之前将 image 'draw' 到 after 上.

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() 弄乱了色彩空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 14:45