仿造QQ头像截图

黄河水2003 2016-10-18 10:31:39


目前已经能写成这样了
我用了FrameLayout布局,下面的图片是一个ImageView,上面是我一个自定义的View,代码如下:

public class MyView extends View{

public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Bitmap bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
Canvas c1 = new Canvas(bitmap);
c1.drawARGB(150, 0, 0, 0);
Paint strokePaint = new Paint();
strokePaint.setAntiAlias(true);
strokePaint.setColor(Color.WHITE);
strokePaint.setStyle(Paint.Style.STROKE);
strokePaint.setStrokeWidth(2);
c1.drawCircle(getWidth() / 2, getHeight() / 2, 100, strokePaint);

//画圆
Bitmap circleBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
Canvas c2 = new Canvas(circleBitmap);
Paint circlePaint = new Paint();
circlePaint.setStyle(Paint.Style.FILL);
circlePaint.setColor(Color.RED);
circlePaint.setAntiAlias(true);
c2.drawCircle(getWidth() / 2, getHeight() / 2, 100, circlePaint);
//两个图层合成
Paint paint = new Paint();
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
c1.drawBitmap(circleBitmap, 0, 0, paint);
paint.setXfermode(null);

canvas.drawBitmap(bitmap, 0, 0, null);
}
}


现在想请问一下各位前辈,如何截取圆形中的图案,前辈给个提示
...全文
217 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
黄河水2003 2016-10-19
  • 打赏
  • 举报
回复
快来人
黄河水2003 2016-10-19
  • 打赏
  • 举报
回复
大神们 帮帮忙 谢谢谢谢谢谢谢谢谢
黄河水2003 2016-10-19
  • 打赏
  • 举报
回复
求大神啊 没有思路啊 请前辈们指导一下
xyb618 2016-10-19
  • 打赏
  • 举报
回复
你可以把那个图片设为背景,圆圈里面是透明的,周围不透明,这样就显示中间那块
ink_s 2016-10-19
  • 打赏
  • 举报
回复
Bitmap.createBitmap(Bitmap source, int x, int y, int width, int height) 前提是你要知道你当前圆圆心所在位置,不如圆的半径为100,现在圆形在300,300点 那么bitmap=Bitmap.createBitmap(原图片, 300-100, 300-100, 200, 200) ; 就会得到一个200*200的bitmap 正好圆的直径也是200
黄河水2003 2016-10-19
  • 打赏
  • 举报
回复
引用 7 楼 ink_s 的回复:
其实我想知道你把中间截出来干嘛
就是仿照那个QQ的那个头像截图啊
ink_s 2016-10-19
  • 打赏
  • 举报
回复
其实我想知道你把中间截出来干嘛
ink_s 2016-10-19
  • 打赏
  • 举报
回复
引用 5 楼 weixin_36104376 的回复:
引用 4 楼 ink_s 的回复:
大神 提示一下
自己用画布画出来 0.0
黄河水2003 2016-10-19
  • 打赏
  • 举报
回复
引用 4 楼 ink_s 的回复:
大神 提示一下
ink_s 2016-10-19
  • 打赏
  • 举报
回复

80,490

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧