我有一个observable,它使用不同的filePath
异步加载图像,我想缓存位图变量。我只是尝试添加.cache
方法,但它没有帮助。如何在ma中完成缓存?
Observable.fromCallable(() -> {
File outputFile = new File(filePath);
Bitmap bitmap = decodeSampledBitmapFromUrl(newTAG, width, height);
return bitmap;
})
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(bitmap -> {
mImageView.setImageBitmap(bitmap);
},
throwable -> {
//handle it
});
答案 0 :(得分:2)
使用Glide
或Picasso
及其内置缓存功能,也可以考虑使用WeakReferences来存储类似的位图。
答案 1 :(得分:0)
你的意思是在你显示的代码后使用位图变量?如果您不使用它,则应拨打Bitmap.recycler()
。