开发者

On an android Canvas, how do I draw overlapping shapes with non-interacting alphas?

开发者 https://www.devze.com 2023-03-30 15:58 出处:网络
On an android Canvas, if I draw a circle with alpha 0xCC and color Color.RED and then draw another circle which partially overlaps the first circle with the same parameters, I\'ll end up with a venn d

On an android Canvas, if I draw a circle with alpha 0xCC and color Color.RED and then draw another circle which partially overlaps the first circle with the same parameters, I'll end up with a venn diagram.

Here is a random example I found (just ignore the [Text] in there). I want to draw overlapping circles like in this diagram, but I don't want the center to be darker, but I do want the whole thing to have alpha so that the map underneath is visible.

On an android Canvas, how do I draw overlapping shapes with non-interacting alphas?

Is there a way to do this directly or do I need to draw to a bitmap without alpha and then set the alpha for the whole bitmap and draw it to a canvas? (开发者_C百科I haven't used bitmaps yet, so I am not sure how they are used yet.)


The easy way would be your suggested solution, ie. drawing all circles with no alpha to a bitmap, then draw that bitmap to another one using the desired alpha. The hard way would be using blend modes, specifically PorterDuff.Mode in Android. An example can be found here.

0

精彩评论

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

关注公众号