我正在开发电影 Android 应用程序,它从 API 获取电影列表,为所有电影提供海报路径。
我想从图像的 URL 获取图像作为 Bitmap
以将其保存为模型类中的 Bitmap
变量。我想将图像保存为数据库中的 blob 以直接检索它,而无需在用户每次打开应用程序时重新下载。这可能吗?
我想做这样的事情,但它总是返回 null。
private Bitmap posterBitmap;
public void setPosterBitmap () {
Picasso.get().load(POSTERS_URL).into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
posterBitmap = bitmap; // I don't want to set it to an Image view here
}
@Override
public void onBitmapFailed(Exception e, Drawable errorDrawable) {}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {}
});
}
提前致谢。
最佳答案
new Thread(() -> {
try {
Bitmap mBitmap = Picasso.get().load(link).get();
} catch (Exception e) {
Log.e(""+e);
}
}).start();
通过使用 实现 'com.squareup.picasso:picasso:2.71828'
关于java - 在 picasso 中使用目标获取位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51450984/