Skip to content

Displaying JPEG images

In this guide, you will load a Base64 encoded JPEG image, decode it, and display it on a DirectGPU screen.

Before starting, make sure you have:

  • CC:Tweaked installed
  • DirectGPU installed
  • A DirectGPU peripheral attached
  • A Base64 encoded JPEG image

First, get the DirectGPU peripheral:

local gpu = peripheral.find("directgpu")

Create a display:

local displayId = gpu.autoDetectAndCreateDisplay()

DirectGPU can decode JPEG images directly.

Use decodeJPEG:

local image = gpu.decodeJPEG(base64JpegData)

This returns an image table containing pixel data.

If you want to resize the image while decoding, use decodeAndScaleJPEG:

local image = gpu.decodeAndScaleJPEG(
base64JpegData,
128,
128
)

If you simply want to fill the display with an image, use loadJPEGFullscreen:

gpu.loadJPEGFullscreen(
displayId,
base64JpegData
)

Then update the display:

gpu.updateDisplay(displayId)

You can also update only a region of the display:

gpu.loadJPEGRegionBytes(
displayId,
base64JpegData,
20,
20,
128,
128
)
gpu.updateDisplay(displayId)