1 #include "../../lv_examples.h"
2 #if LV_USE_SNAPSHOT && LV_BUILD_EXAMPLES
3 
event_cb(lv_event_t * e)4 static void event_cb(lv_event_t * e)
5 {
6     lv_obj_t * snapshot_obj = lv_event_get_user_data(e);
7     lv_obj_t * img = lv_event_get_target(e);
8 
9     if(snapshot_obj) {
10         lv_img_dsc_t * snapshot = (void *)lv_img_get_src(snapshot_obj);
11         if(snapshot) {
12             lv_snapshot_free(snapshot);
13         }
14 
15         /*Update the snapshot, we know parent of object is the container.*/
16         snapshot = lv_snapshot_take(img->parent, LV_IMG_CF_TRUE_COLOR_ALPHA);
17         if(snapshot == NULL)
18             return;
19         lv_img_set_src(snapshot_obj, snapshot);
20     }
21 }
22 
lv_example_snapshot_1(void)23 void lv_example_snapshot_1(void)
24 {
25     LV_IMG_DECLARE(img_star);
26     lv_obj_t * root = lv_scr_act();
27     lv_obj_set_style_bg_color(root, lv_palette_main(LV_PALETTE_LIGHT_BLUE), 0);
28 
29     /*Create an image object to show snapshot*/
30     lv_obj_t * snapshot_obj = lv_img_create(root);
31     lv_obj_set_style_bg_color(snapshot_obj, lv_palette_main(LV_PALETTE_PURPLE), 0);
32     lv_obj_set_style_bg_opa(snapshot_obj, LV_OPA_100, 0);
33     lv_img_set_zoom(snapshot_obj, 128);
34     lv_img_set_angle(snapshot_obj, 300);
35 
36     /*Create the container and its children*/
37     lv_obj_t * container = lv_obj_create(root);
38 
39     lv_obj_center(container);
40     lv_obj_set_size(container, 180, 180);
41     lv_obj_set_flex_flow(container, LV_FLEX_FLOW_ROW_WRAP);
42     lv_obj_set_flex_align(container, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
43     lv_obj_set_style_radius(container, 50, 0);
44     lv_obj_t * img;
45     int i;
46     for(i = 0; i < 4; i++) {
47         img = lv_img_create(container);
48         lv_img_set_src(img, &img_star);
49         lv_obj_set_style_bg_color(img, lv_color_black(), 0);
50         lv_obj_set_style_bg_opa(img, LV_OPA_COVER, 0);
51         lv_obj_set_style_transform_zoom(img, 400, LV_STATE_PRESSED);
52         lv_obj_add_flag(img, LV_OBJ_FLAG_CLICKABLE);
53         lv_obj_add_event_cb(img, event_cb, LV_EVENT_PRESSED, snapshot_obj);
54         lv_obj_add_event_cb(img, event_cb, LV_EVENT_RELEASED, snapshot_obj);
55     }
56 }
57 
58 #endif
59