Skip to content

Commit 76683ac

Browse files
committed
png decode example for display pack
1 parent 7c28719 commit 76683ac

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_RGB332
2+
import pngdec
3+
4+
# Create a PicoGraphics instance
5+
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, pen_type=PEN_RGB332)
6+
7+
# Set the backlight so we can see it!
8+
display.set_backlight(1.0)
9+
10+
# Create an instance of the PNG Decoder
11+
png = pngdec.PNG(display)
12+
13+
# Create some pens for use later.
14+
BG = display.create_pen(200, 200, 200)
15+
TEXT = display.create_pen(0, 0, 0)
16+
17+
# Clear the screen
18+
display.set_pen(BG)
19+
display.clear()
20+
21+
display.set_pen(TEXT)
22+
display.text("PNG Pencil", 15, 80)
23+
24+
try:
25+
# Open our PNG File from flash. In this example we're using an image of a cartoon pencil.
26+
# You can use Thonny to transfer PNG Images to your Pico.
27+
png.open_file("pencil.png")
28+
29+
# Decode our PNG file and set the X and Y
30+
png.decode(50, 100)
31+
32+
# Handle the error if the image doesn't exist on the flash.
33+
except OSError:
34+
print("Error: PNG File missing. Copy the PNG file from the example folder to your Pico using Thonny and run the example again.")
35+
36+
display.update()
37+
38+
# We're not doing anything else with the display now but we want to keep the program running!
39+
while True:
40+
pass
1.09 KB
Loading

0 commit comments

Comments
 (0)