【发布时间】:2013-06-26 17:15:22
【问题描述】:
我正在做一个白板项目,在实现保存功能时遇到了问题。
这是我如何实现绘图功能
Graphics2D g2d = (Graphics2D) frm.getGraphics();
g2d.setColor(Current_Color);
Line2D p2d = new Line2D.Double(StartPoint.getX(),StartPoint.getY(), e.getX()
+ Xoffset, e.getY() + Yoffset);
g2d.setStroke(new BasicStroke(Integer.parseInt(choice_size.getSelectedItem())));
g2d.draw(p2d);
我在文件对话框中使用 JFileChooser
int returnVal = saveFileChooser.showSaveDialog(frm);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File currentDir = saveFileChooser.getCurrentDirectory();
String fileName = saveFileChooser.getSelectedFile()
.getName();
String savePath = currentDir + "\\" + fileName + ".jpg";
try {
ImageIO.write(<image>,<suffix>,<file>);
} catch (IOException e1) {
e1.printStackTrace();
}
}
对于 JFrame,没有像 Frame.getImage() 这样的方法,我想知道如何将我在 JFrame 上绘制的内容保存为图像?
【问题讨论】: