color = point(x,y)
How can this be done in VB.NET?
To get the color at a certain point of an image:
dim myBitmap as bitmap = new bitmap("C:\test.bmp")
dim myColor as color
dim R,G,B as integer
'Gets the color of the top left pixel in the image
myColor = myBitmap.GetPixel(0,0)
R = myColor.R 'Gets the RGB red value
G = myColor.G 'Gets the RGB green value
B = myColor.B 'Gets the RGB blue value
'Conversely, you can use SetPixel() to change a pixels color at a given point:
R = 128
G = 0
B = 128
myColor = Color.FromARGB(255, R,G,B) 'The first value ("A") is "alpha"
value, or opacity.
If you want to get the color of a certain pixel on the screen, you can use a
similar method once a capture of the screen has been made:
'make a new bitmap to hold our image
Dim myBitmap As Bitmap
'make a color to hold our pixel's color
Dim myColor As Color
'Hide our form so it doesn't show up in the image
Me.Hide()
'Allow any events to finish before continuing
'Insures that our form is completely hidden before takeing the
screen capture
Application.DoEvents()
'Use sendkeys to send the "Print Screen" key.
'This is just like if you hit "Print Screen" on your keyboard.
SendKeys.Send("{PRTSC}")
'Copy the image from the clipboard to the bitmap we made earlier.
mybitmap = Clipboard.GetImage
'Show our form again.
Me.Show()
'Now we can use GetPixel just like before:
'Get the color of the pixel located at X=100, y=100.
myColor = myBitmap.GetPixel(100, 100)
'Set the title of our form to the RGB value of the pixel's color
Me.Text = myColor.R & ", " & myColor.G & ", " & myColor.B
Please post your question here:
news://microsoft.public.dotnet.languages.vb
This newsgroup is for VB6(VB Classic) and lower, which is incompatible with
what you are using. DotNet has separate groups; all of which have either
"dotnet" or "vsnet" in the name. If the group has "vb" in the name without
"dotnet", then it's for VB6 and lower only.
Thank you