您好,我的相机 2 api 有问题。我正在使用前置摄像头和表面视图来显示预览。
当我从 StreamConfigurationMap 获得尺寸列表时,我有这个尺寸列表。
> 0 = {Size@5139} "1600x1200"
1 = {Size@5152} "1280x720"
2 = {Size@5153} "960x720"
3 = {Size@5154} "720x480"
4 = {Size@5155} "640x480"
5 = {Size@5156} "480x320"
6 = {Size@5157} "320x240"
7 = {Size@5158} "176x144"
选择要用作预览尺寸的首选尺寸。像这样:
mTexturePreviewSize = getPreferredSize(sizeList, width, height);
选择的首选尺寸是 1600*1200。
调用 CreateCaptureSession 时,
mCaptureRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
mCaptureRequestBuilder.addTarget(surface);
mCameraDevice.createCaptureSession(Arrays.asList(surface, mReader.getSurface()), new CameraCaptureSession.StateCallback() {
@Override
public void onConfigured(CameraCaptureSession session) {
if (mCameraDevice == null) return;
try {
mCaptureRequest = mCaptureRequestBuilder.build();
mCameraSession = session;
mCameraSession.setRepeatingRequest(mCaptureRequest, mCameraSessionCallback, mBackgroundHandler);
} catch (CameraAccessException ex) {
ex.printStackTrace();
}
}
我有onConfigureFailed。我认为列表中的任何大小都可以让我正确配置相机。