ImageCanvas

class plutoprint.ImageCanvas(width: int, height: int, format: ImageFormat = IMAGE_FORMAT_ARGB32)[source]

Bases: Canvas

The ImageCanvas class provides an interface for rendering to memory buffers.

__init__(width: int, height: int, format: ImageFormat = IMAGE_FORMAT_ARGB32) None[source]

Initializes a new ImageCanvas with the specified width, height, and format.

Parameters:
  • width – The width of the canvas in pixels.

  • height – The height of the canvas in pixels.

  • format – The pixel format of the canvas.

classmethod create_for_data(data: memoryview, width: int, height: int, stride: int, format: ImageFormat = IMAGE_FORMAT_ARGB32) ImageCanvas[source]

Creates a new ImageCanvas for the given writable data buffer.

Parameters:
  • data – A writable memoryview representing the image data buffer.

  • width – The width of the canvas in pixels.

  • height – The height of the canvas in pixels.

  • stride – The stride (number of bytes per row) of the image data.

  • format – The pixel format of the canvas.

Returns:

A new instance of ImageCanvas.

get_data() memoryview[source]

Returns a writable memoryview of the image data buffer.

Returns:

A writable memoryview of the image data.

get_width() int[source]

Returns the width of the canvas.

Returns:

The width of the canvas in pixels.

get_height() int[source]

Returns the height of the canvas.

Returns:

The height of the canvas in pixels.

get_stride() int[source]

Returns the stride (number of bytes per row) of the image data.

Returns:

The stride of the image data.

get_format() ImageFormat[source]

Returns the pixel format of the canvas.

Returns:

The pixel format of the canvas.

write_to_png(path: str | bytes | PathLike) None[source]

Writes the image data to a file at the specified path as PNG.

Parameters:

path – The file path where the PNG should be written.

write_to_png_stream(stream: BinaryIO) None[source]

Writes the image data to a writable binary stream as PNG.

Parameters:

stream – A writable binary stream where the PNG data should be written.