问题描述
我有一个从磁盘加载的图像(存储为 BufferedImage
),我在 JPanel
上正确显示但是当我尝试使用下面的命令重新保存此图像时,图像以偏红色调保存。
i have a loaded image from disk (stored as a BufferedImage
), which i display correctly on a JPanel
but when i try to re-save this image using the command below, the image is saved in a reddish hue.
ImageIO.write(image, "jpg", fileName);
注意! image是 BufferedImage
和 fileName
是一个文件
对象指向到将保存的文件名以 .jpg
结尾。
Note! image is a BufferedImage
and fileName
is a File
object pointing to the filename that will be saved which end in ".jpg
".
我读过有问题使用早期JDK中的 ImageIO
方法,但就我所能找到的那样,我不在其中一个版本上。我正在寻找的是一种在不更新JDK的情况下解决这个问题的方法,但是我已经说过我仍然想知道这个问题在JDK中修复了什么(如果它确实仍然是我正在使用的JDK的一个bug )。
I have read that there were problems with ImageIO
methods in earlier JDKs but i'm not on one of those versions as far as i could find. What i am looking for is a way to fix this issue without updating the JDK, however having said that i would still like to know in what JDK this issue was fixed in (if it indeed is still a bug with the JDK i'm using).
谢谢。
推荐答案
好的,解决了我的问题,由于某种原因,我似乎需要将图像转换为BufferedImage.TYPE_INT_RGB。我认为在某些层可能无法正确处理alpha通道。
Ok, solved my problem, it seems that i need to convert the image to BufferedImage.TYPE_INT_RGB for some reason. I think the alpha channels might not be handled correctly at some layer.
这篇关于保存jpg图像时,Java 1.5.0_16损坏了颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!