Using LVGL library to load and display PNG images on ESP32 WROVER E

I’m using ESP32 WROVER E (8MB PSRAM) with TFT display that is 3.5inch SPI Module with ILI9488 driver and SD card module built in. I can’t find any tutorials on how I could display PNG images directly from SD card, without needing to convert to base64 or array. I understand LVGL library could do this. Has anyone done this?

You have to include an external library first, I personally use LodePNG.
If you use VSCode with PlatformIO, you have to add this line to “platformio.ini”:

lib_deps = mbed-unix-guru/lodePNG@0.0.0+sha.6b244485c156

Then, enable LodePNG in lv_conf.h:

#define LV_USE_LODEPNG 1

Finally in your code you can directly load PNG from SDCard, like so:

lv_img_set_src(img, "S:/mypicture.png");

See also the documentation:
https://docs.lvgl.io/8/libs/png.html#example

1 Like

Thanks for the reply. I’m still new in all these, especially LVGL. I’m using Arduino IDE. Different AIs have shown me different configuration for lv_conf.h. For instance below is given by Claude AI. But it did not include #define LV_USE_LODEPNG 1 as you mentioned even though I explicitly said I’m using lodePNG. I wonder if there’s a standard lv_conf.h file that I can use to display PNG on 480x320 display?

#ifndef LV_CONF_H
#define LV_CONF_H

#define LV_COLOR_DEPTH 16
#define LV_COLOR_16_SWAP 0
#define LV_MEM_CUSTOM 0
#define LV_MEM_SIZE (48U * 1024U)
#define LV_USE_PERF_MONITOR 0
#define LV_USE_MEM_MONITOR 0
#define LV_USE_LOG 0
#define LV_FONT_MONTSERRAT_14 1
#define LV_USE_THEME_DEFAULT 1
#define LV_THEME_DEFAULT_DARK 0
#define LV_USE_IMG 1
#define LV_IMG_CACHE_DEF_SIZE 1

#endif

LVGL is very versatile and can adapt to infinite hardware/software configurations, thus a standard conf file is hard to have.

Personally I start always from scratch using the template that is shipped with LVGL itself, you can find it in the source root directory of the library, named lv_conf_template.h.
It’s a pretty long header file with many #defines but I suggest you to read through it to better understand what are the capabilities of the library.

I know that if you are new to the subject it will be hard at start, but keep trying and the results will come soon :slight_smile:

1 Like