Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (604)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (653)
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 1673 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?



my favorite OS:
Java 1.5 -> 1.4 converter:
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.



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

SHC (27 views)
2015-08-01 03:58:20

Jesse (19 views)
2015-07-29 04:35:27

Riven (40 views)
2015-07-27 16:38:00

Riven (21 views)
2015-07-27 15:35:20

Riven (24 views)
2015-07-27 12:26:13

Riven (14 views)
2015-07-27 12:23:39

BurntPizza (36 views)
2015-07-25 00:14:37

BurntPizza (46 views)
2015-07-24 22:06:39

BurntPizza (30 views)
2015-07-24 06:06:53

NoxInc (37 views)
2015-07-22 22:16:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 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‑
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!