BMP 解码器

此扩展允许在 LVGL 中使用 BMP 图像。 该实现使用了 bmp-decoder 库。 像素按需读取(不会加载整个图像),因此使用 BMP 图像需要非常少的 RAM。

如果在 lv_conf.h 中通过 LV_USE_BMP 启用,LVGL 将自动注册一个新的图像解码器,因此 BMP 文件可以直接用作图像源。例如:

lv_img_set_src(my_img, "S:path/to/picture.bmp");

请注意,需要注册一个文件系统驱动程序才能从文件中打开图像。有关更多信息,请阅读此处,或者只需在 lv_conf.h 中通过 LV_USE_FS_... 启用一个文件系统驱动程序。

限制

  • 仅支持 BMP 文件,不支持 BMP 图像作为 C 数组(lv_img_dsc_t)。这是因为 BMP 文件和 LVGL 的图像格式在存储图像数据方面没有实际差异。

  • BMP 文件只能从文件加载。如果您想将它们存储在闪存中,最好使用 LVGL 的图像转换器 将其转换为 C 数组。

  • BMP 文件的颜色格式需要与 LV_COLOR_DEPTH 匹配。使用 GIMP 将图像保存为所需格式。 RGB888 和 ARGB888 都适用于 LV_COLOR_DEPTH 32

  • 不支持调色板。

  • 因为不会读取整个图像,所以无法缩放或旋转。

示例

从文件中打开 BMP 图像

C code  

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

/**
 * Open a BMP file from a file
 */
void lv_example_bmp_1(void)
{
    lv_obj_t * 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 */
#if LV_COLOR_DEPTH == 32
    lv_img_set_src(img, "A:lvgl/examples/libs/bmp/example_32bit.bmp");
#elif LV_COLOR_DEPTH == 16
    lv_img_set_src(img, "A:lvgl/examples/libs/bmp/example_16bit.bmp");
#endif
    lv_obj_center(img);

}

#endif

MicroPython code  

 GitHub Simulator
#!/opt/bin/lv_micropython -i
import lvgl as lv
import display_driver
import fs_driver

fs_drv = lv.fs_drv_t()
fs_driver.fs_register(fs_drv, 'S')

img = lv.img(lv.scr_act())
# The File system is attached to letter 'S'

img.set_src("S:example_32bit.bmp")
img.center()

API

Functions

void lv_bmp_init(void)