Skip to content

How to paint an image [Solved] #1

@ebolisa

Description

@ebolisa

Hi, thanks for sharing!

Your code is working but I'd like to display some images. Which type of image is best to display? bmp?

This' a code I'm using but it needs to be reviewed.

from cydc import CYD
import time

# Create an instance of CYD
cyd = CYD()
cyd.RGBr.off()

def display_bmp(filename, x, y):
    with open(filename, 'rb') as f:
        if f.read(2) != b'BM':
            print("Not a BMP file")
            return
        
        f.seek(10)
        start = int.from_bytes(f.read(4), 'little')
        f.seek(18)
        width = int.from_bytes(f.read(4), 'little')
        height = int.from_bytes(f.read(4), 'little')

        f.seek(start)
        for row in range(height):
            line = f.read(width * 2)
            cyd.display.draw_pixels(line, x, y + height - 1 - row, width, 1)

# Show image
display_bmp('yo.bmp', 0, 0)

time.sleep(5)

cyd.shutdown()

Never-mind:

cyd.display.draw_image('Image128x128.raw',0, 0, 128, 128)

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