【Android】【GUI】01-绘图基本组件及其关系
1 绘图的基本组件
Android官方文档中,描述如下:
To draw something, you need 4 basic components:
- A Bitmap to hold the pixels;
- A Canvas to host the draw calls (writing into the bitmap);
- A drawing primitive (e.g. Rect, Path, text, Bitmap);
- A paint (to describe the colors and styles for the drawing).
简而言之,绘制需要四个基本组件——Canvas、Bitmap、Drawing Primitive、Paint。
2 绘图基本组件的理解
2.1 Bitmap
我们看到的屏幕图像,是由像素点组成的。这些像素点就存储在Bitmap中。因此,Bitmap存储着将要显示在屏幕上的数据。
Bitmap类似我们画画时用的白纸,是图像的实际载体。
2.2 Canvas
Canvas直译过来是“画布”,这个名称和实际作用并不贴切。Canvas实际是工具集,我们借助Canvas将各种图像绘制到Bitmap上。
我们画直线要用到尺子,画圆要用到圆规。Canvas就类似尺子、圆规等工具的集合。借助Canvas,我们可以将各种图形绘制到Bitmap上。
2.3 Drawing Primitive
Drawing Primitive直译过来是“图元”,包含Rect、Path、Text等基础元素。
2.4 Paint
Paint是画笔,包括颜色、粗细、样式、抗锯齿等功能。