Android编程中调用Camera时预览画面有旋转问题的解决方法

更新时间:2023-06-17 11:31:25 阅读: 评论:0

Android编程中调⽤Camera时预览画⾯有旋转问题的解决
⽅法
本⽂实例讲述了Android编程中调⽤Camera时预览画⾯有旋转问题的解决⽅法。分享给⼤家供⼤家参考,具体如下:
在调⽤Camera写应⽤的时候,前后摄像头的情况有时候是不⼀样的。有时候,明明后摄像头没有问题,⽽调⽤到前摄像头时,却倒转了180°,或者其他⾓度,百思不得其解。在查看了Android源码之后,发现它的解决办法很是好,接下来贴个源码,以备⽇后查看。
public static int getDisplayRotation(Activity activity) {
int rotation = WindowManager().getDefaultDisplay()
.getRotation();
pang
switch (rotation) {
ca Surface.ROTATION_0: return 0;
euruscapable
ca Surface.ROTATION_90: return 90;fra
ca Surface.ROTATION_180: return 180;
冰棍英文ca Surface.ROTATION_270: return 270;
prevent是什么意思}
return 0;
}
public static void tCameraDisplayOrientation(Activity activity,
toms
int cameraId, Camera camera) {
// See android.hardware.Camera.tCameraDisplayOrientation for
// documentation.
Camera.CameraInfo info = new Camera.CameraInfo();
int degrees = getDisplayRotation(activity);
mat
2020全国英语四六级考试时间int result;
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
result = (ientation + degrees) % 360;
result = (360 - result) % 360; // compensate the mirror
} el { // back-facing
result = (ientation - degrees + 360) % 360;
}
camera.tDisplayOrientation(result);fuckaway
}
在调⽤Camera的时候只要调⽤tCameraDisplayOrientation这个⽅法就可以了。
希望本⽂所述对⼤家Android程序设计有所帮助。

本文发布于:2023-06-17 11:31:25,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/148151.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:摄像头   问题   旋转   源码
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图