腾讯大牛动态教学:Android-仿微信-QQ-图片裁剪,赶紧收藏起来!

234//通过Xfermode的DST_OUT来产生中间的透明裁剪区域,一定要另起一个Layer(层)67//设置背景。
摘要由CSDN通过智能技术生成

1xfermode = new PorterDuffXfermode(PorterDuff.Mode.DST_OUT);
2
3
4//通过Xfermode的DST_OUT来产生中间的透明裁剪区域,一定要另起一个Layer(层)
5canvas.saveLayer(0, 0, this.getWidth(), this.getHeight(), null, Canvas.ALL_SAVE_FLAG);
6
7//设置背景
8canvas.drawColor(Color.parseColor(“#a8000000”));
9paint.setXfermode(xfermode);

圆形裁剪框的实现

绘制圆形裁剪框很容易实现,主要确定圆心和半径即可

1//中间的透明的圆
2canvas.drawCircle(this.getWidth() / 2, this.getHeight() / 2, clipRadiusWidth, paint);
3//白色的圆边框
4canvas.drawCircle(this.getWidth() / 2, this.getHeight() / 2, clipRadiusWidth, borderPaint);

正方形裁剪框的实现

绘制长方形的话主要要确定四个点的坐标 left ,top, right, botom。很简单

1left = mHorizontalPadding;
2top = this.getHeight() / 2 - clipWidth / 2;
3right = this.getWidth() - mHorizontalPadding;
4botom = this.getHeight() / 2 + clipWidth / 2;

1//绘制中间白色的矩形蒙层
2canvas.drawRect(mHorizontalPadding, this.getHeight() / 2 - clipWidth / 2,
3        this.getWidth() - mHorizontalPadding, this.getHeight() / 2 + clipWidth / 2, paint);
4//绘制白色的矩形边框
5canvas.drawRect(mHorizontalPadding, this.getHeight() / 2 - clipWidth / 2,
6        this.getWidth() - mHorizontalPadding, this.getHeight() / 2 + clipWidth / 2, borderPaint);

九宫格的

九宫格的绘制稍微繁琐一点,分三个步骤

  1. 绘制长方形边框
  2. 绘制九宫格引导线
  3. 绘制裁剪边框的是个直角

绘制长方形边框的这里就不说了,比较简单。

我们来看一下绘制九宫格引导线的

  • 绘制竖直方向两条线
  • 绘制水平方向两条线

1private void drawGuidelines(@NonNull Canvas canvas, Rect clipRect) {
2
3    final float left = clipRect.left;
4    final float top = clipRect.top;
5    final float right = clipRect.right;
6    final float bottom = clipRect.bottom;
7
8    fi

  • 9
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值