restoreCount() 将图层出栈
图一,透明度为127时,为半透明状态
图二,透明度设置为255时,完全不透明
Android图像处理技巧 色彩矩阵分析// ---- 施工中(8月2日--6日) ----
SurfaceView的使用API 作用
lockCanvas() 获得当前Canvas对象
drawColor() 清屏
public class SurfaceViewDemo extends SurfaceView implements Runnable, SurfaceHolder.Callback { private SurfaceHolder mHolder; private Canvas mCanvas; private boolean mIsDrawing; // 子线程标志位 public SurfaceViewDemo(Context context) { super(context); initView(); } private void initView() { mHolder = getHolder(); mHolder.addCallback(this); setFocusable(true); setFocusableInTouchMode(true); this.setKeepScreenOn(true); // mHolder.setFormat(PixelFormat.OPAQUE); } @Override public void surfaceCreated(SurfaceHolder surfaceHolder) { mIsDrawing = true; new Thread(this).start(); } @Override public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) { } @Override public void surfaceDestroyed(SurfaceHolder surfaceHolder) { mIsDrawing = false; } @Override public void run() { while (mIsDrawing) { draws(); } } public void draws() { try { mCanvas = mHolder.lockCanvas(); } catch (Exception e) { } finally { if (mCanvas != null) { mHolder.unlockCanvasAndPost(mCanvas); } } } } SurfaceView实例 1. 正选曲线 @Override public void run() { while (mIsDrawing) { draws(); x += 1; y = (int) (100 * Math.sin(x * 2 * Math.PI/180) + 400); mPath.lineTo(x, y); } } private void draws() { try { mCanvas = mHolder.lockCanvas(); // Surface背景 mCanvas.drawColor(Color.WHITE); mCanvas.drawPath(mPath, mPaint); } catch (Exception e) { } finally { if (mCanvas != null) { mHolder.unlockCanvasAndPost(mCanvas); } } }