What is double buffering technology? Double buffering technology is when the user interface is complete, there will be a buffer to save the results of user operations.
Why use double buffering technology? Take the development of Android games, the interface is all repaint each time, also said to draw a new, the old is gone, so need to use double buffer technology to save the previous content.
How to achieve double buffering? Use a Bitmap object to retain the previous canvas.
Package com.example.phonegaptest;
Import Android.content.Context;
Import Android.graphics.Bitmap;
Import Android.graphics.Bitmap.Config;
Import Android.graphics.Canvas;
Import Android.graphics.Color;
Import Android.graphics.Paint;
Import Android.graphics.Path;
Import Android.util.AttributeSet;
Import android.view.MotionEvent;
Import Android.view.View;
public class Drawview extends View {float PreX;
float prey;
private path Path;
Public Paint Paint = null;
Final int view_width = 320;
Final int view_height = 480;
Bitmap cachebitmap = null;
Canvas Cachecanvas = null;
Public Drawview (context, AttributeSet set) {Super (context, set);
Cachebitmap = Bitmap.createbitmap (View_width, View_height, config.argb_8888);
Cachecanvas = new Canvas ();
Path = new Path ();
Cachecanvas.setbitmap (CACHEBITMAP);
Paint = new Paint (Paint.dither_flag);
Paint.setcolor (color.red);
Paint.setstyle (Paint.Style.STROKE); Paint.setstrokewidth(1);
Paint.setantialias (TRUE);
Paint.setdither (TRUE);
@Override public boolean ontouchevent (Motionevent event) {float x = Event.getx ();
Float y = event.gety ();
Switch (event.getaction ()) {case MotionEvent.ACTION_DOWN:path.moveTo (x, y);
PreX = x;
Prey = y;
Break
Case MotionEvent.ACTION_MOVE:path.quadTo (PreX, Prey, x, y);
PreX = x;
Prey = y;
Break
Case MotionEvent.ACTION_UP:cacheCanvas.drawPath (path, paint);
Path.reset ();
Break
} invalidate ();
return true;
} @Override protected void OnDraw (Canvas Canvas) {Super.ondraw (Canvas);
Paint bmppaint = new Paint ();
Canvas.drawbitmap (cachebitmap, 0, 0, bmppaint);
Canvas.drawpath (path, paint); }
}
Above is the Android double buffering technology implementation of the artboard application example, the need for friends can refer to.