获取图像的宽度和高度与毕加索库 [英] getting image width and height with picasso library
问题描述
我使用毕加索库下载和加载图像到ImageView的。现在我想知道我可以加载它们在imageViews之前获得图像的宽度和高度?
i'm using picasso library to download and load images into imageView. now i want to know how i can get image width and height before loading them in imageViews ?
我有包含两个ImageView的(其中一个是垂直和另一个是水平的)的适配器列表视图。取决于图像的宽度和高度,我想加载图像到imageviews之一。
i have a listview with an adapter that contains two imageView(one of them is vertical and another is horizontal). depends on image width and height i want to load image into one of the imageviews.
推荐答案
您只能下载后得到位图的尺寸 - 你必须使用同步方法调用是这样的:
You can get Bitmap dimensions only after downloading It - you must use synchronous method call like this:
final Bitmap image = Picasso.with(this).load("http://").get();
int width = image.getWidth();
int height = image.getHeight();
在此,你可以调用再次相同的URL加载(它会从缓存中获取):
After this you can call again load with same url (It will be fetched from cache):
Picasso.with(this).load("http://").into(imageView)
编辑:也许更好的方法:
Picasso.with(this).load("http://").into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
imgView.setImageBitmap(bitmap);
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
});
这篇关于获取图像的宽度和高度与毕加索库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!