今天同事使用我写的简单工具类加载圆形图片的时候,跟我说图片拉伸失真了。
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