我正在使用此库(https://github.com/androidquery/androidquery)进行图像下载和显示。有一个回调方法。在这个方法里面,我正在检查位图是否大于屏幕尺寸。如果位图比屏幕尺寸大,那么我将位图划分为5个位图部分并在5个图像视图中显示,因此分辨率很好。
final AQuery[] aq = {new AQuery(hh.imageview), new AQuery(hh.imageview3), new AQuery(hh.thumbnail3),
new AQuery(hh.thumbnail4), new AQuery(hh.thumbnail5), new AQuery(hh.thumbnail6)};
final Bitmap[] bitmap = new Bitmap[6];
aq[0].id(hh.imageview).image(url, false, true, 0, 0, new BitmapAjaxCallback() {
@Override
public void callback(String url, ImageView iv, Bitmap bm, AjaxStatus status) {
if(bm != null) {
if(bm.getHeight()>=maxTextureSize){
int h = bm.getHeight();
int w = bm.getWidth();
/* bitmap[0] = Bitmap.createBitmap(bm, 0 , 0, w, h/6);
iv.setImageBitmap(bitmap[0]);
bitmap[1] = Bitmap.createBitmap(bm, 0 , bitmap[0].getHeight(),
w, h/6);
aq[1].id(hh.imageview3).image(bitmap[1]);
bitmap[2] = Bitmap.createBitmap(bm, 0 , bitmap[0].getHeight() + bitmap[1].getHeight(),
w, h/6);
aq[2].id(hh.thumbnail3).image(bitmap[2]);
bitmap[3] = Bitmap.createBitmap(bm, 0, bitmap[0].getHeight() + bitmap[1].getHeight() + bitmap[2].getHeight(),
w, h/6);
aq[3].id(hh.thumbnail4).image(bitmap[3]);
bitmap[4] = Bitmap.createBitmap(bm, 0, bitmap[0].getHeight() + bitmap[1].getHeight() + bitmap[2].getHeight()+bitmap[3].getHeight(),
w, h/6);
aq[4].id(hh.thumbnail5).image(bitmap[4]);
bitmap[5] = Bitmap.createBitmap(bm, 0, bitmap[0].getHeight() + bitmap[1].getHeight() + bitmap[2].getHeight()+bitmap[3].getHeight()+bitmap[4].getHeight()
, w, h/6);
aq[5].id(hh.thumbnail6).image(bitmap[5]);*/
/* }
else if(bm.getWidth()>=maxTextureSize){
bm =Bitmap.createScaledBitmap(bm, maxTextureSize, bm.getHeight(), true);
iv.setImageBitmap(bm);
} else {
iv.setImageBitmap(bm);
hh.imageview3.setImageDrawable(null);
hh.thumbnail3.setImageDrawable(null);
hh.thumbnail4.setImageDrawable(null);
hh.thumbnail5.setImageDrawable(null);
hh.thumbnail6.setImageDrawable(null);
}
}
}
});
if(bitmap[0] != null) {
bitmap[0].recycle();
bitmap[0] = null;
}
if(bitmap[1] != null) {
bitmap[1].recycle();
bitmap[1] = null;
}
if(bitmap[2] != null) {
bitmap[2].recycle();
bitmap[2] = null;
}
if(bitmap[3] != null) {
bitmap[3].recycle();
bitmap[3] = null;
}
if(bitmap[4] != null) {
bitmap[4].recycle();
bitmap[4] = null;
}
if(bitmap[5] != null) {
bitmap[5].recycle();
bitmap[5] = null;
}
现在我移动了毕加索(http://square.github.io/picasso/)图书馆。而且我在这个库中也看起来与逻辑相同。但无法找到我怎么做到的?请帮帮我。
答案 0 :(得分:1)
Picasso.with(MainActivity.this)
.load(imageUrl)
.into(imageView, new com.squareup.picasso.Callback() {
@Override
public void onSuccess() {
//do smth when picture is loaded successfully
}
@Override
public void onError() {
//do smth when there is picture loading error
}
});
答案 1 :(得分:0)
.into
方法提供了第二个参数,它是对成功和失败的回调。
public void into(android.widget.ImageView target,
Callback callback)
此外,您可以使用.transform(new ImageTransformation())
方法更改大小