[How to] How to capture only the image of the specified object instead of whole of screen?


By screen snapshot at

I can already capture whole of screen.
But when I change from lv_obj_invalidate(lv_scr_act());
to lv_obj_invalidate(my_obj);
It doesn’t work.

If wish to capture only the specified object,
how to set the code ?

Thank you.

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

  • ESP32

What do you want to achieve?

Capture only one specified object.

What have you tried so far?

As the description.

Code to reproduce

Screenshot and/or video

I was already thinking about an lv_canvas feature to take a snapshot of an area.
E.g. lv_canvas_snapshot(canvas, x_ofs, y_ofs) would take a cavas-sized screenshot from x_ofs and y_ofs coordinates.

Would it work in your case?

1 Like

I assume it would take a screenshot of the display the canvas is attached to? Could it be separated from the canvas object, and just store the result in an intermediate image buffer which someone could then use as they wished?

1 Like

Why would it be required? If the problem is that the canvas will be visible on the snapshot than you can make the canvas hidden. (it can happen automatically too).

1 Like

I think that taking a screenshot should be separated from displaying that screenshot. A use might just wants to take a screenshot and use its raw data.

The canvas object doesn’t feel like the right place to put a snapshot API. I feel like it belongs in its own module or within lv_disp (e.g lv_disp_snapshot(disp, img_buf, x_off, y_off).

1 Like

That sounds reasonable! disp would be really a better place.
To avoid the use of a big buffer, we could use the disp_buf to tell parts of the image. E.g.:

lv_disp_snapshot_init(disp, area_in);
void * buf;
while(1) {
  buf = lv_disp_snapshot_get_next(disp, area_act);
  if(buf == NULL) break;

 image_save(buf, area_act);

What do you think?

1 Like

Looks good!

1 Like

I’ve added it to the TODO list if v7.0

1 Like