本文主要是介绍transparent canvas with chroma keying for little vGL,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
-
定义画布尺寸
#define TRANSPARENT_CANVAS_WIDTH 50 #define TRANSPARENT_CANVAS_HIGHT 50
-
创建一个button
lv_btn_create(lv_scr_act(), NULL);
-
定义画布缓冲buffer,注意不能是局部的
static lv_color_t cbuf[LV_CANVAS_BUF_SIZE_INDEXED_1BIT(TRANSPARENT_CANVAS_WIDTH,TRANSPARENT_CANVAS_HIGHT)];
-
创建画布对象
lv_obj_t* canvas = lv_canvas_create(lv_scr_act(), NULL);
-
设置关联画布缓冲buffer
lv_canvas_set_buffer(canvas, cbuf, TRANSPARENT_CANVAS_WIDTH, TRANSPARENT_CANVAS_HIGHT, LV_IMG_CF_INDEXED_1BIT);
-
设置透明和红色2个调色盘
lv_canvas_set_palette(canvas, 0, LV_COLOR_TRANSP);lv_canvas_set_palette(canvas, 1, LV_COLOR_RED);
-
定义颜色变量C0,C1
lv_color_t c0;lv_color_t c1;c0.full = 0;c1.full = 1;
-
绘制C0,C1
lv_canvas_fill_bg(canvas, c1);uint32_t x, y;for (y = 10; y < 30; y++){for (x = 5; x < 20; x++){lv_canvas_set_px(canvas, x, y, c0);}}
-
完整的实现
#define TRANSPARENT_CANVAS_WIDTH 50
#define TRANSPARENT_CANVAS_HIGHT 50
void transparent_canvas_demo(void) {lv_btn_create(lv_scr_act(), NULL);static lv_color_t cbuf[LV_CANVAS_BUF_SIZE_INDEXED_1BIT(TRANSPARENT_CANVAS_WIDTH,TRANSPARENT_CANVAS_HIGHT)];lv_obj_t* canvas = lv_canvas_create(lv_scr_act(), NULL);lv_canvas_set_buffer(canvas, cbuf, TRANSPARENT_CANVAS_WIDTH, TRANSPARENT_CANVAS_HIGHT, LV_IMG_CF_INDEXED_1BIT);lv_canvas_set_palette(canvas, 0, LV_COLOR_TRANSP);lv_canvas_set_palette(canvas, 1, LV_COLOR_RED);lv_color_t c0;lv_color_t c1;c0.full = 0;c1.full = 1;lv_canvas_fill_bg(canvas, c1);uint32_t x, y;for (y = 10; y < 30; y++) {for (x = 5; x < 20; x++) {lv_canvas_set_px(canvas, x, y, c0);}}
}
-
调用transparent_canvas_demo函数,编译运行
这篇关于transparent canvas with chroma keying for little vGL的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!