随笔 - 2649  文章 - 2452  评论 - 0  阅读 - 80424

Snapshot

Snapshot

Snapshot provides APIs to take snapshot image for LVGL object together with its children. The image will look exactly like the object.

Usage

Simply call API lv_snapshot_take to generate the image descriptor which can be set as image object src using lv_img_set_src.

Note, only below color formats are supported for now:

  • LV_IMG_CF_TRUE_COLOR_ALPHA
  • LV_IMG_CF_ALPHA_1BIT
  • LV_IMG_CF_ALPHA_2BIT
  • LV_IMG_CF_ALPHA_4BIT
  • LV_IMG_CF_ALPHA_8BIT

Free the Image

The memory lv_snapshot_take uses are dynamically allocated using lv_mem_alloc. Use API lv_snapshot_free to free the memory it takes. This will firstly free memory the image data takes, then the image descriptor.

Take caution to free the snapshot but not delete the image object. Before free the memory, be sure to firstly unlink it from image object, using lv_img_set_src(NULL) and lv_img_cache_invalidate_src(src).

Below code snippet explains usage of this API.

void update_snapshot(lv_obj_t * obj, lv_obj_t * img_snapshot)
{
    lv_img_dsc_t* snapshot = (void*)lv_img_get_src(img_snapshot);
    if(snapshot) {
        lv_snapshot_free(snapshot);
    }
    snapshot = lv_snapshot_take(obj, LV_IMG_CF_TRUE_COLOR_ALPHA);
    lv_img_set_src(img_snapshot, snapshot);
}

Use Existing Buffer

If the snapshot needs update now and then, or simply caller provides memory, use API lv_res_t lv_snapshot_take_to_buf(lv_obj_t * obj, lv_img_cf_t cf, lv_img_dsc_t * dsc, void * buf, uint32_t buff_size); for this case. It’s caller’s responsibility to alloc/free the memory.

If snapshot is generated successfully, the image descriptor is updated and image data will be stored to provided buf.

Note that snapshot may fail if provided buffer is not enough, which may happen when object size changes. It’s recommended to use API lv_snapshot_buf_size_needed to check the needed buffer size in byte firstly and resize the buffer accordingly.

Example

API

警告

doxygenfile: Unable to find project ‘lvgl’ in breathe_projects dictionary

posted on   AtlasLapetos  阅读(7)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示