项目里面的用户头像要求是圆形的,所以自己重写了个ImageView控件,但是实际显示效果不是很好,图片边缘锯齿比较明显,网上看了一些抗锯齿的方法,都没有效果,哪位高手有比较好的解决方法,或者其它的圆形ImageView实现方式,分享下吧~~~谢啦
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PaintFlagsDrawFilter;
import android.graphics.Path;
import android.util.AttributeSet;
import android.widget.ImageView;
public class RoundImageView extends ImageView {
public RoundImageView(Context context) {
super(context);
}
public RoundImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public RoundImageView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onDraw(Canvas canvas) {
Path clipPath = new Path();
int w = this.getWidth();
int h = this.getHeight();
clipPath.addCircle(w/2, h/2, w/2, Path.Direction.CW);
canvas.clipPath(clipPath);
canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG));
super.onDraw(canvas);
}
}
------解决方案--------------------
1)mPaint.setAntiAlias();
2)mPaint.setFilterBitmap(true)。
文章链接
http://blog.csdn.net/sada09/article/details/8017248
------解决方案--------------------
我发现这样也做不到圆润,只能是减轻锯齿。如果要绝对圆润,估计得要用openGL吧~~
------解决方案--------------------
试试用photoshop做一张圆形的png图,然后通过图片叠加来实现