PDA

Click to See Complete Forum and Search --> : Converting RGB() to R G and B Values


mystiq
Nov 27th, 1999, 02:52 AM
The tip doesn't work:
Public Function UnRGB(RGBCol As Long, Part As Integer) As Integer
'Part: 0=Red, 1=Green, 2=Blue

Select Case Part
Case 0
UnRGB = RGBCol And &HFF
' mask 000000000000000011111111 and shift bits right
Case 1
UnRGB = (RGBCol And &HFF00) / &HFF
' mask 000000001111111100000000 and shift bits right
Case 2
UnRGB = (RGBCol And &HFF0000) / &HFFFF
' mask 111111110000000000000000 and shift bits right
End Select

End Function


It overflows on G and B value, but R works right, i need a working one :-) It's supposed to convert an RGB value (such as the RGB function) into the specified part (R G or B).

------------------
-Mystiq

[This message has been edited by mystiq (edited 11-27-1999).]

[This message has been edited by mystiq (edited 11-27-1999).]

joey o.
Nov 27th, 1999, 05:44 AM
Please tell me what this is supposed to do before I try to answer. Is it supposed to return the value of a color selected,covert colors coded in other formats, or something different? I want to try to help.

mystiq
Nov 27th, 1999, 08:17 AM
In other words: unRGB(RGB(255,128,64),1) should return 128, because 1 is green, and the green value is 128. But the function doesn't work, it'll overflow, only red works.

------------------
-Mystiq

Aaron Young
Nov 27th, 1999, 12:40 PM
Try this instead:

Public Function UnRGB(ByVal RGBCol As Long, ByVal Part As Integer) As Integer
UnRGB = Val("&H" & Mid$(Right$("000000" & Hex(RGBCol), 6), 5 - (2 * Part), 2))
End Function


------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

mystiq
Nov 27th, 1999, 12:43 PM
Yay, that works, thanks :)

------------------
-Mystiq