LodePNG Decoder
LodePNG is an LVGL interface to the LodePNG library — a PNG encoder and decoder in C and C++, without any dependencies, giving you an alternate way to use PNG images in your LVGL UI.
For a detailed introduction, see: https://github.com/lvandeve/lodepng .
If enabled in lv_conf.h
by setting LV_USE_LODEPNG
to 1
, LVGL will
register a new image decoder automatically so PNG files can be used directly as an
image source.
Note
A file system driver needs to be registered to open images from files. To do so, follow the instructions in File System (lv_fs_drv).
The whole PNG image is decoded, so
width × height × 4
bytes of RAM is required from the LVGL heap. The decoded image is stored in RGBA pixel format.
Since it might take significant time to decode PNG images LVGL's Image caching feature can be useful.
Compressing PNG Files
PNG file format supports True color (24/32 bit), and 8-bit palette colors. Usually cliparts, drawings, icons and simple graphics are stored in PNG format, that do not use the whole color space, so it is possible to compress further the image by using 8-bit palette colors, instead of 24/32 bit True color format. Because embedded devices have limited (flash) storage, it is recommended to compress images.
One option is to use a free online PNG compressor site, for example Compress PNG: https://compresspng.com/
Example
Open a PNG image from file and variable
C code
View on GitHub#include "../../lv_examples.h"
#if LV_USE_LODEPNG && LV_USE_IMAGE && LV_BUILD_EXAMPLES
/**
* Open a PNG image from a file and a variable
*/
void lv_example_lodepng_1(void)
{
LV_IMAGE_DECLARE(img_wink_png);
lv_obj_t * img;
img = lv_image_create(lv_screen_active());
lv_image_set_src(img, &img_wink_png);
lv_obj_align(img, LV_ALIGN_LEFT_MID, 20, 0);
img = lv_image_create(lv_screen_active());
/* Assuming a File system is attached to letter 'A'
* E.g. set LV_USE_FS_STDIO 'A' in lv_conf.h */
lv_image_set_src(img, "A:lvgl/examples/libs/lodepng/wink.png");
lv_obj_align(img, LV_ALIGN_RIGHT_MID, -20, 0);
}
#endif