Image freeze in build


I’m struggling with a png image that I can’t freeze in my lv_micropython built.
Is it possible to do it?

I tried to generate a C array with online tools but I don’t know how to use it with micropython instead of lv.img.decoder_create()

Thank you for your help

Hi @Patoche5150!

Yes it’s possible.

According to the docs you need to declare a C variable of type lv_img_dsc_t and populate it statically.
You can use the online image converter to generate a C file with a static lv_img_dsc_t variable that represents your image.

To use it in Micropython you need to rebuild lv_micropython:

  • Put your C file with the image variable somewhere under lib/lv_bindings/lvgl/src/ (or its subdirectories) so the Makefile could find it. Alternatively you can change the Makefile and add your C file under SRC_MOD.
  • To make the image available in Micropython, it needs to be declared (as extern) in some header file that is processed by the LVGL-Micropython-binding script. You can add the extern to lvgl.h or to any file that is included by it, such as lv_conf.h

After these steps, your image should be available in Micropython under the lvgl module.
You can create an image with lv.img_create and call img.set_src with your image as an argrument.

Hi @amirgon,

thank you so much for your response.
I used the online image converter, it is ok, I generated my C file.
Rebuild lv_micropython is also ok, no problem.
But I don’t know how to declare the image file as extern in a header file.
It’s probably easy but I am not used with that. Could you give me the good command line for that ?

Thank you

Yes, you simply need to add a line to some header file, something like:

extern const lv_img_dsc_t my_image;

You can add it, for example, at the end of lvgl.h before the: #ifdef __cplusplus} #endif.

Then build lv_micropython. You only need this line.

my_image above is the name of your image. You can find it at the end of your generated image file.
You would see there something like:

const lv_img_dsc_t my_image = {
  .header.always_zero = 0,
  .header.w = 441,
  .header.h = 428,
  .data_size = 188748 * LV_COLOR_SIZE / 8, = LV_IMG_CF_TRUE_COLOR,
  .data = my_image_map,