[英]Image Review not shown after camera.takePicture
On all the handsets I've tried, including the Galaxy Nexus with both API 2.3.7 and 4.0 after the takePicture method is called the surface view changes to the image that was taken, the "Image Review". 在我尝试的所有手机上,包括带有API 2.3.7和4.0的Galaxy Nexus,在调用takePicture方法后,曲面视图会更改为拍摄的图像,即“图像查看”。
I've tested on these tablet devices and the image review didn't show up: XOOM API 3.1 Galaxy Tab 10.1 API 3.1 Galaxy Tab 10.1 API 3.2 我已经在这些平板电脑设备上进行了测试,并且没有显示图像审核:XOOM API 3.1 Galaxy Tab 10.1 API 3.1 Galaxy Tab 10.1 API 3.2
surfaceView = (SurfaceView)findViewById(R.id.surfaceView);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
...
public void takePicture() {
cam.takePicture(this, null, this); //Shuttercallback, RawCallback, JpegCallback
}
...
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
// Stop preview before changing camera parameters
if(isPreviewRunning) {
this.cam.stopPreview();
}
Camera.Parameters p = this.cam.getParameters();
LogUtils.info("CheckCapture", "Preview Size: " + String.valueOf(width) +"x" + String.valueOf(height));
p.setPreviewSize(width, height);
//Set picture size to a multiple of previewSize to maintain aspect ratio AND minimum capture width
//LogUtils.info("CheckCapture", "Picture Size: " + String.valueOf(width*factor) +"x" + String.valueOf(height*factor));
p.setPictureSize(width, height);
p.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
//Set picture format (we can check device capabilities, but all devices at API level 8 should support JPEG)
p.setPictureFormat(PixelFormat.JPEG);
//Set new camera parameters
try {
this.cam.setParameters(p);
}catch (Exception e) {
e.printStackTrace();
}
//Setup preview display on our surfaceViewHolder
try {
this.cam.setPreviewDisplay(surfaceHolder);
} catch (IOException e) {
e.printStackTrace();
}
//Start preview
this.cam.startPreview();
this.isPreviewRunning = true;
}
on btn_click.onclickListener use callback method as follow 在btn_click.onclickListener上使用回调方法如下
_btn_click.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
ShutterCallback shutterCallBack = new ShutterCallback() {
@Override
public void onShutter() {}
};
PictureCallback pictureCallBack = new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {}
};
PictureCallback pictureCallBackJPG = new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
Bitmap capturedBitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
}
};
setFlashMode();
camera.takePicture(shutterCallBack, pictureCallBack,
pictureCallBackJPG);
showProgressDialog("Bitte warten", CameraCaptureActivity.this);
}
});
in this code main line is 在这段代码的主线是
Bitmap capturedBitmap = BitmapFactory.decodeByteArray(data, 0, data.length); 位图captureBitmap = BitmapFactory.decodeByteArray(data,0,data.length);
use capturedBitmap in imageview.setImageBitmap(capturedBitmap); 在imageview.setImageBitmap(capturedBitmap)中使用capturedBitmap; to show the image. 显示图像。
Happy Coding 快乐的编码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.