Re: Invert image colours



k0m0r schrieb:
Hmm maybe I was asking a wrong question.
I have a BufferedImage and I need to convert the colour of every pixel
to the opposite value,
for example if the rgb is (0,100,255), I need to convert it to
(255,155,0).
I was trying with a manual, but don't know a few things:

I've got two loops:

0 < x < image.getWidth()
0 < y < image.getHeight()

Inside, I can get the RGB value of every pixel:

int rgb = image.getRGB(x,y);

Now, how can I convert this value to the way I want?
I know the RGB contains also alpha value - and I want this to stay
untouched.
Rest of the values should be set to (255-value) and then set back into
int rgb.
How can I do that?
int rgb = image.getRGB(x,y);
rgb = rgb ^ 0x00FFFFFF; // ^ is the bit-wise exclusive-or
image.setRGB(x, y, rgb);

--
Thomas
.



Relevant Pages

  • Re: confused about image colorspaces
    ... says "setRGB(int x, int y, int rgb) Sets a pixel in this BufferedImage ... how to code an "int rgb", so I assumed that was just an INDEX in the LUT ... Sets a pixel in this BufferedImage to the specified RGB value. ...
    (comp.lang.java.programmer)
  • Re: Open RGB Explicit Little endian Dicom Image
    ... I am trying to open RGB Explicit Little endian Dicom Image.Which Tag ... somehow think the transfer syntax conveys some parsing of multiple ... - samples per pixel to set up the correct JPEG header ... One, three, and four image planes are defined. ...
    (comp.protocols.dicom)
  • Re: Contious optical receiver
    ... What differ a prism from a RGB mask? ... So you say the blending a CCD record is not physical? ... The sensor array has a color filter mask over it so each "pixel" is ...
    (sci.physics)
  • Re: interpolation for a color image?
    ... produce a result that is the same as box interpolation of RGB. ... interpolation errors on reparate RGB channels may produce a new pixel value slightly ... store the RGB ratios for each pixel, i.e., keep the original image, convert ...
    (sci.image.processing)
  • Re: Finding Color of Specific Pixel in Loaded Image
    ... Some documentation I read says this is an RGB value... ... You can "see" the individual byte data by viewing the Long in hex format. ... Private Type RGBcolors ... If you want to do it faster then you need to speed up the slow part of the whole process (which is reading the Long value from the pixel in the first place). ...
    (microsoft.public.vb.general.discussion)