ImageHelper

Finding and Loading Images

Methods for finding a template image within the current screen and loading images from file or Base64 strings.

Methods for finding a template image within the current screen and loading images from file or Base64 strings.

FindImage uses OpenCV template matching to locate a template image within the current screen capture - returns a System.Drawing.Rectangle with the location and size of the match. LoadImageFromFile loads an image from a file path into a System.Drawing.Image object for use with GPAL.Selector.WithImage. Base64ToImage converts a Base64 data URI or raw Base64 string into a System.Drawing.Image - the method handles both formats with and without the data URI prefix.

TIP

FindImage is useful for legacy desktop applications and canvas-based UIs where no accessible automation properties are exposed. The template image should be a clean crop at the same screen resolution. Small differences in color or DPI can cause mismatches.

Examples

GPAL Fluent: High-level fluent C# API

//FindImage returns a Rectangle - use the X and Y coordinates to calculate click positions. For automated clicking, use GPAL.Selector.WithImage() instead, which integrates template matching directly into the selector pipeline.

// Find a button by its visual appearance var rect = GPAL.Image .FindImage("C:\templates\submit-btn.png"); Console.WriteLine($"Found at X={rect.X}, Y={rect.Y}"); // Load an image for use with a selector var templateImage = GPAL.Image .LoadImageFromFile("C:\templates\icon.png"); var imageSelector = GPAL.Selector .WithImage(templateImage); // Convert Base64 to image var img = GPAL.Image .Base64ToImage("data:image/png;base64,iVBORw0KGgo...");