Skip to content

Commit 425f132

Browse files
committed
png decode example for tufty
1 parent 76683ac commit 425f132

File tree

2 files changed

+36
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)