scaling transparent images
843807Jan 28 2005 — edited Jan 31 2005I have a set of Images that have transparent sections. If I do plain drawImages on them, it works fine, the background shows through the transparent sections exactly as one would expect. But in some places I have to shrink the images. I tried doing getScaledImage and then drawImage'ing the result, but when I did this, the transparent pixels all turned black. I tried using the drawImage that scales on the fly with the same result.
My images are loaded from GIF files, so they all use an indexed color model with one color designated transparent.
I couldn't find anything in the documentation that discusses transparency when scaling. Does it just not work? Is there a trick to it, some magic parameter I should specify?
(I finally came up with a workaround where I basically wrote my own "scale image" function. To keep it simple I only handle the exact case I need to deal with, which is indexed color model images that are to be reduced by 50% in each dimension, which I handle by just picking up the pixel from every second row and every secone column and ignoring the other pixels -- no averaging or anti-aliasing or anything like that. The quality looked fine for the couple of images I tried it on -- better than I expected, actually. My case was limited enough that writing this scale function wasn't that tough, but obviously this logic doesn't work for more general cases, so I'd still like to have a more general solution.)
Oh, I'm using Java 1.4.2.