png - PNG Decoder¶
The png module provides functions to decode PNG files into raw pixel data
which can be displayed using the card10’s display or its LEDs.
-
png.decode(png_data, format='RGB', bg=ucollections.namedtuple)[source]¶ Decode a PNG image and return raw pixel data.
- Parameters
format (str) –
The intended output format:
png.RGB8: 24 bit RGB.png.RGBA8: 24 bit RGB + 8 bit alpha.png.RGB565: 16 bit RGB. This consumes 1 byte less RAM per pixel thanpng.RGB8.png.RGBA5551: 15 bit RGB + 1 bit alpha.
Default is
png.RGB8.bg (Color) –
Background color.
If the PNG contains an alpha channel but no alpha channel is requested in the output (
png.RGB8orpng.RGB565) this color will be used as the background color.Default is
Color.BLACK.
- Returns
Typle
(width, height, data)
New in version 1.17.
Example with RGBA8 data:
import display import png # Draw a PNG file to the display f = open("example.png") w, h, img = png.decode(f.read(), png.RGBA8) f.close() with display.open() as d: d.clear() d.blit(0, 0, w, h, img, display.RGBA8) d.update()
Example with RGB565 data:
import display import png # Draw a PNG file to the display f = open("example.png") w, h, img = png.decode(f.read(), png.RGB565) f.close() with display.open() as d: d.clear() d.blit(0, 0, w, h, img, True, display.RGB565) d.update()