本文介绍了保存 jpg 图像时 Java 1.5.0_16 损坏的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个从磁盘加载的图像(存储为 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 是一个 BufferedImagefileName 是一个 File 对象,指向将被保存的以.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 的错误)).

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 损坏的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 14:47