Skip to main content

Save a displayio.Bitmap (and associated displayio.Palette) into a BMP file.

Project description

Introduction

Documentation Status Discord Build Status Code Style: Ruff

Save a displayio.Bitmap (and associated displayio.Palette) into a BMP file.

Dependencies

This driver depends on:

CircuitPython 5.0 or later is required.

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-bitmapsaver

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-bitmapsaver

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .venv
source .venv/bin/activate
pip3 install adafruit-circuitpython-bitmapsaver

Usage Example

import board
import busio
import digitalio
from displayio import Bitmap, Palette
import adafruit_sdcard
import storage
from adafruit_bitmapsaver import save_pixels

print('Setting up SD card')
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
cs = digitalio.DigitalInOut(board.SD_CS)
sdcard = adafruit_sdcard.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")

WHITE = 0xFFFFFF
BLACK = 0x000000
RED = 0xFF0000
ORANGE = 0xFFA500
YELLOW = 0xFFFF00
GREEN = 0x00FF00
BLUE = 0x0000FF
PURPLE = 0x800080
PINK = 0xFFC0CB

colors = (BLACK, RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE, WHITE)

print('Building sample bitmap and palette')
bitmap = Bitmap(16, 16, 9)
palette = Palette(len(colors))
for i, c in enumerate(colors):
    palette[i] = c

for x in range(16):
    for y in range(16):
        if x == 0 or y == 0 or x == 15 or y == 15:
            bitmap[x, y] = 1
        elif x == y:
            bitmap[x, y] = 4
        elif x == 15 - y:
            bitmap[x, y] = 5
        else:
            bitmap[x, y] = 0

print('Saving bitmap')
save_pixels('/sd/test.bmp', bitmap, palette)

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

adafruit_circuitpython_bitmapsaver-1.3.10.tar.gz (124.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file adafruit_circuitpython_bitmapsaver-1.3.10.tar.gz.

File metadata

File hashes

Hashes for adafruit_circuitpython_bitmapsaver-1.3.10.tar.gz
Algorithm Hash digest
SHA256 02b5119fad49d7bc0f34db9ba1173241df650cdb162c7f800ddb4ac5b3f038d2
MD5 0761480156d409f7de141395d7ef67fb
BLAKE2b-256 735ae6283d15910a7dd10b622b7e7d2a78089b5c7d1ada9811c60cf5b188b067

See more details on using hashes here.

File details

Details for the file adafruit_circuitpython_bitmapsaver-1.3.10-py3-none-any.whl.

File metadata

File hashes

Hashes for adafruit_circuitpython_bitmapsaver-1.3.10-py3-none-any.whl
Algorithm Hash digest
SHA256 1fc9c67f9ef5a9950a13f60d19f1e35a481d15c487b7a57fcf2d051d69420d93
MD5 538ce9f99403f7a970c96eb27ac6f23c
BLAKE2b-256 1df6d8bb083b406951e808b7ec5e8d0e6380537cd6da9387ad8727f54b8e2322

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page