• Post Reply Bookmark Topic Watch Topic
  • New Topic

BufferedImage get/setRGB

 
lajos kamocsay
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm working on a project that involves image manipulation.

The getRGB method of a BufferedImage class returns an int, of type "TYPE_INT_ARGB". The setRGB method expects the RGB value as an int.

What's the best way of converting this int to the red green and blue components? Is there a wrapper class? (I found ColorModel, but that only works on Raster classes, and doesn't have set methods (why?))

Thanks,
Kamo
 
Mike Cole
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use bitshifting, you can make your own class around it.

Thats the way how a integer-color is build up (argb)
alpha = 0xff000000 = alpha 255
red = 0x00ff0000 = red 255
green = 0x0000ff00 = green 255
blue = 0x000000ff = blue 255

So to add the blue to your int value you can just add it.
For the others you�ll need to shift them to the left.
(8,16,24)
---
You can write a test-prog. and print out the value of the in as hex
sout(String.format("0x%08X",color));
 
Mike Cole
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahh.. i forgot.
To get the values out of an int. You need bitmasking.
 
lajos kamocsay
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

I was afraid I had to do some surgery like that.
I wish there was a Pixel class...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!