gpt4 book ai didi

android - 为什么使用fresco datasource获取位图为空

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:34:14 26 4
gpt4 key购买 nike

为什么onNewResultImpl返回的bitmap为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());

最佳答案

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

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

关于android - 为什么使用fresco datasource获取位图为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30477827/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com