[英]Missing EXIF info in images selected from gallery using EXTERNAL_CONTENT_URI
I'm trying to gather EXIF info (date of picture taken, geotagging, orientation) from images selected from an EXTERNAL_CONTENT_URI intent, but it seems that if the pictures come from the internet (eg Google Photos) the EXIF data is somehow truncated. 我正在尝试从从EXTERNAL_CONTENT_URI意向中选择的图像中收集EXIF信息(拍摄日期,地理标记,方向),但似乎如果这些图像来自互联网(例如Google相册),则EXIF数据会被截断。
For example if I download a picture from a web browser from photos.google.com on my PC, its size is 4.377.104 bytes, and all the EXIF data are there. 例如,如果我从PC上的photos.google.com从网络浏览器下载图片,则图片大小为4.377.104字节,并且所有EXIF数据都在那里。 While if I download the same exact image using the command:
如果我使用以下命令下载相同的图像:
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
its size is 4.363.578 bytes (13526 bytes less than the original) and all the EXIF data are lost 其大小为4.363.578字节(比原始大小少13526字节),并且所有EXIF数据均丢失
Any idea on how to download the full original image? 关于如何下载完整原始图像的任何想法吗?
PS: if I select a picture from the gallery which was taken from the phone and it is still resident on the phone's storage, the EXIF data are present PS:如果我从图库中选择了从手机上拍摄的图片,但该图片仍驻留在手机的存储空间中,则存在EXIF数据
I finally found out a solution. 我终于找到了解决方案。 after getting the source image Uri in the onActivityResult method using
使用onActivityResult方法获取源图像Uri之后
Uri selectedImage = data.getData();
I use the following function to get the necessary data from the picture 我使用以下功能从图片中获取必要的数据
public static ImageInfo getImageInfo(Context context, Uri photoUri) {
Cursor cursor = context.getContentResolver().query(photoUri,
new String[] {
MediaStore.Images.ImageColumns.ORIENTATION,
MediaStore.Images.ImageColumns.LATITUDE,
MediaStore.Images.ImageColumns.LONGITUDE,
MediaStore.Images.ImageColumns.DATE_TAKEN } , null, null, null);
if (cursor.getCount() != 1) {
return null;
}
cursor.moveToFirst();
ImageInfo i = new ImageInfo();
i.Orientation = cursor.getInt(0);
i.Lat = cursor.getDouble(1);
i.Lon = cursor.getDouble(2);
i.DateTakenUTC = cursor.getLong(3)/1000;
cursor.close();
return i;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.