如何防止android从前置摄像头反转图像?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10388789/
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
How to keep android from inverting the image from the front facing camera?
提问by Meghal Shah
My video Camera app does record in the landscape mode, but the front facing camera previews the regular image, but the actual recording is mirrored (flipped or inverted) across the axis.
我的视频相机应用程序确实在横向模式下录制,但前置摄像头预览常规图像,但实际录制是跨轴镜像(翻转或倒置)。
Everything works great on normal rear camera.
在普通后置摄像头上一切正常。
Can anybody suggest me a way to avoid it ? Any suggestions or source code would help a lot. Thank you.
有人可以建议我避免它的方法吗?任何建议或源代码都会有很大帮助。谢谢你。
回答by Paul-Jan
The bad news: this mirroring is hardcoded into the camera service, and can not be disabled.
坏消息:此镜像已硬编码到相机服务中,无法禁用。
The good news: if you are on a recent API (API level >= 14), you can easily use a TextureView to mirror the preview image back to the original. Take the TextureView Exampleover at the Android Documentation, then use setTransformto set a mirroring transform. This will revert the preview image back to the non-mirrored original.
好消息:如果您使用的是最近的 API(API 级别 >= 14),您可以轻松使用 TextureView 将预览图像镜像回原始图像。以Android 文档中的TextureView 示例为例,然后使用setTransform设置镜像变换。这会将预览图像恢复为未镜像的原始图像。
Note that a mirror transform is the same as a scaling transform with a -1 scale on the X axis.
请注意,镜像变换与在 X 轴上具有 -1 比例的缩放变换相同。
If you are on an older API version, you might be able to do the same with a SurfaceView (using setScaleX, API level >= 11).
如果您使用的是较旧的 API 版本,您也许可以对 SurfaceView 执行相同的操作(使用setScaleX,API 级别 >= 11)。
回答by Steve
Try applying a transformation matrix to a TextureView. As per Prevent flipping of the front facing camera
尝试将转换矩阵应用于 TextureView。根据防止翻转前置摄像头
This works for API level >= 14
这适用于 API 级别 >= 14