BufferedImage & ColorModel in Java
Posted
by spol
on Stack Overflow
See other posts from Stack Overflow
or by spol
Published on 2010-04-08T06:03:24Z
Indexed on
2010/04/09
5:33 UTC
Read the original article
Hit count: 200
I am using a image processing library in java to manipulate images.The first step I do is I read an image and create a java.awt.Image.BufferedImage object. I do it in this way,
BufferedImage sourceImage = ImageIO.read( new File( filePath ) );
The above code creates a BufferedImage ojbect with a DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0. This is what happens when I run the above code on my macbook.
But when I run this same code on a linux machine (hosted server), this creates a BufferedImage object with ColorModel: #pixelBits = 24 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@c39a20 transparency = 1 has alpha = false isAlphaPre = false.
And I use the same jpg image in both the cases. I don't know why the color model on the same image is different when run on mac and linux. The colormodel for mac has 4 components and the colormodel for linux has 3 components.There is a problem arising because of this, the image processing library that I use always assumes that there are always 4 components in the colormodel of the image passed, and it throws array out of bounds exception when run on linux box. But on macbook, it runs fine.
I am not sure if I am doing something wrong or there is a problem with the library. Please let me know your thoughts. Also ask me any questions if I am not making sense!
© Stack Overflow or respective owner