LVGL使用笔记

LVGL_显示图片

此笔记记录了如何开启lvgl中加载图片的功能,开启后无需每次将图片转换为.C文件

一、配置

打开lvgl中的lv_conf.h配置文件
配置步骤如下:

  1. 启用对应格式图片的解码器库
//启用png格式的解码器库
#define LV_USE_PNG 1
//启用gif格式的解码器库
#define LV_USE_GIF 1

如需其他格式的图片,类似操作。

  1. 配置文件系统(linux)
/*File system interfaces for common APIs
 *To enable set a driver letter for that API*/
#define LV_USE_FS_STDIO '/'        /*Uses fopen, fread, etc*/
//#define LV_FS_STDIO_PATH "/home/john/"    /*Set the working directory. If commented it will be "./" */
#if LV_USE_FS_STDIO
    #define LV_FS_STDIO_LETTER '/'     /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/
    #define LV_FS_STDIO_PATH "/"         /*Set the working directory. File/directory paths will be appended to it.*/
    #define LV_FS_STDIO_CACHE_SIZE  0   /*>0 to cache this number of bytes in lv_fs_read()*/
#endif
  1. 适当调整分配的内存
/*Size of the memory available for `lv_mem_alloc()` in bytes (>= 2kB)*/
#  define LV_MEM_SIZE (20480U * 1024U)          /*[bytes]*/

注:若内存分配不够,大点的图标就会加载不出来。

二、使用方式

//显示png图片
lv_obj_t *img_logo = lv_img_create(lv_scr_act());
lv_img_set_src(img_logo, "/tmp/test.png");
//显示gif
lv_obj_t *gif = lv_gif_create(lv_scr_act());
lv_gif_set_src(gif, "/tmp/test2.gif");
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值