Graphic2D 和 BufferedImage 有什么区别?

Graphic2D 和 BufferedImage 有什么区别? BufferedImage.CreateGraphic2D()表示什么?

[quote]BufferedImage 子类描述具有可访问图像数据缓冲区的 Image。BufferedImage 由图像数据的 ColorModel 和 Raster 组成。[/quote]

[quote]public Graphics2D createGraphics()创建一个 Graphics2D,可以将它绘制到此 BufferedImage 中。 [/quote]

[quote]Graphics2D 类扩展了 Graphics 类,提供了对几何形状、坐标转换、颜色管理和文本布局更为复杂的控制。它是用于在 Java(tm) 平台上呈现二维形状、文本和图像的基础类。
[/quote]

[quote]Graphics 类是所有图形上下文的抽象基类,允许应用程序可以在组件(已经在各种设备上实现),以及闭屏图像上,进行绘制。

[/quote]

直观的理解:Graphics2D 就相当于画笔,而BufferedImage 就是画笔绘制的结果。

Graphic2D主要用于图形的绘制,比如:线、圆、文本等,

BufferedImage是按照图像的方式访问图像,比如包含了颜色、光栅等

BufferedImage.createGraphic2D(),获取图形绘制的上下文,或者说是画笔,你可以用得到画笔,在图像上绘制各种图形和文本。

画笔与画布

buffered --> 被缓存 image 图像 bufferedImage 被缓存的图像

Graphics2D 就是画笔 BufferedImage.createGraphic2D(),创建这个图像的画笔,用来修改图像