【发布时间】:2014-03-23 17:36:27
【问题描述】:
我想读取一些图像,然后在其上绘制一些形状并将带有形状的图像保存为新文件。我尝试做类似的事情,但它不起作用。
public class Test extends JPanel{
private static BufferedImage br;
public static void main(String[] args) {
try {
br=ImageIO.read(new File("rys1.png"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawImage(br,0,0,this);
g.drawRect(20, 20, 10, 10);
g.setColor(Color.BLACK);
try {
ImageIO.write(br, "png", new File(("D:\\test\\rys"+2)));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
【问题讨论】:
标签: java swing file-io jpanel paintcomponent