Results 1 to 31 of 31

Thread: Convert Hexadecimal Color to RGB

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    Anywhere
    Posts
    136

    Lightbulb Convert Hexadecimal Color to RGB

    Hi Guys, is there a way to know the RGB colors of an Hexadecimal Color like &H00C0C0C0& (Gray) ?

    Thanks

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    Anywhere
    Posts
    136

    Any idea ?

    Any help ?

  3. #3
    Addicted Member
    Join Date
    Aug 2001
    Posts
    184
    if we knew the RBG from that one hex colour u would probably fidn the patten

  4. #4
    Addicted Member
    Join Date
    Aug 2001
    Posts
    184
    just found out, that grey colour = RGB(192, 192, 192)

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    Anywhere
    Posts
    136

    what do u mean ?

    Originally posted by saracen
    if we knew the RBG from that one hex colour u would probably fidn the patten
    Can you elaborate please ?

  6. #6
    Addicted Member
    Join Date
    Aug 2001
    Posts
    184
    well maybe there is a pattern that you can use to get the RGB colour from Hex

    &H00C0C0C0& = RGB(192, 192, 192

    maybe C0 = 192

    try doing that with others to 'maybe' find a pattern

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    Anywhere
    Posts
    136

    Thanks saracen

    There has been a misundersatnding !
    Wghat i want to know is how to get the RGB colors of agiven Hexadecimal

    E.g. : If a have &H0080C0FF& how can i know it's RGB ?

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    Anywhere
    Posts
    136

    Any Help ?

    So

  9. #9
    Addicted Member
    Join Date
    Aug 2001
    Posts
    184
    found the pattern, and heres a way to do it.
    not the best of ways (theres got to be better)
    Attached Files Attached Files

  10. #10
    Addicted Member
    Join Date
    Aug 2001
    Posts
    184
    errr ^^^ about that program, but the &H0080C0FF& stuff in the 1st text box and press the button

    then the RGB numbers will appear, and label 4's back colour will change

  11. #11
    Addicted Member
    Join Date
    Aug 2001
    Posts
    184
    or to miss out all these textbox's and jump straight to the colour....

  12. #12
    Addicted Member
    Join Date
    Aug 2001
    Posts
    184
    opps..
    Attached Files Attached Files

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    Anywhere
    Posts
    136

    Thumbs up Thanks Man

    Thanks, it's working greatly. Thank you for your time and support

  14. #14
    Addicted Member
    Join Date
    Aug 2001
    Posts
    184
    It's ok... i wanted to know that aswell

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    Anywhere
    Posts
    136

    One more thing

    What i wanna do. When i write msgbox label1.backcolor, i get -2147483633. how can convert this scary number to R, G and B ?

  16. #16
    Addicted Member
    Join Date
    Aug 2001
    Posts
    184
    Your getting that strange number because thats in Dec

    use

    MsgBox Text5.Text + ", " + Text6.Text + ", " + Text7.Text

    with my original code

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    Anywhere
    Posts
    136

    Yes,

    Yes, i know, But i have 3 seperate RGB colors (R, G and B) and i wanna compare them to backgrounds of controls to see if they match, in this case, i trigger a certain action ....

  18. #18
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    have you ever tried Msgbox Me.BackColor?
    it is a decimal number.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  19. #19
    Addicted Member
    Join Date
    Aug 2001
    Posts
    184
    Are the backgrounds of controls in Dec then?

    is so y convert them to rgb?

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    Anywhere
    Posts
    136

    Yes,

    Originally posted by saracen
    Are the backgrounds of controls in Dec then?

    is so y convert them to rgb?
    Yes, i think they are. I don't specify them. I open the color dialog then choose a color at design time.
    When back to runtime, i issue control.backcolor i get these numbers e.g. (-174.....). One more thing, my comparing numbers are RGB.

  21. #21
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    ok so when you get the decimals to RGB, remember that the colors are represented in decimals, so you would have to convert the RGB values to decimal by using RGB(red,green,blue) and then compare them. get what i mean
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  22. #22
    Addicted Member
    Join Date
    Aug 2001
    Posts
    184
    ok - i've lost the plot completely

  23. #23
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    ok post what RGB values you have, what decimal values you have, and ill see if i can make sense out of all this.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  24. #24

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    Anywhere
    Posts
    136

    Yes,

    what do you mena BuggyProgrammer ? Can you expain, how to convert from RGB to the value i get when i display msgbox : control.backcolor ? (-1274.....)

  25. #25
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    if you form is red, and you are trying to see if you form is red or pink ,
    if me.backcolor = 255 then '255 is red in decimals, or FF in hex
    msgbox "hi"
    end if
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  26. #26
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    you can check decimal for hex and it will show the same value

    if 255= &HFF& Then MsgBox "255 and &HFF& both means red!"
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  27. #27

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    Anywhere
    Posts
    136

    what do u mean ?

    Wait i'm a little bit lost lost here, this is my situation :
    I have let's say three values, 225, 75 and 130 which represents the RGB colors. I want then to compare these to the backcolor of the controls to see if they match with existing controls.
    If they do (match) i want to trigger a certain action.

  28. #28

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    Anywhere
    Posts
    136

    Unhappy Any Help ?

    ??

  29. #29
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    This demo will do the Conversion from: Decimal - RGB - Hex.

    So take what u need.
    (Place a MS Common Dialog Control 6.x on a Form)
    VB Code:
    1. 'Requires the Common Dialog Control 6.X Component
    2.  
    3. Option Explicit
    4.  
    5. Private Type RGBArray 'Used for both Decimal RGB, and Hex RGB storage
    6.     R As Variant
    7.     G As Variant
    8.     B As Variant
    9. End Type
    10. Dim hexRGB As RGBArray
    11. Dim decRGB As RGBArray
    12. Dim decColour As Long   'Temp storage for selected Decimal Colour
    13.  
    14. Private Sub Form_Load()
    15. 'Open the Common Dialog Colour Box
    16.     ' Set Cancel to True
    17.     CommonDialog1.CancelError = True
    18.     On Error GoTo ErrHandler
    19.     'Set the Flags property
    20.     CommonDialog1.Flags = cdlCCRGBInit
    21.     ' Display the Color Dialog box
    22.     CommonDialog1.ShowColor
    23.  
    24.     decColour = CommonDialog1.Color
    25.    
    26. 'Convert the Decimal Colour Value to RGB
    27.     decRGB.B = Int(decColour / 65536)
    28.     decRGB.G = Int((decColour - (65536 * decRGB.B)) / 256)
    29.     decRGB.R = decColour - (65536 * decRGB.B + 256 * decRGB.G)
    30.  
    31.  
    32. 'Convert the Decimal Colour Values to Hex
    33.     hexRGB.R = Format(Hex(decRGB.R), "00")
    34.     hexRGB.G = Format(Hex(decRGB.G), "00")
    35.     hexRGB.B = Format(Hex(decRGB.B), "00")
    36.    
    37.     MsgBox "Red: " & hexRGB.R & "  Green: " & hexRGB.G & "  Blue: " & hexRGB.B
    38.  
    39.   Exit Sub
    40.  
    41. ErrHandler:
    42.     ' User pressed the Cancel button
    43. End Sub


    Bruce.

  30. #30
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: what do u mean ?

    Originally posted by rogergho
    Wait i'm a little bit lost lost here, this is my situation :
    I have let's say three values, 225, 75 and 130 which represents the RGB colors. I want then to compare these to the backcolor of the controls to see if they match with existing controls.
    If they do (match) i want to trigger a certain action.
    You can use the RGB function to do this

    Code:
    If Command1.ForeColor = RGB(text1.text,text2.text,text3.text) then ...
    Hope this helps,

  31. #31
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Originally posted by BuggyProgrammer
    ok so when you get the decimals to RGB, remember that the colors are represented in decimals, so you would have to convert the RGB values to decimal by using RGB(red,green,blue) and then compare them. get what i mean
    thats what i said up there why doesnt he listen to me
    Remember, if someone's post was not helpful, you can always rate their post negatively .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width