GPAL - Generally Positive Automation Library v1.0
GPAL The Fluent Automation LIbrary
Loading...
Searching...
No Matches
GenerallyPositive.ImageHelper Class Reference

Provides comprehensive image capture, conversion, and matching capabilities for automation scenarios. Supports both desktop (headful) and browser (headless/headful) screenshot workflows with fluent chaining. More...

Inheritance diagram for GenerallyPositive.ImageHelper:
GenerallyPositive.Browser.IImageHelper GenerallyPositive.Browser.IAllowGraphicSettings GenerallyPositive.Browser.IAllowScreenshot GenerallyPositive.Browser.IAllowToGPALObject< TResult >

Public Member Functions

IAllowGraphicSettings CaptureScreen (object ApplicationOrBrowser=null)
 Captures the current screen or visible browser tab. Works in both headful (desktop screenshot) and headless (browser screenshot) modes. Output is always a PNG-format image internally.
IAllowGraphicSettings ToBase64String (out string base64String)
 Converts the last captured screenshot to a Base64 string (JPEG format).
IAllowGraphicSettings ToBitmap (out Bitmap bitmap)
 Returns the last captured screenshot as a Bitmap.
IAllowGraphicSettings SaveTo (GPALFile file)
 Saves the captured screenshot to a file (overwrites if exists).
Rectangle FindImage (string imagePath, object ApplicationOrBrowser=null)
 Finds the location of a template image within the current screen/browser screenshot using OpenCV template matching.
IImageHelper ToGPALObject ()
 Returns this instance as IImageHelper for interface-based usage.

Static Public Member Functions

static System.Drawing.Image LoadImageFromFile (string filename)
 Loads an image from the specified file path.
static Image Base64ToImage (string base64String)
 Converts a Base64 string (with or without data URI prefix) to a System.Drawing.Image.

Properties

Browser.Browser Browser [get, set]
 Gets or sets the associated Browser instance for headless capture operations.
static Bitmap ScreenShot [get, set]
 Static reference to the most recent screenshot captured by this helper.

Detailed Description

Provides comprehensive image capture, conversion, and matching capabilities for automation scenarios. Supports both desktop (headful) and browser (headless/headful) screenshot workflows with fluent chaining.

Definition at line 33 of file ImageHelper.cs.

Member Function Documentation

◆ Base64ToImage()

Image GenerallyPositive.ImageHelper.Base64ToImage ( string base64String)
static

Converts a Base64 string (with or without data URI prefix) to a System.Drawing.Image.

Parameters
base64StringBase64-encoded image string.
Returns
A System.Drawing.Image instance.
Image img = ImageHelper.Base64ToImage(myBase64String);
Provides comprehensive image capture, conversion, and matching capabilities for automation scenarios....
static Image Base64ToImage(string base64String)
Converts a Base64 string (with or without data URI prefix) to a System.Drawing.Image.

Definition at line 314 of file ImageHelper.cs.

◆ CaptureScreen()

IAllowGraphicSettings GenerallyPositive.ImageHelper.CaptureScreen ( object ApplicationOrBrowser = null)

Captures the current screen or visible browser tab. Works in both headful (desktop screenshot) and headless (browser screenshot) modes. Output is always a PNG-format image internally.

Parameters
ApplicationOrBrowserOptional. Pass a Browser.Browser instance for browser-specific capture logic.
Returns
Fluent interface - chain to ToBase64String, ToBitmap, or SaveTo.
// Desktop screenshot
var helper = new ImageHelper();
helper.CaptureScreen()
.SaveToFile(new GPALFile("screenshot.png"));
// Browser screenshot (headless or headful)
myBrowser.ImageHelper.CaptureScreen(myBrowser)
.ToBase64String(out string b64)
.ToBitmap(out Bitmap bmp);
GPAL File object instantied with GPAL.File Used to load tokens into a GPALGrid [rows/columns].
Definition GPALFile.cs:36

Implements GenerallyPositive.Browser.IAllowScreenshot.

Definition at line 76 of file ImageHelper.cs.

◆ FindImage()

Rectangle GenerallyPositive.ImageHelper.FindImage ( string imagePath,
object ApplicationOrBrowser = null )

Finds the location of a template image within the current screen/browser screenshot using OpenCV template matching.

Parameters
imagePathPath to the template image to search for.
Returns
A Rectangle representing the location and size of the best match. Returns empty rectangle if no match is found.
Rectangle match = helper.FindImage(@"C:\templates\login_button.png");
if (!match.IsEmpty)
GPAL.PublishSimpleEvent(Enums.GPALEventType.NOTICE, $"Found at: [{match.Location}]");
Everything starts here, all the GPAL controls and global settings using fluent syntax are here....
Definition GPAL.cs:49
static void PublishSimpleEvent(GPALEventType gPALEventType, string msg, dynamic gPALObject=null, Enums.GPALObjectType gPALObjectType=GPALObjectType.None, Exception ex=null)
Publish a message to either the information channel or exception channel (if exception passed in) Pub...
Definition GPAL.cs:2406

Definition at line 347 of file ImageHelper.cs.

◆ LoadImageFromFile()

System.Drawing.Image GenerallyPositive.ImageHelper.LoadImageFromFile ( string filename)
static

Loads an image from the specified file path.

Parameters
filenamePath to the image file.
Returns
A System.Drawing.Image instance.
Image img = ImageHelper.LoadImageFromFile(@"C:\images\template.png");
static System.Drawing.Image LoadImageFromFile(string filename)
Loads an image from the specified file path.

Definition at line 299 of file ImageHelper.cs.

◆ SaveTo()

IAllowGraphicSettings GenerallyPositive.ImageHelper.SaveTo ( GPALFile file)

Saves the captured screenshot to a file (overwrites if exists).

Parameters
fileGPALFile object specifying the target path.
Returns
Fluent interface for chaining.
helper.CaptureScreen(myBrowser)
.SaveToFile(new GPALFile(@"C:\Screenshots\login.png"));

Implements GenerallyPositive.Browser.IAllowGraphicSettings.

Definition at line 245 of file ImageHelper.cs.

◆ ToBase64String()

IAllowGraphicSettings GenerallyPositive.ImageHelper.ToBase64String ( out string base64String)

Converts the last captured screenshot to a Base64 string (JPEG format).

Parameters
base64StringOutput parameter containing the Base64-encoded image.
Returns
Fluent interface for chaining.
helper.CaptureScreen()
.ToBase64String(out string base64)
.SaveToFile(new GPALFile("image.png"));

Implements GenerallyPositive.Browser.IAllowGraphicSettings.

Definition at line 205 of file ImageHelper.cs.

◆ ToBitmap()

IAllowGraphicSettings GenerallyPositive.ImageHelper.ToBitmap ( out Bitmap bitmap)

Returns the last captured screenshot as a Bitmap.

Parameters
bitmapOutput parameter containing the Bitmap.
Returns
Fluent interface for chaining.

Implements GenerallyPositive.Browser.IAllowGraphicSettings.

Definition at line 227 of file ImageHelper.cs.

◆ ToGPALObject()

IImageHelper GenerallyPositive.ImageHelper.ToGPALObject ( )

Returns this instance as IImageHelper for interface-based usage.

Returns
This instance cast to IImageHelper.

Implements GenerallyPositive.Browser.IAllowToGPALObject< TResult >.

Definition at line 406 of file ImageHelper.cs.

Property Documentation

◆ Browser

Browser.Browser GenerallyPositive.ImageHelper.Browser
getset

Gets or sets the associated Browser instance for headless capture operations.

Definition at line 38 of file ImageHelper.cs.

◆ ScreenShot

Bitmap GenerallyPositive.ImageHelper.ScreenShot
staticgetset

Static reference to the most recent screenshot captured by this helper.

Definition at line 43 of file ImageHelper.cs.


The documentation for this class was generated from the following file: