【问题标题】:Missing EXIF info in images selected from gallery using EXTERNAL_CONTENT_URI使用 EXTERNAL_CONTENT_URI 从图库中选择的图像中缺少 EXIF 信息
【发布时间】:2017-06-06 16:43:33
【问题描述】:

我正在尝试从从 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 数据存在

【问题讨论】:

    标签: android gps exif geotagging


    【解决方案1】:

    我终于找到了解决办法。在 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;
        }
    

    【讨论】:

    • 它是什么 - ImageInfo?
    • 这是一个自定义对象,包含我需要的数据
    猜你喜欢
    • 1970-01-01
    • 2013-11-16
    • 1970-01-01
    • 1970-01-01
    • 2012-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-23
    相关资源
    最近更新 更多