手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >Android编程中调用Camera时预览画面有旋转问题的解决方法
Android编程中调用Camera时预览画面有旋转问题的解决方法
摘要:本文实例讲述了Android编程中调用Camera时预览画面有旋转问题的解决方法。分享给大家供大家参考,具体如下:在调用Camera写应用的...

本文实例讲述了Android编程中调用Camera时预览画面有旋转问题的解决方法。分享给大家供大家参考,具体如下:

在调用Camera写应用的时候,前后摄像头的情况有时候是不一样的。有时候,明明后摄像头没有问题,而调用到前摄像头时,却倒转了180°,或者其他角度,百思不得其解。在查看了Android源码之后,发现它的解决办法很是好,接下来贴个源码,以备日后查看。

public static int getDisplayRotation(Activity activity) { int rotation = activity.getWindowManager().getDefaultDisplay() .getRotation(); switch (rotation) { case Surface.ROTATION_0: return 0; case Surface.ROTATION_90: return 90; case Surface.ROTATION_180: return 180; case Surface.ROTATION_270: return 270; } return 0; } public static void setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { // See android.hardware.Camera.setCameraDisplayOrientation for // documentation. Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int degrees = getDisplayRotation(activity); int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); }

在调用Camera的时候只要调用setCameraDisplayOrientation这个方法就可以了。

希望本文所述对大家Android程序设计有所帮助。

【Android编程中调用Camera时预览画面有旋转问题的解决方法】相关文章:

Android编程设置全屏的方法实例

基于Android中实现定时器的3种解决方法

Android中使用Toast.cancel()方法优化toast内容显示的解决方法

android中图片翻页效果简单的实现方法

Android手机内存中文件的读写方法小结

Android 将 android view 的位置设为右下角的解决方法

android将搜索引擎设置为中国雅虎无法搜索问题解决方法

Android编程实现检测当前电源状态的方法

深入android中The connection to adb is down的问题以及解决方法

android使用Messenger绑定Service的多种实现方法

精品推荐
分类导航