gpt4 book ai didi

android - 在三星机器人上拍摄的图库图像即使是纵向拍摄也始终是横向的

转载 作者:太空狗 更新时间:2023-10-29 15:26:17 26 4
gpt4 key购买 nike

使用以下代码从图库中选取图片:

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

我怎样才能正确地呈现图像或者确定正确的方向以便我可以旋转图像?

最佳答案

我能够通过以下代码获取方向:

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();
}
}
}

https://vikaskanani.wordpress.com/2011/07/17/android-re-size-image-without-loosing-exif-information/

关于android - 在三星机器人上拍摄的图库图像即使是纵向拍摄也始终是横向的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32090603/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com