Java PNG到JPG Bug
我想在这个教程。但我遇到了一个问题。生成的图像有一个粉红色的图层。
I am trying to convert a PNG image to a JPEG image following this tutorial. But I encounter a problem. The resulting image has a pink layer.
有没有人有这个问题的解决方案?或者我应该使用什么代码将图像转换为所需格式?
Does anyone have a solution for this problem? Or what code should I use in order to convert the image into the desired format?
提前致谢!
-
创建所需大小的BufferedImage,例如:
Create a BufferedImage of desired size, e.g.:
BufferedImage img = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB)
用适当的背景颜色填充它:
fill it with a proper background color:
img.getGraphics()。fillRect(....)
在该背景顶部的图像图形上调用drawImage:
Call drawImage on the image's graphics atop of that background:
img.getGraphics()。drawImage(image,0 ,0,null);
然后像往常一样将图像写为JPG。
then write down your image as JPG as usual.