• Welcome to Valhalla Legends Archive.
 

RGB Revert

Started by Networks, November 20, 2005, 05:32 PM

Previous topic - Next topic

Networks

Any clue how to get the three R-G-B values from the long RGB() outputs?

Networks

Never mind I figured it out and made my own function for it:


Public Function LongToRGBString(ByVal Color As Long) As String
    Dim HexColor    As String
    HexColor = CStr(Hex(Color))
    If (HexColor <> 0) Then
        LongToRGBString = CByte("&H" & Right$(HexColor, 2)) & ", " & CByte("&H" & Mid$(HexColor, 3, 2)) & ", " & CByte("&H" & Left$(HexColor, 2))
    Else
        LongToRGBString = "255, 255, 255"
    End If
End Function

Joe[x86]

Yeah, you figured it out. In &HFF5522, &H = long, hex; FF = Red; 55 = Green; 22 = Blue.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

MyndFyre

Quote from: Joe on November 22, 2005, 06:57 AM
Yeah, you figured it out. In &HFF5522, &H = long, hex; FF = Red; 55 = Green; 22 = Blue.

&H doesn't indicate that it's a Long variable, only that the following value is encoded in hex.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Networks

It bugged out a bit so I googled a bit and found something much more efficient and stable:


Public Function ColorCodeToRGB(lColorCode As Long) As String
    Dim lColor As Long
    lColor = lColorCode      'work long
    iRed = lColor Mod &H100  'get red component
    lColor = lColor \ &H100  'divide
    iGreen = lColor Mod &H100 'get green component
    lColor = lColor \ &H100  'divide
    iBlue = lColor Mod &H100 'get blue component

    ColorCodeToRGB = iRed & ", " & iGreen & ", " & iBlue
End Function

Joe[x86]

Quote from: MyndFyre on November 22, 2005, 03:39 PM
Quote from: Joe on November 22, 2005, 06:57 AM
Yeah, you figured it out. In &HFF5522, &H = long, hex; FF = Red; 55 = Green; 22 = Blue.

&H doesn't indicate that it's a Long variable, only that the following value is encoded in hex.

& represents long.

Dim Val&
Dim Val as Long

Dim Val$
Dim Val as String

Dim Val#
Dim Val as Double

Etc.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Networks

I think it's a hex based representation of a long value which is converted later during storage or w/e.

rabbit

Quote from: Joe on November 23, 2005, 09:53 PM
Quote from: MyndFyre on November 22, 2005, 03:39 PM
Quote from: Joe on November 22, 2005, 06:57 AM
Yeah, you figured it out. In &HFF5522, &H = long, hex; FF = Red; 55 = Green; 22 = Blue.

&H doesn't indicate that it's a Long variable, only that the following value is encoded in hex.

& represents long.

Dim Val&
Dim Val as Long

Dim Val$
Dim Val as String

Dim Val#
Dim Val as Double

Etc.
&H means "base 16", just like &O means "base 8".  Non-base 10 values default to Long anyway, unless assigned to an Integer.  Bad Joe.
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

Joe[x86]

#8
Damn misleading language. & still means long, usually. =p

EDIT -
My bad, I guess its stored in Blue-Green-Red instead of Red-Green-Blue.

Option Explicit

Public Sub Main()
    Dim m_lRGB As Long
    Dim m_bRed1 As Byte, m_bGreen1 As Byte, m_bBlue1 As Byte
    Dim m_bRed2 As Byte, m_bGreen2 As Byte, m_bBlue2 As Byte
    m_bRed1 = 1
    m_bGreen1 = 2
    m_bBlue1 = 3
    m_lRGB = RGB(m_bRed1, m_bGreen1, m_bBlue1)
    Call ReverseRGB(m_lRGB, m_bRed2, m_bGreen2, m_bBlue2)
    Call MsgBox("RGB(" & m_bRed1 & ", " & m_bGreen1 & ", " & m_bBlue1 & ")")
    Call MsgBox("RGB(" & m_bRed2 & ", " & m_bGreen2 & ", " & m_bBlue2 & ")")
End Sub

Public Sub ReverseRGB(ByVal p_lRGB As Long, ByRef r_bRed As Byte, ByRef r_bGreen As Byte, ByRef r_bBlue As Byte)
    r_bBlue = Val("&H" & Mid(Right("000000" & Hex(p_lRGB), 6), 1, 2))
    r_bGreen = Val("&H" & Mid(Right("000000" & Hex(p_lRGB), 6), 3, 2))
    r_bRed = Val("&H" & Mid(Right("000000" & Hex(p_lRGB), 6), 5, 2))
End Sub
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Networks

Quote from: Joe on November 26, 2005, 12:48 AM
Damn misleading language. & still means long, usually. =p

EDIT -
My bad, I guess its stored in Blue-Green-Red instead of Red-Green-Blue.

Option Explicit

Public Sub Main()
    Dim m_lRGB As Long
    Dim m_bRed1 As Byte, m_bGreen1 As Byte, m_bBlue1 As Byte
    Dim m_bRed2 As Byte, m_bGreen2 As Byte, m_bBlue2 As Byte
    m_bRed1 = 1
    m_bGreen1 = 2
    m_bBlue1 = 3
    m_lRGB = RGB(m_bRed1, m_bGreen1, m_bBlue1)
    Call ReverseRGB(m_lRGB, m_bRed2, m_bGreen2, m_bBlue2)
    Call MsgBox("RGB(" & m_bRed1 & ", " & m_bGreen1 & ", " & m_bBlue1 & ")")
    Call MsgBox("RGB(" & m_bRed2 & ", " & m_bGreen2 & ", " & m_bBlue2 & ")")
End Sub

Public Sub ReverseRGB(ByVal p_lRGB As Long, ByRef r_bRed As Byte, ByRef r_bGreen As Byte, ByRef r_bBlue As Byte)
    r_bBlue = Val("&H" & Mid(Right("000000" & Hex(p_lRGB), 6), 1, 2))
    r_bGreen = Val("&H" & Mid(Right("000000" & Hex(p_lRGB), 6), 3, 2))
    r_bRed = Val("&H" & Mid(Right("000000" & Hex(p_lRGB), 6), 5, 2))
End Sub


No I believe it's stored as R-G-B, the code I provided above works fine.

Joe[x86]

Yes, it extracts the value red, which is at the end of it. Then it divides by 0x100, taking the next byte one value to the right. Then it removes blue, which was in the middle. Then it divides by 0x100 again. Then it finally extracts blue, which was at the high end of it. Its extracting it in the order R G B, but its doing it backwards, so its B G R.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

iNsaNe

Why don't you just use code already given in vb6...

Form1.BackColor = RGB(R, G, B)

R = Red as Integer
G = Green as Integer
B = Blue as Integer

UserLoser

Quote from: iNsaNe on March 05, 2006, 04:46 PM
Why don't you just use code already given in vb6...

Form1.BackColor = RGB(R, G, B)

R = Red as Integer
G = Green as Integer
B = Blue as Integer

Read the topic title, RGB revert.  Meaning: he wants to get the red, green, blue values from a value already assigned from RGB()

RealityRipple

Why not Just convert the decimal to hex using the Hex() function? Then you can split it up into pairs... (remember to add trailing zeroes first)...

Mystical

Jesus your sig laggs... when i scoll past it..