您当前的位置: 首页 > 

暂无认证

  • 11浏览

    0关注

    94281博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

LVGL 8.2.0之Canvas

发布时间:2022-03-20 13:41:58 ,浏览量:11

Drawing on the Canvas and rotate
#define CANVAS_WIDTH 240 #define CANVAS_HEIGHT 240 static void lv_example_canvas_1(void) { lv_draw_rect_dsc_t rect_dsc; lv_draw_rect_dsc_init(&rect_dsc); //初时化矩形描述符变量 rect_dsc.radius = 10; // 圆角为10 rect_dsc.bg_opa = LV_OPA_COVER; //透明度为覆盖着色 rect_dsc.bg_grad.dir = LV_GRAD_DIR_HOR; //水平方向grad rect_dsc.bg_grad.stops[0].color = lv_palette_main(LV_PALETTE_RED); //0 grad为红色 rect_dsc.bg_grad.stops[1].color = lv_palette_main(LV_PALETTE_BLUE);//1 grad为蓝色 rect_dsc.border_width = 2; //边框宽度为2 rect_dsc.border_opa = LV_OPA_90; //边框透明度为90% rect_dsc.border_color = lv_color_white(); //边框颜色为白色 rect_dsc.shadow_width = 5; //阴影宽度为5 rect_dsc.shadow_ofs_x = 5; //阴影向右偏移5 rect_dsc.shadow_ofs_y = 5; //阴影向下偏移5 lv_draw_label_dsc_t label_dsc; lv_draw_label_dsc_init(&label_dsc); //初时化label描述符变量 label_dsc.color = lv_palette_main(LV_PALETTE_ORANGE); static lv_color_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)]; //颜色数组 lv_obj_t* canvas = lv_canvas_create(lv_scr_act()); //创建画布对象 lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_TRUE_COLOR); //设置画布大小,颜色 lv_obj_center(canvas); //画布居中 lv_canvas_fill_bg(canvas, lv_palette_lighten(LV_PALETTE_GREY, 3), LV_OPA_COVER); //画布填充淡灰色 lv_canvas_draw_rect(canvas, 70, 60, 100, 70, &rect_dsc); //在画布上绘制矩形 lv_canvas_draw_text(canvas, 40, 20, 100, &label_dsc, "Some text on text canvas"); //在画布上绘制文字 /*Test the rotation. It requires another buffer where the original image is␣
    ,→stored.
    *So copy the current image to buffer and rotate it to the canvas*/ static lv_color_t cbuf_tmp[CANVAS_WIDTH * CANVAS_HEIGHT]; //画布暂存数组 memcpy(cbuf_tmp, cbuf, sizeof(cbuf_tmp)); //画布内容复制到暂存数组 lv_img_dsc_t img; //图片描述符变量 img.data = (void*)cbuf_tmp; img.header.cf = LV_IMG_CF_TRUE_COLOR; img.header.w = CANVAS_WIDTH; img.header.h = CANVAS_HEIGHT; lv_canvas_fill_bg(canvas, lv_palette_lighten(LV_PALETTE_GREY, 3), LV_OPA_COVER); lv_canvas_transform(canvas, &img, 120, LV_IMG_ZOOM_NONE, 0, 0, CANVAS_WIDTH / 2, CANVAS_HEIGHT / 2, true); //旋转120,缩小到一半显示画布内容 } 
  • 调用函数lv_example_canvas_1,运行效果图 在这里插入图片描述
Transparent Canvas with chroma keying
#define CANVAS_WIDTH 50 #define CANVAS_HEIGHT 50 /**
 * Create a transparent canvas with Chroma keying and indexed color format (palette).
*/ static void lv_example_canvas_2(void) { /*Create a button to better see the transparency*/ lv_btn_create(lv_scr_act()); /*Create a buffer for the canvas*/ static lv_color_t cbuf[LV_CANVAS_BUF_SIZE_INDEXED_1BIT(CANVAS_WIDTH, CANVAS_HEIGHT)]; // 存放颜色数组 /*Create a canvas and initialize its palette*/ lv_obj_t* canvas = lv_canvas_create(lv_scr_act()); //创建画布对象 lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_INDEXED_1BIT); //将画布对象与颜色数组关联上 lv_canvas_set_palette(canvas, 0, LV_COLOR_CHROMA_KEY);//设置id 0调色盘 lv_canvas_set_palette(canvas, 1, lv_palette_main(LV_PALETTE_RED));//设置id 1调色盘 /*Create colors with the indices of the palette*/ lv_color_t c0; lv_color_t c1; c0.full = 0; c1.full = 1; /*Red background (There is no dedicated alpha channel in indexed images so LV_OPA_
    ,→COVER is ignored)*/ lv_canvas_fill_bg(canvas, c1, LV_OPA_COVER); //填充c1调色盘颜色 /*Create hole on the canvas*/ uint32_t x; uint32_t y; for (y = 10; y < 30; y++) { for (x = 5; x < 20; x++) { lv_canvas_set_px_color(canvas, x, y, c0); //设置c0调色盘颜色 } } } 
  • 调用函数lv_example_canvas_2,运行效果图 在这里插入图片描述
关注
打赏
1655516835
查看更多评论
立即登录/注册

微信扫码登录

1.8965s