我正在编写一个有趣的图像库,但遇到了一个似乎无法解决的问题。该类非常简单:拍照、处理照片、通过JFrame显示照片,最后将其保存为BufferedImage(javax.imageio.ImageIO)。这是我通过JFrame看到的图片(这是我的ColorEnhance类...在Drustan星云中):
这是保存后的版本(png格式,但ImageIO.write()支持的所有类型看起来都一样):
我不确定变化发生在哪里,但当我通过模糊方法运行它时,整条线从png中突然出现...无论如何,这是一些代码:
![The image as seen from the JFrame](https://istack.dev59.com/F0SCW.gif)
![The image as seen after it has been saved](https://istack.dev59.com/jvcWL.gif)
public void writeToFile(BufferedImage finalPic, String nameToAppend)
{
String temp=fileName.replace(".", nameToAppend+".");
String ext=fileName.substring(fileName.indexOf(".")+1);
File file=new File(temp);
try
{
ImageIO.write(finalPic, ext.toUpperCase(), file);
System.out.println("Successfully saved to: "+temp);
} catch (Exception e) { e.getMessage(); }
}
public void displayImage(String titleName)
{
ImageIcon icon = new ImageIcon(newPic);
JFrame frame = new JFrame(titleName);
JLabel label = new JLabel(icon);
label.setIcon(icon);
frame.getContentPane().add(label, BorderLayout.CENTER);
frame.setSize(WIDTH, HEIGHT+22);
frame.setVisible(true);
}
最后一点是,保存功能对于某些处理类比其他处理类更有效。如果您需要查看更多代码,请随时提问,谢谢。
ImageIO
不是问题的原因,一定是你有问题的ImageFilter
。 - Extreme Coders