Post by chriscrawford on Aug 19, 2015 8:52:45 GMT -8
Once again I have fought the idiocies of Java, and again I have triumphed by cheating. Here's the problem: I am trying to draw the actor's face onto the main screen. First I draw it using the face drawing package I created last year. This produces a PNG image with the face and a transparent background. I then draw that PNG image onto the main window, with this result:
Whut the hay-ill? What is this white background??? It's a transparent background; I have checked that a dozen times and it is created with a transparent background and that transparent background is preserved throughout the drawing process. Yet it imposes a white background no matter what I try.
After a day wasted fighting Java, trying to get it maintain the transparent background, I came up with another kluge to force Java to do what I want. I created a mask of the background face. This is a copy of the background face with the brightness set to zero, so that the face is reduced to black and white, like so:
I then draw the face as usual into its PNG image, and THEN draw that result on top of the mask image using an AlphaComposite with source mode = Source In. This draws the face PNG into the mask, but ONLY where there's some image in the mask -- the black area. This wipes out the white background, producing the desired result:
The moral of the story is this: don't try to do it the way they want you to do it, just do it any way that works and move on to the next problem. Of course, you pros know that there are a few details I'm leaving out, and there is a weakness in my solution, but the basic concept is sound: I Hate Java because it doesn't do what it claims to do.
Whut the hay-ill? What is this white background??? It's a transparent background; I have checked that a dozen times and it is created with a transparent background and that transparent background is preserved throughout the drawing process. Yet it imposes a white background no matter what I try.
After a day wasted fighting Java, trying to get it maintain the transparent background, I came up with another kluge to force Java to do what I want. I created a mask of the background face. This is a copy of the background face with the brightness set to zero, so that the face is reduced to black and white, like so:
I then draw the face as usual into its PNG image, and THEN draw that result on top of the mask image using an AlphaComposite with source mode = Source In. This draws the face PNG into the mask, but ONLY where there's some image in the mask -- the black area. This wipes out the white background, producing the desired result:
The moral of the story is this: don't try to do it the way they want you to do it, just do it any way that works and move on to the next problem. Of course, you pros know that there are a few details I'm leaving out, and there is a weakness in my solution, but the basic concept is sound: I Hate Java because it doesn't do what it claims to do.