Skip to content

PNG Images

PNG methods allow you to decode, scale, and render PNG images directly onto displays. Images are provided as Base64 encoded PNG data unless otherwise specified.

Method
decodeAndScalePNG(base64PngData : string, targetWidth : number, targetHeight : number) : table
decodePNG(base64PngData : string) : table
getPNGDimensions(base64PngData : string) : table
loadPNGFullscreen(displayId : DisplayID, base64PngData : string) : ()
loadPNGRegion(displayId : DisplayID, pngBinaryData : string, x : number, y : number, w : number, h : number) : ()
loadPNGRegionBytes(displayId : DisplayID, base64PngData : string, x : number, y : number, w : number, h : number) : ()

Decodes a Base64 PNG image and scales it to the requested size.

Useful when you need image data before drawing.

Requires: base64PngData : string, targetWidth : number, targetHeight : number

Returns: Image data table.

local image = gpu.decodeAndScalePNG(
base64PngData,
128,
128
)

Decodes a Base64 PNG image and returns its pixel data.

Requires: base64PngData : string

Returns: Image data table.

local image = gpu.decodePNG(base64PngData)

Gets the dimensions of a PNG without fully decoding or rendering it.

Requires: base64PngData : string

Returns:

{
width,
height
}
local dims = gpu.getPNGDimensions(base64PngData)
print(dims.width, dims.height)

Decodes a PNG image and fills the entire display with it.

Call updateDisplay afterwards to push the framebuffer.

Requires: DisplayID, base64PngData : string

gpu.loadPNGFullscreen(displayId, base64PngData)
gpu.updateDisplay(displayId)

Loads PNG binary data into a specific region of a display.

Useful for updating only part of the framebuffer.

Requires: DisplayID, pngBinaryData : string, x : number, y : number, w : number, h : number

gpu.loadPNGRegion(
displayId,
pngBinaryData,
0,
0,
100,
100
)

Loads a Base64 encoded PNG into a specific display region.

This is the Base64 version of loadPNGRegion.

Requires: DisplayID, base64PngData : string, x : number, y : number, w : number, h : number

gpu.loadPNGRegionBytes(
displayId,
base64PngData,
50,
50,
128,
128
)