【问题标题】:Get exif data from image received by email从电子邮件收到的图像中获取 exif 数据
【发布时间】:2012-08-13 06:28:53
【问题描述】:

我有一个处理图像文件的 Activity:

 if (Intent.ACTION_VIEW.equals(action) && type != null && type.startsWith("image/")) {
        Uri imageUri = i.getData();
        try {
            Bitmap image = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

这让我得到了位图中的图像,但是我还需要从中获取 exif 数据。使用image.compress 保存图像会删除此数据。

例如,如果我在 gmail 中单击 View,则没有可以使用的真实路径,因此我一直在尝试获取 exif 数据。有没有办法获取传递给我的活动的数据的byte[],或从Bitmap 对象获取exif 数据?

注意:

这个:

ExifInterface exifData = new ExifInterface(imageUri.getPath());

不会导致异常,但是我得到所有标签的 null,如果我尝试打印路径,我会得到:

/my.email@gmail.com/messages/248/attachments/0.1/BEST/false

如果我先在gmail中点击save然后view,我可以通过上述方法成功检索exif数据,将imageUri.getPath()传递给exif构造函数。

如果没有办法让view 工作,那么我怎样才能让用户在将文件保存到磁盘后才提示用户使用我的应用程序?这就是我的意图过滤器现在的样子:

<activity android:name=".GameActivity">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="image/*" />
    </intent-filter>
</activity>

【问题讨论】:

    标签: java android exif


    【解决方案1】:

    应该可以通过以下方式提取exif数据:

    How to use ExifInterface with a stream or URI

    取自那里: http://android-er.blogspot.co.at/2011/04/read-exif-of-jpg-file.html

    //Get Real URL
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = parentActivity.managedQuery(contentUri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    String realURL = cursor.getString(column_index);
    
    //Access Exif
    ExifInterface exifInterface = new ExifInterface(realURL);
    String focal_length = exifInterface.getAttribute(ExifInterface.TAG_FOCAL_LENGTH);
    

    【讨论】:

    • 这不是只有在下载图像时才有效吗?就我而言,我认为图像不会保存到磁盘。我在点击Download之前点击gmail中的View打开它,我认为这不会将它添加到图库数据库中?。
    • 如何查看尚未下载的图片?恕我直言,每个视图 cmd 都会下载图像并将其存储在 tmp 文件中。 (但这只是猜测)
    • 刚试了会导致崩溃,我认为是因为该列不存在。它可能会将其下载到临时文件中,但显然我无权访问它。 imageUri.getPath() 返回:/my.email@gmail.com/messages/248/attachments/0.1/BEST/false
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-13
    • 2019-04-16
    • 1970-01-01
    相关资源
    最近更新 更多