在安卓中使用Picasso读取图片的EXIF数据

5
我有以下代码,它可以从URL下载图像并在imageView中显示:
Picasso.with(getActivity())
          .load(mImagesUrls[mPosition])
          .resize(500, 500)
          .centerCrop()
          .into(mSlideImage);

除了显示图像外,我还需要检索一些EXIF数据。在Android上查找如何做到这一点,我找到了“ExifInterface”类,但它的构造函数如下:
- ExifInterface(String filename)
读取指定图像文件中的Exif标签。
- ExifInterface(FileDescriptor fileDescriptor)
从指定的图像文件描述符中读取Exif标签。
- ExifInterface(InputStream inputStream)
从指定的图像输入流中读取Exif标签。
我该如何获取这些构造函数所需的任何参数?我在使用Picasso时只能找到将图像加载为位图的方法,似乎不支持EXIF数据。

我也遇到了同样的问题,你有解决方案吗? - João Armando
很遗憾,我从来没有找到解决这个问题的方法。该项目已经被放弃了。 - Alucard
1个回答

0

我不知道它是否有帮助,但我已经制作了一个例子,在我的情况下可以工作,但这只是一个例子:

public void transformPicture(final File file, final OnImageReady onImageReady) {
float rotation = 0;
try {
    Uri uri = Uri.fromFile(file);
    ExifInterface exifInterface = new ExifInterface(uri.getPath());
    int orientation = exifInterface.getAttributeInt(TAG_ORIENTATION, ORIENTATION_NORMAL);
    switch (orientation){
    case ExifInterface.ORIENTATION_ROTATE_90: {
        rotation = -90f;
        break;
    }
    case ExifInterface.ORIENTATION_ROTATE_180: {
        rotation = -180f;
        break;
    }
    case ExifInterface.ORIENTATION_ROTATE_270: {
        rotation = 90f;
        break;
    }
    }
} catch (IOException e) {
    e.printStackTrace();
}

Picasso.get().load(file)
    .resize(getTargetMaxSize(), getTargetMaxSize())
    .centerInside()
    .rotate(rotation)
    .into(myView);
}

请记住,您只能从文件而非网络中读取exif。 同时可以查看Exif方向标签

您甚至可以像这样获取ExifInterface:

String fileName = "/path/file.any";
ExifInterface exifInterface1 = new ExifInterface(fileName);

FileInputStream fis = new FileInputStream(new File(fileName));
ExifInterface exifInterface3 = new ExifInterface(fis);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接