![](/img/trans.png)
[英]Android: Is EXTERNAL_CONTENT_URI enough for a photo gallery?
[英]Missing EXIF info in images selected from gallery using EXTERNAL_CONTENT_URI
我正在嘗試從從EXTERNAL_CONTENT_URI意向中選擇的圖像中收集EXIF信息(拍攝日期,地理標記,方向),但似乎如果這些圖像來自互聯網(例如Google相冊),則EXIF數據會被截斷。
例如,如果我從PC上的photos.google.com從網絡瀏覽器下載圖片,則圖片大小為4.377.104字節,並且所有EXIF數據都在那里。 如果我使用以下命令下載相同的圖像:
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
其大小為4.363.578字節(比原始大小少13526字節),並且所有EXIF數據均丟失
關於如何下載完整原始圖像的任何想法嗎?
PS:如果我從圖庫中選擇了從手機上拍攝的圖片,但該圖片仍駐留在手機的存儲空間中,則存在EXIF數據
我終於找到了解決方案。 使用onActivityResult方法獲取源圖像Uri之后
Uri selectedImage = data.getData();
我使用以下功能從圖片中獲取必要的數據
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.