SurfaceView cameraView = (CameraView) this.findViewById(R.id.CameraView);
SurfaceHolder surfaceHolder = cameraView.getHolder();
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
另外,我們可能會希望在活動中實(shí)現(xiàn)SurfaceHolder.Callback,從而使得在創(chuàng)建、修改及銷毀該Surface時(shí)活動將會獲得通知。為了實(shí)現(xiàn)回調(diào),需要添加以下方法。
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {}
public void surfaceCreated(SurfaceHolder holder) {}
public void surfaceDestroyed(SurfaceHolder holder) {}
最后,需要告訴SurfaceHolder使用該活動作為回調(diào)處理程序。
surfaceHolder.addCallback(this);
現(xiàn)在活動應(yīng)該看起來如下所示。
package com.apress.proandroidmedia.ch2.snapshot;
import android.app.Activity;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class SnapShot extends Activity implements SurfaceHolder.Callback {
SurfaceView cameraView;
SurfaceHolder surfaceHolder;
@Override
public void onCreate(Bundle savedInstanceState)
{