fWX228941 / document

document descripe my groun-up
0 stars 0 forks source link

SurfaceView #10

Open fWX228941 opened 5 years ago

fWX228941 commented 5 years ago

SurfaceHolder surfaceView控制器,用来操作surface,处理其在canvas上绘制的效果,控制大小,像素等

surfaceHolder = getHolder();
setZorderOnTop(true);// 如果想让SurfaceView显示图片或者视频 置于activity显示窗口的最顶层才能正常显示
surfaceHolder.serFormat(PixelFormat.TRANSLUCENT);   //设置surfaceView的背景色
surfaceHolder.addCallback(new SurfaceHolder.Callback(){
@Override
Public void surfaceCreated(SurfaceHolder surfaceHolder){
//在surface的大小发生改变时激发
}
@Override
Public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2){
//在创建时激发,一般在这里调用画图的线程
}
@Override
Public void surfaceDestroyed(SurfaceHolder surfaceHolder){
// 销毁时触发,将画图的线程停止,释放
If (mThread != null ) {
mThread.interrupt();
mThread = null;
}
}
});
开始绘制时
Canvas canvas = surfaceHolder.lockCanvas();// 获取canvas 对象并锁定画布
If(canvas == null ) return;
XXX
surfaceHolder.unlockCanvasAndPost(canvas);// 图画完之后,提交改变,将图形内容显示出来

画图任务繁重的时候都是使用的SurfaceView