圆角图片github项目:RoundAngleImageView 【常用】
来源:互联网 发布:淘宝网店手机可以开吗? 编辑:程序博客网 时间:2024/06/09 15:26
import android.content.Context;import android.graphics.Bitmap;import android.graphics.Bitmap.Config;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.Path;import android.graphics.PorterDuff;import android.graphics.PorterDuffXfermode;import android.graphics.RectF;import android.util.AttributeSet;import android.widget.ImageView;public class RoundAngleImageView extends ImageView { private Paint paint; private int roundWidth = 10; private int roundHeight = 10; private Paint paint2; public RoundAngleImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(context, attrs); } public RoundAngleImageView(Context context, AttributeSet attrs) { super(context, attrs); init(context, attrs); } public RoundAngleImageView(Context context) { super(context); init(context, null); } private void init(Context context, AttributeSet attrs) { float density = context.getResources().getDisplayMetrics().density; roundWidth = (int) (roundWidth * density); roundHeight = (int) (roundHeight * density); paint = new Paint(); paint.setColor(Color.WHITE); paint.setAntiAlias(true); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); paint2 = new Paint(); paint2.setXfermode(null); } @Override public void draw(Canvas canvas) { Bitmap bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Config.ARGB_8888); Canvas canvas2 = new Canvas(bitmap); super.draw(canvas2); drawLiftUp(canvas2); drawRightUp(canvas2); drawLiftDown(canvas2); drawRightDown(canvas2); canvas.drawBitmap(bitmap, 0, 0, paint2); bitmap.recycle(); } private void drawLiftUp(Canvas canvas) { Path path = new Path(); path.moveTo(0, roundHeight); path.lineTo(0, 0); path.lineTo(roundWidth, 0); path.arcTo(new RectF( 0, 0, roundWidth*2, roundHeight*2), -90, -90); path.close(); canvas.drawPath(path, paint); } private void drawLiftDown(Canvas canvas) { Path path = new Path(); path.moveTo(0, getHeight()-roundHeight); path.lineTo(0, getHeight()); path.lineTo(roundWidth, getHeight()); path.arcTo(new RectF( 0, getHeight()-roundHeight*2, 0+roundWidth*2, getHeight()), 90, 90); path.close(); canvas.drawPath(path, paint); } private void drawRightDown(Canvas canvas) { Path path = new Path(); path.moveTo(getWidth()-roundWidth, getHeight()); path.lineTo(getWidth(), getHeight()); path.lineTo(getWidth(), getHeight()-roundHeight); path.arcTo(new RectF( getWidth()-roundWidth*2, getHeight()-roundHeight*2, getWidth(), getHeight()), 0, 90); path.close(); canvas.drawPath(path, paint); } private void drawRightUp(Canvas canvas) { Path path = new Path(); path.moveTo(getWidth(), roundHeight); path.lineTo(getWidth(), 0); path.lineTo(getWidth()-roundWidth, 0); path.arcTo(new RectF( getWidth()-roundWidth*2, 0, getWidth(), 0+roundHeight*2), -90, 90); path.close(); canvas.drawPath(path, paint); }}
0 0
- 圆角图片github项目:RoundAngleImageView 【常用】
- 圆图片 github项目 CircleImageView【常用】
- 常用github项目
- 常用的github项目
- 【github】常用Github项目类库
- 【github】常用Github项目类库
- 【github】常用Github项目类库
- 【github】常用Github项目类库
- 【github】常用Github项目类库
- 【github】常用Github项目类库
- 【github】常用Github项目类库
- github上常用的项目
- github项目之自定义图片形状(圆形和圆角矩形)
- Github上的项目描述添加图片
- 常用Github上比较优秀的项目
- 【android】常用Github项目类库
- Android常用Github项目类库
- github 常用项目记录帖,持续更新...
- 打开保存指定格式文件
- Zxing二维码开源项目
- Android学习第三天之FrameLayout帧布局
- mac 下的mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock
- Jenkins Ubuntu环境安装启动步骤
- 圆角图片github项目:RoundAngleImageView 【常用】
- 关于UIAlertController 的一些用法
- 关于DP的单调队列优化和斜率优化区别
- 把apk、so等文件,打包到system.img的方法
- cloudstack 创建与删除VM流程
- Android之JSON封装与Javascript解析JSON
- android中图片加载的4种途径和加载方法
- 为什么会文不对题
- alter table新增字段操作究竟有何影响?(下篇)