最近寫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);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/249558.html
標籤:其他
