【问题标题】:Reading EXIF data from image using Picasso in android在android中使用毕加索从图像中读取EXIF数据
【发布时间】:2016-12-24 18:36:51
【问题描述】:

我有以下代码从 URL 下载图像并将其显示在 imageView 中:

Picasso.with(getActivity())
          .load(mImagesUrls[mPosition])
          .resize(500, 500)
          .centerCrop()
          .into(mSlideImage);

但除了显示图像之外,我还需要检索一些 EXIF 数据。谷歌搜索如何为 android 执行此操作将我带到“ExifInterface”类,但它的构造函数如下:

  1. ExifInterface(字符串文件名)
    • 从指定图像文件读取Exif标签。
  2. ExifInterface(文件描述符文件描述符)
    • 从指定图像文件描述符读取Exif标签。
  3. ExifInterface(InputStream 输入流)
    • 从指定图像输入流读取Exif标签。

我怎样才能得到这些构造函数需要的任何参数?我能用毕加索找到的只是一种将图像加载为位图的方法,这似乎不支持 EXIF 数据。

【问题讨论】:

  • 我也遇到了同样的问题,你有解决办法吗?
  • 可悲的是,没有,从来没有解决这个问题。项目被放弃了。

标签: java android picasso android-image exif


【解决方案1】:

我不知道它是否有帮助,但我做了一个例子,在我的情况下有效,但这只是一个例子:

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 Orientation Tag

你甚至可以像这样获得 ExifInterface:

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

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

【讨论】:

    猜你喜欢
    • 2017-05-18
    • 2018-01-01
    • 2016-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多