Making color image with transparency into black & white w/transparency
- From: gswarthout@xxxxxxxxx
- Date: 29 Mar 2007 09:59:36 -0700
I need to turn a series of icon images into black & white equivalents
programattically in a paint method.
I'm starting with roughly circular images which are colored within and
everything outside of the circle is transparent. The transparency
displays properly when the images are used in their normal form.
On the fly, however, I want to recolor select images into gray-scale
reflections of their original form, which I do with the following
code:
<Code>
BufferedImage grayImage = new BufferedImage(usableWidth, usableHeight,
BufferedImage.TYPE_BYTE_GRAY);
Graphics2D grayGraphics = grayImage.createGraphics();
grayGraphics.drawImage(originalImage, 0, 0, usableWidth, usableHeight,
this);
</Code>
This produces the effect I want with one problem, the previously
transparent corners of the image are now black. I then draw this gray-
scale image into a new image which allows for transparency thusly:
<Code>
BufferedImage bufferedImage = new BufferedImage(usableWidth,
usableHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = bufferedImage.createGraphics();
g2d.drawImage(grayImage, 0, 0, usableWidth, usableHeight, this);
</Code>
to being transparent (ignoring that it would turn all other instancesFrom here I have been unable to find a way to change the corners back
of black transparent as well). I've tried XORing black with white
and, sure enough, this turns black into white and vice versa, but not
transparent. I've tried it with new (Color 255, 255, 255, 0) which
would be a fully transparent white and it still doesn't work.
How can I accomplish this feat with either A) the way I started or, B)
a better way that I haven't explored?
Any help would be appreciated.
Greg
.
- Follow-Ups:
- Re: Making color image with transparency into black & white w/transparency
- From: gswarthout
- Re: Making color image with transparency into black & white w/transparency
- From: Knute Johnson
- Re: Making color image with transparency into black & white w/transparency
- Prev by Date: Re: Horizontally scrolling JTable
- Next by Date: Re: Making color image with transparency into black & white w/transparency
- Previous by thread: SWT without Eclipse?
- Next by thread: Re: Making color image with transparency into black & white w/transparency
- Index(es):
Relevant Pages
|
|