Android ImageLoader显示圆形图片拉伸

在使用ImageLoader加载圆形图片时发现图片出现拉伸失真的情况。通过查看源码,发现在矩阵转换时使用了`Matrix.ScaleToFit.FILL`,导致长方形图片被填充并拉伸。将填充方式改为`Matrix.ScaleToFit.CENTER`即可避免图片拉伸,确保正确显示圆形图片。
摘要由CSDN通过智能技术生成

今天同事使用我写的简单工具类加载圆形图片的时候,跟我说图片拉伸失真了。
wtf? 我使用的ImageLoader(github地址)自带的圆角控件时,居然会导致长方形的图片拉伸。
点进去源码一看,原来在矩阵转换的时候写的fill,改成center就好了
shaderMatrix.setRectToRect(this.mBitmapRect, this.mRect, Matrix.ScaleToFit.CENTER);
Matrix.setRectToRect(RectF src,RectF dst, Matrix.ScaleToFit stf)这个方法就是对矩阵的转换,Matrix.ScaleToFit总共有4个值CENTER,END,START,FILL。

偷懒的直接复制下面的

public class MyCircleBitmapDisplayer  implements BitmapDisplayer {
   

        protected final Integer strokeColor;
        protected final float strokeWidth;

        public MyCircleBitmapDisplayer() {
            this((Integer)null);
        }

        public MyCircleBitmapDisplayer(Integer strokeColor) {
            this(strokeColor, 0.0F);
        }

        public MyCircleBitmapDisplayer(Integer strokeColor, float strokeWidth) {
            this.strokeColor = strokeColor;
            this.strokeW
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值