CreateImg

Syntax

Image = CreateImg(Width, Height, BackgroundColor=#PG_Img_Transparent, PixelFormat=#PG_Img_Format_BGRA32)

Description

Creates a new, empty ProGUI image resource with the specified dimensions, background color, and pixel format. This image can then be used as a drawing target or as a source for brushes and borders.

Parameters

Width
The width of the image to create, in pixels.

Height
The height of the image to create, in pixels.

BackgroundColor (optional)
The initial background color for the image. Use standard RGB() or RGBA() values. Default is #PG_Img_Transparent, which creates a fully transparent image (clears the background with RGBA(0,0,0,0)). If an RGBA value is provided, its alpha channel determines the initial opacity.

PixelFormat (optional)
The internal pixel format for the image. Default is #PG_Img_Format_BGRA32 (standard 32-bit color with alpha).

#PG_Img_Format_BGRA32 : 32-bit Blue-Green-Red-Alpha format. Standard format.
#PG_Img_Format_A8      : 8-bit Alpha format. Useful for creating masks.

Return Value

Returns a handle to the newly created ProGUI image object if successful, or #Null if the image could not be created (e.g., invalid dimensions, memory allocation failure).

Remarks

The created image handle should be freed using FreeImg() when no longer needed. ProGUI uses reference counting, so the image data is only destroyed when the last reference is released. The image is created with a default interpolation mode of #PG_InterpolationMode_Linear. You can draw onto the created image using OutputImg() and the drawing commands within a BeginDraw()/EndDraw() block.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

; Create a 100x50 transparent image
TransparentImage = CreateImg(100, 50)

; Create a 200x100 image with a semi-transparent red background
RedImage = CreateImg(200, 100, RGBA(255, 0, 0, 128))

; Create an 8-bit alpha mask image (will be black, but alpha matters)
MaskImage = CreateImg(50, 50, RGBA(0,0,0,255), #PG_Img_Format_A8)

If TransparentImage
    Debug "Transparent Image created. Width: " + ImgGetWidth(TransparentImage)
    ; You can now draw on this image using OutputImg() and BeginDraw()
    FreeImg(TransparentImage)
EndIf

If RedImage
    Debug "Red Image created. Height: " + ImgGetHeight(RedImage)
    ; ...
    FreeImg(RedImage)
EndIf

If MaskImage
    Debug "Alpha Mask Image created."
    ; ...
    FreeImg(MaskImage)
EndIf

StopProGUI()

See Also

LoadImg, FreeImg, OutputImg, BeginDraw, DrawClear

Supported OS

Windows, Linux