我在我的应用程序中使用了retrofit observable defer运算符,用于将位图加载到imageview中。
这里我的代码是......
public void getImages(final String bgBitmap, final ImageView bgImgView) {
Observable.defer(new Func0<Observable<Bitmap>>() {
@Override
public Observable<Bitmap> call() {
try {
Bitmap bitmapLogo = HelpUtil.getBitmapFromBase64(bgBitmap);
return Observable.just(HelpUtil.scaleBitmap(bitmapLogo));
}
catch (Exception e) {
return Observable.error(e);
}
}
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.filter(new Func1<Bitmap, Boolean>() {
@Override
public Boolean call(Bitmap bitmap) {
return bitmap!=null;
}
})
.subscribe(new Action1<Bitmap>() {
@Override
public void call(Bitmap bitmap) {
bgImgView.setImageBitmap(bitmap);
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
}
});
}
在imageview中加载图像时,其图像闪烁错误,然后加载正确的图像。任何人都可以帮助我吗?