App:Library:LVGL:docs:Others:Snapshot

提供: robot-jp wiki
2022年6月22日 (水) 21:16時点におけるTakashi (トーク | 投稿記録)による版
ナビゲーションに移動検索に移動

https://docs.lvgl.io/8.2/others/snapshot.html

英文 自動翻訳


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

Simple snapshot example

API

Functions

lv_img_dsc_t *lv_snapshot_take(lv_obj_t *obj, lv_img_cf_t cf)[1]
Take snapshot for object with its children.
Parameters[2]
  • obj -- The object to generate snapshot.
  • cf -- color format for generated image.
Returns
a pointer to an image descriptor, or NULL if failed.
void lv_snapshot_free(lv_img_dsc_t *dsc)[3]
Free the snapshot image returned by [4]lv_snapshot_take It will firstly free the data image takes, then the image descriptor.
Parameters
dsc -- The image descriptor generated by lv_snapshot_take.
uint32_t lv_snapshot_buf_size_needed(lv_obj_t *obj, lv_img_cf_t cf)[5]
Get the buffer needed for object snapshot image.
Parameters[6]
  • obj -- The object to generate snapshot.
  • cf -- color format for generated image.
Returns
the buffer size needed in bytes
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)[7]
Take snapshot for object with its children, save image info to provided buffer.
Parameters
  • obj -- The[8] object to generate snapshot.
  • cf -- color format for generated image.
  • dsc -- image descriptor to store the image result.
  • buff -- the buffer to store image data.
  • buff_size -- provided buffer size in bytes.
Returns
LV_RES_OK on success, LV_RES_INV on error.



戻る : Previous