Page 1 of 1

how to show image in lcd display

Posted: Sat Aug 01, 2020 3:58 pm
by timm-zz
Hi,
i want show image in my devices which driver is st7789v.
i use this lib https://github.com/russhughes/st7789py_mpy,
so i can show text ,but i dont know how to show image in screen :(

Re: how to show image in lcd display

Posted: Sat Aug 22, 2020 2:04 pm
by mcauser
Here's how you draw some random colours.

Code: Select all

>>> import random
>>> for i in range(400):
>>>     display.write(None, bytearray([random.getrandbits(8)]))
You use display.write(command=None, data=your-bytes) to send pixel data to the display.

To understand what it is doing, try writing the same 2 bytes, hundreds of times in a loop with a delay on each iteration.
2 bytes = 1 pixel. You will see how the display memory translates to the pixels on screen.

To get a recognisable image on the screen, you need to convert the image into the bytes in the format the driver expects, then write them in the correct order.

The display supports a bunch of different colour depths, 65k-16M.
If you run it at 65K, that's 16 bits per pixel, or RGB565
16M is 24 bits per pixel, or RGB888

You could use the framebuf in RGB565 mode.
https://docs.micropython.org/en/latest/ ... mebuf.html
Create a framebuf, draw some shapes, write to the display.

To show your image, you'll need to convert it to a RGB565 array of bytes. There's tools available online to help with that.
Then configure the driver to run in 65k mode.
Then write that array of bytes.
You'd need to use display.set_window() to position the "cursor" to the desired start pixel in the display memory.
If your display is 240x240 but you only want to draw a 32x32 image, set_window() lets you isolate a section of display memory to write to.