SlashShot
12-23-2007, 12:22 AM
basically what the title says.
Private Function findColor(ByVal Color As Color, ByVal Area As Rectangle) As Point
Dim AreaSize As Size = Area.Size
Dim TempBitmap As New Bitmap(AreaSize.Width, AreaSize.Height)
Graphics.FromImage(TempBitmap).CopyFromScreen(Area .Location, New Point(), AreaSize)
For x As Integer = 0 To Area.Height - 1
For y As Integer = 0 To Area.Width - 1
If TempBitmap.GetPixel(x, y) = Color Then Return New Point(Area.X + x, Area.Y + y)
Next
Next
Return New Point(-1, -1)
End Function
for actually getting the Color to find:
or using a button where you press down, and release over the selected color, use this as an example
in this case, a picturebox called PictureBoxColor has its background color changed to the hovered over color.
Private Sub btnGetColor_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnGetColor.MouseDown
tmrGetColor.Start()
End Sub
Private Sub tmrGetColor_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrGetColor.Tick
Dim TempBitmap As New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
Graphics.FromImage(TempBitmap).CopyFromScreen(Scre en.PrimaryScreen.Bounds.Location, New Point(), Screen.PrimaryScreen.Bounds.Size)
PictureBoxColor.BackColor = TempBitmap.GetPixel(System.Windows.Forms.Cursor.Po sition.X, System.Windows.Forms.Cursor.Position.Y)
End Sub
Private Sub btnGetColor_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnGetColor.MouseUp
tmrGetColor.Stop()
End Sub
Private Function findColor(ByVal Color As Color, ByVal Area As Rectangle) As Point
Dim AreaSize As Size = Area.Size
Dim TempBitmap As New Bitmap(AreaSize.Width, AreaSize.Height)
Graphics.FromImage(TempBitmap).CopyFromScreen(Area .Location, New Point(), AreaSize)
For x As Integer = 0 To Area.Height - 1
For y As Integer = 0 To Area.Width - 1
If TempBitmap.GetPixel(x, y) = Color Then Return New Point(Area.X + x, Area.Y + y)
Next
Next
Return New Point(-1, -1)
End Function
for actually getting the Color to find:
or using a button where you press down, and release over the selected color, use this as an example
in this case, a picturebox called PictureBoxColor has its background color changed to the hovered over color.
Private Sub btnGetColor_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnGetColor.MouseDown
tmrGetColor.Start()
End Sub
Private Sub tmrGetColor_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrGetColor.Tick
Dim TempBitmap As New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
Graphics.FromImage(TempBitmap).CopyFromScreen(Scre en.PrimaryScreen.Bounds.Location, New Point(), Screen.PrimaryScreen.Bounds.Size)
PictureBoxColor.BackColor = TempBitmap.GetPixel(System.Windows.Forms.Cursor.Po sition.X, System.Windows.Forms.Cursor.Position.Y)
End Sub
Private Sub btnGetColor_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnGetColor.MouseUp
tmrGetColor.Stop()
End Sub