Reputation: 119
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 (e.g. Google Photos) the EXIF data is somehow truncated.
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. 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
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
Upvotes: 0
Views: 680
Reputation: 119
I finally found out a solution. after getting the source image Uri in the onActivityResult method using
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;
}
Upvotes: 1