lv_canvas.h

API reference for lv_canvas.h

Report on GitHub
See Also: Private HeaderThis header has a companion private implementation with internal data structures.lv_canvas_private.h

Functions

lv_canvas_set_buffer

Set a buffer for the canvas.

Use lv_canvas_set_draw_buf() instead if you need to set a buffer with alignment requirement.

 
void lv_canvas_set_buffer(lv_obj_t *obj, void *buf, int32_t w, int32_t h, lv_color_format_t cf)
Parameters
NameTypeDescription
objlv_obj_t *pointer to a canvas object
bufvoid *buffer where content of canvas will be. The required size is (lv_image_color_format_get_px_size(cf) * w) / 8 * h) It can be allocated with lv_malloc() or it can be statically allocated array (e.g. static lv_color_t buf[100*50]) or it can be an address in RAM or external SRAM
wint32_twidth of canvas
hint32_theight of canvas
cflv_color_format_tcolor format. LV_COLOR_FORMAT...

lv_canvas_set_draw_buf

Set a draw buffer for the canvas. A draw buffer either can be allocated by lv_draw_buf_create() or defined statically by LV_DRAW_BUF_DEFINE_STATIC. When buffer start address and stride has alignment requirement, it's recommended to use lv_draw_buf_create.

 
void lv_canvas_set_draw_buf(lv_obj_t *obj, lv_draw_buf_t *draw_buf)
Parameters
NameTypeDescription
objlv_obj_t *pointer to a canvas object
draw_buflv_draw_buf_t *pointer to a draw buffer

lv_canvas_set_px

Set a pixel's color and opacity

 
void lv_canvas_set_px(lv_obj_t *obj, int32_t x, int32_t y, lv_color_t color, lv_opa_t opa)
Parameters
NameTypeDescription
objlv_obj_t *pointer to a canvas
xint32_tX coordinate of the pixel
yint32_tY coordinate of the pixel
colorlv_color_tthe color
opalv_opa_tthe opacity

The following color formats are supported LV_COLOR_FORMAT_I1/2/4/8, LV_COLOR_FORMAT_A8, LV_COLOR_FORMAT_RGB565, LV_COLOR_FORMAT_RGB888, LV_COLOR_FORMAT_XRGB8888, LV_COLOR_FORMAT_ARGB8888

this function invalidates the canvas object every time, for best performance, if you're changing a lot of pixels in a loop, call lv_display_enable_invalidation before the loop starts so the invalidation isn't done on every call

lv_canvas_set_palette

Set the palette color of a canvas for index format. Valid only for LV_COLOR_FORMAT_I1/2/4/8

 
void lv_canvas_set_palette(lv_obj_t *obj, uint8_t index, lv_color32_t color)
Parameters
NameTypeDescription
objlv_obj_t *pointer to canvas object
indexuint8_tthe palette color to set:
- for LV_COLOR_FORMAT_I1: 0..1
- for LV_COLOR_FORMAT_I2: 0..3
- for LV_COLOR_FORMAT_I4: 0..15
- for LV_COLOR_FORMAT_I8: 0..255
colorlv_color32_tthe color to set

Macros

LV_CANVAS_BUF_SIZE

 
#define LV_CANVAS_BUF_SIZE(w, h, bpp, stride) \
    (((((w * bpp + 7) >> 3) + stride - 1) & ~(stride - 1)) * h + LV_DRAW_BUF_ALIGN)

Variables

lv_canvas_class

 
const lv_obj_class_t lv_canvas_class

Dependencies

How is this guide?

Last updated on

On this page