libpng Decoder
libpng is an LVGL interface to the the official PNG reference library, which supports almost all PNG features, is extensible, and has been extensively tested for over 28 years.
For a detailed introduction, see: http://www.libpng.org/pub/png/libpng.html .
Install
sudo apt install libpng-dev
Adding libpng to Your Project
Cmake:
find_package(PNG REQUIRED)
include_directories(${PNG_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE ${PNG_LIBRARIES})
Usage
Set LV_USE_LIBPNG
in lv_conf.h
to 1
.
See the examples below.
It should be noted that each image of this decoder needs to consume
width × height × 4
bytes of RAM, and it needs to be combined with the Image caching feature to ensure that the memory usage is within a reasonable range. The decoded image is stored in RGBA pixel format.
Example
Open a PNG image from file and variable
C code
View on GitHub#include "../../lv_examples.h"
#if LV_BUILD_EXAMPLES
#if LV_USE_LIBPNG
/**
* Open a PNG image from a file
*/
void lv_example_libpng_1(void)
{
LV_IMAGE_DECLARE(img_png_demo);
lv_obj_t * img;
img = lv_image_create(lv_screen_active());
lv_image_set_src(img, &img_png_demo);
lv_obj_align(img, LV_ALIGN_LEFT_MID, 10, 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/libpng/png_demo.png");
lv_obj_align(img, LV_ALIGN_RIGHT_MID, -10, 0);
}
#else
void lv_example_libpng_1(void)
{
lv_obj_t * label = lv_label_create(lv_screen_active());
lv_label_set_text(label, "LibPNG is not installed");
lv_obj_center(label);
}
#endif
#endif