2013-08-30 27 views
0

这是我的相机活动,它处于肖像模式。我正在旋转设备,相机随之旋转。旋转设备改变图像的方向?

Camera

这是我第二Activity在我的图像在显示ImageView倒挂,从PictureCallback()好评。我已经尝试过ExifInterface但其返回方向0

second

回答

0

我有一个类似的问题。 ExifInterface中的方向0表示未定义。如果发生这种情况我问MediaStore和我的情况下,如果ExifInterface返回相机0

String[] cols = { MediaStore.Images.Media.ORIENTATION }; 
Cursor cur = context.getContentResolver().query(uri, cols, null, null, null); 
int orientation = 0; 

if (cur != null && cur.moveToFirst()) { 
     orientation = cur.getInt(cur.getColumnIndex(MediaStore.Images.Media.ORIENTATION)); 
} 
+0

仍取向= 0; – Mihir

0

设置它总是返回正确的方向:

public static void setCameraDisplayOrientation(Activity activity, 
      int cameraId, android.hardware.Camera camera) { 
     try { 

      android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); 
      android.hardware.Camera.getCameraInfo(cameraId, info); 
      int rotation = activity.getWindowManager().getDefaultDisplay() 
        .getRotation(); 
      int degrees = 0; 
      switch (rotation) { 
      case Surface.ROTATION_0: 
       degrees = 0; 
       break; 
      case Surface.ROTATION_90: 
       degrees = 90; 
       break; 
      case Surface.ROTATION_180: 
       degrees = 180; 
       break; 
      case Surface.ROTATION_270: 
       degrees = 270; 
       break; 
      } 

      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); 
     } catch (Exception e) { 
      // TODO: handle exception 
     } 
    } 

并使用ExifInterface时的显示效果