Understanding how to load images

Description

What MCU/Processor/Board and compiler are you using?

Nim/gcc

What do you want to achieve?

I am trying to reproduce using Nim this example. But I think that maybe I am not understanding correctly what is done.

What have you tried so far?

So far, I tried to do something similar to python:

  1. read the binary file
  2. create lv_img_dsc_t and populated data and data_size

Do I have to do something with header?

Code to reproduce

I see that in C it uses:

    LV_IMG_DECLARE(img_cogwheel_argb);
    lv_img_set_src(obj, &img_cogwheel_argb);

I see that in python uses:

try:
    with open('../assets/img_cogwheel_argb.png', 'rb') as f:
        png_data = f.read()
except:
    print("Could not find img_cogwheel_argb.png")
    sys.exit()

img_cogwheel_argb = lv.img_dsc_t({
  'data_size': len(png_data),
  'data': png_data
})

I understand what python is trying to do. It is less clear to me what happens on the C side.

Screenshot and/or video

N/A

Hello,

For use in C, you need to first convert the image with LVGL’s Online image converter - BMP, JPG or PNG to C array or binary | LVGL.

This will leave you with an array with all of the pixel data of the image, the name of the array should be somewhere in the .c file.
If you have an image named img_cogwheel_argb.png and convert that to a .c file using the tool, you can include it in your code somewhere and “declare” it using LV_IMG_DECLARE(img_cogwheel_argb).

Then you need to create an image object with lv_img_create() and set the source of that image object (the image itself) to the image array generated earlier. Hope this clears things up! Also see the documentation here for working examples: Image (lv_img) — LVGL documentation