Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8983549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:52:03+00:00 2026-06-15T20:52:03+00:00

I am wondering how I could search a set rectangle on the screen and

  • 0

I am wondering how I could search a set rectangle on the screen and have it compare to an image that I specify to see if it matches?

Lets say it could Search x1 y1 to x2 y2 and compare against an image? and return the boolean?

I know Auto-it has a similar function seen here: http://www.autohotkey.com/docs/commands/ImageSearch.htm

Has anyone done this that they could reference? I am using vb.net.

EDIT: Abdias, I have put your code into a class instead and I am calling it like this:

     Dim bm As Bitmap = Bitmap.FromFile(Label1.Text)
    Dim bm2 As Bitmap = Bitmap.FromFile(Label2.Text)
    Dim pnt As Point = ImageFinder.Contains(bm, bm2)
    If pnt <> Nothing Then
        MessageBox.Show("Possible match found at " & pnt.X.ToString() & " " & pnt.Y.ToString())
    Else
        MessageBox.Show("No match.")
    End If

It seems that every set of images I try return no point. Even though they 100% contain eachother. I took an image and cropped it by a couple px and still did not return a match. I have made sure the source is larger. I tried saving a couple images as 24 bit jpg in paint and still nothing.

Here are two sample images.enter image description hereenter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:52:04+00:00Added an answer on June 15, 2026 at 8:52 pm

    I made this function which can see if an image exist within a bigger image. It is written as an extension, but can easily be modified to a normal function as well as supporting a region.

    To use it:

    • Load main image into standard Bitmap as bmp
    • Load image to look for into bmpSearch

    Then call:

    Dim pt as Point = bmp.Contains(bmpSearch)
    If pt <> Nothing Then
        '... image found at pt
    End If
    

    The code for the extension (room for optimizations, but written as a 20 minute exercise for another question on this site):

    '
    '-- Extension for Bitmap
    '
    <Extension()>
    Public Function Contains(src As Bitmap, ByRef bmp As Bitmap) As Point
        '
        '-- Some logic pre-checks
        '
        If src Is Nothing OrElse bmp Is Nothing Then Return Nothing
    
        If src.Width = bmp.Width AndAlso src.Height = bmp.Height Then
            If src.GetPixel(0, 0) = bmp.GetPixel(0, 0) Then
                Return New Point(0, 0)
            Else
                Return Nothing
            End If
        ElseIf src.Width < bmp.Width OrElse src.Height < bmp.Height Then
            Return Nothing
        End If
        '
        '-- Prepare optimizations
        '
        Dim sr As New Rectangle(0, 0, src.Width, src.Height)
        Dim br As New Rectangle(0, 0, bmp.Width, bmp.Height)
    
        Dim srcLock As BitmapData = src.LockBits(sr, Imaging.ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb)
        Dim bmpLock As BitmapData = bmp.LockBits(br, Imaging.ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb)
    
        Dim sStride As Integer = srcLock.Stride
        Dim bStride As Integer = bmpLock.Stride
    
        Dim srcSz As Integer = sStride * src.Height
        Dim bmpSz As Integer = bStride * bmp.Height
    
        Dim srcBuff(srcSz) As Byte
        Dim bmpBuff(bmpSz) As Byte
    
        Marshal.Copy(srcLock.Scan0, srcBuff, 0, srcSz)
        Marshal.Copy(bmpLock.Scan0, bmpBuff, 0, bmpSz)
    
        ' we don't need to lock the image anymore as we have a local copy
        bmp.UnlockBits(bmpLock)
        src.UnlockBits(srcLock)
    
        Dim x, y, x2, y2, sx, sy, bx, by, sw, sh, bw, bh As Integer
        Dim r, g, b As Byte
    
        Dim p As Point = Nothing
    
        bw = bmp.Width
        bh = bmp.Height
    
        sw = src.Width - bw      ' limit scan to only what we need. the extra corner
        sh = src.Height - bh     ' point we need is taken care of in the loop itself.
    
        bx = 0 : by = 0
        '
        '-- Scan source for bitmap
        '
        For y = 0 To sh
            sy = y * sStride
            For x = 0 To sw
    
                sx = sy + x * 3
                '
                '-- Find start point/pixel
                '
                r = srcBuff(sx + 2)
                g = srcBuff(sx + 1)
                b = srcBuff(sx)
    
                If r = bmpBuff(2) AndAlso g = bmpBuff(1) AndAlso b = bmpBuff(0) Then
                    p = New Point(x, y)
                    '
                    '-- We have a pixel match, check the region
                    '
                    For y2 = 0 To bh - 1
                        by = y2 * bStride
                        For x2 = 0 To bw - 1
                            bx = by + x2 * 3
    
                            sy = (y + y2) * sStride
                            sx = sy + (x + x2) * 3
    
                            r = srcBuff(sx + 2)
                            g = srcBuff(sx + 1)
                            b = srcBuff(sx)
    
                            If Not (r = bmpBuff(bx + 2) AndAlso
                                    g = bmpBuff(bx + 1) AndAlso
                                    b = bmpBuff(bx)) Then
                                '
                                '-- Not matching, continue checking
                                '
                                p = Nothing
                                sy = y * sStride
                                Exit For
                            End If
    
                        Next
                        If p = Nothing Then Exit For
                    Next
                End If 'end of region check
    
                If p <> Nothing Then Exit For
            Next
            If p <> Nothing Then Exit For
        Next
    
        bmpBuff = Nothing
        srcBuff = Nothing
    
        Return p
    
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering, could jQuery search for all inputs that have a CSS class of
I was wondering if anyone could show me how to search this array that
I was wondering how could I reload any website using javascript and set it
I have a Python list of objects that could be pretty long. At particular
Let's say I have a large set of data within which each datum has
I was wondering how I could search for certain text (ie: description), and use
I was wondering if Search Engine spiders can see the comments, when I open
i am wondering could i access my app internal storage using emulator. I mean
Hi sorry still learning here and slow to learning code arguments. Just wondering could
i was wondering how could i emulate a mouse click with c# with kinect.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.