|
-
Aug 27th, 2002, 11:14 AM
#1
Thread Starter
yay gay
Converting from RGB to HEX
is ther any function in .NET to convert from rgb to hex and hex to rgb?
-
Aug 27th, 2002, 08:51 PM
#2
Addicted Member
what is rgb? i know what hex is if you tell mre what rgb is then i can possibly help.
-
Aug 27th, 2002, 11:08 PM
#3
Hyperactive Member
Iam not sure,Thou.. here is my own function for that:
Code:
Public Sub HexMe(ByVal icolor As Color)
Dim hexval As String
hexval += IIf(Len(Hex(icolor.R)) = 1, Hex(icolor.R) & "0", Hex(icolor.R))
hexval += IIf(Len(Hex(icolor.G)) = 1, Hex(icolor.G) & "0", Hex(icolor.G))
hexval += IIf(Len(Hex(icolor.B)) = 1, Hex(icolor.B) & "0", Hex(icolor.B))
MsgBox(hexval)
End Sub
Public Sub RGBMe(ByVal icolor As Color)
MsgBox("R= " & icolor.R.ToString & " G= " & icolor.G.ToString & " B= " & icolor.B.ToString)
End Sub
and this is how you call it.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
RGBMe(Label1.BackColor)
HexMe(Label1.BackColor)
End Sub
-
Aug 28th, 2002, 05:10 PM
#4
Member
Hey dude, Sorry, I don't really understand what you mean, RGB colors ARE hex values. If you mean ‘System.Drawing.Color’ structure, it has two function (FromArgb, ToArgb) that can help.
Generally to get Red, Green, Blue parts of a RGB color:
Dim myRGBColor As Integer
Dim myRedPart, myGreenPart, myBluePart As Byte
myBluePart = CByte(myRGBColor And &HFF)
myGreenPart = CByte((myRGBColor And &HFF00) \ &H100)
myRedPart = CByte((myRGBColor And &HFF0000) \ &H10000)
To create a RGB color from Red, Green and Blue parts:
myRGBColor = myBluePart Or (myGreenPart * &H100) Or (myRedPart * &H10000)
PS: .Net RGB colors include one more part, Alpha channel. This part is used to tell the machine that how much transparent your color is. 0 is complete transparent, 255 is opaque. To get the Alpha part:
Dim myAlphaPart As Byte
myAlphaPart = CByte(((myRGBColor And &HFF000000) \ &H1000000) And &HFF)
And to set it:
myRGBColor = (myRGBColor And &H00FFFFFF) Or &HFF000000 'Opaque
myRGBColor = (myRGBColor And &H00FFFFFF) Or &H80000000 '50% Transparent
myRGBColor = myRGBColor And &H00FFFFFF 'Full Transparent
-
Aug 28th, 2002, 07:47 PM
#5
Frenzied Member
RGB is red green blue 0 - 255 for each 0r 00 - FF which ever
Magiaus
If I helped give me some points.
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
|