How to use pictures directly in lvgl8


I tried the method in the picture, although no error is reported, but the picture cannot be displayed on the interface.

Assuming you file system is set up correctly, consider including this in your initialization of your image:

    lv_obj_set_width(img, LV_SIZE_CONTENT);
    lv_obj_set_height(img, LV_SIZE_CONTENT);

If that does not work out, make sure your image is the correct color depth, matching your LVGL configuration, and that it is in fact present on the file system.

1 Like

Thanks a lot, I’ll try it out. Another embarrassing thing is that I don’t know if the file system is set correctly.

Nothing embarasing about that :slightly_smiling_face: Embedded program can be chalenging. There are some other ways of storing your image as well, see this LVGL tool, where you can do things like convert your image to a C array and add it to your project as a C file.

Speaking of that particular way of doing it, note that this very often takes about an order of magnitude more space than using the .png file directly. However, you don’t need to set up a file system to use an image. For example, I have a PNG image that is ~1.5KB and converted it into a file that is a 16-bit color C array, which becomes 8KB. 32-bit color will take even more. Depends on your situation which is appropriate to use.

Which MCU/platform are you using for this project?

1 Like

thank you for your reply.
I have always displayed pictures by converting the images into C arrays, but it does require more space, so I thought of directly manipulating the picture files to display.
I am running lvgl under linux arm7.