Visual Basic Picture Compareing

I was thinking of doing prebased pictures, and then compare them for true / false values. So for example I give vb the coords to grab the image from the screen, so like x,y " Top Left ", and x,y " Bottom Left. It would then generate a picture in a png format maby, and then it could compare a stored png for any differences? I found a link on youtube that seems to do picutre compare can someone help me automate it so it don't have to ask user for the pictures. Is there away to store the pictures inside of the vb program so they are not floating on the local drive, or do they have to be outside of the program. Thanks.

Can this be automated?
LVL 1
Jack_JonesAsked:
Who is Participating?
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
K...so the embedded pictures should be BITMAPS.

Click on Project --> Add Existing Item --> Select the Bitmap.
In Solution Explorer, select the newly added Bitmap.
In the Properties Pane, change the Build Action to Embedded Resource.
You can access the embedded resource using code like this:

    Dim AlarmClock As New Bitmap(Me.GetType, "AlarmClock.bmp")

Note that this is one of the few cases in VB.Net where the string names are CASE SENSITIVE.  The "AlarmClock.bmp" must match exactly as it is listed in Solution Explorer.

Now, to compare a piece of the screen to the embedded bitmap you use Graphics.CopyFromScreen() as before but use a bigger area.  Then you use two nested for loops to compare the pixels and drop out immediately if any don't match:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim AlarmClock As New Bitmap(Me.GetType, "Alarmclock.BMP")
        If IsImageAt(New Point(100, 75), AlarmClock) Then

        Else

        End If
    End Sub

    Private Function IsImageAt(ByVal pt As Point, ByVal embeddedBMP As Bitmap) As Boolean
        Dim bmp As New Bitmap(embeddedBMP.Size.Width, embeddedBMP.Size.Height)
        Using G As Graphics = Graphics.FromImage(bmp)
            G.CopyFromScreen(pt, New Point(0, 0), embeddedBMP.Size)
        End Using
        For x As Integer = 0 To embeddedBMP.Size.Width - 1
            For y As Integer = 0 To embeddedBMP.Size.Height - 1
                If Not embeddedBMP.GetPixel(x, y).Equals(bmp.GetPixel(x, y)) Then
                    Return False
                End If
            Next
        Next
        Return True
    End Function

Open in new window

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Yes, it is possible to embed images in the app itself.

How big are the images?  For small images, you can compare pixel by pixel and return a true/false.  This is a slow operation and not very practical for large images.

It can be automated by polling with a Timer control.

*Again, only if we are talking small images!
0
 
Jack_JonesAuthor Commented:
250kb - 600kb max image size
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
What is the resolution?

For example: 125x40 pixels
0
 
Jack_JonesAuthor Commented:
min would be 40 x 40, up to 150 x 150
0
 
Jack_JonesAuthor Commented:
Tested and working great, thanks for your help all day lol. You rock!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.