0
我正在創建一個GUI,以保存用戶在JLabel上繪製的圖像。這是我的saveImage方法的代碼。我可以彈出框讓我可以選擇保存文件的位置,但實際上並未保存文件。如何從JLabel保存圖像
public void saveImage()
{
BufferedImage image = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D image2 = image.createGraphics();
image2.setBackground(Color.WHITE);
image2.clearRect(0, 0, this.getWidth(), this.getHeight());
this.paintAll(image2);
try
{
File output = new File("rectangle.png");
ImageIO.write(image, "Rectangles", output);
final JFileChooser fchooser = new JFileChooser(".");
int retvalue = fchooser.showSaveDialog(RectangleLabel.this);
if (retvalue == JFileChooser.APPROVE_OPTION)
{
fchooser.setSelectedFile(output);
File f = fchooser.getSelectedFile();
}
}
catch(IOException ie)
{
}
}
so ...哪裏的代碼? – Frakcool