1 #include "../../lv_examples.h"
2 #if LV_USE_CANVAS && LV_BUILD_EXAMPLES
3
4 #define CANVAS_WIDTH 50
5 #define CANVAS_HEIGHT 50
6
7 /**
8 * Create a transparent canvas with Chroma keying and indexed color format (palette).
9 */
lv_example_canvas_2(void)10 void lv_example_canvas_2(void)
11 {
12 /*Create a button to better see the transparency*/
13 lv_btn_create(lv_scr_act());
14
15 /*Create a buffer for the canvas*/
16 static lv_color_t cbuf[LV_CANVAS_BUF_SIZE_INDEXED_1BIT(CANVAS_WIDTH, CANVAS_HEIGHT)];
17
18 /*Create a canvas and initialize its palette*/
19 lv_obj_t * canvas = lv_canvas_create(lv_scr_act());
20 lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_INDEXED_1BIT);
21 lv_canvas_set_palette(canvas, 0, LV_COLOR_CHROMA_KEY);
22 lv_canvas_set_palette(canvas, 1, lv_palette_main(LV_PALETTE_RED));
23
24 /*Create colors with the indices of the palette*/
25 lv_color_t c0;
26 lv_color_t c1;
27
28 c0.full = 0;
29 c1.full = 1;
30
31 /*Red background (There is no dedicated alpha channel in indexed images so LV_OPA_COVER is ignored)*/
32 lv_canvas_fill_bg(canvas, c1, LV_OPA_COVER);
33
34 /*Create hole on the canvas*/
35 uint32_t x;
36 uint32_t y;
37 for(y = 10; y < 30; y++) {
38 for(x = 5; x < 20; x++) {
39 lv_canvas_set_px_color(canvas, x, y, c0);
40 }
41 }
42
43 }
44 #endif
45