Extracting colors
-
I want to extract Red, Green and Blue values separately from value which return from Color.ToArgb function. How to do that.
Assuming VB.NET, the Color struct holds all that is required. ToArgb() is the method that turns a Color into an Int32, that is quite the opposite of what you want. Have a look at the FromArgb(Int32) method and the R, G, B properties. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Assuming VB.NET, the Color struct holds all that is required. ToArgb() is the method that turns a Color into an Int32, that is quite the opposite of what you want. Have a look at the FromArgb(Int32) method and the R, G, B properties. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
I think you don't undetstand what i meant. Consider following code.
Dim img As New Bitmap(PictureBox1.Image)
Dim col As Integer = d.GetPixel(x, y).ToArgb ' x and y means any x and y coordination of BitmapVariable col will hold some value that return from GetPixel function. Now I want to extract R value, G value and B value separately from variable col. That's what i want.
-
I think you don't undetstand what i meant. Consider following code.
Dim img As New Bitmap(PictureBox1.Image)
Dim col As Integer = d.GetPixel(x, y).ToArgb ' x and y means any x and y coordination of BitmapVariable col will hold some value that return from GetPixel function. Now I want to extract R value, G value and B value separately from variable col. That's what i want.
-
I think you don't undetstand what i meant. Consider following code.
Dim img As New Bitmap(PictureBox1.Image)
Dim col As Integer = d.GetPixel(x, y).ToArgb ' x and y means any x and y coordination of BitmapVariable col will hold some value that return from GetPixel function. Now I want to extract R value, G value and B value separately from variable col. That's what i want.
At the risk of repeating myself:
Dim Red As Integer = Color.FromArgb(col).R
:)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
At the risk of repeating myself:
Dim Red As Integer = Color.FromArgb(col).R
:)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
I want to extract Red, Green and Blue values separately from value which return from Color.ToArgb function. How to do that.
The mathematical alternative is:
Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click showColorComponents(Color.LightYellow) showColorComponents(Color.FromArgb(11, 22, 33, 44)) End Sub Private Sub showColorComponents(ByVal col As Color) log("col=" & col.ToString & " = " & col.A & "," & col.R & "," & col.G & "," & col.B) Dim I As Int32 = col.ToArgb() log("I=0x" & I.ToString("X8")) Dim B As Int32 = I And 255 Dim G As Int32 = (I >> 8) And 255 Dim R As Int32 = (I >> 16) And 255 Dim A As Int32 = (I >> 24) And 255 log("ARGB=" & A & "," & R & "," & G & "," & B) End Sub
:)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
To be absolutely sure, I also gave an alternative that does not rely on the features of the Color type. See below message. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
At the risk of repeating myself:
Dim Red As Integer = Color.FromArgb(col).R
:)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.