Skip to main content

Earsing Pixels..

2 replies [Last post]
bddeveloper
Offline
Joined: 2008-01-14
Points: 0

Hello,

I'm trying to erase the pixels where an image is and when I set the color to transparent and draw a filled rectangle the result is a black box where the picture is. I thought I followed the sample in the book correctly but I guess I haven't. Has anyone seen this and what is the best way to erase the pixels.

Thank you,

Scott

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
bddeveloper
Offline
Joined: 2008-01-14
Points: 0

I found a end user coding error! I was using Translucent instead of creating a Transparent color object!

For those who might need the answer here it is:
offGC.setComposite(AlphaComposite.Src);
offGC.setColor(new Color(0,0,0,1));
offGC.fillRect(x, y, width, height);

billf
Offline
Joined: 2004-02-13
Points: 0

> offGC.setColor(new Color(0,0,0,1));

BTW, that should be:

offGC.setColor(new Color(0,0,0,0));

It's also better if you can store the Color instance in a variable, so you don't need to create a new object every time. Generally speaking, you want to try to avoid allocating objects during animation, because on some players GC pauses might be noticeable. GRIN and the other hdcookbook code tries pretty hard to avoid allocating objects during animation.

Cheers,

Bill