Why is using fresco datasource to get bitmap empty

Why is bitmap returning 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());

      

+3


source to share


3 answers


I made some changes to make things work in your code, please consider this. I also tested it and it worked great.



// 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());

      

+12


source


EDIT: you are using fetchEncodedImage

, not fetchDecodedImage

. This means that each return of the image will not have a base bitmap. But if you change that to fetchDecodedImage

and you still see zero bitmaps, it will be because of what I wrote about below.

See 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 CloseableBitmap

s, and those that do not have a base bitmap to return, so this method returns a zero bitmap.

+4


source


You must call fetchDecodedImage,

not fetchEncodedImage,

if you want a bitmap.

+3


source







All Articles