1

我是一个年轻的“程序员”,我正在尝试编写一个代码来搜索屏幕上是否出现 400 x 500 图像(我计算机中的 bmp 文件)。

代码如下所示:

公开课形式1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    'Dim-ing section'
    Dim scrsize As Size = New Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
    Dim scrtake = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
    Dim path As String = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory, "fishbot.bmp")
    Dim resource As New Bitmap(path)

    Dim a As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(scrtake)
    Dim b As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(resource)

    a.CopyFromScreen(New Point(0, 0), New Point(0, 0), scrsize)



   'as a test to see if the code is compiled until here'
    Me.BackgroundImage = scrtake 
   'end test'

    For x As Integer = 100 To scrsize.Height - 400
        For y As Integer = 300 To scrsize.Width - 300
            For x1 As Integer = 0 To resource.Height
                For y1 As Integer = 0 To resource.Width
                    If scrtake.GetPixel(x, y) = resource.GetPixel(x1, y1) Then
                        TextBox1.Text = "found"

                    End If
                Next
            Next
        Next
    Next







End Sub

此外,这些元素已经在表单上。

 For x As Integer = 100 To scrsize.Height - 400
            For y As Integer = 300 To scrsize.Width - 300
                For x1 As Integer = 0 To resource.Height
                    For y1 As Integer = 0 To resource.Width
                    If scrtake.GetPixel(x, y) = resource.GetPixel(x1, y1) Then
                        TextBox1.Text = "found"

                    End If
                Next
            Next
        Next
    Next

此代码返回:“参数必须为正且 < 高度。参数名称:y”,我找不到解决方案。还检查了很多网站,但仍然一无所获如果您知道更好的像素比较系统或提高速度的东西,请与我分享:)。

4

1 回答 1

1

好的查看了你的代码

For x1 As Integer = 0 To resource.Height

应该

For x1 As Integer = 0 To resource.Height - 1 etc

100x100 位图的可寻址区域为 0-99 x 0-99,因为 0 也是有效索引

于 2014-02-04T13:09:42.653 回答