2 Replies - 243 Views - Last Post: 11 August 2012 - 08:22 AM Rate Topic: -----

#1 ownlikeaboss  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 11-August 12

Find image in image (have a piece of code but not sure if it works)

Posted 11 August 2012 - 07:33 AM

I want to find and get the location of image1 in image2, i got a piece of code from a site but it doesn't work properly.
Can somebody check this?

Private Function FindImage(Image1 As Bitmap, Image2 As Bitmap) As Point

        For y = 0 To Image1.Height - Image2.Height - 1

            For x = 0 To Image1.Width - Image2.Width - 1

                ix = 0
                iy = 0
                cnt = 0

                While iy < Image2.Height And ix < Image2.Width And Image1.GetPixel(x + ix, y + iy) = Image2.GetPixel(ix, iy)

                    cnt += 1
                    ix += 1

                    If ix = Image2.Width Then

                        ix = 0
                        iy += 1

                    End If

                End While

                If cnt = Image2.Width * Image2.Height Then

                    MessageBox.Show("succes")
                    Return New Point(ix, iy)
                    Exit Function

                End If

            Next

        Next

        MessageBox.Show("fail")
        Return New Point(-1, -1)

    End Function


Is This A Good Question/Topic? 0
  • +

Replies To: Find image in image (have a piece of code but not sure if it works)

#2 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1817
  • View blog
  • Posts: 4,625
  • Joined: 14-March 10

Re: Find image in image (have a piece of code but not sure if it works)

Posted 11 August 2012 - 07:56 AM

How not working properly are you talking about? Tell us what it gives out and what you want it to do or what wrong with it!
Was This Post Helpful? 0
  • +
  • -

#3 ownlikeaboss  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 11-August 12

Re: Find image in image (have a piece of code but not sure if it works)

Posted 11 August 2012 - 08:22 AM

I said that i want to find image 1 in image 2, but every time i execute the code i get fail. I don't know what's wrong it that's the problem!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1