【发布时间】:2014-05-06 13:56:57
【问题描述】:
如何绘制两个矩形和路径的交集。看这张图。
图 1 是我现在所拥有的。图2是我想要实现的。这是我的观点的代码:
public class MyView extends View {
public MyView(Context context) {
super(context);
}
public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paintRectA = new Paint();
Paint paintRectB = new Paint();
Paint paintPath = new Paint();
paintRectA.setColor(Color.BLUE);
paintRectB.setColor(Color.RED);
paintPath.setColor(Color.CYAN);
RectF rectA = new RectF(0, 0, 50, 100);
RectF rectB = new RectF(50, 0, 100, 100);
Path path = new Path();
path.lineTo(100, 0);
path.quadTo(50, 100, 0, 0);
path.close();
canvas.drawRect(rectA, paintRectA);
canvas.drawRect(rectB, paintRectB);
canvas.drawPath(path, paintPath);
}
}
【问题讨论】:
-
了解 porter duff xfer 模式
标签: android canvas path intersection