gpt4 book ai didi

来自相机或图库的 Android EXIF 数据图像丢失

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

我需要读取 Image 的一些 Exif 属性(用 Camera 拍摄或从 Gallery).

这是我启动相机的方式:

Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File file = new File(myObject.getLocalUrl());
Uri fileURI = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileURI);
startActivityForResult(intent, CAPTURE_IMAGE_REQUEST_CODE);

下面是我如何启动Gallery Picker:

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(Intent.createChooser(intent, getString(R.string.image_picker_select_image)), SELECT_IMAGE_FROM_GALLERY_REQUEST_CODE);

问题是,例如,在第一种情况(Camera)中,Image 被拍摄并保存在 External StorageExif信息丢失。

Gallery 中选取的 Images 也是如此。这就是我在 onActivityResult 方法中获取 Image 的方式:

Uri uri = data.getData();
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);

最后是我如何读取 Exif 数据:

ExifInterface exifInterface = null;
try {
exifInterface = new ExifInterface(myObject.getLocalUrl());
} catch (IOException e) {
e.printStackTrace();
}
String exifOrientation = exifInterface.getAttribute(ExifInterface.TAG_ORIENTATION);
String exifMake = exifInterface.getAttribute(ExifInterface.TAG_MAKE);
String exifModel = exifInterface.getAttribute(ExifInterface.TAG_MODEL);

我试过下一个:

  1. 使用我的设备相机拍摄照片(不使用我的应用)。
  2. 使用 ExifInterface 读取 Exif 数据。
  3. 它就像一个魅力。

所以我想问题是当 Image 被保存时(在用 Camera 拍摄之后)或者 Image 是从GalleryExif 数据丢失。

我在 Stackoverflow 中至少阅读了 20-30 篇文章,但基本上每个人都有的问题是 orientation exif 信息丢失了,所以解决方案是在 Exif 数据中写入正确的 orientation

这个解决方案不适合我,因为我不想覆盖 Exif 数据,我只想读取原始数据。

任何想法/提示?谢谢。

最佳答案

试试下面的方法:将 Uri 传递给这个方法

 public static int getOrientation(Context context, Uri photoUri) {
Cursor cursor = context.getContentResolver().query(photoUri,
new String[] { MediaStore.Images.ImageColumns.ORIENTATION },null, null, null);
try {
if (cursor.moveToFirst()) {
return cursor.getInt(0);
} else {
return -1;
}
} finally {
cursor.close();
}
}

有许多 ImageColumn 可用于重新分级图像信息。

关于来自相机或图库的 Android EXIF 数据图像丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42133451/

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