Android-清除Canvs内容的实现

SurfaceView背景透明:

setZOrderOnTop(true);
SurfaceHolder holder = this.getHolder(); holder.setFormat(PixelFormat.TRANSLUCENT);

清除Canvas内容的实现方式一:

Canvas canvas = null;
try {
  synchronized (holder) {
    canvas = holder.lockCanvas(null);
    if (canvas == null) {
      return;
    }
    canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); 
  }
} catch (Exception e) {
  e.printStackTrace();
} finally {
  if (canvas != null) {
    holder.unlockCanvasAndPost(canvas);
  }
}

方式二:

 Paint paint = new Paint();  
 paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));  
 canvas.drawPaint(paint);  
 paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));  

 

Android-清除Canvs内容的实现,布布扣,bubuko.com

Android-清除Canvs内容的实现

上一篇:数据库中的数据排序


下一篇:用adb pull命令从android系统中读取文件失败的原因及解决办法