How to set a img as the background image


What MCU/Processor/Board and compiler are you using?


What LVGL version are you using?


What do you want to achieve?

Set a img as the background image, and put other widgets on the background image.

What have you tried so far?

Code to reproduce

/You code here/

    lv_img_set_src(img, &bgimg);

## Screenshot and/or video
If possible, add screenshots and/or videos about the current state.

Just simply add img first on the screen, and then any other widget can be added after it to screen, or just a child of img.
Visible LVGL “screen” can be built as tree-hierarchy from the objects (just like HTML DOM), so you add also child LVGL objects to img.

For example (MicroPython code):

screen = lv.obj()

# Set background image
background_image = lv.img(screen)

# Add child button to parent screen, it will be shown in front of background image
button1 = lv.btn(screen)
button1.set_pos(x, y)

# Add child button to image parent, it will be also shown in front of background image
button2 = lv.btn(background_image)
button2.set_pos(x, y)

# Show screen

That’s perfect! Thanks a lot!

Sorry @wushili , does it really work for an image which is sourced from a file as a binary file and it does not give an effect to another object?

I have tried it, since I used an lcd touchscreen, it works but gives a slow response when touching it, and the MCU often restarts by itself.

The MCU I use is ESP32