从电子邮件收到的图像中获取exif数据

时间:2022-09-23 09:46:40

I have an Activity that handles image files:

我有一个处理图像文件的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();
        }
    }

This gets me the image in the bitmap, however I also need to get exif data from it. Saving the image using image.compress removes this data.

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

If I click View in gmail for example, there is no real path that I can use, so I'm stuck at trying to get the exif data. Is there a way to get a byte[] of the data passed into my activity, or get the exif data from a Bitmap object?

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

Note:

This:

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

Does not cause an exception, however I get null for all the tags, and if I try to print the path, I get this:

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

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

If I first hit save and then view in gmail, I can successfully retrieve the exif data with the above method, passing imageUri.getPath() to an exif constructor.

如果我先点击保存然后在gmail中查看,我可以使用上面的方法成功检索exif数据,将imageUri.getPath()传递给exif构造函数。

If there is no way to make view work, then how can I make it so the user is prompted to use my application only after saving the file to disk? This is how my intent filters look like right now:

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

<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>

1 个解决方案

#1


0  

it should be possible to extract the exif data with:

应该可以用以下方法提取exif数据:

How to use ExifInterface with a stream or URI

如何将ExifInterface与流或URI一起使用

Taken from there: http://android-er.blogspot.co.at/2011/04/read-exif-of-jpg-file.html

取自那里: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);

#1


0  

it should be possible to extract the exif data with:

应该可以用以下方法提取exif数据:

How to use ExifInterface with a stream or URI

如何将ExifInterface与流或URI一起使用

Taken from there: http://android-er.blogspot.co.at/2011/04/read-exif-of-jpg-file.html

取自那里: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);