Skip to content

img.get_pixels() Index out of range #1

@djairjr

Description

@djairjr

Thank you very much for your work. I was just looking for a way to use bitmaps with Neopixel. I made some modifications to the Adafruit libraries to be able to add the functionality of combining LED matrices in different configurations.
In my case, I could only use two 32x8 matrices composing one 64x8.
But I couldn't compose something like 32x16. I had to make an arrangement in two libraries: Pixel_Framebuf and Led_Animation to achieve what I wanted.
https://github.com/djairjr/Adafruit_CircuitPython_Pixel_Framebuf
https://github.com/djairjr/Adafruit_CircuitPython_LED_Animation

I'm just looking for a way to implement BMP image support in Circuitpython and your example helped me a lot. I can view the image you shared but I am having difficulty viewing images created here on my computer. The image loads correctly but I am always getting the index out of range message, in line 23 get_pixels function.

Is there a limitation on the size of the images?
Could I add a 16x16 image? Or even 24x16?
Where could I change this?

Here is my code:

# SPDX-FileCopyrightText: 2020 Melissa LeBlanc-Williams, written for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
This example runs on an Seeed Xiao RP2040
"""
import board, time, os
import neopixel
import displayio

# My custom version
from tile_framebuf import TileFramebuffer
from bmp_reader import BMPReader

pixel_pin = board.D6
pixel_width = 32
pixel_height = 8
num_tiles = 2


pixels = neopixel.NeoPixel(
    pixel_pin,
    pixel_width * pixel_height * num_tiles, # dont forget to multiply for num_tiles
    brightness=0.1,
    auto_write=False,
)

pixel_framebuf = TileFramebuffer(
    pixels,
    pixel_width,
    pixel_height,
    num_tiles,
    rotation = 0
)

img = BMPReader('Mario.bmp') # Yes... him.
pixel_grid = img.get_pixels()

i=0

for row in range(img.height):
    for col in range(img.width):
        # The Unicorn Hat arranges its pixels starting top-right and alternates
        # back and forth with each row so we need to reverse the even rows
        if row % 2 == 0:
            col = img.width - 1 - col

        pixel_framebuf.pixel(row + 4, col + 4, pixel_grid[row][col])
        i += 1

pixel_framebuf.display()

Mario.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions