在我的java中有一个保存按钮,在完成绘图后保存绘图..
来自Button java(已更新)theres以及drawingArea.saveImage();
中的错误 public void actionPerformed(ActionEvent e)
{
if (e.getSource()==btnClear)
drawingArea.clear();
else if (e.getSource()==infobutton)
{
//default title and icon
JOptionPane.showMessageDialog(this,"Paint java created by bla bla bla bla bla blaa");
}
else if (e.getSource()==colorBtn)
{
color = JColorChooser.showDialog(null,"LOL",color);
drawingArea.setColorBtn(color);
}
else if (e.getSource()==colorBg)
{
color = JColorChooser.showDialog(null,"LOL",color);
drawingArea.setColorBg(color);
drawingArea.repaint();
}
if(e.getSource()==save)
{
drawingArea.saveImage();
}
}
这里是来自DrawingArea java(更新)
public void saveImage(DrawingArea drawingArea)
throws FileNotFoundException, IOException
{
BufferedImage image=new BufferedImage(drawingArea.getWidth(), drawingArea.getHeight(),BufferedImage.TYPE_INT_RGB);
Graphics2D g2=(Graphics2D)image.getGraphics();
drawingArea.paint(g2);
try {
ImageIO.write(image, "png", new File("/tmp/drawingArea.png"));
} catch (Exception e) {
}
}