当前位置:网站首页>Esp32 development -lvgl display picture

Esp32 development -lvgl display picture

2022-06-11 04:07:00 z_ Curtain

How to use pictures

LVGL There are two ways to display pictures in
1、 As internal memory (RAM or ROM) The variables in the
2、 As a document


Read pictures internally

advantage : Data is compiled into firmware along with code , Easy to use .
shortcoming : Images need to be converted into array form by tools , Too many pictures perhaps The picture resolution is too large Compilation errors may occur during ( Constant data exceeded DROM).

The method of use is similar to the external font library , Use the tool to turn the picture into a .c file , In the file, there will be a constant array and... For storing image data LVGL Picture data type structure of , At the same time, the structure variable can use the picture .

const lv_img_dsc_t test = {
    
  .header.always_zero = 0,
  .header.w = 225,
  .header.h = 113,
  .data_size = 25425 * LV_COLOR_SIZE / 8,
  .header.cf = LV_IMG_CF_TRUE_COLOR,
  .data = test_map,
};

adopt LVGL api The picture can be displayed

lv_obj_t * icon = lv_img_create(lv_scr_act(), NULL);
/*From variable*/
LV_IMG_DECLARE(test );
lv_img_set_src(icon, &test );

If the image is converted using an online or tool converter , You should use LV_IMG_DECLARE(my_icon_dsc) The image declares the bits to be used in the file
Set up .

// amount to extern
#define LV_IMG_DECLARE(var_name) extern const lv_img_dsc_t var_name;

External read picture

There are two ways to store external pictures

1、 As png、jpg Wait for the picture format

Need to use SD Memory devices such as cards store pictures , It also needs to decode the picture ,LVGL Provide picture decoding API( Only partial format decoding should be supported , for example PNG)

lv_res_t res;
lv_img_decoder_dsc_t dsc;
res = lv_img_decoder_open(&dsc, &my_img_dsc, LV_COLOR_WHITE);
if(res == LV_RES_OK) {
    
 /*Do something with `dsc->img_data`*/
 lv_img_decoder_close(&dsc);
}

2、 As bin file

When pictures are bin When the file is read , need esp32 Run the file system , For details, please refer to ESP-IDF demo Medium spiffs.

Besides , It needs to be realized lvgl File manipulation functions in the file system . Refer to the following figure for specific documents .
 Insert picture description here

As a binary file ,bin The file can specify the desired color format :
RGB332 be used for 8 Metachromatic depth
RGB565 be used for 16 Metachromatic depth
RGB565 In exchange for 16 Bit color depth ( Swapped two bytes )
RGB888 be used for 32 Metachromatic depth

lv_obj_t * icon = lv_img_create(lv_scr_act(), NULL);
/*From file*/
lv_img_set_src(icon, "S:test.bin");
原网站

版权声明
本文为[z_ Curtain]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020549199541.html