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

更新时间:2023-06-04 12:55:10 阅读: 评论:0

Android编程中调⽤Camera时预览画⾯有旋转问题的解决
⽅法
本⽂实例讲述了Android编程中调⽤Camera时预览画⾯有旋转问题的解决⽅法。分享给⼤家供⼤家参考,具体如下:
在调⽤Camera写应⽤的时候,前后摄像头的情况有时候是不⼀样的。有时候,明明后摄像头没有问题,⽽调⽤到前摄像头时,却倒转了180°,或者其他⾓度,百思不得其解。在查看了Android源码之后,发现它的解决办法很是好,接下来贴个源码,以备⽇后查看。
public static int getDisplayRotation(Activity activity) {
int rotation = WindowManager().getDefaultDisplay()属相猪
.getRotation();
switch (rotation) {
ca Surface.ROTATION_0: return 0;
ca Surface.ROTATION_90: return 90;
ca Surface.ROTATION_180: return 180;
ca Surface.ROTATION_270: return 270;
}
return 0;
}
复古主义public static void tCameraDisplayOrientation(Activity activity,
文静>电脑键盘
int cameraId, Camera camera) {预备党员转正决议
// See android.hardware.Camera.tCameraDisplayOrientation for钓鱼钩
// documentation.
Camera.CameraInfo info = new Camera.CameraInfo();
int degrees = getDisplayRotation(activity);
int result;
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
联想电话
result = (ientation + degrees) % 360;
result = (360 - result) % 360; // compensate the mirror
期末总结500字} el { // back-facing
result = (ientation - degrees + 360) % 360;
}
camera.tDisplayOrientation(result);
}
在调⽤Camera的时候只要调⽤tCameraDisplayOrientation这个⽅法就可以了。
希望本⽂所述对⼤家Android程序设计有所帮助。

本文发布于:2023-06-04 12:55:10,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/985495.html

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

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