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

Page 1 of 1

## 2 Replies - 356 Views - Last Post: 11 August 2012 - 08:22 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=288588&amp;s=ae7554978dd46fb7e1ec2639bf0427b8&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 ownlikeaboss

Reputation: 0
• 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

• Critical Section

Reputation: 1820
• Posts: 4,627
• 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!

### #3 ownlikeaboss

Reputation: 0
• 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!