【发布时间】:2015-08-19 08:44:48
【问题描述】:
使用以下代码从图库中挑选图片:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intent, PICK_FILE_RESULT_CODE);
使用以下代码获取结果:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_FILE_RESULT_CODE) {
if (resultCode == RESULT_OK && data != null && data.getData() != null) {
// Get the Uri of the selected file
Uri uri = data.getData();
//Using Picasso to load uri to imageView
//Image is in landscape even if it was taken in portrait
}
}
}
该代码适用于 HTC 和 Nexus 手机,但仅适用于三星设备(Galaxy 5 和 Galaxy 5 mini),如果照片是纵向拍摄的,则方向错误。查看 ExifInterface 时,方向未定义..
File imageFile = new File(uri.getPath());
ExifInterface exif = new ExifInterface(
imageFile.getAbsolutePath());
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
//orientation is always 0 for samsung devices = ORIENTATION_UNDEFINED
我怎样才能正确地呈现图像或者确定正确的方向以便我可以旋转图像?
【问题讨论】:
-
向我发送 2 张示例图片(每个方向 1 张),如果我找到任何定义方向的信息,我会告诉你 (bitbank@pobox.com)。
-
我已经发送了一封包含图片的电子邮件,感谢您抽出宝贵的时间! @BitBank
-
图像确实包含 EXIF 方向信息。第一个是“左90度”,第二个是“180度”。
-
我之前没有尝试过Android
ExifInterface类,但如果你觉得它不够用,你可能会发现metadata-extractor 库很有用。对于快速测试,Phil Harvey 的出色 Exiftool 非常出色。 -
感谢@BitBank 的帮助,我找到了方向,看看我的回答
标签: android orientation exif samsung-mobile android-gallery