private Paint paint;
private Canvas mBufferCanvas;
private Bitmap mBufferBitmap;
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
//先创建canvas进行绘制
if (mBufferBitmap == null){
mBufferBitmap = Bitmap.createBitmap(getWidth(),getHeight(), Bitmap.Config.ARGB_8888);
mBufferCanvas = new Canvas(mBufferBitmap);
}
mBufferCanvas.drawCircle(event.getX(),event.getY(),50,paint);
break;
case MotionEvent.ACTION_UP:
invalidate();
break;
}
return super.onTouchEvent(event);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//系统canvas绘制已经绘制好的bitmap绘制,原理也是bitmap的管理
canvas.drawBitmap(mBufferBitmap,0,0,null);
}
Canvas缓冲绘制
最新推荐文章于 2024-04-27 22:23:55 发布