invert images

A

ally

i have the problem that if i want to invert an colored image with
pixel1=-image.getRGB(i,j);
image.setRGB(i,j, pixel1);
then i get an black screen...

with an grayscaled image it works very well

can anyone help me

thanks ally
 
A

ak

pixel1=-image.getRGB(i,j);
image.setRGB(i,j, pixel1);
then i get an black screen...

int p = image.getRGB(i,j);
int r = 255 - (p & 0xFF);
int g = 255 - ((p >> 8) & 0xFF);
int b = 255 - ((b >> 16) & 0xFF);
int pi = (0xFF << 24) | (b << 16) | (g << 8) | r;
image.setRGB(i,j, pi);

____________

http://reader.imagero.com the best java image reader.
 
M

Marco Schmidt

ally:
i have the problem that if i want to invert an colored image with
pixel1=-image.getRGB(i,j);
image.setRGB(i,j, pixel1);
then i get an black screen...

See
<http://www.geocities.com/marcoschmidt.geo/java-image-faq.html#rgba>
for a description of Java's ARGB int pixel format and some sample code
for manipulating such a pixel. Inverting means subtracting each sample
(but not the transparency part) from 255.

The bitwise not operator ~ is also an option, but only applied to the
lower 24 bits:

int invPixel = (pixel & 0xff000000) | ((~pixel) & 0x00ffffff);

Regards,
Marco
 
T

Thomas Weidenfeller

ak said:
int p = image.getRGB(i,j);
int r = 255 - (p & 0xFF);
int g = 255 - ((p >> 8) & 0xFF);
int b = 255 - ((b >> 16) & 0xFF);

I would seriously consider a binary-not operation for the above part.

/Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top