使用SCALER_CROP_REGION裁剪时,Camera2预览会拉伸 [英] Camera2 preview stretched when cropping with SCALER_CROP_REGION

查看:854
本文介绍了使用SCALER_CROP_REGION裁剪时,Camera2预览会拉伸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用camera2 API在全屏中显示预览.我选择的摄像头尺寸为 4160x3120 (16:9),屏幕为 1080x1920 (9:16).因此,如果我想对预览进行正确缩放,则必须裁剪相机输出:

I want to display a preview in fullscreen using camera2 api. The camera size I selected is 4160x3120 (16:9) and my screen is 1080x1920 (9:16). Therefore if I want the preview to be right scaled I have to crop the camera output :

Rect zoomCrop = new Rect(0, 0, 1755, 3120);
captureRequestBuilder.set(CaptureRequest.SCALER_CROP_REGION, zoomCrop);

裁剪后的预览的尺寸应为 1755x3120 ,该比例也应为9:16.预览仍然很努力.

The cropped preview should be of size 1755x3120 which has a ratio of 9:16 as well. Still the preview is streched.

问题: 我是否正确使用SCALER_CROP_REGION?如果没有,我应该如何使用它?

Question : Am I using SCALER_CROP_REGION correctly ? If not, how am I supposed to use it ?

预先感谢

推荐答案

我一直在努力解决同一类问题,因为我想将相机预览流实现为 square TextureView.

I've been struggling with the same sort of problem, as I want to implement a camera preview stream into a square TextureView.

使用SCALER_CROP_REGION似乎是解决纵横比不兼容的问题的明显场所,但是我认为该操作实际上不会改变结果的纵横比,因此它不能防止拉伸/翘曲.行为. (文档对此进行了讨论)

Working with the SCALER_CROP_REGION seemed like the obvious place to resolve issues with incompatible aspect ratios, but I don't think that operation will ever actually change the aspect ratio of the result, hence it doesn't prevent stretching/warping behaviour. (the docs talk about this)

我已经实现了与Camera2Basic示例项目中类似的转换,从而取得了进步-请参见

I've made progress by implementing a similar transform to the one in the Camera2Basic example project - see the function configureTransform in Camera2BasicFragment).

使用这种视图级别的缩放矩阵,您可以在不更改视图大小的情况下管理摄像机预览的缩放/裁剪.

Using this sort of view-level scaling matrix, you can manage the scaling/cropping of the camera preview without altering the size of your view.

这篇关于使用SCALER_CROP_REGION裁剪时,Camera2预览会拉伸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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