#### Archived

This topic is now archived and is closed to further replies.

# whats the formula for inverting color/

This topic is 5820 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi say I have an RGBA value of 100,120,200,230. How would i get the inverse? it cant possibly be 1/200, 1/120,1/200, 1/230! thanks for help
:::Al:::
[Triple Buffer V2.0] - Resource leak imminent. Memory status: Fragile

##### Share on other sites
255-r,255-g,255-b,255-a

##### Share on other sites
Every RGBA component has a value of 0 to 255. So an inverted color is 255-the value.
R,G,B,A -> 255-R, 255-G, 255-B, 255-A

##### Share on other sites
thanks a bunch

:::Al:::
[Triple Buffer V2.0] - Resource leak imminent. Memory status: Fragile

##### Share on other sites
You can also do this:
R= R*-1 + 255
G= G*-1 + 255
B= B*-1 + 255

or
R = ~R;
G = ~G;
B = ~B;

##### Share on other sites
What does that mean???

##### Share on other sites
Andos:

~ for integers is a "bitwise NOT".

i.e. every binary 1 bit becomes a 0 and vice versa.

We could go on for days posting subtle and obfuscated code snippets which all do the same basic thing of inverting the colour. I think the basic question has been answered though

r = r^255;
g = g^255;
b = b^255;

--
Simon O'Connor
Creative Asylum Ltd
www.creative-asylum.com

[edited by - S1CA on December 8, 2002 11:15:21 AM]

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633298
• Total Posts
3011259
• ### Who's Online (See full list)

There are no registered users currently online

×