使用 Java 将 PNG 转换为 JPG 时出现问题 (ImageIO.write())
我正在使用 ImageIO.write() 将 PNG 文件转换为 JPG。由于某种原因,我的结果图像上面有一层粉红色的层。我已经广泛寻找解决方案,但没有找到任何解决方案。该代码适用于除 PNG 之外的所有其他类型的图像。
I am using ImageIO.write() to convert PNG files to JPG. For some reason, my result image has a pink layer over it. I have searched far and wide for a solution but haven't found any. The code works for all other types of images except PNG.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不确定其他代码片段如何工作,因为缓冲区在创建后没有被使用。我发现这个粉色问题是 jvm 版本特定的。
我发现的最简单的解决方案就是这样做。
I'm not sure how the other code snippet works given buffer is not used after it's created. I've found this pink problem to be jvm version specific.
The easiest solution I've found is to do this.
快速阅读标记为 ImageIO 的其他 SO 答案导致这个。
根本原因可能是有错误的阅读器。建议的解决方法是使用不同的阅读器包。
编辑上面的链接已损坏,但这似乎就是这样。
编辑以上链接已损坏,这里是 archive.org。
Quick reading of other SO answers tagged ImageIO led to this.
The root cause can be a buggy reader. The proposed workaround is using different reader package.
Edit Above link is broken, but this appears to be it.
Edit The above links are broken, here it is on archive.org.
我也遇到了同样的问题,但是如果我以 png 格式编写它就可以解决。
像这样的事情,
I too had the same problem, but if i write it in png format then it gets solved.
Something like this,
我发现这个 链接 其中有一些可能有用的代码。我用我的一些图像尝试了您的代码,但无法重现该问题。我尝试了 devyn_a 的最后一个答案,它没有破坏任何东西。这是使用 devyn_a 的解决方案修改的代码。
知道这是否能解决问题将会很有趣。
I found this link which has some code that might be of use. I tried your code with a few of my images but I couldn't reproduce the issue. I tried the last answer by devyn_a and it didn't break anything. Here's your code modified with devyn_a's solution.
It would be interesting to know if this resolves the issue.