最近寫Android,調用相機接口拍照,但是返回來的結果老是會旋轉,而且在不同的手機上旋轉角度還不一樣。
解決辦法
可以在拍完照以後,獲取圖片的旋轉信息,然後往相反方向旋轉
獲取旋轉角度代碼如下
// 從指定路徑path下讀取圖片,並獲取其EXIF信息
ExifInterface exifInterface = new ExifInterface(path);
// 獲取圖片的旋轉信息
int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
degree = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
degree = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
degree = 270;
break;
}
將圖像轉回去
// picture是ImageView
picture.setPivotX(picture.getWidth()/2);
picture.setPivotY(picture.getHeight()/2);
// 設置旋轉角度
picture.setRotation(degree);