lv_canvas.h
API reference for lv_canvas.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)| Name | Type | Description |
|---|---|---|
obj | lv_obj_t * | pointer to a canvas object |
buf | void * | 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 |
w | int32_t | width of canvas |
h | int32_t | height of canvas |
cf | lv_color_format_t | color 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)| Name | Type | Description |
|---|---|---|
obj | lv_obj_t * | pointer to a canvas object |
draw_buf | lv_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)| Name | Type | Description |
|---|---|---|
obj | lv_obj_t * | pointer to a canvas |
x | int32_t | X coordinate of the pixel |
y | int32_t | Y coordinate of the pixel |
color | lv_color_t | the color |
opa | lv_opa_t | the 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)| Name | Type | Description |
|---|---|---|
obj | lv_obj_t * | pointer to canvas object |
index | uint8_t | the 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 |
color | lv_color32_t | the color to set |
lv_canvas_get_draw_buf
lv_draw_buf_t * lv_canvas_get_draw_buf(lv_obj_t *obj)| Name | Type |
|---|---|
obj | lv_obj_t * |
lv_canvas_get_px
Get a pixel's color and opacity
lv_color32_t lv_canvas_get_px(lv_obj_t *obj, int32_t x, int32_t y)| Name | Type | Description |
|---|---|---|
obj | lv_obj_t * | pointer to a canvas |
x | int32_t | X coordinate of the pixel |
y | int32_t | Y coordinate of the pixel |
Returns: lv_color32_t — ARGB8888 color of the pixel
lv_canvas_get_image
Get the image of the canvas as a pointer to an lv_image_dsc_t variable.
lv_image_dsc_t * lv_canvas_get_image(lv_obj_t *obj)| Name | Type | Description |
|---|---|---|
obj | lv_obj_t * | pointer to a canvas object |
Returns: lv_image_dsc_t * — pointer to the image descriptor.
lv_canvas_get_buf
Return the pointer for the buffer. It's recommended to use this function instead of the buffer form the return value of lv_canvas_get_image() as is can be aligned
const void * lv_canvas_get_buf(lv_obj_t *obj)| Name | Type | Description |
|---|---|---|
obj | lv_obj_t * | pointer to a canvas object |
Returns: const void * — pointer to the buffer
lv_canvas_create
Create a canvas object
lv_obj_t * lv_canvas_create(lv_obj_t *parent)| Name | Type | Description |
|---|---|---|
parent | lv_obj_t * | pointer to a parent widget May be NULL.. When NULL, the widget is created as a screen on the default display. |
Returns: lv_obj_t * — pointer to the created canvas
lv_canvas_copy_buf
Copy a buffer to the canvas
void lv_canvas_copy_buf(lv_obj_t *obj, const lv_area_t *canvas_area, lv_draw_buf_t *src_buf, const lv_area_t *src_area)| Name | Type | Description |
|---|---|---|
obj | lv_obj_t * | pointer to a canvas object |
canvas_area | const lv_area_t * | the area of the canvas to copy the new data to |
src_buf | lv_draw_buf_t * | pointer to a buffer holding the source data |
src_area | const lv_area_t * | the area of the source buffer to copy from. May be NULL. When NULL the whole buffer is copied. |
canvas_area and src_area should be the same size. If canvas_area and the size of src_buf are the same, src_area can be left NULL.
lv_canvas_fill_bg
Fill the canvas with color
void lv_canvas_fill_bg(lv_obj_t *obj, lv_color_t color, lv_opa_t opa)| Name | Type | Description |
|---|---|---|
obj | lv_obj_t * | pointer to a canvas |
color | lv_color_t | the background color |
opa | lv_opa_t | the desired opacity |
lv_canvas_init_layer
Initialize a layer to use LVGL's generic draw functions (lv_draw_rect/label/...) on the canvas. Needs to be usd in pair with lv_canvas_finish_layer.
void lv_canvas_init_layer(lv_obj_t *obj, lv_layer_t *layer)| Name | Type | Description |
|---|---|---|
obj | lv_obj_t * | pointer to a canvas |
layer | lv_layer_t * | pointer to a layer variable to initialize |
lv_canvas_finish_layer
Wait until all the drawings are finished on layer. Needs to be usd in pair with lv_canvas_init_layer.
void lv_canvas_finish_layer(lv_obj_t *canvas, lv_layer_t *layer)| Name | Type | Description |
|---|---|---|
canvas | lv_obj_t * | pointer to a canvas |
layer | lv_layer_t * | pointer to a layer to finalize |
lv_canvas_buf_size
Just a wrapper to LV_CANVAS_BUF_SIZE for bindings.
uint32_t lv_canvas_buf_size(int32_t w, int32_t h, uint8_t bpp, uint8_t stride)| Name | Type |
|---|---|
w | int32_t |
h | int32_t |
bpp | uint8_t |
stride | uint8_t |
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_classDependencies
Indirect dependencies
lv_anim.hlv_area.hlv_assert.hlv_bidi.hlv_color.hlv_color_op.hlv_display.hlv_draw.hlv_draw_arc.hlv_draw_blur.hlv_draw_buf.hlv_draw_image.hlv_draw_label.hlv_draw_line.hlv_draw_rect.hlv_draw_triangle.hlv_event.hlv_ext_data.hlv_flex.hlv_font.hlv_fs.hlv_grad.hlv_grid.hlv_group.hlv_image_decoder.hlv_image_dsc.hlv_indev.hlv_layout.hlv_ll.hlv_log.hlv_math.hlv_matrix.hlv_mem.hlv_obj.hlv_obj_class.hlv_obj_draw.hlv_obj_event.hlv_obj_pos.hlv_obj_property.hlv_obj_scroll.hlv_obj_style.hlv_obj_style_gen.hlv_obj_tree.hlv_observer.hlv_palette.hlv_profiler.hlv_profiler_builtin.hlv_sprintf.hlv_string.hlv_style.hlv_style_gen.hlv_symbol_def.hlv_text.hlv_timer.hlv_types.h
Last updated on