Canvas(画布)(lv_canvas)
Overview(概述)
显示原文
A Canvas inherits from Image and extends it, enabling the user to draw anything. Rectangles, text, images, lines, arcs, etc. can be drawn here using LVGL's extensive drawing engine.
画布(Canvas)继承自 Image 并对其进行了扩展,使用户能够绘制任何内容。在这里,可以使用 LVGL 强大的绘图引擎绘制矩形、文本、图像、线条、弧线等等。
Parts and Styles(部分和样式)
显示原文
LV_PART_MAIN
Uses the typical rectangle and image style properties.
LV_PART_MAIN
使用典型的矩形和图像样式属性。
Usage(用法)
Buffer(缓冲区)
显示原文
The Canvas needs a buffer in which it store the drawn image. To assign a
buffer to a Canvas, use
lv_canvas_set_buffer(canvas, buffer, width, height, LV_COLOR_FORMAT_...).
Where buffer
is a static buffer (not just a local variable) to hold
the image of the canvas. For example for a 100x50 ARGB8888 buffer:
static uint8_t buffer[100 * 50 * 4]
.
Or you can use
static uint8_t buffer[LV_CANVAS_BUF_SIZE(width, height, bit_per_pixel, stride_in_bytes)]
.
Canvas supports all the color formats like
LV_COLOR_FORMAT_ARGB8888
or LV_COLOR_FORMAT_I2
. See the full
list in the Color formats section.
Canvas 需要一个缓冲区来存储绘制的图像。 要为 Canvas 分配缓冲区,请使用函数 lv_canvas_set_buffer(canvas, buffer, width, height, LV_COLOR_FORMAT_...) , 其中参数 buffer
是一个静态缓冲区(不能是局部变量)来保存画布的图像。例如,对于 100x50 的 ARGB888缓冲区,可以这样分配:
static uint8_t buffer[100 * 50 * 4]
static uint8_t buffer[LV_CANVAS_BUF_SIZE(width, height, bit_per_pixel, stride_in_bytes)]
画布支持所有LVGL内置支持的颜色格式,如 LV_COLOR_FORMAT_ARGB8888
或 LV_COLOR_FORMAT_I2
,请阅读 Color formats 了解完整的格式列表。
Indexed colors(颜色索引)
显示原文
For indexed color formats (LV_COLOR_FORMAT_I1/2/4/8
), the palette needs to be
populated for all palette indices that will be used using
lv_canvas_set_palette(canvas, index, color). For example, the following
sets pixels with index==3 to red.
lv_canvas_set_palette(canvas, 3, lv_color_hex(0xff0000))
对于索引颜色格式(LV_COLOR_FORMAT_I1/2/4/8
),需要使用 :cpp:expr:`lv_canvas_set_palette(canvas, index, color)`为所有将要使用的调色板索引填充调色板。例如,以