Refreshing canvas after setting buffer

I hope someone can assist with refreshing a canvas buffer from camera data. I am fetching a buffer from a camera in RGB565 format, as below.

scr = lv.obj()
canvas = lv.canvas(scr)
buf = camera.capture()
canvas.set_buffer(buf, 240, 240, lv.img.CF.TRUE_COLOR)

If I wish to update the buffer, the updates are not displayed, for example.

for x in range(10):
    buf = camera.capture()
    canvas.set_buffer(buf, 240, 240, lv.img.CF.TRUE_COLOR)

I tried using an img widget as opposed to a canvas widget but was unable to get the buffer to display in the img widget. Any assistance would be great! Thank you.

Hi @numski !

“camera” is not part of LVGL. You didn’t specify what camera.capture() returns. A memoryview? Something else?

Anyway, you are not supposed to call set_buffer repeatedly. You call it once to allocate a buffer for the canvas. You can call copy_buf later to copy some buffer into the canvas.

Here is a small example on the online simulator to demonstrate this.

Ok, right, camera is another module I have loaded which is not part of lvgl. I didn’t include my camera or screen initialization since it’s specific to my build and I don’t want to confuse anyone with it. It correctly displays the picture initially and I’m assuming it’s a list of bytes returned from the camera which is RGB565 format, which should be 16bit. I’ll give the copy_buf a shot and report back. Thank you.