pimoroni-pico/micropython/examples/inky_frame/display_png.py

37 wiersze
1.0 KiB
Python
Czysty Zwykły widok Historia

2024-03-26 12:35:40 +00:00
from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3"
import pngdec
# Create a PicoGraphics instance
graphics = PicoGraphics(DISPLAY)
2024-03-26 13:29:51 +00:00
WIDTH, HEIGHT = graphics.get_bounds()
2024-03-26 12:35:40 +00:00
# Set the font
graphics.set_font("bitmap8")
# Create an instance of the PNG Decoder
png = pngdec.PNG(graphics)
# Clear the screen
graphics.set_pen(1)
graphics.clear()
graphics.set_pen(0)
# Few lines of text.
2024-03-28 09:41:33 +00:00
graphics.text("PNG Pencil", 70, 100, WIDTH, 3)
2024-03-26 12:35:40 +00:00
2024-03-28 09:41:33 +00:00
# Open our PNG File from flash. In this example we're using a cartoon pencil.
2024-03-26 12:35:40 +00:00
# You can use Thonny to transfer PNG Images to your Inky Frame.
2024-03-26 13:29:51 +00:00
try:
2024-03-28 09:41:33 +00:00
png.open_file("pencil_256x256.png")
2024-03-26 12:35:40 +00:00
2024-03-26 13:29:51 +00:00
# Decode our PNG file and set the X and Y
2024-03-28 09:41:33 +00:00
png.decode(200, 100)
2024-03-26 13:29:51 +00:00
except OSError:
2024-03-28 09:41:33 +00:00
graphics.text("Unable to find PNG file! Copy 'pencil_256x256.png' to your Inky Frame using Thonny :)", 10, 70, WIDTH, 3)
2024-03-26 12:35:40 +00:00
# Start the screen update
graphics.update()