PNG decoder

Allow the use of PNG images in LVGL. This implementation uses lodepng library.

If enabled in lv_conf.h by LV_USE_PNG LVGL will register a new image decoder automatically so PNG files can be directly used as any other image sources.

Note that, a file system driver needs to registered to open images from files. Read more about it here or just enable one in lv_conf.h with LV_USE_FS_...

The whole PNG image is decoded so during decoding RAM equals to image width x image height x 4 bytes are required.

As it might take significant time to decode PNG images LVGL's images caching feature can be useful.

Example

Open a PNG image from file and variable

C code  

 GitHub
#include "../../lv_examples.h"
#if LV_USE_PNG && LV_BUILD_EXAMPLES

/**
 * Open a PNG image from a file and a variable
 */
void lv_example_png_1(void)
{
    LV_IMG_DECLARE(img_wink_png);
    lv_obj_t * img;

    img = lv_img_create(lv_scr_act());
    lv_img_set_src(img, &img_wink_png);
    lv_obj_align(img, LV_ALIGN_LEFT_MID, 20, 0);

    img = lv_img_create(lv_scr_act());
    /* Assuming a File system is attached to letter 'A'
     * E.g. set LV_USE_FS_STDIO 'A' in lv_conf.h */
    lv_img_set_src(img, "A:lvgl/examples/libs/png/wink.png");
    lv_obj_align(img, LV_ALIGN_RIGHT_MID, -20, 0);
}

#endif

MicroPython code  

 GitHub Simulator
Error encountered while trying to open /home/runner/work/lvgl/lvgl/examples/libs/png/lv_example_png_1.py

API

Functions

void lv_png_init(void)

Register the PNG decoder functions in LittlevGL