b2dSetImagePixels

Category: 2D Overlay

Syntax:

b2dSetImagePixels:Void(imageHandle:Int, pixels:Int[], width:Int, height:Int)


Parameters

Returns

Void



Summary

Copies a whole Int array into an image in one call: one $AARRGGBB Int per pixel.

Sets every pixel of the image from an Int array, row by row from the top left: pixels[y * width + x]. Each Int is a colour as $AARRGGBB, with the alpha in the top byte ($FF000000 is solid). width and height must be the image's own size; if they aren't, nothing changes and an error is printed.

It's far quicker than calling b2dSetPixel for every pixel: a 320 x 240 image takes a millisecond or two, so a program can draw its own pixels into an array (a software renderer, an emulator, a plasma effect) and show them every frame. If the image is locked (b2dLockImage), the pixels go into the locked copy and reach the screen at b2dUnlockImage.

Works on images and render targets.

View detailed documentation online



Example
Global pix:Int[76800]                  ; 320 x 240

Function Main()
    b2dGraphics(640, 480, BBR_WINDOW_MODE_WT)
    Local img:Int = b2dCreateRenderTarget(320, 240, 0, 0, 0, 1.0)
    b2dSetImageSmooth(img, False)
    Local x:Int, y:Int, frame:Int
    While inpIsKeyDown(VKEY_ESCAPE) = False
        sysUpdateEvents()
        For y = 0 To 239
            For x = 0 To 319
                pix[y * 320 + x] = $FF000000 + (((x + frame) BitXor y) BitAnd 255)
            Next
        Next
        b2dSetImagePixels(img, pix, 320, 240)
        b2dCls()
        b2dDrawImageQuad(img, 0, 0, 640, 0, 640, 480, 0, 480)
        b2dFlip()
        frame = frame + 1
    Wend
    Return False
EndFunction

BambooBasic © 2026 Michael Denathorn