国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android編程中調(diào)用Camera時預(yù)覽畫面有旋轉(zhuǎn)問題的解決方法

2020-04-11 11:15:42
字體:
供稿:網(wǎng)友

本文實例講述了Android編程中調(diào)用Camera時預(yù)覽畫面有旋轉(zhuǎn)問題的解決方法。分享給大家供大家參考,具體如下:

在調(diào)用Camera寫應(yīng)用的時候,前后攝像頭的情況有時候是不一樣的。有時候,明明后攝像頭沒有問題,而調(diào)用到前攝像頭時,卻倒轉(zhuǎn)了180°,或者其他角度,百思不得其解。在查看了Android源碼之后,發(fā)現(xiàn)它的解決辦法很是好,接下來貼個源碼,以備日后查看。

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);}

在調(diào)用Camera的時候只要調(diào)用setCameraDisplayOrientation這個方法就可以了。

希望本文所述對大家Android程序設(shè)計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 邹平县| 准格尔旗| 兖州市| 卢龙县| 大悟县| 察哈| 潞城市| 米泉市| 长泰县| 抚顺县| 洛宁县| 额敏县| 寻甸| 彩票| 卓尼县| 涞水县| 开阳县| 揭东县| 黄山市| 昌都县| 桓台县| 大竹县| 临安市| 吴忠市| 射阳县| 平顶山市| 灵丘县| 邳州市| 丰镇市| 七台河市| 海伦市| 富平县| 兰州市| 温宿县| 平塘县| 林西县| 同江市| 苏尼特右旗| 大足县| 濉溪县| 古浪县|