最近在看自定义控件---绘制view
今天先上点Canvas的源码,持续更新中。。。
下面是一点Canvas源码
/**
* The Canvas class holds the "draw" calls. 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), and a paint (to describe the colors and styles for the
* drawing).
*
* <div class="special reference">
* <h3>Developer Guides</h3>
* <p>For more information about how to use Canvas, read the
* <a href="{@docRoot}guide/topics/graphics/2d-graphics.html">
* Canvas and Drawables</a> developer guide.</p></div>
*/
public class Canvas {
/** @hide */
public static boolean sCompatibilityRestore = false;
/**
* Should only be assigned in constructors (or setBitmap if software canvas),
* freed in finalizer.
* @hide
*/
protected long mNativeCanvasWrapper;
/**
* Construct an empty raster canvas. Use setBitmap() to specify a bitmap to
* draw into. The initial target density is {@link Bitmap#DENSITY_NONE};
* this will typically be replaced when a target bitmap is set for the
* canvas.
*/
public Canvas() {
if (!isHardwareAccelerated()) {
// 0 means no native bitmap
mNativeCanvasWrapper = initRaster(null);
mFinalizer = new CanvasFinalizer(mNativeCanvasWrapper);
} else {
mFinalizer = null;
}
}
Canvas 类保存了draw 的调用,你需要四个基本的组件来绘制。1.bitmap保存像素的位图。2.canvas保存draw的调用。3一个原始绘画材料,4.一个画笔(color,style)
有两个构造方法,一个无参