Skip to content

Width and height in def get_pixels(self) changed? #2

@chr-sto

Description

@chr-sto

Hello Stuart,
could it be that there is a little bug in get_pixels? Please test your code with a 2x8 Image. I changed height and width in the for-loop. After that, my results were better.
Best regards,
Christian

def get_pixels(self):
"""
Returns a multi-dimensional array of the RGB values of each pixel in the
image, arranged by rows and columns from the top-left. Access any pixel
by its location, eg:

    pixels = BMPReader(filename).get_pixels()
    top_left_px = pixels[0][0] # [255, 0, 0]
    bottom_right_px = pixels[8][8] # [0, 255, 255]
    """
    pixel_grid = []
    pixel_data = list(self._pixel_data) # So we're working on a copy

    for x in range(self.height):
        col = []
        for y in range(self.width):
            r = pixel_data.pop()
            g = pixel_data.pop()
            b = pixel_data.pop()
            col.append((r, g, b))
        col.reverse()
        pixel_grid.append(col)

    return pixel_grid

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