1.绘图基本操作
请参考下面基础示例:
1 int width = 200, height = 250;2 //创建图片对象
3 BufferedImage image = newBufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);4 //基于图片对象打开绘图
5 Graphics2D graphics =image.createGraphics();6 //绘图逻辑 START (基于业务逻辑进行绘图处理)……7
8 //绘制圆形
9 graphics.setColor(Color.BLACK);10 Ellipse2D.Double ellipse = new Ellipse2D.Double(20, 20, 100, 100);11 graphics.draw(ellipse);12
13 //绘图逻辑 END14 //处理绘图
15 graphics.dispose();16 //将绘制好的图片写入到图片
17 ImageIO.write(image, "png", new File("abc.png"));
如上代码所示,使用java绘图基本操作流程如下:
a.得到一个 BufferedImage ,可以是直接指定分辨率new一个空图片,也
b.基于此BufferedImage 创建一个绘图对象,使用createGraphics 方法,得 Graphics2D 实例
c.使用Graphics2D 实例进行画图,所有绘图坐标基于创建此Graphics2D 的BufferedImage。示例中在图片上画了一个圆形。
d.调用Graphics2D 对象的 dispose() 方法,进行绘图处理&#x