在矩形外部填充画布
我想填充画布上矩形之外的区域。我用来
canvas.drawRect(pTopLeft.x, pTopLeft.y, pBotRight.x, pBotRight.y, paint);
绘制矩形,但不知道如何填充矩形/剪辑之外。
谢谢 杰夫
I want to fill the area outside a rectangle on a canvas. I use
canvas.drawRect(pTopLeft.x, pTopLeft.y, pBotRight.x, pBotRight.y, paint);
to draw the rectangle, but can't figure out how to fill outside the rectangle/clip.
Thanks
Geoff
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
谢谢 ted 和 trojanfoe - 我想出的最好的解决方案是
Thanks ted and trojanfoe - the neatest solution I've come up with is
你不会在剪辑之外填充;这就是剪辑要防止的事情!如果要填充矩形外部和绘图层边界内部的空间,请构造四个辅助矩形:
然后填充它们。
You aren't going to fill outside the clip; that's the kind of thing clip is there to prevent! If you want to fill the space outside a rect and inside the drawing layer bounds, construct four auxiliary rects:
Then fill these.
ICS及以上...
参考Android:如何在API15中使用clipRect
ICS and above ...
Reference Android: Howto use clipRect in API15
您无法在
Canvas
之外进行绘制;该区域属于父View
。您是否有能力子类化父View
并在该类中进行绘图?如果您想在
Canvas
剪辑之外进行绘制,则必须invalidate()
您感兴趣的区域。You can't draw outside of the
Canvas
; that area belongs to the parentView
. Do you have the ability to subclass the parentView
and do your drawing in that class instead?If you want to draw outside of the
Canvas
clip then you'll have toinvalidate()
the areas you are interested in.