开发者

Android: how to get a Canvas' current clip path?

开发者 https://www.devze.com 2023-02-17 13:53 出处:网络
I have a situation where I am drawing to Canvas.A开发者_运维技巧s I draw, I sometimes need to update the Canvas\' clip by intersecting the clip with a given path.This works great.But, I have the situa

I have a situation where I am drawing to Canvas. A开发者_运维技巧s I draw, I sometimes need to update the Canvas' clip by intersecting the clip with a given path. This works great. But, I have the situation where I need to create a new Canvas for new series of drawing commands, but it needs to start with the previous Canvas' clip. Because Path does not expose an intersect() method, and because Canvas does not expose a getCurrentClipPath() method, the only solution I can think of is to keep a list of previously used paths, and apply them sequentially to my new canvas. However, this solution has memory and cpu ramifications.

Am I missing an obvious way to retrieve a Canvas' current clip path, or to create a new Canvas using properties (but not drawing commands) from an old one?


You should use Canvas.save() prior to installing your new clip region and then Canvas.restore() when you want to return to the old one.

  • Android javadoc: Canvas.save()
0

精彩评论

暂无评论...
验证码 换一张
取 消