Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have hex I need RGB

Status
Not open for further replies.

Hawkeye123456

Programmer
May 5, 2000
24
0
0
US
Is there a way to comvert he values back to RGB???
 
Hi Hawkeye,<br><br>Can you give an example? For instance, are you dealing with 6 digit hex values, or three separate ones?<br><br>It's my understanding that an RGB value is simply a 24 bit number where the most-significant byte represents Red, the next Green, and the least-significant byte represents Blue. If your hex value is in this format then it's already in RGB format.<br><br>If you have the colours as three separate hex values, then the RGB function will do the maths and assemble them into one 24-bit number.<br>e.g.<br>&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;'These are integers.<br>&nbsp;&nbsp;&nbsp;MyRed = &H30<br>&nbsp;&nbsp;&nbsp;MyGreen = &HFF<br>&nbsp;&nbsp;&nbsp;MyBlue = &H10<br><br>&nbsp;&nbsp;&nbsp;'MyRGB is a long.<br>&nbsp;&nbsp;&nbsp;MyRGB = RGB(MyRed, MyGreen, MyBlue)<br><br>will place the composite RGB value in MyRGB.<br><br>Hope this helps. Post more details if it doesn't.<br><br>Regards,<br>Tim
 
ok here is my example.&nbsp;&nbsp;I have a program that uses RGB values to show a color and HEX value.&nbsp;&nbsp;(#FFFFFF=white=255,255,255)<br><br>I want to let the user use the common dialog box to chooe a color, and then move the bars to the correct spots to represent the color.
 
not sure if this is of any help, but this is the source code of a very simple color choser I wrote<br>(R G B are the scrollbars, theres a Picture box, and a couple of labels, to show indivisual hex for r and g and so on, and one with them combine, only if its one digit, it shows 1 digit instead of 0F)<br><br>Option Explicit<br><br>Private Sub B_Change()<br>change<br>End Sub<br><br>Private Sub Form_Load()<br>change<br>End Sub<br><br>Private Sub G_Change()<br>change<br>End Sub<br><br>Private Sub R_Change()<br>change<br>End Sub<br><br>Sub change()<br>Picture1.BackColor = RGB(R.Value, G.Value, B.Value)<br>Label1.Caption = &quot;# &quot; & Hex(R.Value) & Hex(G.Value) & Hex(B.Value)<br>Label2.Caption = Hex(R.Value)<br>Label3.Caption = Hex(G.Value)<br>Label4.Caption = Hex(B.Value)<br>End Sub<br> <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML,Visual InterDev 6, ASP(WebProgramming), QBasic(least i didnt start with COBOL)
 
Here is one more example.&nbsp;&nbsp;I use the hex function on the commondialog color and then I need to get the correct RGB values out of each of the values.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top