converting png file to bytearray

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
stijn
Posts: 269
Joined: Thu Apr 24, 2014 9:13 am

Re: converting png file to bytearray

Post by stijn » Thu May 17, 2018 4:58 pm

deshipu wrote:
Thu May 17, 2018 4:16 pm
Which of the 4 different formats described there?
I'm not sure what you mean? The whole page is about the BMP file format (which I assume is the one OutoftheBOTS_ means when saying 'save it as a BMP file') and only mentions some related formats exist without much further description. Or maybe I'm missing something.

OutoftheBOTS_
Posts: 397
Joined: Mon Nov 20, 2017 10:18 am

Re: converting png file to bytearray

Post by OutoftheBOTS_ » Thu May 17, 2018 8:14 pm

I have used this little bit of info here http://paulbourke.net/dataformats/bmp/ as a basis for my use of BMP images and so far it has got the job done that I needed without any hiccups.

In the end the original question was for someone to be able to load an image on a epaper screen. I have definitely found the simplest way to do this is from a BMP file again see my example of a 16 bit bmp file being loaded onto a SPI TFT here https://www.youtube.com/watch?v=4OeWaat3jZs and the waveshare wiki also suggest easiest way is using 1 bit BMP file for their epaper screens see https://www.waveshare.com/wiki/1.54inch_e-Paper_Module

OutoftheBOTS_
Posts: 397
Joined: Mon Nov 20, 2017 10:18 am

Re: converting png file to bytearray

Post by OutoftheBOTS_ » Thu May 17, 2018 8:21 pm

devnull wrote:
Thu May 17, 2018 10:02 am
OK, I am now using mono-bitmaps and are able to convert the image to a bytearray using PIL (pillow.image).

I can also write the image (icon) to the screen at whatever position I require, but when I use the writer class to add text next to it, it appears to overwrite the icon, and vice versa.

But if I repeatedly issue the display_frame() function, then the page toggles between just the icon, and the text frames, it almost appears that there are 2 separate pages.
I am still waiting for some hardware to arrive so I haven't yet played with a epaper but did do a quick read over the datasheet for the hardware that I plan to use and I remember the epaper do have 2 memory buffers (when reading it I though it was a bit strange). Off memory it had something to do with they way the epaper screens do their update of the image.

The epaper screens are definitely a bit more complex to use than the TFTs

OutoftheBOTS_
Posts: 397
Joined: Mon Nov 20, 2017 10:18 am

Re: converting png file to bytearray

Post by OutoftheBOTS_ » Thu May 17, 2018 8:22 pm

here from the waveshare wiki
Display a Frame (DisplayFrame)

DisplayFrame is used to display the data from the frame memory.

Note:

The module has two memory areas. Once DisplayFrame is invoked, the following function SetFrameMemory will set the other memory area, e.g. to set all the two memory areas, the process is: SetFrameMemory --> DisplayFrame --> SetFrameMemory --> DisplayFrame, i.e. set and update twice.
The data from SPI interface is first saved into the memory and then updated if the module received the update command.
The module will flicker during full update.
The module won't flicker during partial update, however, it may retain a "ghost image" of the last page.
So looking at it you have to write everything twice or you get the problem you have

the process is: SetFrameMemory --> DisplayFrame --> SetFrameMemory --> DisplayFrame, i.e. set and update twice.

Post Reply