我正在开发相机应用程序。我想快速拍摄相机,图像显示就像facebook Messenger中的那个。我尝试使用默认方法OnPictureTaken()
,但似乎很慢。
初始化变量:
Camera mCamera = Camera.open();
SurfaceView mPreview;
内部方法OnCreate()
:
mPreview = (SurfaceView) findViewById(R.id.surfaceView1);
mPreview.getHolder().addCallback(this);
mPreview.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mCamera.takePicture(null, null, jpegCallback);
方法OnPictureTaken()
:
Camera.PictureCallback jpegCallback = new Camera.PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
mCamera.stopPreview();
mCamera.release();
}
};
表面方法:
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
try {
mCamera.setPreviewDisplay(mPreview.getHolder());
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
是否有其他选择以某种方式捕捉表面?