「App:Library:LVGL:docs:Others:Snapshot」の版間の差分
17行目: | 17行目: | ||
|- | |- | ||
| | | | ||
− | Snapshot provides APIs to take snapshot image for LVGL object together with its children. The image will look exactly like the object. | + | Snapshot provides APIs to take snapshot image for LVGL object together with its children. |
+ | |||
+ | The image will look exactly like the object. | ||
| | | | ||
|} | |} | ||
49行目: | 51行目: | ||
|- | |- | ||
| | | | ||
− | The memory <code style="color: #bb0000;">lv_snapshot_take</code> uses are dynamically allocated using <code style="color: #bb0000;">lv_mem_alloc</code>. Use API <code style="color: #bb0000;">lv_snapshot_free</code> to free the memory it takes. This will firstly free memory the image data takes, then the image descriptor. | + | The memory <code style="color: #bb0000;">lv_snapshot_take</code> uses are dynamically allocated using <code style="color: #bb0000;">lv_mem_alloc</code>. |
+ | |||
+ | Use API <code style="color: #bb0000;">lv_snapshot_free</code> 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 <code style="color: #bb0000;">lv_img_set_src(NULL)</code> and <code style="color: #bb0000;">lv_img_cache_invalidate_src(src)</code>. | 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 <code style="color: #bb0000;">lv_img_set_src(NULL)</code> and <code style="color: #bb0000;">lv_img_cache_invalidate_src(src)</code>. | ||
79行目: | 83行目: | ||
If snapshot is generated successfully, the image descriptor is updated and image data will be stored to provided <code style="color: #bb0000;">buf</code>. | If snapshot is generated successfully, the image descriptor is updated and image data will be stored to provided <code style="color: #bb0000;">buf</code>. | ||
− | Note that snapshot may fail if provided buffer is not enough, which may happen when object size changes. It's recommended to use API <code style="color: #bb0000;">lv_snapshot_buf_size_needed</code> to check the needed buffer size in byte firstly and resize the buffer accordingly. | + | |
+ | Note that snapshot may fail if provided buffer is not enough, which may happen when object size changes. | ||
+ | |||
+ | It's recommended to use API <code style="color: #bb0000;">lv_snapshot_buf_size_needed</code> to check the needed buffer size in byte firstly and resize the buffer accordingly. | ||
| | | | ||
|} | |} | ||
109行目: | 116行目: | ||
Functions | Functions | ||
− | <span style="background-color: #e7f2fa; color: #2980b9;">lv_img_dsc_t *lv_snapshot_take(lv_obj_t *obj, lv_img_cf_t cf) </span> | + | <span style="background-color: #e7f2fa; color: #2980b9;">[https://docs.lvgl.io/8.2/overview/image.html#_CPPv412lv_img_dsc_t '''lv_img_dsc_t'''] *lv_snapshot_take([https://docs.lvgl.io/8.2/widgets/obj.html#_CPPv48lv_obj_t '''lv_obj_t'''] *obj, [https://docs.lvgl.io/8.2/overview/image.html#_CPPv411lv_img_cf_t '''lv_img_cf_t'''] cf) </span> |
: Take snapshot for object with its children. | : Take snapshot for object with its children. | ||
− | :Parameters | + | :'''Parameters''' |
− | ::* obj -- The object to generate snapshot. | + | ::* '''obj''' -- The object to generate snapshot. |
− | ::* cf -- color format for generated image. | + | ::* '''cf''' -- color format for generated image. |
− | :Returns | + | :'''Returns''' |
:: a pointer to an image descriptor, or NULL if failed. | :: a pointer to an image descriptor, or NULL if failed. | ||
− | <span style="background-color: #e7f2fa; color: #2980b9;">void lv_snapshot_free(lv_img_dsc_t *dsc) </span> | + | <span style="background-color: #e7f2fa; color: #2980b9;">void lv_snapshot_free([https://docs.lvgl.io/8.2/overview/image.html#_CPPv412lv_img_dsc_t '''lv_img_dsc_t'''] *dsc) </span> |
− | : Free the snapshot image returned by lv_snapshot_take It will firstly free the data image takes, then the image descriptor. | + | : Free the snapshot image returned by [https://docs.lvgl.io/8.2/others/snapshot.html#lv__snapshot_8h_1ac45005ac1ae1e130e2f62ed27237fe25 '''lv_snapshot_take'''] It will firstly free the data image takes, then the image descriptor. |
− | :Parameters | + | :'''Parameters''' |
− | :: dsc -- The image descriptor generated by lv_snapshot_take. | + | :: '''dsc''' -- The image descriptor generated by lv_snapshot_take. |
− | <span style="background-color: #e7f2fa; color: #2980b9;">uint32_t lv_snapshot_buf_size_needed(lv_obj_t *obj, lv_img_cf_t cf) </span> | + | <span style="background-color: #e7f2fa; color: #2980b9;">uint32_t lv_snapshot_buf_size_needed([https://docs.lvgl.io/8.2/widgets/obj.html#_CPPv48lv_obj_t '''lv_obj_t'''] *obj, [https://docs.lvgl.io/8.2/overview/image.html#_CPPv411lv_img_cf_t '''lv_img_cf_t'''] cf) </span> |
: Get the buffer needed for object snapshot image. | : Get the buffer needed for object snapshot image. | ||
− | :Parameters | + | :'''Parameters''' |
− | ::* obj -- The object to generate snapshot. | + | ::* '''obj''' -- The object to generate snapshot. |
− | ::* cf -- color format for generated image. | + | ::* '''cf''' -- color format for generated image. |
− | :Returns | + | :'''Returns''' |
:: the buffer size needed in bytes | :: the buffer size needed in bytes | ||
− | <span style="background-color: #e7f2fa; color: #2980b9;">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) </span> | + | <span style="background-color: #e7f2fa; color: #2980b9;">lv_res_t lv_snapshot_take_to_buf([https://docs.lvgl.io/8.2/widgets/obj.html#_CPPv48lv_obj_t '''lv_obj_t'''] *obj, [https://docs.lvgl.io/8.2/overview/image.html#_CPPv411lv_img_cf_t '''lv_img_cf_t'''] cf, [https://docs.lvgl.io/8.2/overview/image.html#_CPPv412lv_img_dsc_t '''lv_img_dsc_t'''] *dsc, void *buf, uint32_t buff_size) </span> |
: Take snapshot for object with its children, save image info to provided buffer. | : Take snapshot for object with its children, save image info to provided buffer. | ||
− | :Parameters | + | :'''Parameters''' |
− | ::* obj -- The object to generate snapshot. | + | ::* '''obj''' -- The object to generate snapshot. |
− | ::* cf -- color format for generated image. | + | ::* '''cf''' -- color format for generated image. |
− | ::* dsc -- image descriptor to store the image result. | + | ::* '''dsc''' -- image descriptor to store the image result. |
− | ::* buff -- the buffer to store image data. | + | ::* '''buff''' -- the buffer to store image data. |
− | ::* buff_size -- provided buffer size in bytes. | + | ::* '''buff_size''' -- provided buffer size in bytes. |
− | :Returns | + | :'''Returns''' |
:: LV_RES_OK on success, LV_RES_INV on error. | :: LV_RES_OK on success, LV_RES_INV on error. | ||
| | | | ||
|} | |} | ||
:[[App:Library:LVGL:docs:Others|戻る : Previous]] | :[[App:Library:LVGL:docs:Others|戻る : Previous]] |
2022年6月22日 (水) 21:32時点における版
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 Note, only below color formats are supported for now:
|
Free the Image
英文 | 自動翻訳 |
---|---|
The memory Use API 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 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 If snapshot is generated successfully, the image descriptor is updated and image data will be stored to provided
It's recommended to use API |
Example
Simple snapshot example
英文 | 自動翻訳 |
---|---|
API
英文 | 自動翻訳 |
---|---|
Functions lv_img_dsc_t *lv_snapshot_take(lv_obj_t *obj, lv_img_cf_t cf)
void lv_snapshot_free(lv_img_dsc_t *dsc)
uint32_t lv_snapshot_buf_size_needed(lv_obj_t *obj, lv_img_cf_t cf)
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)
|