使用毕加索时随机图像旋转 [英] Random image gets rotated when using picasso
问题描述
我在RecyclerView中加载了不同的图像,并使用Picasso从互联网上获取了图像,但是随机地,iPhone中的图像却上下颠倒旋转,我不明白为什么.
在互联网上看起来还不错.
I load different images in my RecyclerView and I use Picasso to get them from internet, but randomly an image from iPhone is getting rotated upside down and I don't understand why.
It looks fine on the internet.
我的代码是:
Picasso.with(context)
.load(URLConstants.URL_BASE + imageURL)
.placeholder(image)
.error(image)
.into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
Matrix matrix = new Matrix();
try {
ExifInterface exif = new ExifInterface(URLConstants.URL_BASE + imageURL);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
Log.d("EXIF", "Exif: " + orientation);
if (orientation == 6) {
matrix.setRotate(90);
} else if (orientation == 3) {
matrix.setRotate(180);
} else if (orientation == 8) {
matrix.setRotate(270);
}
} catch (Exception e) {
e.printStackTrace();
}
Bitmap oriented = Bitmap.createBitmap(bitmap, 0, 0,
bitmap.getWidth(), bitmap.getHeight(), matrix, true);
imageView.setImageBitmap(oriented);
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
});
我不知道
ExifInterface exif = new ExifInterface(URLConstants.URL_BASE + imageURL);
是否可以使用URL.
如果没有,我还有什么其他方式?
works with URLs or not.
And if they don't, what other way do I have?
推荐答案
正确.此方法不适用于URL.
Right. This method will not work with URL.
ExifInterface exif = new ExifInterface(URLConstants.URL_BASE + imageURL);
您应该在下载的位图上检查此控件.在这种情况下,不检查下载的位图.您可以将其保存为temp.jpeg.旁边是android ExifInterface.java中的方法,它在注释中像这样说.
you should check this control on downloaded Bitmap.In this case it is not check downloaded one. You can save it like temp.jpeg. Beside It is the method in android ExifInterface.java, it says like that on comment.
/**
* Reads Exif tags from the specified JPEG file.
*/
public ExifInterface(String filename) throws IOException {
if (filename == null) {
throw new IllegalArgumentException("filename cannot be null");
}
mFilename = filename;
loadAttributes();
}
已编辑
您可以检查此类的正确方向 https://github.com/eralpyucel/ProfileImage/blob/master/app/src/main/java/com/eralp/profilephoto/PhotoFunctions.java
You can check this class for proper orientation https://github.com/eralpyucel/ProfileImage/blob/master/app/src/main/java/com/eralp/profilephoto/PhotoFunctions.java
这篇关于使用毕加索时随机图像旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!