10

使用时出现此错误CameraX.LensFacing.FRONT,正在模拟器上进行测试

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: meter.meter, PID: 15289
    java.lang.RuntimeException: Unable to start activity ComponentInfo{meter.meter/meter.meter.CameraActivity}: java.lang.IllegalArgumentException: Suggested resolution map missing resolution for camera 1
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.IllegalArgumentException: Suggested resolution map missing resolution for camera 1
        at androidx.camera.core.Preview.onSuggestedResolutionUpdated(Preview.java:310)
        at androidx.camera.core.UseCase.updateSuggestedResolution(UseCase.java:375)
        at androidx.camera.core.CameraX.calculateSuggestedResolutions(CameraX.java:458)
        at androidx.camera.core.CameraX.bindToLifecycle(CameraX.java:144)
        at meter.meter.CameraActivity.onCreate(CameraActivity.java:68)
        at android.app.Activity.performCreate(Activity.java:7136)
        at android.app.Activity.performCreate(Activity.java:7127)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)

代码:

PreviewConfig config = new PreviewConfig.Builder().setLensFacing(CameraX.LensFacing.FRONT).build();

    Preview preview = new Preview(config);

    TextureView textureView = findViewById(R.id.textureView);


    preview.setOnPreviewOutputUpdateListener(new Preview.OnPreviewOutputUpdateListener() {

                     @Override
                     public void onUpdated(Preview.PreviewOutput output) {
                            textureView.setSurfaceTexture(output.getSurfaceTexture());
                        }
                    });

                    ImageCaptureConfig imageCaptureConfig = new ImageCaptureConfig.Builder().build();

                    imageCapture = new ImageCapture(imageCaptureConfig);
                    CameraX.bindToLifecycle((LifecycleOwner) this,imageCapture, preview);
4

5 回答 5

13

添加setLensFacing(CameraX.LensFacing.FRONT)ImageCaptureConfig应该可以解决您的问题

于 2019-05-16T07:35:58.600 回答
10

作为对 Nestos 答案的补充,我必须同时添加 ImageCaptureConfigsetLensFacing(CameraX.LensFacing.FRONT)和 PreviewConfig 才能完成这项工作。

于 2019-07-07T20:54:51.433 回答
2

您应该调用您传递给 setLensFacing(..)的每个配置UseCaseCameraX.bindToLifecycle((LifecycleOwner) this, imageCapture, preview)

于 2019-09-20T11:57:21.327 回答
1

PreviewConfig ImageCaptureConfig ImageAnalysisConfig 都需要添加

setLensFacing(CameraX.LensFacing.FRONT)

这就是我设置它的方式

于 2020-05-02T09:14:50.620 回答
1

您需要将 lensFacing 添加setLensFacing(lensFacing)到以下区域: 1. PreviewConfig 2. ImageCaptureConfig 3. ImageAnalysisConfig

那应该这样做。

于 2020-05-07T14:29:06.240 回答