1CANVAS_WIDTH = 50 2CANVAS_HEIGHT = 50 3LV_COLOR_CHROMA_KEY = lv.color_hex(0x00ff00) 4 5def LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h): 6 return int(((w / 8) + 1) * h) 7 8def LV_IMG_BUF_SIZE_INDEXED_1BIT(w, h): 9 return LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h) + 4 * 2 10 11def LV_CANVAS_BUF_SIZE_INDEXED_1BIT(w, h): 12 return LV_IMG_BUF_SIZE_INDEXED_1BIT(w, h) 13 14# 15# Create a transparent canvas with Chroma keying and indexed color format (palette). 16# 17 18# Create a button to better see the transparency 19btn=lv.btn(lv.scr_act()) 20 21# Create a buffer for the canvas 22cbuf= bytearray(LV_CANVAS_BUF_SIZE_INDEXED_1BIT(CANVAS_WIDTH, CANVAS_HEIGHT)) 23 24# Create a canvas and initialize its palette 25canvas = lv.canvas(lv.scr_act()) 26canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.INDEXED_1BIT) 27canvas.set_palette(0, LV_COLOR_CHROMA_KEY) 28canvas.set_palette(1, lv.palette_main(lv.PALETTE.RED)) 29 30# Create colors with the indices of the palette 31c0 = lv.color_t() 32c1 = lv.color_t() 33 34c0.full = 0 35c1.full = 1 36 37# Red background (There is no dedicated alpha channel in indexed images so LV_OPA_COVER is ignored) 38canvas.fill_bg(c1, lv.OPA.COVER) 39 40# Create hole on the canvas 41for y in range(10,30): 42 for x in range(5,20): 43 canvas.set_px(x, y, c0) 44