Why is bitmap returned in onNewResultImpl null?
final ImageView imageView = (ImageView) findViewById (R.id.imageView);
ImageRequest request = ImageRequest.fromUri(pic_uri);
ImagePipeline imagePipeline = Fresco.getImagePipeline();
DataSource dataSource = imagePipeline.fetchEncodedImage(request, this);
CloseableReference<CloseableImage> imageReference = null;
dataSource.subscribe (new BaseBitmapDataSubscriber() {
@Override
protected void onNewResultImpl(Bitmap bitmap) {
LogUtils._d("onNewResultImpl....");
if(bitmap == null) {
LogUtils._d("bitmap is null");
}
imageView.setImageBitmap(bitmap);
}
@Override
protected void onFailureImpl(DataSource dataSource) {
LogUtils._d("onFailureImpl....");
}
}, CallerThreadExecutor.getInstance());
I have made some modification to make things work in your code, consider using this. I have also tested it and it worked all fine.
// To get image using Fresco
ImageRequest imageRequest = ImageRequestBuilder
.newBuilderWithSource( Uri.parse(getFeedItem(position).feedImageUrl.get(index)))
.setProgressiveRenderingEnabled(true)
.build();
ImagePipeline imagePipeline = Fresco.getImagePipeline();
DataSource<CloseableReference<CloseableImage>> dataSource =
imagePipeline.fetchDecodedImage(imageRequest,mContext);
dataSource.subscribe(new BaseBitmapDataSubscriber() {
@Override
public void onNewResultImpl(@Nullable Bitmap bitmap) {
// You can use the bitmap in only limited ways
// No need to do any cleanup.
}
@Override
public void onFailureImpl(DataSource dataSource) {
// No cleanup required here.
}
}, CallerThreadExecutor.getInstance());
EDIT: You are using fetchEncodedImage rather than fetchDecodedImage. That means that every image returns will have no underlying bitmap. But if you change that to fetchDecodedImage and still see null Bitmaps, it will be because of what I have written about below.
See the source code here: https://github.com/facebook/fresco/blob/master/imagepipeline/src/main/java/com/facebook/imagepipeline/datasource/BaseBitmapDataSubscriber.java#L57-L61
Not all images that are returned are CloseableBitmaps, and those that are not do not have an underlying bitmap to return, so this method returns a null Bitmap.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With