【发布时间】:2015-03-01 13:05:12
【问题描述】:
我正在尝试在我的应用中处理图像。我目前面临的问题与图像的方向有关。从 Android 的相机文件夹中选择的图像的缩略图会旋转 90 度。我得到的缩略图如下;
Uri thumbUri = Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, uri.getLastPathSegment());
if (thumbUri != null){
try {
List<String> parts = uri.getPathSegments();
String lastPart = parts.get(parts.size() - 1);
int index = lastPart.indexOf(":");
if (index != -1)
{
lastPart = lastPart.substring(index+1);
}
long id = Long.parseLong(lastPart);
// get a thumbnail for the image
Bitmap bitmap = MediaStore.Images.Thumbnails.getThumbnail(
context.getContentResolver(),
id,
MediaStore.Images.Thumbnails.MINI_KIND,
null
);
if (bitmap != null)
{
return bitmap;
}
}
catch (Exception e)
{
Log.e(LOG_TAG, "Unable to generate thumbnail from thumbnail uri " + e.getMessage(), e);
}
}
还尝试通过从ExifInterface 读取方向来修复它;
ExifInterface ei = new ExifInterface(uri.getPath());
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
但是 orientation 返回的总是 0 ORIENTATION_UNDEFINED。无法理解我在这里做错了什么。
【问题讨论】:
-
@HBizhi
ExifInterface对我没有帮助,因为我已经提到了问题。