毕加索onBitmapLoaded从未调用 [英] Picasso onBitmapLoaded never called
本文介绍了毕加索onBitmapLoaded从未调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了同样的问题,我想将Picasso生成的可绘制对象用于图像缓存目的,但是我却无法获得相同的效果.这是我用来访问位图可绘制对象的代码:
I am having the same problem, that I want to use the drawables that are generated by the Picasso for Image Caching Purpose, but I am not able to get the same. Here is the code which I am using to access the Bitmap Drawables :
Target targetBitmap = new Target() {
@Override
public void onPrepareLoad(Drawable arg0) {
}
@Override
public void onBitmapLoaded(Bitmap arg0, Picasso.LoadedFrom arg1) {
mBitmap = arg0;
BitmapDrawable d = new BitmapDrawable(context.getResources(), arg0);
int margin = 2;
int border = 0;
Rect r = new Rect(margin, margin, width - margin, height - margin);
int imageWidth = r.width();
int imageHeight = r.height();
if (imageHeight > r.height() - (border * 2)) {
imageHeight = r.height() - (border * 2);
}
r.left += ((r.width() - imageWidth) / 2) - border;
r.right = r.left + imageWidth + border + border;
r.top += ((r.height() - imageHeight) / 2) + border;
r.bottom = r.top + imageHeight + border + border;
Paint p = new Paint();
p.setColor(0xFFFFFF);
c.drawRect(r, p);
r.left += border;
r.right -= border;
r.top += border;
r.bottom -= border;
d.setBounds(r);
d.draw(c);
}
@Override
public void onBitmapFailed(Drawable arg0) {
}
};
Picasso.with(context).load(app.getListBookDetails().get(img_num).getImage_150x225()).into(targetBitmap);
但是这里从不调用onBitmapLoaded方法.如何使用此方法?如果可以的话请帮忙.我刮了一切,但徒劳无功.
But here onBitmapLoaded method is never called. How can I access this method ? Please help if you can. I have scratched everything but has gone all in vain.
谢谢 萨那特(Sanat)
Thanks Sanat
推荐答案
以下是示例代码,以防您要防止目标对象被垃圾回收:
Here is the sample code in case you want to prevent Target object from being garbage collected:
final Target mTarget = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom loadedFrom) {
Log.d("DEBUG", "onBitmapLoaded");
BitmapDrawable mBitmapDrawable = new BitmapDrawable(getResources(), bitmap);
navigationMenuItem.setIcon(mBitmapDrawable);
}
@Override
public void onBitmapFailed(Drawable drawable) {
Log.d("DEBUG", "onBitmapFailed");
}
@Override
public void onPrepareLoad(Drawable drawable) {
Log.d("DEBUG", "onPrepareLoad");
}
};
Picasso.with(this).load(tempUrl).into(mTarget);
这篇关于毕加索onBitmapLoaded从未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文