2
我正在使用commonware的攝像頭示例來嘗試創建一個拍攝圖片的android應用程序。預覽顯示相機旋轉90度,我已通過應用糾正:保存攝像頭圖像android ....他們被遊動90度
camera.setDisplayOrientation(90);
但是,圖像仍保存旋轉90度的另一種方式。我該如何調整這個功能,以便在保存圖像時將它們保存在與查看器相同的「方面」中?
請指教, TIA
我正在使用commonware的攝像頭示例來嘗試創建一個拍攝圖片的android應用程序。預覽顯示相機旋轉90度,我已通過應用糾正:保存攝像頭圖像android ....他們被遊動90度
camera.setDisplayOrientation(90);
但是,圖像仍保存旋轉90度的另一種方式。我該如何調整這個功能,以便在保存圖像時將它們保存在與查看器相同的「方面」中?
請指教, TIA
根據this post,這種情況只在某些設備,它取決於製造商。
我設法通過檢測設備的方向角度相應要解決這個問題,應用旋轉,像這樣:
ExifInterface exitInterface = new ExifInterface(imagePath);
int orientation = exitInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
int degree = 0;
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;
}
然後轉動使用自定義的方法,我的位圖:
public static Bitmap rotateImage(Bitmap src, float degree)
{
// create new matrix
Matrix matrix = new Matrix();
// setup rotation degree
matrix.postRotate(degree);
Bitmap bmp = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
return bmp;
}