【问题标题】:Android EXIF data Image from Camera or Gallery lost相机或图库中的 Android EXIF 数据图像丢失
【发布时间】:2017-06-27 06:30:08
【问题描述】:

我需要阅读Image 的一些Exif 属性(与Camera 一起获取或从Gallery 中选择)。

这是我如何启动Camera

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被取出并保存在ExternalStorage中之后,Exif的信息就丢失了。

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. 使用我的设备Camera(不使用我的App)拍摄picture
  2. 使用ExifInterface读取Exif数据。
  3. 它就像一个魅力。

所以我想问题是当Image 被保存(在它与Camera 一起使用之后)或从Gallery 中选择Image 时,Exif 数据会丢失。

我在Stackoverflow这里阅读了至少20-30个帖子,但基本上每个人都有的问题是orientationexif信息丢失,所以解决方案是在orientation中写正确的Exif 数据。

该解决方案对我来说并不好,因为我不想覆盖 Exif 数据,我只想阅读原始数据。

有什么想法/提示吗? 谢谢。

【问题讨论】:

  • new ExifInterface(myObject.getLocalUrl());。我的对象是什么?它与 onActivityResult() 有什么关系?更好地展示完整的代码。
  • That's how I get the Image in the onActivityResult method:。无关紧要。没关系。您应该向我们展示如何从 .jpg 文件中获取 exif。
  • the problem that everyone has is that the orientation exif information is lost, so the solution is writing the right orientation in the Exif data.。这一切对我来说毫无意义。 JPG 文件不会丢失 exif 信息。
  • in the first case (Camera), after the Image is taken and saved in the External Storage, the Exif information get lost.。 ?相机应用程序会将图像保存为 .jpg 文件。带有 exif 标头。就这样。你不是又存东西了吧?请显示完整的 onActivityResult 代码。
  • 2. Read the Exif data using ExifInterface.。那么你有什么不同呢?从画廊或如何挑选?

标签: android image-processing camera exif photo-gallery


【解决方案1】:

尝试以下方法:将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();
            }
        }

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

【讨论】:

  • 我尝试过使用ExifInterface 方法和这种方法,在这两种情况下我只得到0 作为我测试过的两部手机中每张图片的方向(Moto G4 和三星 Galaxy J5)
猜你喜欢
  • 1970-01-01
  • 2014-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多