Transparency in Java Imaging

  • Thread starter Bernhard Messerer
  • Start date
B

Bernhard Messerer

Hi all!

When I have multiple images in Java (I'm using JAI, but I thing this has
to do with ColorModel, which is present in AWT) which I want to stack
above each other, is there any possibility to define white as
"transparent", i.e. whenever an image contains white pixels they should
not be drawn... any ideas?
If this is impossible, how else do I use transparency when drawing
images? (i.e. how can I stack them, without each overwriting the image
below it)?

thanks in advance and kind regards,

Messi
 
J

JCM

Hi Messi,

I presume you're loading in these images from external files. One
solution is to simply set those pixels as transparent in an image
editing program. For example, if you save GIF files in Photoshop with
a certain color marked as transparant, Java will do the right thing.

-Josh
 
N

Neomorph

JCM,

Thanks for your replies. Yes, currently I'm using images with integrated
alpha channel, but this proves difficult, as the images get larger and
because of the sheer mass of images, it is diffcult to add an alpha
channel everywhere; also, other applications cannot use the images
anymore then...
The second approach has the flaw that it exclusively works with AWT
images where one can use getRGB() and setRGB(). This doesn't seem to be
an option, as I'm using JAI RenderedOps. Earlier I used BufferedImages
(which provide getRGB() and setRGB()) methods but that was _very_ slow
decoding images into BIs (I have no idea why, it shouold simply contain
a raster of pixels, right?).

You can also create your own image from a buffer (array) of int-s using a
MemoryImageSource.
Each int is one pixel: (8bit alpha)(8-bit red)(8-bit green)(8-bit blue)
(most significant bits on the left, of course).

If you change the contents of the int array, you can directly change colors
and alpha channel in the fastest way.

I used this for a mandelbrot generator :)
 
B

Bernhard Messerer

Thanks for your response,

This allows me to do it for AWT imaging; However, this is too slow (as I
have e.g. three layers 8x5 images = 40x3=120 images, 80 to overlay). I
first tried with AWT imaging but converted to JAI because the latter was
MUCH faster... and how to do it there?

regards,

Messi

Check the article with source code at:

"Maintaining Transparency for Image Transformations"
http://www.developer.com/java/other/article.php/895051

Thanks,

-----Original Message-----
From: Bernhard Messerer [SMTP:[email protected]]
Posted At: Wednesday, August 06, 2003 4:56 AM
Posted To: comp.lang.java.programmer
Conversation: Transparency in Java Imaging
Subject: Transparency in Java Imaging

Hi all!

When I have multiple images in Java (I'm using JAI, but I thing this
has
to do with ColorModel, which is present in AWT) which I want to stack
above each other, is there any possibility to define white as
"transparent", i.e. whenever an image contains white pixels they
should
not be drawn... any ideas?
If this is impossible, how else do I use transparency when drawing
images? (i.e. how can I stack them, without each overwriting the image

below it)?

thanks in advance and kind regards,

Messi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top