Java 防止前置摄像头翻转

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9754346/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 07:11:42  来源:igfitidea点击:

Prevent flipping of the front facing camera

javaandroidcamera

提问by daedalus28

I'm attempting to access the raw feed of android's front facing camera. By default, the front facing camera's preview is flipped horizontally so users can see themselves as if looking into a mirror - that's great, but not what I need. What's the best way to get the raw feed? Is there some way to disable the automatic flipping, or should I attempt to flip it in code myself? My application needs to display a real-time feed of the front facing camera without it being flipped like a mirror.

我正在尝试访问 android 前置摄像头的原始提要。默认情况下,前置摄像头的预览是水平翻转的,因此用户可以像照镜子一样看到自己 - 这很好,但不是我需要的。获取原始饲料的最佳方法是什么?有什么方法可以禁用自动翻转,还是我应该尝试自己在代码中翻转它?我的应用程序需要显示前置摄像头的实时馈送,而不是像镜子一样翻转。

回答by Sean Owen

The data from the front camera is as the camera the sees it, looking at you. The left side of its image is your right side. I think this is what you want already? When put onto a SurfaceViewit is flipped so it acts as you say, but that's a separate cosmetic transformation.

来自前置摄像头的数据就像摄像头看到的一样,看着你。其图像的左侧是您的右侧。我想这就是你想要的吗?当放在 a 上时,SurfaceView它会翻转,所以它就像你说的那样,但这是一个单独的外观转换。

At least, this is how every device I've seen works and I've looked hard at this to implement front camera support in Barcode Scanner/ Barcode Scanner+.

至少,这是我见过的每台设备的工作方式,我努力研究以在Barcode Scanner/ Barcode Scanner+ 中实现前置摄像头支持。

回答by Steve

If you want to use a front-facing camera for barcode scanning you can use TextureView and apply a transformation matrix to it. When the texture is updated you can read the image data and use that.

如果您想使用前置摄像头进行条码扫描,您可以使用 TextureView 并对其应用转换矩阵。当纹理更新时,您可以读取图像数据并使用它。

See https://github.com/hadders/camera-reverse

https://github.com/haders/camera-reverse

Specifically from MainActivity.java

具体来自 MainActivity.java

mCamera.setDisplayOrientation(90);
Matrix matrix = new Matrix();
matrix.setScale(-1, 1);
matrix.postTranslate(width, 0);
mTextureView.setTransform(matrix);