I. Understanding the double buffering mechanism
1. Create an artboard, and a picture ()
2. Set the picture as an artboard
3. The artboard will then be painted on the image.
4. Then put the image on the view provided by the artboard to display
Ii. examples (using a double-buffering mechanism for artboards)
Public classDrawviewextendsView {Private intView_width = 0; Private intView_height = 0; Private floatPrevX = 0; Private floatPrevy = 0; PrivatePath MPath; PrivateBitmap Mcachebitmap; PrivateCanvas Mcachecanvas; PrivatePaint Mpaint; PublicDrawview (Context context, AttributeSet attrs) {Super(context, attrs); //get the width of the screen heightWindowManager WindowManager =(WindowManager) Context.getsystemservice (Context.window_service); Display Display=Windowmanager.getdefaultdisplay (); View_width=display.getwidth (); View_height=display.getheight (); //creating a double-buffered boardMcachebitmap = Bitmap.createbitmap (View_width, View_height, Bitmap.Config.ARGB_8888);//Create a picture bufferMcachecanvas =NewCanvas (MCACHEBITMAP);//draw the canvas into the buffer//Create PathMPath =NewPath (); //Create PaintMpaint =NewPaint (); Mpaint.setstrokewidth (3); Mpaint.setcolor (color.red); Mpaint.setstyle (Paint.Style.STROKE); Mpaint.setantialias (true); Mpaint.setdither (true); } @Override Public Booleanontouchevent (Motionevent event) {floatCurrentX =Event.getx (); floatCurrentY =event.gety (); Switch(Event.getaction ()) { CaseMotionEvent.ACTION_DOWN:prevX=CurrentX; Prevy=CurrentY; Mpath.moveto (Event.getx (), event.gety ()); Break; CaseMotionEvent.ACTION_MOVE:prevX=CurrentX; Prevy=CurrentY; Mpath.quadto (Prevx,prevy,currentx,currenty); Break; CaseMotionEvent.ACTION_UP:mPath.reset (); Break; } mcachecanvas.drawpath (MPath, mpaint); Invalidate (); //to change the return to true so that the Ontouchevent () method is executed return true; } @Overrideprotected voidOnDraw (canvas canvas) {Super. OnDraw (canvas); Paint Paint=NewPaint (); Canvas.drawbitmap (Mcachebitmap,0,0, paint); }}
View Code
Image:
Introduction to double buffering mechanism