# 如何在canvas上的两点之间绘制弧？

` `float radius = 20; final RectF oval = new RectF(); oval.set(point1.x - radius, point1.y - radius, point1.x + radius, point1.y+ radius); Path myPath = new Path(); myPath.arcTo(oval, startAngle, -(float) sweepAngle, true);` `

` `int startAngle = (int) (180 / Math.PI * Math.atan2(point.y - point1.y, point.x - point1.x));` `

` `@Override protected void onDraw(Canvas canvas) { Paint p = new Paint(); RectF rectF = new RectF(50, 20, 100, 80); p.setColor(Color.BLACK); canvas.drawArc (rectF, 90, 45, true, p); }` `

` ` int sweepAngle = (int) (360 * (getProgress() / 100.f));` `

` ` int startAngle = 270 - sweepAngle / 2;` `

1. 它总是从左侧开始，从上到下。 所以顶部的起始angular度等于270（注意顺时针旋转，0 = 3点，所以12点钟等于270度）
2. 接下来，我想计算一下我将从我的出发点（270）离开多远，并且这样做，我只计算一半的扫描angular度，因为只有一半的弧线将在左侧，另一半在右边。

` `sweepAngle = 90 degrees (90 degrees is quarter of a circle) start angle = 225 (45 degrees away from 270)` `

` `public static Bitmap clipRoundedCorner(Bitmap bitmap, float r, boolean tr, boolean tl, boolean bl, boolean br) { int W = bitmap.getWidth(); int H = bitmap.getHeight(); if (r < 0) r = 0; int smallLeg = W; if(H < W ) smallLeg = H; if (r > smallLeg) r = smallLeg / 2; float lineStop = r/2; Path path = new Path(); path.moveTo(0,0); if(tr) { path.moveTo(0, lineStop); path.arcTo(new RectF(0,0, r,r), 180, 90, false); } path.lineTo(W-lineStop, 0); if(tl) path.arcTo(new RectF(Wr,0, W,r), 270, 90, false); else path.lineTo(W, 0); path.lineTo(W, H-lineStop); if(bl) path.arcTo(new RectF(Wr,Hr, W,H), 0, 90, false); else path.lineTo(W, H); path.lineTo(lineStop, H); if(br) path.arcTo(new RectF(0,Hr, r,H), 90, 90, false); else path.lineTo(0,H); if(tr) path.lineTo(0,lineStop); else path.lineTo(0,0); Bitmap output = Bitmap.createBitmap(W, H, Config.ARGB_8888); Canvas canvas = new Canvas(output); final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(Color.BLACK); canvas.drawPath(path, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, 0, 0, paint); return output; }` `
• 一劳永逸，如何正确保存Fragments的实例状态到后退栈？
• 如何在Retrofit库中设置超时？
• 如何从代码获取设备的IP地址？
• 我如何使用我的应用程序的付费版本作为免费版本的“钥匙”？
• 在Mac OS X上设置adb
• 如何在Android的蓝牙打印机上打印图像？
• 使用proguard删除日志通话
• 通知通过旧的意图附加
• Android：从preferences.xml开始活动
• 当它是一个引用（主题）时，以编程方式获取颜色值
• 无法find哈希stringandroid-23的目标