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("" + 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);
}
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于