Glide.with(context)
.asBitmap()
.load(uri)
.into(new SimpleTarget<Bitmap>(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
int width = resource.getWidth();
int height = resource.getHeight();
// 设置想要的大小
int newWidth = ScreenUtils.getScreenWidth(context);
int newHeight = newWidth * height / width;
// 计算缩放比例
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// 取得想要缩放的matrix参数
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// 得到新的图片
resource = Bitmap.createBitmap(resource, 0, 0, width, height, matrix, true);
gifImageView.setImageBitmap(resource);
}
});
网友评论