Fresco修改decoder,解决超大图显示模糊的问题。

  |   0 评论   |   106 浏览

    private void setImageUrl() {
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(model.getImage()))
    .setImageDecodeOptions(Utils.getFileTypeIsGif(model.getImage()) ? null ://null表示使用原有默认decoder
    ImageDecodeOptions.newBuilder()
    .setCustomImageDecoder(new ImageDecoder() {
    @Override
    public CloseableImage decode(EncodedImage encodedImage, int length, QualityInfo qualityInfo, ImageDecodeOptions options) {
    Bitmap bitmap = null;
    if (encodedImage.getHeight() > Utils.dip2px(manager.getContext(), 150)) {
    int height = Utils.dip2px(manager.getContext(), 150);
    int width = Utils.getWidth(manager.getContext());
    width = width > encodedImage.getWidth() ? encodedImage.getWidth() : width;
    SkiaImageRegionDecoder inDecoder = new SkiaImageRegionDecoder();
    Rect region = new Rect();
    region.left = (encodedImage.getWidth() - width) / 2;
    region.right = region.left + width;
    region.top = (encodedImage.getHeight() - height) / 2;
    region.bottom = region.top + height;
    try {
    inDecoder.init(manager.getContext(), Uri.parse(“file://” + FrescoUtils.getImageFileOnDisk(Uri.parse(model.getImage())).getAbsolutePath()));
    bitmap = inDecoder.decodeRegion(region, 1);
    } catch (Exception e) {
    LogInfo.LogOut(e);
    }
    }
    if (bitmap == null) {//TODO 此处最好使用原有默认decoder
    bitmap = BitmapFactory.decodeStream(encodedImage.getInputStream());
    }
    return new CloseableStaticBitmap(
    bitmap,
    SimpleBitmapReleaser.getInstance(),
    ImmutableQualityInfo.FULL_QUALITY,
    0);

    }
    })
    .build())
    .build();
    DraweeController controller = Fresco.newDraweeControllerBuilder()
    .setImageRequest(request)
    .setAutoPlayAnimations(Utils.getFileTypeIsGif(model.getImage()))
    .setOldController(image.getController())
    .setControllerListener(new BaseControllerListener())
    .build();
    image.setController(controller);
    }

    知识共享许可协议

    评论

    发表评论

    validate