Skip to content

Image

from slint import Image
python

Image objects can be set on Slint Image elements for display. Construct Image objects from a path to an image file on disk, using load_from_path.

size: tuple[int, int]
width: int
height: int
path: Optional[pathlib.Path]
load_from_path(path: str | os.PathLike[Any] | pathlib.Path) -> Image

Loads the image from the specified path. Returns None if the image can’t be loaded.

load_from_svg_data(data: Sequence[int]) -> Image

Creates a new image from a string that describes the image in SVG format.

load_from_array(array: Buffer) -> Image

Creates a new image from an array-like object that implements the Buffer Protocol. Use this function to import images created by third-party modules such as matplotlib or Pillow.

The array must satisfy certain constraints to represent an image:

  • The buffer’s format needs to be B (unsigned char)
  • The shape must be a tuple of (height, width, bytes-per-pixel)
  • If a stride is defined, the row stride must be equal to width * bytes-per-pixel, and the column stride must equal the bytes-per-pixel.
  • A value of 3 for bytes-per-pixel is interpreted as RGB image, a value of 4 means RGBA.

Example of importing a matplot figure into an image:

import slint
import matplotlib
from matplotlib.backends.backend_agg import FigureCanvasAgg
from matplotlib.figure import Figure
fig = Figure(figsize=(5, 4), dpi=100)
canvas = FigureCanvasAgg(fig)
ax = fig.add_subplot()
ax.plot([1, 2, 3])
canvas.draw()
buffer = canvas.buffer_rgba()
img = slint.Image.load_from_array(buffer)
python

Example of loading an image with Pillow:

import slint
from PIL import Image
import numpy as np
pil_img = Image.open("hello.jpeg")
array = np.array(pil_img)
img = slint.Image.load_from_array(array)
python

© 2026 SixtyFPS GmbH