Platforms to show: All Mac Windows Linux Cross-Platform

Back to Picture class.

Picture.FindPictureMBS(pic as picture, byref x as Integer, byref y as Integer, StartX as Integer = 0, StartY as Integer = 0, Tolerance as Integer = 3) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Graphics & Pictures MBS Picture Plugin 9.8 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Finds the given picture inside the picture.
Example
// this is search image
dim p as new Picture(20,20,32)
p.Graphics.ForeColor = &c0000FF
p.Graphics.FillRect 0, 0, 20, 20

// this is target image
dim q as new Picture(500, 500, 32)

// with some color at Random position
q.Graphics.ForeColor = &c0000FF
q.Graphics.FillRect rnd*480, rnd*480, 30, 30

// do a search
dim x, y as Integer

if q.FindPictureMBS(p, x,y) then
// found image, so draw rectangle there

q.Graphics.ForeColor = &cFF0000
q.Graphics.DrawRect x, y, p.Width, p.Height
end if

window1.Backdrop = q

Returns true on success and fills x/y variables.
Pixels are compared exactly, so a little bit color correction and make the picture being not found.

StartX/StartY can give start position. Tolerance defines how much two pixel component values can differ and still be considered the same. This helps with color matching and other drawings which may alter pixels a little bit.
If function returns true, you can use x+1, y as the new start position and search again.

Some examples using this method:

Blog Entries

The items on this page are in the following plugins: MBS Picture Plugin.


The biggest plugin in space...