The Bitmap and Palette classes work together to generate colored pixels. So let's discuss them together.


This one is nice and easy. It's a 2D array of pixels. Each bitmap is width pixels wide and height pixels tall. Each pixel contains a value and you specify the maximum number of possible values with value_count. You can think of this as the total number of colors if you want.

Here is how you would create a bitmap 320 pixels wide, 240 pixels high, with each pixel having 3 possible values.

bitmap = displayio.Bitmap(320, 240, 3)

Here is how you would set the pixel at (x, y) = (23, 42) to a value of 2:

bitmap[23, 42] = 2

Note that the maximum x value is width - 1, the maximum y value is height - 1 and the maximum pixel value is value_count - 1.  This is due to the zero based indexing. Similarly, the first pixel and color value are all at 0.


This is also pretty straight forward. It is a simple list of color values. You specify the total number of colors with color_count.

Here is how you would create a palette with 3 total colors:

palette = displayio.Palette(3)

Here is how you would specify the color for each entry:

palette[0] = 0xFF0000 # red
palette[1] = 0x00FF00 # green
palette[2] = 0x0000FF # blue

Note how the last entry is at color_count - 1.

Bitmap + Palette

Think of the Bitmap and Palette working together like this:

This guide was first published on Apr 30, 2019. It was last updated on 2021-02-27 10:36:25 -0500.

This page (Bitmap and Palette) was last updated on Jun 23, 2022.

Text editor powered by tinymce.