你可以通过SurfaceHolder接口访问这个surface,getHolder()方法可以得到这个接口。...如果你要查看 surface被创建和销毁的时机,可以重载surfaceCreated(SurfaceHolder)和 surfaceDestroyed(SurfaceHolder)。...2> 由于surface可能被销毁,它只在SurfaceHolder.Callback.surfaceCreated()和 SurfaceHolder.Callback.surfaceDestroyed...SurfaceHolder Abstract interface to someone holding a display surface....SurfaceHolder是用来操作surface的接口,通过SurfaceView的getHolder来获取 Surface、SurfaceView和SurfaceHolder的关系类似MVC。
{ private SurfaceHolder surfaceHolder; private Path path = new Path(); public HuabanView(Context...= getHolder(); surfaceHolder.addCallback(this);//获得surfaceview的生命周期 } public HuabanView(Context...holder) { new HuabanThread().start(); } @Override public void surfaceChanged(SurfaceHolder holder..., int format, int width, int height) { } @Override public void surfaceDestroyed(SurfaceHolder holder...{ private SurfaceHolder surfaceHolder; private Path path = new Path(); private int x = 0; public
2、调用MediaPlayer.setDisplay(holder)设置surfaceHolder,surfaceHolder可以通过surfaceview的getHolder()方法获得。...这是大致步骤,但只有这些是不够的 在第二步之前需要确保surfaceHolder已经准备好了。因此需要给surfaceHolder设置一个callback, 调用addCallback()方法。...Callback 有三个回调函数,如下: SurfaceHolder.Callback { @Override public void surfaceCreated(SurfaceHolder...} } surfaceCreated()会在SurfaceHolder被创建的时候回调,在这里可以做一些初始化的操作,surfaceDestroyed()会在SurfaceHolder被销毁的时候回调,...一般,会在surfaceCreated中给MediaPlayer设置surfaceHolder。
(SurfaceHolder holder){} //在创建时激发,一般在这里调用画图的线程。...3)SurfaceHolder SurfaceHolder,surface的控制器,用来操纵surface。处理它的Canvas上画的效果和动画,控制表面,大小,像素等。...4)总结整个过程 继承SurfaceView并实现SurfaceHolder.Callback接口 ----> SurfaceView.getHolder()获得SurfaceHolder对象 --...-->SurfaceHolder.addCallback(callback)添加回调函数---->SurfaceHolder.lockCanvas()获得Canvas对象并锁定画布----> Canvas...绘画 ---->SurfaceHolder.unlockCanvasAndPost(Canvas canvas)结束锁定画图,并提交改变,将图形显示。
代码如下: 对于SurfaceHolder.Callback接口 public class SurfaceViewTemplate extends SurfaceView implements SurfaceHolder.Callback...一般我们通常定义以下三个成员变量 //SurfaceHolder private SurfaceHolder mSurfaceHolder; // 用于绘图的Canvas...SurfaceHolder对象,并注册SurfaceHolder的回调方法。..., Runnable { //SurfaceHolder private SurfaceHolder mSurfaceHolder; // 用于绘图的Canvas private..., Runnable { //SurfaceHolder private SurfaceHolder mSurfaceHolder; // 用于绘图的Canvas private
) 和 SurfaceDestoryed(SurfaceHolder) 方法, 这两个回调方法是 SurfaceHolder.Callback 中设定; -- Surface 控制 : SurfaceView...通过 SurfaceHolder 控制 Surface; (2) SurfaceHolder 简介 Surfaceholder 简介 : SurfaceHolder 是 Surface 的控制器, 用于控制...(), 锁定画布, 可以获得 Canvas 对象, 之后就可以在 Canvas 上绘图了; (3) SurfaceHolder.Callback 简介 SurfaceHolder.Callback 接口...: Surface 销毁"); } } (3) 获取 SurfaceHolder 对象 并添加回调接口子类 获取 SurfaceHolder 流程 : -- a....(this); /* 为 SurfaceHolder 设置回调函数, 即 SurfaceHolder.Callback 子类对象 */ SurfaceHolder 其它设置 : --
定义我们的Camera相关参数,包括摄像头的ID,Camera变量及Camera的回调方法,最后再定义一个内部的SurfaceHolder ?...然后我们先修改构造函数,在构造函数中获取的SurfaceHolder,并在其中加入回调和基本的参数设置,如下图 ?...surfaceHolder) { //开启摄像机 startCamera(mCameraIndex); } @Override public...void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) { } @Override public...void surfaceDestroyed(SurfaceHolder surfaceHolder) { //关闭摄像机 stopCamera(); }
然后我们再继承SurfaceHolder.Callback 这个接口 ,这样我们的GameCanvas类要实现其几个方法 1 public void surfaceCreated(SurfaceHolder...holder) {} 2 public void surfaceDestroyed(SurfaceHolder holder) {} 3 public void surfaceChanged(SurfaceHolder...这样每个方法里面都会有个参数 SurfaceHolder 这个是什么呢??...暂且先不讨论它,后面你会明白他有什么用了, 声明一个SurfaceHolder handle对象,然后在surfaceCreated()方法里面初始化它 如下: handle = this.getHolder...游戏大体框架如下: public class GameCanvas extends SurfaceView implements SurfaceHolder.Callback{ private SurfaceHolder
Camera提供一个setPreviewDisplay(SurfaceHolder)的方法来连接surfaceHolder,并通过他来控制surfaceView....关系如下: Camera — –>SurfaceHolder——>SurfaceView. (2)知道怎么预览了,当然也要知道怎么开启相机.Camera.open()这是个静态方法,如果相机没有别人用着...很奇怪的是,这个方法,不能随便放,如放在构造方法或者onCreate()方法中,都会照成没有预览效果. (3) SurfaceHolder.Callback,这是个holder用来显示surfaceView...{ SurfaceHolder holder; Camera myCamera; public MySurfaceView(Context context...{ SurfaceHolder holder; Camera myCamera; private ShutterCallback shutter = new
2、 SurfaceHolder SurfaceHolder是控制surface的一个抽象接口,你可以通过SurfaceHolder来控制surface的尺寸和格式,或者修改surface的像素,监视...当用在一个SurfaceView 中时, 它只在SurfaceHolder.Callback.surfaceCreated()和SurfaceHolder.Callback.surfaceDestroyed...设置Callback的方法是SurfaceHolder.addCallback。...当用在一个SurfaceView 中时, //它只在SurfaceHolder.Callback.surfaceCreated()和SurfaceHolder.Callback.surfaceDestroyed...surfaceCallback = new SurfaceHolder.Callback() { @Override public void surfaceCreated(SurfaceHolder
getSurfaceHolder() { return super.getSurfaceHolder(); } @Override public void onCreate(SurfaceHolder...surfaceHolder) { super.onCreate(surfaceHolder); } @Override public void onDestroy...() { super.onDestroy(); } @Override public void onSurfaceChanged(SurfaceHolder holder...关于Engine的几个主要方法如下: class MyEngine extends Engine{ //获取SurfaceHolder时调用 @Override public SurfaceHolder...实现绘制的方式,就跟SurfaceView的绘制一样了: @Override public void onSurfaceCreated(SurfaceHolder holder) {
利用getHolder()获取SurfaceHolder对象,调用SurfaceHolder.addCallback添加回调 SurfaceHolder.lockCanvas 获取Canvas对象并锁定画布...,调用Canvas绘图,SurfaceHolder.unlockCanvasAndPost 结束锁定画布,提交改变。...SurfaceHolder SurfaceHolder回调自己的三个生命周期: surfaceCreated(SurfaceHolder holder)创建时 surfaceChanged(SurfaceHolder...{ public static final int PROGRESS = 101; SurfaceView surfaceView,surfaceView_danmu; SurfaceHolder surfaceHolder...; SurfaceHolder surfaceHolder; MediaPlayer mediaPlayer = new MediaPlayer(); ArrayList<Music list=new
03 — SurfaceHolder SurfaceHolder是一个接口,其作用就像一个关于Surface的监听器。...除下面将要提到的SurfaceHolder.Callback外,SurfaceHolder还提供了很多重要的方法,其中最重要的就是: abstract void addCallback(SurfaceHolder.Callbackcallback...) 为SurfaceHolder添加一个SurfaceHolder.Callback回调接口。...04 — SurfaceHolder.Callback 前面已经讲到SurfaceHolder是一个接口,它通过回调方法的方式,让我们可以感知到Surface的创建、销毁或者改变。...SurfaceHolder.Callback中定义了三个接口方法: abstract void surfaceChanged(SurfaceHolder holder, int format, int
中获取 //绘制图像的 SurfaceView SurfaceView surfaceView; //在 SurfaceView 回调函数中获取 SurfaceHolder surfaceHolder...Surface 画布 : 这里的 Surface 画布从 SurfaceView 中获得 , SurfaceHolder.Callback 的监听方法中获取 SurfaceHolder 及 Surface...设置 SurfaceHolder 回调函数 : 首先要获取 SurfaceView 的 SurfaceHolder ; 设置 SurfaceHolder 监听回调函数 SurfaceHolder.Callback...; //监听获取画布 this.surfaceHolder = this.surfaceView.getHolder(); surfaceHolder.addCallback...surfaceHolder; ...
{ private SurfaceHolder holder; private MyThread myThread; // 处理绘图的线程 public MyView(Context...holder; public MyThread(SurfaceHolder holder) { this.holder = holder; isRun = true; }...首先是声明一个继承SurfaceView并且实现SurfaceHolder.CallBack的子类 class MyView extends SurfaceView implements SurfaceHolder.Callback...{ @Override public void surfaceChanged(SurfaceHolder holder, int format, int width...在子类中获得一个用于控制suerfce对象的surfaceHolder对象 holder = SurfaceView.getHodler(); holder.addCallback() 3.
import android.util.Log; import android.view.KeyEvent; import android.view.Menu; import android.view.SurfaceHolder...surfaceHolder; private Camera camera; private File picture; private Button btnSave; private final...= surfaceView.getHolder(); // Camera interface to instantiate components surfaceHolder.addCallback(...surfaceCallback); // Add a callback for the SurfaceHolder surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS...surfaceCallback = new SurfaceHolder.Callback() { public void surfaceCreated(SurfaceHolder holder) {
; import android.view.SurfaceHolder.Callback; import android.view.SurfaceView; public class MySurfaceView...extends SurfaceView implements Runnable, Callback { private SurfaceHolder mHolder; // 用于控制SurfaceView.../** * 当SurfaceView创建的时候,调用此函数 */ @Override public void surfaceCreated(SurfaceHolder.../** * 当SurfaceView销毁的时候,调用此函数 */ @Override public void surfaceDestroyed(SurfaceHolder...holder),surfaceChanged(SurfaceHolder holder, int format, int width,int height),surfaceDestroyed(SurfaceHolder
要想在SurfaceView中画出bitmap等,必须用如下格式 private void draw() { Canvas canvas = surfaceHolder.lockCanvas...(); if (canvas == null) return; //draw something surfaceHolder.unlockCanvasAndPost...(canvas); } 然后开启一个线程,每隔一定时间调用这个draw函数、 GameView在创建的时候做如下这些事: 1.初始化一些参数,比如屏幕宽高,bitmap的生成 2.获得SurfaceHolder...接口访问这个surface,getHolder()方法可以得到这个接口 */ surfaceHolder = getHolder(); surfaceHolder.addCallback...(new Callback() { @Override public void surfaceDestroyed(SurfaceHolder arg0)
isRecording; } }); } private SurfaceHolder.Callback mSurfaceCallback = new...SurfaceHolder.Callback() { /** * * @param surfaceHolder 持有当前 Surface 的 SurfaceHolder...对象 */ @Override public void surfaceCreated(SurfaceHolder surfaceHolder) {...一般在这里将画图的线程停止销毁 * * @param surfaceHolder 持有当前 Surface 的 SurfaceHolder 对象 *.../ @Override public void surfaceDestroyed(SurfaceHolder surfaceHolder) { if
surfaceHolder; private Camera camera; private File picture; private Button btnSave; @Override public...= surfaceView.getHolder(); // Camera interface to instantiate components surfaceHolder.addCallback(...surfaceCallback); // Add a callback for the SurfaceHolder surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS...surfaceCallback = new SurfaceHolder.Callback() { public void surfaceCreated(SurfaceHolder holder) {...Setting camera parameters camera.startPreview(); // Start Preview } public void surfaceDestroyed(SurfaceHolder
领取专属 10元无门槛券
手把手带您无忧上云