[英]How can I detect photo is taken vertical or not? (I find a way but it does not work)
boolean isVertical = true ;
ExifInterface exif2;
try {
exif2 = new ExifInterface(path_img);
int orientation = exif2.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
isVertical = false ;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
isVertical =false ;
break;
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
orientation
s的值始終為1
我該如何解決這個問題?
嘗試這個
int rotate = 0;
try {
getContentResolver().notifyChange(imageUri, null);
File imageFile = new File(imagePath);
ExifInterface exif = new ExifInterface(
imageFile.getAbsolutePath());
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
}
Log.v(Common.TAG, "Exif orientation: " + orientation);
} catch (Exception e) {
e.printStackTrace();
}
我建議您創建一個新的位圖,然后獲取它的寬度和高度。
Bitmap bitmap = BitmapFactory.decodeFile("full_path_of_bitmap");
if(bitmap.getWidth() > bitmap.getHeight())
// Picture is Landscape.
else
// Picture is Portrait.
Kolay明膠。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.