gpt4 book ai didi

android - 在矩形外填充 Canvas

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:08:01 26 4
gpt4 key购买 nike

我想填充 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com