Compare commits
14 Commits
b9f984d573
...
49b2e193de
Author | SHA1 | Date |
---|---|---|
Ryan | 49b2e193de | |
thirdr | 662df5a8b1 | |
thirdr | eb841fbe53 | |
thirdr | 14877b1793 | |
thirdr | 233896ac81 | |
thirdr | badc679c2b | |
thirdr | fc67c0db86 | |
thirdr | 3b56bc1781 | |
thirdr | d74279dbdf | |
thirdr | 4a7f552f8a | |
thirdr | a4e8fda4d8 | |
thirdr | 111e00de64 | |
thirdr | 9cce6a7474 | |
thirdr | dc63b215cd |
|
@ -0,0 +1,36 @@
|
|||
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)
|
||||
WIDTH, HEIGHT = graphics.get_bounds()
|
||||
|
||||
# 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.
|
||||
graphics.text("PNG Pencil", 70, 100, WIDTH, 3)
|
||||
|
||||
# Open our PNG File from flash. In this example we're using a cartoon pencil.
|
||||
# You can use Thonny to transfer PNG Images to your Inky Frame.
|
||||
try:
|
||||
png.open_file("pencil_256x256.png")
|
||||
|
||||
# Decode our PNG file and set the X and Y
|
||||
png.decode(200, 100)
|
||||
|
||||
except OSError:
|
||||
graphics.text("Unable to find PNG file! Copy 'pencil_256x256.png' to your Inky Frame using Thonny :)", 10, 70, WIDTH, 3)
|
||||
|
||||
# Start the screen update
|
||||
graphics.update()
|
Binary file not shown.
After Width: | Height: | Size: 5.4 KiB |
|
@ -0,0 +1,40 @@
|
|||
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_RGB332
|
||||
import pngdec
|
||||
|
||||
# Create a PicoGraphics instance
|
||||
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, pen_type=PEN_RGB332)
|
||||
|
||||
# Set the backlight so we can see it!
|
||||
display.set_backlight(1.0)
|
||||
|
||||
# Create an instance of the PNG Decoder
|
||||
png = pngdec.PNG(display)
|
||||
|
||||
# Create some pens for use later.
|
||||
BG = display.create_pen(200, 200, 200)
|
||||
TEXT = display.create_pen(0, 0, 0)
|
||||
|
||||
# Clear the screen
|
||||
display.set_pen(BG)
|
||||
display.clear()
|
||||
|
||||
display.set_pen(TEXT)
|
||||
display.text("PNG Pencil", 15, 80)
|
||||
|
||||
try:
|
||||
# Open our PNG File from flash. In this example we're using an image of a cartoon pencil.
|
||||
# You can use Thonny to transfer PNG Images to your Pico.
|
||||
png.open_file("pencil.png")
|
||||
|
||||
# Decode our PNG file and set the X and Y
|
||||
png.decode(20, 100, scale=3)
|
||||
|
||||
# Handle the error if the image doesn't exist on the flash.
|
||||
except OSError:
|
||||
print("Error: PNG File missing. Copy the PNG file from the example folder to your Pico using Thonny and run the example again.")
|
||||
|
||||
display.update()
|
||||
|
||||
# We're not doing anything else with the display now but we want to keep the program running!
|
||||
while True:
|
||||
pass
|
|
@ -0,0 +1,66 @@
|
|||
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY_2, PEN_P8
|
||||
import pngdec
|
||||
|
||||
# Create a PicoGraphics instance
|
||||
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY_2, pen_type=PEN_P8, rotate=270)
|
||||
|
||||
# Get the display width/height so we can position the PNGs
|
||||
width, height = display.get_bounds()
|
||||
|
||||
# Set the backlight so we can see it!
|
||||
display.set_backlight(1.0)
|
||||
|
||||
# Create an instance of the PNG Decoder
|
||||
png = pngdec.PNG(display)
|
||||
|
||||
# Create some pens for use later.
|
||||
BG = display.create_pen(200, 200, 200)
|
||||
|
||||
# 16 Reds
|
||||
for i in range(16):
|
||||
display.create_pen(i * 16, 0, 0)
|
||||
|
||||
# 16 Greens
|
||||
for i in range(16):
|
||||
display.create_pen(0, i * 16, 0)
|
||||
|
||||
# 16 Blues
|
||||
for i in range(16):
|
||||
display.create_pen(0, 0, i * 16)
|
||||
|
||||
# Adding in an white background colour at the beginning of each offset.
|
||||
for i in range(3):
|
||||
display.update_pen(i * 16, 200, 200, 200)
|
||||
|
||||
# Clear the screen
|
||||
display.set_pen(BG)
|
||||
display.clear()
|
||||
|
||||
|
||||
try:
|
||||
# Open our PNG File from flash. In this example we're using an image of a cartoon pencil.
|
||||
# You can use Thonny to transfer PNG Images to your Pico.
|
||||
png.open_file("pencil_gray.png")
|
||||
|
||||
# Horizontally/vertically center the three PNG Images.
|
||||
png_w = png.get_width()
|
||||
png_h = png.get_height()
|
||||
|
||||
offset_x = (width - png_w * 2) // 2
|
||||
height_y = (height // 3)
|
||||
offset_y = (height_y - png_h * 2) // 2
|
||||
|
||||
# Decode our PNG file and set the X and Y
|
||||
png.decode(offset_x, offset_y, scale=2, mode=pngdec.PNG_COPY, palette_offset=0)
|
||||
png.decode(offset_x, offset_y + height_y, scale=2, mode=pngdec.PNG_COPY, palette_offset=16)
|
||||
png.decode(offset_x, offset_y + (height_y * 2), scale=2, mode=pngdec.PNG_COPY, palette_offset=32)
|
||||
|
||||
# Handle the error if the image doesn't exist on the flash.
|
||||
except OSError:
|
||||
print("Error: PNG File missing. Copy the PNG file from the example folder to your Pico using Thonny and run the example again.")
|
||||
|
||||
display.update()
|
||||
|
||||
# We're not doing anything else with the display now but we want to keep the program running!
|
||||
while True:
|
||||
pass
|
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 497 B |
|
@ -0,0 +1,36 @@
|
|||
from picographics import PicoGraphics, DISPLAY_TUFTY_2040
|
||||
import pngdec
|
||||
|
||||
display = PicoGraphics(display=DISPLAY_TUFTY_2040)
|
||||
|
||||
# Create an instance of the PNG Decoder
|
||||
png = pngdec.PNG(display)
|
||||
|
||||
# Create some pens for use later.
|
||||
BG = display.create_pen(200, 200, 200)
|
||||
TEXT = display.create_pen(0, 0, 0)
|
||||
|
||||
# Clear the screen
|
||||
display.set_pen(BG)
|
||||
display.clear()
|
||||
|
||||
display.set_pen(TEXT)
|
||||
display.text("PNG Pencil", 105, 80)
|
||||
|
||||
try:
|
||||
# Open our PNG File from flash. In this example we're using an image of a cartoon pencil.
|
||||
# You can use Thonny to transfer PNG Images to your Pico.
|
||||
png.open_file("pencil.png")
|
||||
|
||||
# Decode our PNG file and set the X and Y
|
||||
png.decode(140, 100)
|
||||
|
||||
# Handle the error if the image doesn't exist on the flash.
|
||||
except OSError:
|
||||
print("Error: PNG File missing. Copy the PNG file from the example folder to your Pico using Thonny and run the example again.")
|
||||
|
||||
display.update()
|
||||
|
||||
# We're not doing anything else with the display now but we want to keep the program running!
|
||||
while True:
|
||||
pass
|
|
@ -0,0 +1,54 @@
|
|||
from picographics import PicoGraphics, DISPLAY_TUFTY_2040, PEN_P8
|
||||
import pngdec
|
||||
|
||||
display = PicoGraphics(display=DISPLAY_TUFTY_2040, pen_type=PEN_P8)
|
||||
|
||||
# Create an instance of the PNG Decoder
|
||||
png = pngdec.PNG(display)
|
||||
|
||||
# Create some pens for use later.
|
||||
BG = display.create_pen(200, 200, 200)
|
||||
TEXT = display.create_pen(0, 0, 0)
|
||||
|
||||
# 16 Reds
|
||||
for i in range(15):
|
||||
display.create_pen(i * 16, 0, 0)
|
||||
|
||||
# 16 Greens
|
||||
for i in range(16):
|
||||
display.create_pen(0, i * 16, 0)
|
||||
|
||||
# 16 Blues
|
||||
for i in range(15):
|
||||
display.create_pen(0, 0, i * 16)
|
||||
|
||||
# Adding in an white background colour at the beginning of each offset.
|
||||
for i in range(3):
|
||||
display.update_pen(i * 16, 200, 200, 200)
|
||||
|
||||
# Clear the screen
|
||||
display.set_pen(BG)
|
||||
display.clear()
|
||||
|
||||
display.set_pen(TEXT)
|
||||
display.text("PNG Pencil \n& Offset Palette", 125, 115)
|
||||
|
||||
try:
|
||||
# Open our PNG File from flash. In this example we're using an image of a cartoon pencil.
|
||||
# You can use Thonny to transfer PNG Images to your Pico.
|
||||
png.open_file("pencil_gray.png")
|
||||
|
||||
# Decode our PNG file and set the X and Y
|
||||
png.decode(35, 10, scale=2, mode=pngdec.PNG_COPY, palette_offset=0)
|
||||
png.decode(35, 90, scale=2, mode=pngdec.PNG_COPY, palette_offset=16)
|
||||
png.decode(35, 170, scale=2, mode=pngdec.PNG_COPY, palette_offset=32)
|
||||
|
||||
# Handle the error if the image doesn't exist on the flash.
|
||||
except OSError:
|
||||
print("Error: PNG File missing. Copy the PNG file from the example folder to your Pico using Thonny and run the example again.")
|
||||
|
||||
display.update()
|
||||
|
||||
# We're not doing anything else with the display now but we want to keep the program running!
|
||||
while True:
|
||||
pass
|
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 497 B |
|
@ -584,3 +584,42 @@ The arguments for `decode` are as follows:
|
|||
2. Decode Y
|
||||
3. Flags - one of `JPEG_SCALE_FULL`, `JPEG_SCALE_HALF`, `JPEG_SCALE_QUARTER` or `JPEG_SCALE_EIGHTH`
|
||||
4. If you want to turn off dither altogether, try `dither=False`. This is useful if you want to [pre-dither your images](https://ditherit.com/) or for artsy posterization effects.
|
||||
|
||||
### PNG Files
|
||||
|
||||
We've included BitBank's PNGDEC - https://github.com/bitbank2/PNGDEC - so you can display PNG files on your LCDs.
|
||||
|
||||
Eg:
|
||||
|
||||
```python
|
||||
import picographics
|
||||
import pngdec
|
||||
|
||||
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, pen_type=PEN_RGB332)
|
||||
|
||||
# Create a new PNG decoder for our PicoGraphics
|
||||
png = pngdec.PNG(display)
|
||||
|
||||
# Open the PNG file
|
||||
png.open_file("filename.jpeg")
|
||||
|
||||
# Decode the PNG
|
||||
png.decode(0, 0)
|
||||
|
||||
# Display the result
|
||||
display.update()
|
||||
```
|
||||
|
||||
PNG files must be small enough to load into RAM for decoding.
|
||||
|
||||
PNGDEC Supports the following PNG types:
|
||||
|
||||
1. True Colour
|
||||
2. True Colour (with Alpha)
|
||||
3. Indexed
|
||||
4. Grayscale
|
||||
|
||||
The arguments for `decode` are as follows:
|
||||
|
||||
1. Decode X - where to place the decoded JPEG on screen
|
||||
2. Decode Y
|
Loading…
Reference in New Issue