开发者

Alpha compositing issues

Say I want to create a custom control that would look something like this:

http://karmalita.com/stuff/alpha1.png

The width of the popup balloon can change, and the relative position of the "pointer triangle" can change as well. Of course, additional graphics/text will be drawn on top.

I want it based on images, rather than trying to do the whole thin开发者_StackOverflowg vector. And of course, the images have varying translucency, which is where the complications arise.

I know there are various ways of doing it (currently I use four images, one of which gets copied a bunch of times....it works but is messy), but I'm interested in finding the easiest, cleanest way. What would be nice would be if I could use a nine-patch for the main rectangle (below left), then draw the pointer triangle (below right) on top of it.

http://karmalita.com/stuff/alpha2.png

But of course that won't work, since the bottom edge of the rectangle will bleed through the pointer triangle, and the shadows will accumulate, etc.

Is there some Porter-Duff magic I can do?

Or should I simply mask the area of the pointer using an inverse clip rect, then draw the nine-patch (stretched appropriately), so it looks like this....

http://karmalita.com/stuff/alpha3.png

....then remove the clip rect, then draw the pointer triangle in the area where the clip rect was?

Or what? Is there an easier/better/more efficient way?

Although I'd love a solution for this specific problem, I'm mostly interested in a general solution for these sorts of scenarios.


Interesting one...

I was about to say "No, there's no way except the inverse clip-rect solution", but I have an (untested) idea:

When you add the arrow section to the regular 9-patch balloon, the result (luckily) is that all the pixels get more opaque.

Therefore (and here's the untested bit) you should be able to pre-calculate a modified version of the 'arrow' patch which - when applied on top of the regular balloon, gives the correct effect: For example the resulting arrow patch would have less shadow where the regular patch already contributes.

I'll let you think about the maths for that, but I guess it's pretty straightforward.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜