【发布时间】:2016-06-28 03:10:08
【问题描述】:
这是困扰我几个月的问题。我看过所有关于旋转从图库中选择或通过图像捕获意图拍摄的图像的 SO 帖子,但没有一个有效。当然,最大的罪魁祸首是三星设备,但我什至在我的 Nexus 上看到了一些时髦的行为。
我正在使用意图从图库和相机中选择图像,但风景照片似乎总是旋转 90 度。第一步总是ExifInterface,类似这样:
ExifInterface exif = new ExifInterface(imageUri.getLastPathSegment();
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
int rotationNeeded = getRotationFromExifData(orientation);
Matrix matrix = new Matrix();
matrix.setRotate(rotationNeeded);
getRotationFromExifData(orientation) 在哪里:
private static int getRotationFromExifData(int orientation) {
Log.d(LOG_TAG, "Orientation: " + orientation);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
Log.d(LOG_TAG, "Exif returned 90");
return 90;
case ExifInterface.ORIENTATION_ROTATE_180:
Log.d(LOG_TAG, "Exif returned 180");
return 180;
case ExifInterface.ORIENTATION_ROTATE_270:
Log.d(LOG_TAG, "Exif returned 270");
return 270;
default: // Normal or 0
Log.d(LOG_TAG, "Exif returned 0");
return 0;
}
}
这不起作用,ExifInterface(据我所见)总是返回 0(或正常),尤其是在三星设备上。
其他步骤包括查询 MediaStore 和其他不起作用的垃圾。有人可以告诉我使用所有本机意图获得正确图像旋转的确切方法,以便正确显示所有图像吗?提前致谢。
【问题讨论】:
标签: android image android-intent bitmap rotation