b2dDrawImage9Slice

Category: 2D Overlay

Syntax:

b2dDrawImage9Slice:Void(image:Int, x:Int, y:Int, width:Int, height:Int, left:Int, top:Int, right:Int, bottom:Int)


Parameters

Returns

Void



Summary

Draws an image as a box of any size, keeping its corners at their own size (9-slice).

Draws the image stretched to a width x height box with its top-left at x,y, the way panels, buttons and windows are usually drawn. left, top, right and bottom are the widths of the image's border, in pixels of the image. They split it into nine pieces: the four corners are drawn at their own size, the top and bottom edges stretch across, the left and right edges stretch down, and the middle stretches both ways. So one small image makes boxes of any size, and the border looks the same at every size and resolution.

If the box is smaller than its borders (width less than left + right, or height less than top + bottom), the borders shrink to fit. A border of 0 leaves that side with no edge piece.

The box always starts at x,y: the image's handle (b2dSetImageHandle, b2dSetImageMidHandle) isn't used. Honours b2dSetColor tint and b2dSetAlpha, like b2dDrawImageQuadUV, which draws the nine pieces.

View detailed documentation online



Example

; panel.png is 48 x 48 with a 16 pixel border
Global panel:Int = b2dLoadImage("Media/panel.png")

; a window, and a button below it, from the same image
b2dDrawImage9Slice(panel, 20, 20, 320, 200, 16, 16, 16, 16)
b2dDrawImage9Slice(panel, 20, 240, 120, 40, 16, 16, 16, 16)


BambooBasic © 2026 Michael Denathorn