|
-
Oct 14th, 2000, 09:41 PM
#1
Does any one have any routines for taking RGB values and turning them into HEX that they would like to "make public"?
-
Oct 15th, 2000, 05:44 AM
#2
Monday Morning Lunatic
They're already hex:
0x00BBGGRR (on Intel, anyway...I think)
So:
Code:
unsigned short usRed;
unsigned short usGreen;
unsigned short usBlue;
unsigned long ulColour = 0xaabbcc;
usRed = ulColour;
usGreen = ulColour >> 8;
usBlue = ulColour >> 16;
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 15th, 2000, 09:51 AM
#3
I dont think thats HEX, but if it is, thats not the kind im talking about. Im talking about the kind used for color values in HTML.
-
Oct 15th, 2000, 10:11 AM
#4
Monday Morning Lunatic
Oops...silly me. I thought you wanted to split the numbers up 
In that case, how about this to convert it to a hex string:
Code:
unsigned long lColour = 0xccbbaa;
char *pcHexStr = "#000000";
char cTemp;
for(int i = 0; i < 6; i++) {
cTemp = (lColour >> (i*4)) & 0x0f;
pcHexStr[i+1] = cTemp + ((cTemp > 9) ? ('a' - 0xa) : '0');
}
cout << pcHexStr << endl
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 15th, 2000, 08:37 PM
#5
I cant seem to get it to work. Every time it comes to that code, windows says the app has crashed.
-
Oct 16th, 2000, 01:40 PM
#6
Monday Morning Lunatic
I don't know what it is, then, since it worked perfectly on mine. Did you copy the code directly, or have you changed it at all? Remember - the buffer must be at least 7 characters long.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|