Introduction to double buffering mechanism

Source: Internet
Author: User
Tags gety

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.