Syntax
Brush = CreateBrushImg(Img)
Description
Creates a new image brush (bitmap brush) using the specified ProGUI image object. This brush can then be used to fill areas with the image content, potentially tiled or stretched depending on the brush's extend mode and transformations.
Parameters
Return Value
Returns a handle to the newly created image brush object if successful, or #Null if the
image handle was invalid or the brush could not be created.
Remarks
The created brush initially uses the image's dimensions and content. Its appearance when filling larger or smaller areas depends on the extend mode (BrushSetExtendMode) and any applied transformations (BrushSetScale, BrushSetRotation, BrushSetPosition). The interpolation mode (BrushSetInterpolationMode) affects rendering quality when the brush is scaled. Remember to free the brush using FreeBrush() when it's no longer needed. Use BrushSetImg() to alter the image used.
Example
IncludeFile "ProGUI_PB.pbi"
Global MyBrush
Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw)
DrawClear(RGB(240, 240, 240), 1)
; Fill a rectangle using the image brush
DrawBoxFill(50, 50, 300, 200, MyBrush)
EndProcedure
StartProGUI()
MyWindow = CreateWindow(0, 0, 400, 300, "Image Brush Example")
MyImage = CreateImg(50, 50, RGB(255, 0, 0)) ; Create a simple red square image
BeginDraw(OutputImg(MyImage))
DrawBox(10, 10, 30, 30, RGB(0, 255, 0)) ; Draw green square inside
EndDraw()
If MyWindow And MyImage
MyBrush = CreateBrushImg(MyImage)
If MyBrush
; Set the brush to repeat
BrushSetExtendMode(MyBrush, #PG_Brush_ExtendMode_Repeat, #PG_Brush_ExtendMode_Repeat)
; Optionally scale the brush pattern
; BrushSetScale(MyBrush, 0.5, 0.5)
AddEventHandler(MyWindow, #PG_Event_Draw, @DrawHandler())
WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
FreeBrush(MyBrush) ; Free the brush
EndIf
FreeImg(MyImage) ; Free the image
EndIf
StopProGUI()
See Also
CreateImg, LoadImg, BrushSetExtendMode, BrushSetScale, BrushSetImg, DrawBoxFill, FreeBrush, FreeImg
Supported OS
Windows, Linux