本文介绍了如何设置android camera2预览和捕获大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用SurfaceView
来显示我捕获的预览.我想使用width = 1080,height = 1920进行预览.在哪里可以设置预览的大小?
I am using a SurfaceView
to show the preview I capture. I want to use width=1080,height=1920 for the preview. Where can I set the size of the preview?
我用谷歌搜索了一个答案,但它们都是针对相机版本一的.我正在使用android.hardware.camera2.
I googled for an answer, but they are all for camera version one. I am using the android.hardware.camera2.
private void takePreview() {
try {
final CaptureRequest.Builder previewRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
previewRequestBuilder.addTarget(mSurfaceHolder.getSurface());
mCameraDevice.createCaptureSession(Arrays.asList(mSurfaceHolder.getSurface(), mImageReader.getSurface()), new CameraCaptureSession.StateCallback() // ③
{
@Override
public void onConfigured(CameraCaptureSession cameraCaptureSession) {
if (null == mCameraDevice) return;
mCameraCaptureSession = cameraCaptureSession;
try {
previewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
previewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH);
previewRequestBuilder.set(CaptureRequest.JPEG_THUMBNAIL_SIZE, new Size(1080,1920));
CaptureRequest previewRequest = previewRequestBuilder.build();
mCameraCaptureSession.setRepeatingRequest(previewRequest, null, childHandler);
} catch (CameraAccessException e) {
Log.e("takePreview","onConfigured(CameraCaptureSession cameraCaptureSession)",e);
}
}
@Override
public void onConfigureFailed(CameraCaptureSession cameraCaptureSession) {
Log.e("takePreview","onConfigureFailed");
}
}, childHandler);
} catch (CameraAccessException e) {
Log.e("takePreview","CameraAccessException");
}
}
推荐答案
如对 createCaptureSession :
这篇关于如何设置android camera2预览和捕获大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!