Android_Canvas_Bitmap_关系


@作者 : 西野奈留
@博客:http://blog.csdn.net/narunishino
-2016/4/09-


Canvas:(中文翻译)n.帆布,vt.用帆布覆盖。

primitive:(中文翻译)n.原始事物。

http://developer.android.com/reference/android/graphics/Canvas.html

android.graphics.Canvas

Class Overview //文档中的解释。
The Canvas class holds the “draw” calls. To draw something, you need 4 basic components:
1. A Bitmap to hold the pixels,
2. a Canvas to host the draw calls (writing into the bitmap),
3. a drawing primitive (e.g. Rect, Path, text, Bitmap),
4. a paint (to describe the colors and styles for the drawing).

平时看到的资料都把Canvas比喻成画布。

今天深入的去了解了一下,似乎不是画布哦,应该比喻成 画板 更加贴切。

而bitmap是画板(Canvas)上的那张白纸。

Canvas的2个构造方法:

1.public Canvas ()

Construct an empty raster canvas. Use setBitmap() to specify a bitmap to draw into. The initial target density is DENSITY_NONE; this will typically be replaced when a target bitmap is set for the canvas.

2.public Canvas (Bitmap bitmap)

Construct a canvas with the specified bitmap to draw into. The bitmap must be mutable.

从第一个构造方法的解释中可以看到,如果不给Canvas指定bitmap的话,系统会自动给Canvas一个bitmap1。

这时候如果你指定一个bitmap2给Canvas的话,你指定的这个bitmap2就会把原来系统默认的bitmap1给替换掉。

也就是说,你把画板(Canvas)中的原来就有的白纸(bitmap1)换成了你自己的白纸(bitmap2)(如果你之前在上面(bitmap2)画过东西的话就不是白纸了,反正就是换成你自己的纸)。


从源码的角度来解释的话,请看这里http://lwn.me/2014/04/13/canvas/

-End-


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值