Tar*_*rek 4 java android picasso android-bitmap
我正在开发电影 Android 应用程序,它从 API 获取电影列表,该 API 提供所有电影的海报路径。
我想Bitmap从图像的 URL 获取图像,并将其保存为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) {}
});
}
Run Code Online (Sandbox Code Playgroud)
提前致谢。
小智 5
new Thread(() -> {
try {
Bitmap mBitmap = Picasso.get().load(link).get();
} catch (Exception e) {
Log.e(""+e);
}
}).start();
Run Code Online (Sandbox Code Playgroud)
通过使用实现 'com.squareup.picasso:picasso:2.71828'