即使在拍摄人像始终处于横向三星机器人拍摄的图像画廊 [英] Gallery images taken on Samsung androids always in landscape even if taken in portrait
问题描述
从采摘的图像画廊与下列code:
Picking images from gallery with the following code:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intent, PICK_FILE_RESULT_CODE);
获取结果与下面code:
Getting result with the following 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
}
}
}
在code正常工作对于HTC和Nexus手机,但只是三星设备(银河5和Galaxy 5迷你型)的方向是错的,如果该照片拍摄于肖像。当在ExifInterface寻找的方向是不确定的。
The code works fine for HTC and Nexus phones, but just for Samsung devices (Galaxy 5 and Galaxy 5 mini) the orientation is wrong if the photo was taken in portrait. When looking at the ExifInterface the orientation is undefined..
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
我如何present图像正确判断替代正确的方向,这样我可以旋转图像?
How can I present the images correctly alternative determine the correct orientation so that I can rotate the image?
推荐答案
我能得到具有以下code中的定位:
I was able to get the orientation with the following code:
public static int getExifOrientation(Context context, Uri uri) {
ContentResolver contentResolver = context.getContentResolver();
Cursor cursor = null;
try {
String id = DocumentsContract.getDocumentId(uri);
id = id.split(":")[1];
cursor = contentResolver.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
CONTENT_ORIENTATION, MediaStore.Images.Media._ID + " = ?", new String[] { id }, null);
if (cursor == null || !cursor.moveToFirst()) {
return 0;
}
return cursor.getInt(0);
} catch (RuntimeException ignored) {
// If the orientation column doesn't exist, assume no rotation.
return 0;
} finally {
if (cursor != null) {
cursor.close();
}
}
}
<一个href=\"https://vikaskanani.word$p$pss.com/2011/07/17/android-re-size-image-without-loosing-exif-information/\" rel=\"nofollow\">https://vikaskanani.word$p$pss.com/2011/07/17/android-re-size-image-without-loosing-exif-information/
这篇关于即使在拍摄人像始终处于横向三星机器人拍摄的图像画廊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!