gpt4 book ai didi

android-camera2 - Android Camera2 api 多个表面 Co​​nfigureFailed

转载 作者:行者123 更新时间:2023-12-02 03:08:23 24 4
gpt4 key购买 nike

我正在尝试使用 camera2 API 开发一个 android 相机应用程序。代码工作正常。但是在 nexus 5X 上测试它之后,如果我添加多个 Surface,createCaptureSession 总是失败,下面调用的 onConfigureFailed 方法是我正在使用的代码

知道为什么这只发生在 nexus 5X 上

protected void startPreview() {
if (null == mCameraDevice) {
// Log.d(TAG, "mCameraDevice is null");
return;
}
//close Preview Session
if (mCaptureSession != null) {
mCaptureSession.close();
mCaptureSession = null;
}

try {
SurfaceTexture texture = mTextureView.getSurfaceTexture();
assert texture != null;
texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
Surface previewSurface = new Surface(texture);
mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
mPreviewBuilder.addTarget(previewSurface);

//mCameraDevice.createCaptureSession(Arrays.asList(previewSurface, mImageReader), new CameraCaptureSession.StateCallback(){ this line fails
mCameraDevice.createCaptureSession(Arrays.asList(previewSurface), new CameraCaptureSession.StateCallback(){ // this works
@Override
public void onConfigured(CameraCaptureSession cameraCaptureSession) {

mCaptureSession = cameraCaptureSession;

mPreviewBuilder.set(CaptureRequest.CONTROL_AF_MODE,CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
updatePreview();
}

@Override
public void onConfigureFailed(CameraCaptureSession cameraCaptureSession) {
Toast.makeText(this, "onConfigureFailed", Toast.LENGTH_SHORT).show();
}
}, null);

} catch (Exception e) {
Log.e(TAG, "startPreview faild",e);
e.printStackTrace();
}
}

最佳答案

调低分辨率似乎解决了这个问题。我是在运行安卓7.0的三星S7(SM-G930V)上体验的。我选择的分辨率是 2048x1152 或宽度或高度约为 2048 的输出大小。

关于android-camera2 - Android Camera2 api 多个表面 Co​​nfigureFailed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41213561/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com