[英]Reading EXIF data from image using Picasso in android
我有以下代碼可從URL下載圖像並將其顯示在imageView中:
Picasso.with(getActivity())
.load(mImagesUrls[mPosition])
.resize(500, 500)
.centerCrop()
.into(mSlideImage);
但是除了顯示圖像之外,我還需要檢索一些EXIF數據。 谷歌搜索如何為Android執行此操作將我帶到“ ExifInterface”類,但其構造函數如下:
- ExifInterface(字符串文件名)
- 從指定的圖像文件中讀取Exif標簽。
- ExifInterface(FileDescriptor fileDescriptor)
- 從指定的圖像文件描述符讀取Exif標簽。
- ExifInterface(InputStream inputStream)
- 從指定的圖像輸入流中讀取Exif標簽。
如何獲得這些構造函數所需的任何參數? 我用畢加索所能找到的只是一種將圖像加載為位圖的方法,它似乎不支持EXIF數據。
我不知道它是否能幫上忙,但我舉了一個在我的情況下可行的例子,但這只是一個例子:
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.