Allow the use of PNG images in LVGL. This implementation uses lodepng library.
git clone https://github.com/littlevgl/lv_lib_png.git
#include "lv_lib_png/lv_png.h"
lv_png_init()
LV_IMG_DECLARE(png_decoder_test);
lv_obj_t * img = lv_img_create(lv_scr_act(), NULL);
lv_img_set_src(img, &png_decoder_test);
By deafult lodepng
uses C file IO API (e.g. fopen
) and images can be opened like this:
lv_img_set_src(img, "./lv_lib_lodepng/png_decoder_test.png");
If you want to make lodepng
to use LVGL's file system API add #define LV_PNG_USE_LV_FILESYSTEM 1
to the end of yourlv_conf.h
.
In this case you need to register a driver fo LVGL. The following functions are required:
open_cb()
read_cb()
close_cb()
size_cb()
After that fiels can be opened like this:
lv_img_set_src(img, "P:lv_lib_lodepng/png_decoder_test.png");
Note that the path of the file might be different.
To store a PNG image in flash it needs to be converted to C array with Online Image converter. Choose Raw with alpha
Color format and C array
Output format. Copy the result C array to your project and use it like this:
LV_IMG_DECLARE(my_test_img);
lv_obj_t * img = lv_img_create(lv_scr_act(), NULL);
lv_img_set_src(img, &my_test_img);
To learn more about the PNG decoder itself read this blog post
To learn more about the Image decoder interface of LittlevGL read the realevant part of the documentation.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。