Hey guys, i want to make a prog that u choose the colour and gives you the RGB numbers, anyone can help ?:P
[highlight=vbnet]Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
Dim x As Bitmap = PictureBox1.Image
Dim ref As Color = x.GetPixel(e.X, e.Y)
Dim rVal As Integer = ref.R
Dim gVal As Integer = ref.G
Dim bVal As Integer = ref.B
End Sub[/highlight]
Good Job hassan, that was fast
hassan's code doesn't work
Parameter must be positive and < Height. Parameter name: y
edit: it only works when you wait for the controls to load, so put this code on mousedown.
edit2: still doesn't work on mouse down. worked for a few seconds though...
@user782106 ,I wrote up two functions for you, use the one you prefer:
[highlight="VB.Net"] Private Function GetRGB(ByVal color As System.Drawing.Color) As List(Of Byte)
Dim rByte As New List(Of Byte)
rByte.Add(color.R)
rByte.Add(color.B)
rByte.Add(color.G)
Return rByte
End Function
Private Function GetRGBString(ByVal color As System.Drawing.Color, ByVal delimiter As Char) As String
Return String.Concat(color.R, delimiter, color.G, delimiter, color.B)
End Function
End Class[/highlight]
Thanks, even though I don't really need it just trying to help the op
ill try it later thanks anw
Kevin's one is the simplest method. You can just use the R, G and B properties of the Color class straight up and that's your RGB.