Java 从电子邮件接收的图像中获取exif数据
我有一个处理图像文件的活动:Java 从电子邮件接收的图像中获取exif数据,java,android,exif,Java,Android,Exif,我有一个处理图像文件的活动: if (Intent.ACTION_VIEW.equals(action) && type != null && type.startsWith("image/")) { Uri imageUri = i.getData(); try { Bitmap image = MediaStore.Images.Media.getBitmap(getContentResolver(),
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中单击查看
,就没有真正的路径可供使用,因此我只能尝试获取exif数据。是否有方法获取传递到“我的活动”中的数据的字节[]
,或从位图
对象获取exif数据
注意:
这:
不会导致异常,但是我为所有标记获取null,如果我尝试打印路径,则会得到以下结果:
/my.email@gmail.com/messages/248/attachments/0.1/BEST/false
如果我首先在gmail中点击save
,然后点击view
,我就可以用上面的方法成功地检索exif数据,并将imageUri.getPath()
传递给exif构造函数
如果无法使视图
正常工作,那么我如何才能使其正常工作,以便仅在将文件保存到磁盘后提示用户使用我的应用程序?这就是我的意图过滤器现在的样子:
<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>
应该可以通过以下方式提取exif数据:
从此处开始:
这不是只有在下载图像时才起作用吗?在我的情况下,我不认为图像保存到磁盘。我在gmail中点击View
,然后点击Download
,打开它,我想这不会将它添加到gallery数据库中。你如何查看尚未下载的图像?imho every view cmd将下载图像并将其存储在tmp文件中。(但这只是一个猜测)刚刚尝试了它,它导致了崩溃,我认为是因为该列不存在。它可能会把它下载到一个临时文件中,但显然我没有访问权限imageUri.getPath()
返回以下内容:/my。email@gmail.com/messages/248/attachments/0.1/BEST/false
。
<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>
//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);