码迷,mamicode.com
首页 > 移动开发 > 详细

Android-清除Canvs内容的实现

时间:2014-06-24 17:59:49      阅读:348      评论:0      收藏:0      [点我收藏+]

标签:android   style   class   blog   code   color   

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内容的实现

标签:android   style   class   blog   code   color   

原文地址:http://www.cnblogs.com/biyaxiong/p/3805645.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!