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,运行效果图
#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
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?