/ README.rst
README.rst
1 Introduction 2 ============ 3 4 .. image:: https://readthedocs.org/projects/adafruit-circuitpython-bitmapsaver/badge/?version=latest 5 :target: https://circuitpython.readthedocs.io/projects/bitmapsaver/en/latest/ 6 :alt: Documentation Status 7 8 .. image:: https://img.shields.io/discord/327254708534116352.svg 9 :target: https://adafru.it/discord 10 :alt: Discord 11 12 .. image:: https://github.com/adafruit/Adafruit_CircuitPython_BitmapSaver/workflows/Build%20CI/badge.svg 13 :target: https://github.com/adafruit/Adafruit_CircuitPython_BitmapSaver/actions/ 14 :alt: Build Status 15 16 Save a displayio.Bitmap (and associated displayio.Palette) into a BMP file. 17 18 19 Dependencies 20 ============= 21 This driver depends on: 22 23 * `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_ 24 25 CircuitPython 5.0 or later is required. 26 27 Please ensure all dependencies are available on the CircuitPython filesystem. 28 This is easily achieved by downloading 29 `the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_. 30 31 Installing from PyPI 32 ===================== 33 .. note:: This library is not available on PyPI yet. Install documentation is included 34 as a standard element. Stay tuned for PyPI availability! 35 36 On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from 37 PyPI <https://pypi.org/project/adafruit-circuitpython-bitmapsaver/>`_. To install for current user: 38 39 .. code-block:: shell 40 41 pip3 install adafruit-circuitpython-bitmapsaver 42 43 To install system-wide (this may be required in some cases): 44 45 .. code-block:: shell 46 47 sudo pip3 install adafruit-circuitpython-bitmapsaver 48 49 To install in a virtual environment in your current project: 50 51 .. code-block:: shell 52 53 mkdir project-name && cd project-name 54 python3 -m venv .env 55 source .env/bin/activate 56 pip3 install adafruit-circuitpython-bitmapsaver 57 58 Usage Example 59 ============= 60 61 .. code-block:: python 62 63 import board 64 import busio 65 import digitalio 66 from displayio import Bitmap, Palette 67 import adafruit_sdcard 68 import storage 69 from adafruit_bitmap_saver import save_bitmap 70 71 print('Setting up SD card') 72 spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) 73 cs = digitalio.DigitalInOut(board.SD_CS) 74 sdcard = adafruit_sdcard.SDCard(spi, cs) 75 vfs = storage.VfsFat(sdcard) 76 storage.mount(vfs, "/sd") 77 78 WHITE = 0xFFFFFF 79 BLACK = 0x000000 80 RED = 0xFF0000 81 ORANGE = 0xFFA500 82 YELLOW = 0xFFFF00 83 GREEN = 0x00FF00 84 BLUE = 0x0000FF 85 PURPLE = 0x800080 86 PINK = 0xFFC0CB 87 88 colors = (BLACK, RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE, WHITE) 89 90 print('Building sample bitmap and palette') 91 bitmap = Bitmap(16, 16, 9) 92 palette = Palette(len(colors)) 93 for i, c in enumerate(colors): 94 palette[i] = c 95 96 for x in range(16): 97 for y in range(16): 98 if x == 0 or y == 0 or x == 15 or y == 15: 99 bitmap[x, y] = 1 100 elif x == y: 101 bitmap[x, y] = 4 102 elif x == 15 - y: 103 bitmap[x, y] = 5 104 else: 105 bitmap[x, y] = 0 106 107 print('Saving bitmap') 108 save_pixels('/sd/test.bmp', bitmap, palette) 109 110 Contributing 111 ============ 112 113 Contributions are welcome! Please read our `Code of Conduct 114 <https://github.com/adafruit/Adafruit_CircuitPython_BitmapSaver/blob/master/CODE_OF_CONDUCT.md>`_ 115 before contributing to help this project stay welcoming. 116 117 Documentation 118 ============= 119 120 For information on building library documentation, please check out `this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.