如何在Camera 2 API中配置捕获大小 [英] How to configure the capture size in Camera 2 API

查看:396
本文介绍了如何在Camera 2 API中配置捕获大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个android相机应用程序.我的疑问是如何将支持的分辨率作为参数传递给相机.

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);

而且,我也得到了

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

错误,尽管我的手机摄像头支持此大小(根据getOutputSizes()的调试结果).

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.

推荐答案

不要混淆

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

这篇关于如何在Camera 2 API中配置捕获大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆