How to configure the capture size in Camera 2 API

☆樱花仙子☆ 提交于 2019-12-13 16:52:22

问题


I'm making an android camera application. My doubt is how do I pass the supported resolutions as parameters to the camera.

So, first I'm getting all the supported resolution sizes:

Size[] sizes = configurationMap.getOutputSizes(ImageFormat.YUV_420_888);
Log.d("test","size:"+sizes.length);

for(Size size : sizes){
    Log.d("test", "width: " + size.getWidth() + " height" + size.getHeight());
}

Then I'm configuring the input with one of these sizes.

InputConfiguration inputConfiguration = new InputConfiguration(1920, 1080, ImageFormat.YUV_420_888);

The I'm passing this input to a capture session

cameraDevice.createReprocessableCaptureSession(inputConfiguration, Arrays.asList(previewSurface), new CameraCaptureSession.StateCallback() {
    @Override
    public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
        try {
            cameraCaptureSession.setRepeatingRequest(mCaptureRequestBuilder.build(), null, handler);
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
        Toast.makeText(getApplicationContext(),"Camera Preview Failed!!",Toast.LENGTH_SHORT).show();
    }
}, null);

And, I'm also getting an

java.lang.IllegalArgumentException: input size 1920x1080 is not valid

error, though this size is supported on my phone camera (from the debug result of getOutputSizes()).

So, my question is on my approach and where I'm wrong.


回答1:


Don't confuse getOutputSizes(imageFormat) with getInputSizes(imageFormat). Note that you must check separately that the format is supported for input or output.



来源:https://stackoverflow.com/questions/52697534/how-to-configure-the-capture-size-in-camera-2-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!