欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2015年11月20日 14:16:39   作者:嗨皮  
這篇文章主要介紹了Android編程中調(diào)用Camera時預(yù)覽畫面有旋轉(zhuǎn)問題的解決方法,涉及Android針對Camera調(diào)用攝像頭源碼部分的相關(guān)修改技巧,需要的朋友可以參考下

本文實例講述了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è)計有所幫助。

相關(guān)文章

最新評論