Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (524)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [s] how to create BufferedImage from alpha raster?  (Read 1493 times)
0 Members and 1 Guest are viewing this topic.
Offline TheBohemian

Junior Devvie




Java will rule them all!


« Posted 2004-03-25 00:00:33 »

I want to separate the alpha channel of a BufferedImage (getAlphaRaster() ) and generate a new one which will look like a grey-scale image then.

My problem is that I do not find the right ColorModel which i can pass to the constructor of BufferedImage.

Has anyone done this before and can help?

cya

TheBohemian

---------------------------------------
my favorite OS: http://jnode.sf.net
Java 1.5 -> 1.4 converter: http://retroweaver.sf.net
Offline TheBohemian

Junior Devvie




Java will rule them all!


« Reply #1 - Posted 2004-04-02 08:04:12 »

I have solved the problem on my own. Here is how it goes:

First make sure the image really has a separate alpha channel. If image.getTransparency() == Transparency.TRANSLUCENT holds then image.getAlphaRaster() will not return null.

The generation of a BufferedImage which contains only the alpha channel requires ColorModel instance which matches the format of the alpha raster (the primary problem). Such a ColorModel can be created this way:

ColorModel grayscaleColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY),
       new int[] {8}, false, false, ComponentColorModel.BITMASK, DataBuffer.TYPE_BYTE);
       
As you see the alpha channel is treated as a grayscale image. With that colormodel the BufferedImage can be created this way:

BufferedImage maskImage = new BufferedImage(grayscaleColorModel, image.getAlphaRaster(), false, new Hashtable());

Now we have an image which can be drawn into other (for iinstance RGBA) images.

cya

TheBohemian

---------------------------------------
my favorite OS: http://jnode.sf.net
Java 1.5 -> 1.4 converter: http://retroweaver.sf.net
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (23 views)
2014-11-25 11:26:43

Gibbo3771 (22 views)
2014-11-24 19:59:16

trollwarrior1 (36 views)
2014-11-22 12:13:56

xFryIx (74 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (41 views)
2014-11-12 21:09:33

kovacsa (69 views)
2014-11-07 19:57:14
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!