Method uiimage.find(+ 1 overload)
Overload
Finds image(s) or color(s) displayed in a window or other area.
public static uiimage find(IFArea area, IFImage image, IFFlags flags = 0, int diff = 0, Func<uiimage, IFAlso> also = null)
Parameters
area (IFArea)
Where to search:
|
image (IFImage)
Image or color to find. Or array of them. More info: IFImage. |
flags (IFFlags) |
diff (int)
Maximal allowed color difference. Can be 0 - 100, but should be as small as possible. Use to find images with slightly different colors than the specified image. |
also (Func<uiimage, IFAlso>)
Callback function. Called for each found image instance and receives its rectangle, match index and list index. Can return one of IFAlso values.
|
Returns
uiimage
Returns a uiimage object that contains the rectangle of the found image and can click it etc.
Returns |
Exceptions
AuWndException
Invalid window handle (the area argument). |
ArgumentException
An argument is/contains a |
FileNotFoundException
Image file does not exist. |
Exception
Exceptions of ImageUtil.LoadGdipBitmap. |
AuException
Something failed. |
Remarks
To create code for this function, use tool Find image or color in window.
The speed mostly depends on:
- The size of the search area. Use the smallest possible area (control or UI element or rectangle in window).
- Flags IFFlags.WindowDC (makes faster), IFFlags.PrintWindow. The speed depends on window.
- Video driver. Can be much slower if incorrect, generic or virtual PC driver is used. The above flags should help.
- diff. Should be as small as possible.
If flag IFFlags.WindowDC or IFFlags.PrintWindow not used, the search area must be visible on the screen, because this function then gets pixels from the screen.
Can find only images that exactly match the specified image. With diff can find images with slightly different colors and brightness.
Transparent and partially transparent pixels of image are ignored. You can draw transparent areas with an image editor that supports it, for example Paint.NET.
This function is not the best way to find objects when the script is intended for long use or for use on multiple computers or must be very reliable. Because it may fail to find the image after changing some settings - system theme, application theme, text size (DPI), font smoothing (if the image contains text), etc. Also are possible various unexpected temporary conditions that may distort or hide the image, for example adjacent window shadow, a tooltip or some temporary window. If possible, in such scripts instead use other functions, eg find control or UI element.
Flags IFFlags.WindowDC and IFFlags.PrintWindow cannot be used if area is Bitmap or RECT.
Examples
Code created with tool Find image or color in window.
var w = wnd.find(1, "Window Name");
string image = "image:iVBORw0KGgoAAAANSUhEUgAAABYAAAANCAYAAACtpZ5jAAAAAXNSR0IArs4c...";
var im = uiimage.find(1, w, image);
im.MouseClick();
Overload(top)
Finds image(s) or color(s) displayed in a window or other area. Can wait and throw NotFoundException.
public static uiimage find(Seconds wait, IFArea area, IFImage image, IFFlags flags = 0, int diff = 0, Func<uiimage, IFAlso> also = null)
Parameters
wait (Seconds)
The wait timeout, seconds. If 0, does not wait. If negative, does not throw exception when not found. |
area (IFArea)
Where to search:
|
image (IFImage)
Image or color to find. Or array of them. More info: IFImage. |
flags (IFFlags) |
diff (int)
Maximal allowed color difference. Can be 0 - 100, but should be as small as possible. Use to find images with slightly different colors than the specified image. |
also (Func<uiimage, IFAlso>)
Callback function. Called for each found image instance and receives its rectangle, match index and list index. Can return one of IFAlso values.
|
Returns
uiimage
Returns a uiimage object that contains the rectangle of the found image and can click it etc.
If not found, throws exception or returns |
Exceptions
NotFoundException |
AuWndException
Invalid window handle (the area argument), or the window closed while waiting. |
ArgumentException
An argument is/contains a |
FileNotFoundException
Image file does not exist. |
Exception
Exceptions of ImageUtil.LoadGdipBitmap. |
AuException
Something failed. |
Remarks
To create code for this function, use tool Find image or color in window.
The speed mostly depends on:
- The size of the search area. Use the smallest possible area (control or UI element or rectangle in window).
- Flags IFFlags.WindowDC (makes faster), IFFlags.PrintWindow. The speed depends on window.
- Video driver. Can be much slower if incorrect, generic or virtual PC driver is used. The above flags should help.
- diff. Should be as small as possible.
If flag IFFlags.WindowDC or IFFlags.PrintWindow not used, the search area must be visible on the screen, because this function then gets pixels from the screen.
Can find only images that exactly match the specified image. With diff can find images with slightly different colors and brightness.
Transparent and partially transparent pixels of image are ignored. You can draw transparent areas with an image editor that supports it, for example Paint.NET.
This function is not the best way to find objects when the script is intended for long use or for use on multiple computers or must be very reliable. Because it may fail to find the image after changing some settings - system theme, application theme, text size (DPI), font smoothing (if the image contains text), etc. Also are possible various unexpected temporary conditions that may distort or hide the image, for example adjacent window shadow, a tooltip or some temporary window. If possible, in such scripts instead use other functions, eg find control or UI element.
Flags IFFlags.WindowDC and IFFlags.PrintWindow cannot be used if area is Bitmap or RECT.
Examples
Code created with tool Find image or color in window.
var w = wnd.find(1, "Window Name");
string image = "image:iVBORw0KGgoAAAANSUhEUgAAABYAAAANCAYAAACtpZ5jAAAAAXNSR0IArs4c...";
var im = uiimage.find(1, w, image);
im.MouseClick();