如何获得1:1的Android相机预览比例 [英] How to get Android Camera Preview ratio 1:1

查看:620
本文介绍了如何获得1:1的Android相机预览比例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现Android相机预览,并希望以1:1的比例显示(就像Instagram相机一样).
我知道如何将预览帧大小设为1:1,但是预览中显示的相机输出受到挤压.实时预览看起来仍然是4:3的比例,但被压缩为1:1的帧.有没有办法以1:1的比例进行实时预览?

I am trying to implement the a Android camera preview and want to have it display in 1:1 ratio (just like the Instagram camera).
I know how to deal with the preview frame size to be 1:1, but the camera output shows on the preview is squeezed. It looks like the live preview is still in 4:3 ratio but is squeezed to 1:1 frame. Is there a way to have the live preview also in 1:1 ratio?

我没有在此处粘贴任何代码,因为我尝试了很多方法,但是都失败了,我什么也不能张贴...

I am not pasting any code here because I have tried many approach but all failed, nothing I can post...

谢谢

推荐答案

您已经注意到,相机预览帧为4:3.通常,您还可以 setPreviewSize()使宽高比约为9:4(例如800x480).我还没有遇到在 getSupportedPreviewSizes()之间具有正方形的Android设备.

As you have noticed, camera preview frames are 4:3. Often, you can also setPreviewSize() to have aspect ratio ~9:4 (e.g. 800x480). I have not encountered an Android device that will have a square among getSupportedPreviewSizes().

显示方形预览的选项如下:将预览SurfaceView覆盖在两侧的非透明边距上(有效地裁剪外观).或者,您可以在通过OpenGL显示 TextureSurface 时裁剪图像.或者,您可以 setPreviewCallbackWithBuffer(),将yuv帧裁剪为所需的大小,然后显示它(最好是通过OpenGL).

Your options to display a square preview are as follows: overlay the preview SurfaceView with non-transparent margins ontwo sides (effectively cropping the look). Or you could crop the image while displaying the TextureSurface through OpenGL. Or you could setPreviewCallbackWithBuffer(), crop the yuv frame to your desired size, and display it (prefferably, through OpenGL).

这篇关于如何获得1:1的Android相机预览比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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