量子计算中的李群与李代数:从数学基石到时间最优控制实践
2026/5/24 5:45:04
LVGL 可以轻松的设置背景图片,API 为lv_obj_set_style_bg_image_src
验证发现,可以设置不同对象的背景图片,比如当前屏幕lv_screen_active()的,或者某个控件的,比如一个按钮 Button 的。
lv_obj_set_style_bg_image_src(lv_screen_active(),"C:../apps/images/bg_03.png",0);比如设置的背景图片是 png 格式的,就需要 LVGL 开启#define LV_USE_LODEPNG 1,或者使用#define LV_USE_LIBPNG 1与额外的libpng库
注意【背景图片的路径必须是全局的】,比如【字符串常量】,或者动态申请的内存,或者是静态全局的数组。也就是背景图设置后,是异步【刷图】的,如果背景图片使用了【局部变量】,设置完,局部变量失效,导致背景图不能正常的显示。
由于 LVGL 的路径需要增加前缀,比如A:或者C:之类的,拼接的路径,一定要注意是全局的,也就是变量的生命周期。
lv_obj_set_style_bg_image_src(lv_screen_active(), "C:../apps/images/bg_03.png", 0);
voidlv_example_get_started_2(void){lv_obj_t*btn=lv_button_create(lv_screen_active());/*Add a button the current screen*/lv_obj_set_pos(btn,10,10);/*Set its position*/lv_obj_set_size(btn,120,50);/*Set its size*/lv_obj_add_event_cb(btn,btn_event_cb,LV_EVENT_ALL,NULL);/*Assign a callback to the button*/lv_obj_t*label=lv_label_create(btn);/*Add a label to the button*/lv_label_set_text(label,"Button");/*Set the labels text*/lv_obj_set_style_text_color(label,lv_color_black(),LV_STATE_DEFAULT);lv_obj_center(label);// lv_obj_set_style_bg_image_src(lv_screen_active(), "C:../apps/images/bg_03.png", 0);lv_obj_set_style_bg_image_src(btn,"C:../apps/images/bg_04.png",0);}