我想填充 Canvas 上矩形以外的区域。我用
canvas.drawRect(pTopLeft.x, pTopLeft.y, pBotRight.x, pBotRight.y, paint);
绘制矩形,但无法弄清楚如何在矩形/剪辑之外进行填充。
谢谢 杰夫
最佳答案
感谢 ted 和 trojanfoe - 我想出的最巧妙的解决方案是
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);
关于android - 在矩形外填充 Canvas ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4998389/