gpt4 book ai didi

java - CameraDevice 无法创建 session [Camera2]

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:15:22 25 4
gpt4 key购买 nike

我正在尝试使用 Camera2 API 将相机数据流式传输到 SurfaceView。我正在遵循本指南:Camera2 guide

我无法通过第 5 步

MainActivity.java::onCreate()

setContentView(R.layout.activity_main);

surfaceView = (SurfaceView)findViewById(R.id.surface);
manager = (CameraManager)getSystemService(Context.CAMERA_SERVICE);

MainActivity.java::onClick()

for (String id : manager.getCameraIdList()) {
CameraCharacteristics characteristics = manager.getCameraCharacteristics(id);

Integer direction = characteristics.get(CameraCharacteristics.LENS_FACING);

if (direction != null && direction == CameraCharacteristics.LENS_FACING_BACK) {
if (checkCallingOrSelfPermission("android.permission.CAMERA") == PackageManager.PERMISSION_GRANTED)
manager.openCamera(id, new StateCallback(), null);

break;
}
}

MainActivity.java.StateCallback::onOpened(CameraDevice camera)

List<Surface> surfaces = new LinkedList<>();
surfaces.add(surfaceView.getHolder().getSurface());

CaptureRequest.Builder builder = camera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
builder.addTarget(surfaces.get(0));

camera.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() {
@Override
public void onConfigured(CameraCaptureSession session) {
Log.i(TAG, "Configured");
}

@Override
public void onConfigureFailed(CameraCaptureSession session) {
Log.e(TAG, "Configured failed"); // Ends up in this function :(
}
}, null);

程序在 onConfigureFailed() 函数中结束。我不知道可能是什么错误,也不知道如何检查是什么。

我的猜测是我在 CaptureRequest 中遗漏了一些东西,但我不知道是什么。

我在 Samsung Galaxy S4 上运行.

最佳答案

添加到onConfigured:

  if (null == cameraDevice) {
Log.e(TAG, "updatePreview error, return");
return;
}
captureRequestBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
try {
cameraCaptureSessions.setRepeatingRequest(captureRequestBuilder.build(), null, mBackgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}

关于java - CameraDevice 无法创建 session [Camera2],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33987245/

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