ImgGrab

Syntax

NewImage = ImgGrab(Img, x, y, Width, Height)

Description

Creates a new ProGUI image object by copying a rectangular portion from an existing image.

Parameters

Img
The handle of the source ProGUI image object.

x
The horizontal starting coordinate (in pixels, top-left corner) within the source image to start grabbing from.

y
The vertical starting coordinate (in pixels, top-left corner) within the source image to start grabbing from.

Width
The width (in pixels) of the rectangular area to grab.

Height
The height (in pixels) of the rectangular area to grab.

Return Value

Returns a handle to the newly created ProGUI image object containing the grabbed portion if successful. Returns #Null or #False if the source image handle is invalid, or if the specified grab area is invalid (e.g., zero width/height, coordinates outside the source image bounds).

Remarks

The coordinates and dimensions are specified in pixels relative to the source image. The returned image is a new resource and must be freed independently using FreeImg() when no longer needed.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

; Create a source image
SourceImg = CreateImg(200, 150, RGB(0, 0, 255))
If SourceImg
    BeginDraw(OutputImg(SourceImg))
        DrawBox(50, 50, 100, 50, RGB(255, 255, 0), 1.0) ; Draw a yellow rect inside
    EndDraw()

    ; Grab a portion (including part of the yellow rect)
    GrabbedImg = ImgGrab(SourceImg, 25, 25, 150, 100)

    If GrabbedImg
        Debug "Image grabbed successfully. Size: " + ImgGetWidth(GrabbedImg) + "x" + ImgGetHeight(GrabbedImg)
        ; You can now use GrabbedImg, e.g., draw it
        ; ...
        FreeImg(GrabbedImg)
    Else
        Debug "Failed to grab image portion."
    EndIf

    FreeImg(SourceImg)
EndIf

StopProGUI()

See Also

CreateImg, LoadImg, FreeImg, DrawImgEx

Supported OS

Windows, Linux