-
May 21st, 2017, 02:14 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Color Conversion
How do I convert &H00FFF8F0& to RGB?
Thanks
-
May 21st, 2017, 03:02 PM
#2
Re: Color Conversion
Try this
Code:
Dim c As Color = ColorTranslator.FromWin32(&H00FFF8F0&)
Debug.WriteLine("R=" & c.R & ", G=" & c.G & ", B=" & c.B)
-
May 21st, 2017, 03:39 PM
#3
Re: [RESOLVED] Color Conversion
@AccessShell
Keep in mind that &HFFF8F0 is #F0F8FF in Html colors (because in binary format R is in lower byte so is in right position when we
read a hex value).
Code:
Sub rgb(color, r, g, b)
Dim ba$
ba$ = Hex$(color)
ba$ = Right$("00000" & ba$, 6)
r = Val("&h" & Mid$(ba$, 1, 2))
g = Val("&h" & Mid$(ba$, 3, 2))
b = Val("&h" & Mid$(ba$, 5, 2))
End Sub
Sub test()
Dim r, g, b
rgb &HFF8000, r, g, b
Debug.Print r, g, b
End Sub
@4x2y
This is for vb6...your code it isn't for vb6.
-
May 21st, 2017, 04:22 PM
#4
Thread Starter
Fanatic Member
Re: [RESOLVED] Color Conversion
Got that. I understand now. The original code I received fro 4x2y did not work. The code I got now from georgekar works. Thanks
-
May 22nd, 2017, 03:13 PM
#5
Re: [RESOLVED] Color Conversion
Sorry, didn't notice it is VB6 question, anyway here is another method (named ToRGB in order to not shadow the built-in function RGB)
Code:
Private Sub ToRGB(lngColor As Long, R As Integer, G As Integer, B As Integer)
R = (lngColor And &HFF0000) \ &H10000
G = (lngColor And &HFF00&) \ &H100&
B = lngColor And &HFF&
End Sub
Private Sub test()
Dim R As Integer, G As Integer, B As Integer
ToRGB &HFFF8F0, R, G, B
Debug.Print "R=" & R & ", G=" & G & ", B=" & B
End Sub
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
|