What you want to do is set the PorterDuff mode on a Paint object; you
can then use that in any function which takes a Paint as a parameter,
and the correct transfer mode will be applied. I've assembled some
quite complex imagery in my apps this way.

String

On Apr 23, 9:47 pm, "Rob Y." <[email protected]> wrote:
> I'm having the same problem.  A Paint object treats Color.TRANSPARENT
> as 'paint transparently' - i.e. don't paint anything.  What you and I
> want is something that 'paints transparency' - ie. replace whatever
> color is there with transparency.
>
> I don't see anything in Canvas or Paint that lets you control this
> behavior.  Pretty silly, since it ought to be easy to implement.
> Maybe they could just define a Color.TRANSPARENCY that has this
> behavior.  But that would be kludgey.  You'd have to set aside a
> particular ARGB value (0xffffffff?) with that meaning, and wouldn't be
> able to use it as a normal ARGB value.
>
> There is the Canvas.drawColor(color, PorterDuff.Mode).  That lets you
> control the way the color is combined with the Canvas.  But drawColor
> is the only function that seems to support this kind of control.  So,
> I guess if all you wanted to erase was a rectangle, you could set a
> clipping rectangle and erase just that.  In fact, I think I'm going to
> try that (I am just drawing rectangles).  The other thing I was going
> to try was similar to your 'replace black with transparency' idea.  I
> think you can do that by running a getPixel loop across the whole
> bitmap, and then replacing any black pixels with transparent pixels (0
> should do the trick).  Sounds awfully inefficient, but nothing better
> seems to be provided.
>
> If somebody out there knows of a 'right' way to just get a Paint
> object to erase to transparency, please speak up before I commit the
> above atrocity.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group 
> athttp://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to