5

为什么位图返回onNewResultImplnull?

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

3 回答 3

14

我进行了一些修改以使您的代码可以正常工作,请考虑使用它。我也对其进行了测试,并且一切正常。

// 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());
于 2015-06-09T06:36:40.053 回答
4

编辑:您正在使用fetchEncodedImage而不是fetchDecodedImage. 这意味着返回的每个图像都没有底层位图。但是,如果您将其更改为fetchDecodedImage并仍然看到空位图,那将是因为我在下面所写的内容。

在此处查看源代码:https ://github.com/facebook/fresco/blob/master/imagepipeline/src/main/java/com/facebook/imagepipeline/datasource/BaseBitmapDataSubscriber.java#L57-L61

并非所有返回的图像都是CloseableBitmaps,而不是的图像没有要返回的底层位图,因此此方法返回空位图。

于 2015-05-29T10:58:27.777 回答
3

如果您需要位图,则fetchDecodedImage,不应调用。fetchEncodedImage,

于 2015-05-29T13:25:00.693 回答