简体   繁体   English

Android:降低TextureView的高度以进行相机预览

[英]Android: reduce height of TextureView for camera preview

I'm studing this Google project with an example of Camera2 using: https://github.com/googlesamples/android-Camera2Basic 我正在使用以下Camera2示例研究此Google项目: https : //github.com/googlesamples/android-Camera2Basic

This example works perfectly. 这个例子非常完美。 Now I want to have the area preview smaller than in this example; 现在,我要使区域预览小于此示例; so I changed the ratio like this: 所以我改变了这样的比例:

mTextureView.setAspectRatio(getScreenWidth(), getScreenHeight() - bottom_area_height);

but the result is bad... the preview doesn't have a good ratio now (is too stretched horizontally): 但是结果很差...预览现在没有很好的比例(水平拉伸太长): 在此处输入图片说明

Have you got an idea guys? 你们有个主意吗?

Thank you very much! 非常感谢你!

You did get what you asked for, which is a different aspect ratio. 您确实得到了要求的东西,这是不同的纵横比。 Unfortunately, there's only one aspect ratio that's correct, since it needs to match that of the camera preview buffers. 不幸的是,只有一个正确的纵横比是正确的,因为它需要与相机预览缓冲区的纵横比匹配。

If you want a smaller preview, you need to shrink it in both directions to maintain the correct aspect ratio. 如果想要较小的预览,则需要在两个方向上缩小以保持正确的宽高比。 So if you update the layout to have a narrower space, and keep the aspect ratio the same, the height should also go down. 因此,如果将布局更新为更窄的空间,并保持宽高比不变,则高度也应降低。 Or reduce the height of the surrounding frame; 或降低周围框架的高度; in any case, the aspect ratio must remain what it is to have no stretching. 在任何情况下,纵横比都必须保持不拉伸的状态。

AutoFitTextureView isn't designed to crop the preview, which is the other option for avoiding stretching. AutoFitTextureView并非旨在裁剪预览,这是避免拉伸的另一种选择。 That could be done by messing with the TextureView transform, but it does mean you're cutting off some of the view. 这可以通过弄乱TextureView变换来完成,但这确实意味着您要切断某些视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM