首页 > 代码库 > Canvas
Canvas
it holds all of your "draw" calls. Via the Canvas, your drawing is actually performed upon an underlying Bitmap
, which is placed into the window.
说明及理解:
1.在View的事件回调方法onDraw()中,要做的仅仅是直接使用draw方法(canvas已经提供给你了,不需要再考虑canvas问题)。对于SurfaceView,可以通过surfaceHolder.lockCanvas()方法获得特定的canvas。
2.如果要自己新建一个Canvas,必需定义一个Bitmap。这样在canvas上调用的各种draw方法画出的内容都将承载在bitmap上。
However, if you need to create a new Canvas, then you must define the Bitmap
upon which drawing will actually be performed. The Bitmap is always required for a Canvas. You can set up a new Canvas like this:
Bitmap b =Bitmap.createBitmap(100,100,Bitmap.Config.ARGB_8888);
Canvas c =newCanvas(b);
3.你可以把你自己的Bitmap放到其它Canvas上。 通过
方法。Canvas.drawBitmap(Bitmap,...)
但建议,你最终的图像是画在View.onDraw()的画布上或者surfaceHolder.lockCanvas()的画布上。
4.Canvas类有自己的画画方法集。如drawBitmap(...),drawRect(...)等等。你可能用到的其他的类,它们也有自己的画画方法。如你画在Canvas上的Drawable对象,也有draw()方法。它们是把canvas作为draw()方法的参数。