Fresco 由缓存转Bitmap

2021-01-13 14:18:24 浏览数 (2)

代码语言:javascript复制
// To get image using Fresco
ImageRequest imageRequest = ImageRequestBuilder
    .newBuilderWithSource(Uri.parse(ImgUrl))
    .setProgressiveRenderingEnabled(true)
    .build();

ImagePipeline imagePipeline = Fresco.getImagePipeline();
DataSource<CloseableReference<CloseableImage>>
    dataSource = imagePipeline.fetchDecodedImage(imageRequest,this);

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.
        imageView.setImageBitmap(bitmap);
    }

    @Override
    public void onFailureImpl(DataSource dataSource) {
        // No cleanup required here.
    }
}, CallerThreadExecutor.getInstance());

0 人点赞