public class CircleImageView extends View {
private Paint mPaint;
private Paint mTargetPaint;
private Bitmap mSourceBitmap;
private Bitmap mTargetBitmap;
private Canvas mTargetCanvas;
private int mWidth;
private int mHeight;
public CircleImageView(Context context) {
this(context, null);
}
public CircleImageView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public CircleImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mTargetPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mTargetPaint.setXfermode(new PorterDuffXfermode(SRC_IN));
mSourceBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.xiaojiangshi);
mTargetBitmap = Bitmap.createBitmap(mSourceBitmap.getWidth(), mSourceBitmap.getHeight(), Bitmap.Config.ARGB_8888);
mTargetCanvas = new Canvas(mTargetBitmap);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mWidth = w;
mHeight = h;
}
@Override
protected void onDraw(Canvas canvas) {
// 生成圆形Bitmap过程.
int radius = Math.min(mWidth, mHeight) / 2;
// 先绘制圆形
mTargetCanvas.drawCircle(mWidth / 2, mHeight / 2, radius, mPaint);
// 再绘制Bitmap
mTargetCanvas.drawBitmap(mSourceBitmap, 0, 0, mTargetPaint);
canvas.drawBitmap(mTargetBitmap, 0, 0, null);
}
}
mTargetPaint.setXfermode(new PorterDuffXfermode(SRC_IN));
mPath.reset(); mPath.moveTo(mWidth / 2, 0); mPath.lineTo(0, mHeight); mPath.lineTo(mWidth, mHeight); mPath.close(); mTargetCanvas.drawPath(mPath, mPaint);
RectF rectF = new RectF(0, 0, mWidth, mHeight); mTargetCanvas.drawArc(rectF, 210, 120, true, mPaint);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有