Android Camera2输出大小 [英] Android Camera2 Output sizes

查看:415
本文介绍了Android Camera2输出大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Android Lollipop上测试了新的Camera2 API.我想获取支持的预览尺寸:

StreamConfigurationMap streamConfigurationMap = cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
Size[] sizes = streamConfigurationMap.getOutputSizes(SurfaceTexture.class);

,在具有2560x1600px分辨率的Samsung Galaxy Tab S上,最大预览尺寸为1440x1080px.所以我的PreviewSize是1440x1080px,TextureView的表面尺寸是2560x1600px,所以图像失真了.

我测试了已过时的旧相机API.

Camera.Parameters parameters =  camera.getParameters();
List<Camera.Size> sizes = parameters.getSupportedPictureSizes();

上面的代码返回预览大小的32种混合形式,例如:2560x19201920x10801080x19202560x2560等.在这种情况下,我可以选择最佳大小并显示正确的图像./p>

我不知道如何强制新的API获得最佳大小.我知道解决方案是缩小显示预览的视图的大小,但是内置的相机应用程序可以在全屏模式下正常工作. 预先感谢您的所有建议!

解决方案

正如@Alex Cohn所说,要使用Camera API2取决于制造商.

您可以检查是否支持Camera API2 camCharacteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);返回与相机API2的支持级别相对应的int. 如果您获得的级别基本上等于CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY,则您的电话制造商不支持Camera API2.

->因此,SCALER_STREAM_CONFIGURATION_MAP可能返回与Camera API1可访问的分辨率不同的分辨率. 这就是您获得

的原因

最大预览尺寸为1440x1080px

令我震惊的是4年前提出的问题...而且仍然有制造商不愿意升级到Camera API2. 尽管Camera API2为您提供了更多功能,但也许Camera API1毕竟还没有死.

如果能使用一些碎片信息,或者至少知道使用Camera API2时实际要瞄准多少设备(由于具有LEGACY支持,并非所有的Android L及更高版本,开发人员都应该知道这一点),我们将很高兴 >

I have tested new Camera2 API on Android Lollipop. I want to fetch supported preview size:

StreamConfigurationMap streamConfigurationMap = cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
Size[] sizes = streamConfigurationMap.getOutputSizes(SurfaceTexture.class);

and the maximum preview size is 1440x1080px on Samsung Galaxy Tab S that has 2560x1600px resolution. So my previewSize is 1440x1080px and TextureView surface size is 2560x1600px so image is distorted.

I tested old Camera API that is deprecated.

Camera.Parameters parameters =  camera.getParameters();
List<Camera.Size> sizes = parameters.getSupportedPictureSizes();

And the code above returns 32 varius combinations of preview size such as: 2560x1920, 1920x1080, 1080x1920, 2560x2560 etc. In that case I am able to choose optimal size and display correct image.

I do not know how to force new API to get optimal size. I know that the solution is to resize down view that displays preview, but built-in camera app works in fullscreen mode correctly. Thanks in advance for all suggestions!

解决方案

As @Alex Cohn said it depends on the manufacturers to embrace Camera API2.

You can check if the Camera API2 is supported with camCharacteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL); returning an int corresponding to the level of support for Camera API2. If the level you get is equal to CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACYbasically your phone manufacturer does not support Camera API2.

--> As a consequence the SCALER_STREAM_CONFIGURATION_MAP may return different resolutions than the ones accessible with Camera API1. This is the reason why you get

the maximum preview size is 1440x1080px

What really shocks me it that the question was asked 4 years ago... and there are still manufacturers that did not care to upgrade to Camera API2. While Camera API2 gives you much more features, maybe Camera API1 is not dead after all.

Would be nice to have some fragmentation information, at least to know how many devices you actually target if you use Camera API2 (it's not all the Android L and above because of the LEGACY support, developers deserve to know that)

这篇关于Android Camera2输出大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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