Results 1 to 9 of 9
- 03-03-2010, 10:31 AM #1
BufferedImage - greyscale - color information
Hi,
I read a grey-scale image (sample_image.bmp) and i want to output a colour information.
But now I'm confused. Why isn't the rgb value represents a black colour?Java Code:public static void main(String[] args) throws Exception { BufferedImage bi = ImageIO.read(new File("sample_image.bmp")); System.out.println(bi.getRGB(0, 0)); System.out.println(Integer.toHexString(bi.getRGB(0, 0))); }
I understand, that the type of the image is TYPE_BYTE_GREY but how can i get the "black" colour information in hex? or how to acquire the value of the grey tone?
Suggestions?
Thanks!"There is no foolproof thing; fools are too smart."
"Why can't you solve my Problem ?"
- 03-03-2010, 06:58 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
Did you check the type of your BufferedImage? .bmp format isn't necessarily black and white (although some pictures may look like that).
kind regards,
Jos
- 03-03-2010, 07:10 PM #3
The type of the input image is TYPE_BYTE_GREY.
But why it isnt black? Gimp shows #040404 as a color value (of the pixel [0,0]).
But the output of the HexString is FF222222. That does not look right. The first FF is the A value and thats allright. But the 222222 does not match 040404."There is no foolproof thing; fools are too smart."
"Why can't you solve my Problem ?"
- 03-03-2010, 08:30 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
Hm, your code snippet does make sense and I've seen gimp play funny tricks before and 0x222222 is a very dark gray value ... and I played a bit with your little duck image and that value does make sense: that background value is indeed 0x222222 with full opacity.
kind regards,
Jos
- 03-03-2010, 09:14 PM #5
so gimp isn't right here
*trying irfanview*
thanks!"There is no foolproof thing; fools are too smart."
"Why can't you solve my Problem ?"
- 03-03-2010, 09:23 PM #6
hm...
irfanview also says, that RGB: 4,4,4 is right :-(
if i try to copy and write the new image back it is brighter... somehow i don't understand whats going wrong
Java Code:public static void main(String[] args) throws Exception { BufferedImage bi = ImageIO.read(new File("sample_image.bmp")); System.out.println(bi.getRGB(0, 0)); System.out.println(Integer.toHexString(bi.getRGB(0, 0))); BufferedImage biCopy = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_INT_RGB); for (int x = 0; x < bi.getWidth(); x++) { for (int y = 0; y < bi.getHeight(); y++) { biCopy.setRGB(x, y, bi.getRGB(x, y)); } } ImageIO.write(biCopy, "bmp", new File("sample_out.bmp")); }"There is no foolproof thing; fools are too smart."
"Why can't you solve my Problem ?"
- 03-03-2010, 09:54 PM #7
- 03-03-2010, 10:22 PM #8
i hate doing evil hacks :-(
but is there any other options besides THIS:
Java Code:public static void main(String[] args) throws Exception { BufferedImage bi = ImageIO.read(new File("sample_image.bmp")); System.out.println(bi.getRGB(0, 0)); System.out.println(Integer.toHexString(bi.getRGB(0, 0))); BufferedImage biCopy = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_INT_RGB); for (int x = 0; x < bi.getWidth(); x++) { for (int y = 0; y < bi.getHeight(); y++) { int gray = bi.getRaster().getPixel(x, y, (int[]) null)[0]; int rgbVal = (gray << 16) + (gray << 8) + (gray); biCopy.setRGB(x, y, rgbVal); } } ImageIO.write(biCopy, "bmp", new File("sample_out.bmp")); }"There is no foolproof thing; fools are too smart."
"Why can't you solve my Problem ?"
- 03-04-2010, 10:09 AM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
There's another workaround in the bug report (see your own link) but then you end up with a LUT image, I don't know it you want that. I never noticed this (old) bug. I opened your image in a MS image manipulation program and indeed it shows a bit darker than it shows up in my Java code; strange ...
kind regards,
Jos
Similar Threads
-
BufferedImage rgb
By Bill87 in forum New To JavaReplies: 2Last Post: 02-25-2010, 06:31 PM -
[COLOR="Navy"]execute .bat file in mysql [/COLOR]
By msankar.ravi in forum NetworkingReplies: 0Last Post: 02-24-2010, 04:27 AM -
Using BufferedImage
By timkd127 in forum New To JavaReplies: 5Last Post: 12-19-2009, 09:17 PM -
BufferedImage through FTP
By dudejonne in forum New To JavaReplies: 7Last Post: 11-05-2009, 05:36 PM -
BufferedImage to Byte
By Java Tip in forum Java TipReplies: 0Last Post: 01-22-2008, 08:17 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks