【发布时间】:2014-10-15 22:37:46
【问题描述】:
我知道这个问题之前已经讨论过很多次了,我也看过很多问题和很多答案,但我尝试过都无济于事,要么是因为我缺乏理解,要么是我的设备。另外,大多数问题现在已经过时了。我遇到了纵向图像旋转到横向的经典问题。
无论如何,我有一个正在使用的自定义相机。这是我主要活动中的一个功能:
public static int getImageOrientation(String imagePath){
int orientation = -1;
try {
ExifInterface exif = new ExifInterface(imagePath);
int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (exifOrientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
orientation = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
orientation = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
orientation = 90;
break;
case ExifInterface.ORIENTATION_NORMAL:
orientation = 0;
break;
default:
break;
}
} catch (IOException e) {
Log.e("LOG_TAG", "Unable to get image exif orientation", e);
}
return orientation;
}
这个函数在我的 onactivityresult 中被调用:
String abspath = data.getExtras().getString(EXTRA_IMAGE_PATH);
mMediaUri = Uri.fromFile(new File(abspath));
rotation = getImageOrientation(abspath);
现在,我要做的是,我将旋转存储在我的后端,这样当图像出现在列表视图中时,它就会知道是否要旋转。问题是 -1 不断被返回。我可能做错了什么?我只想知道这张照片是纵向还是横向拍摄的。
【问题讨论】:
-
每台设备上都会发生这种情况吗?
-
嘿,这发生在我的三星 Galaxy S4、Genymotion 的 Google Galaxy Nexus 和 Nexus 7 模拟器上。
标签: android android-camera photo