我想填充画布上矩形外的区域.我用
canvas.drawRect(pTopLeft.x, pTopLeft.y, pBotRight.x, pBotRight.y, paint);
Run Code Online (Sandbox Code Playgroud)
绘制矩形,但无法弄清楚如何填充矩形/剪辑外.
谢谢杰夫
Geo*_*off 18
谢谢泰德和特洛伊福福 - 我提出的最好的解决方案是
Point pTopLeft = new Point();
Point pBotRight = new Point();
//TODO:set x,y for points
Rect rHole = new Rect(pTopLeft.x, pTopLeft.y, pBotRight.x, pBotRight.y);
//assume current clip is full canvas
//put a hole in the current clip
canvas.clipRect(rHole, Region.Op.DIFFERENCE);
//fill with semi-transparent red
canvas.drawARGB(50, 255, 0, 0);
//restore full canvas clip for any subsequent operations
canvas.clipRect(new Rect(0, 0, canvas.getWidth(), canvas.getHeight())
, Region.Op.REPLACE);
Run Code Online (Sandbox Code Playgroud)
你不会在剪辑之外填写; 这就是夹子有防止的东西!如果要填充rect之外的空间和绘图层边界内部,请构造四个辅助rects:
Rect above = new Rect(0, 0, canvas.getWidth(), pTopLeft.y);
Rect left = new Rect(0, pTopLeft.y, pTopLeft.x, pBotRight.y);
Rect right = new Rect(pBotRight.x, pTopLeft.y, canvas.getWidth(), pBotRight.y);
Rect bottom = new Rect(0, pBotRight.y, canvas.getWidth(), canvas.getHeight());
Run Code Online (Sandbox Code Playgroud)
然后填写这些.
| 归档时间: |
|
| 查看次数: |
7509 次 |
| 最近记录: |