动画图像 (lv_animimg)

概述

动画图像与普通的“图像”对象类似。唯一的区别是,动画图像设置的是多个源图像的数组,而不是单个源图像。

您可以指定动画的持续时间和重复次数。

部件和样式

  • LV_PART_MAIN 一个背景矩形,使用典型的背景样式属性,并通过图像样式属性显示图像本身。

用法

图像来源

要为动画图像设置图像,请使用 lv_animimg_set_src(imgbtn, dsc[], num)

事件

动画图像对象不发送特殊事件。

请参阅基础对象的事件。

了解更多关于事件的信息。

按键

此对象类型不处理任何按键

了解更多关于按键的信息。

示例

简单的动画图像

一个简单的示例,用于演示动画图像的使用。

C code  

 GitHub
#include "../../lv_examples.h"
#if LV_USE_ANIMIMG && LV_BUILD_EXAMPLES
LV_IMG_DECLARE(animimg001)
LV_IMG_DECLARE(animimg002)
LV_IMG_DECLARE(animimg003)

static const lv_img_dsc_t * anim_imgs[3] = {
    &animimg001,
    &animimg002,
    &animimg003,
};

void lv_example_animimg_1(void)
{
    lv_obj_t * animimg0 = lv_animimg_create(lv_scr_act());
    lv_obj_center(animimg0);
    lv_animimg_set_src(animimg0, (lv_img_dsc_t **) anim_imgs, 3);
    lv_animimg_set_duration(animimg0, 1000);
    lv_animimg_set_repeat_count(animimg0, LV_ANIM_REPEAT_INFINITE);
    lv_animimg_start(animimg0);
}

#endif

MicroPython code  

 GitHub Simulator
from imagetools import get_png_info, open_png

# Register PNG image decoder
decoder = lv.img.decoder_create()
decoder.info_cb = get_png_info
decoder.open_cb = open_png

anim_imgs = [None]*3
# Create an image from the png file
try:
    with open('../../assets/animimg001.png','rb') as f:
        anim001_data = f.read()
except:
    print("Could not find animimg001.png")
    sys.exit()

anim_imgs[0] = lv.img_dsc_t({
  'data_size': len(anim001_data),
  'data': anim001_data
})

try:
    with open('../../assets/animimg002.png','rb') as f:
        anim002_data = f.read()
except:
    print("Could not find animimg002.png")
    sys.exit()

anim_imgs[1] = lv.img_dsc_t({
  'data_size': len(anim002_data),
  'data': anim002_data
})

try:
    with open('../../assets/animimg003.png','rb') as f:
        anim003_data = f.read()
except:
    print("Could not find animimg003.png")
    sys.exit()

anim_imgs[2] = lv.img_dsc_t({
  'data_size': len(anim003_data),
  'data': anim003_data
})

animimg0 = lv.animimg(lv.scr_act())
animimg0.center()
animimg0.set_src(anim_imgs, 3)
animimg0.set_duration(1000)
animimg0.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
animimg0.start()




API

Typedefs

typedef uint8_t lv_animimg_part_t

Enums

Values:

enumerator LV_ANIM_IMG_PART_MAIN

Functions

lv_obj_t *lv_animimg_create(lv_obj_t *parent)

Create an animation image objects

Parameters

parent -- pointer to an object, it will be the parent of the new button

Returns

pointer to the created animation image object

void lv_animimg_set_src(lv_obj_t *img, lv_img_dsc_t *dsc[], uint8_t num)

Set the image animation images source.

Parameters
  • img -- pointer to an animation image object

  • dsc -- pointer to a series images

  • num -- images' number

void lv_animimg_start(lv_obj_t *obj)

Startup the image animation.

Parameters

obj -- pointer to an animation image object

void lv_animimg_set_duration(lv_obj_t *img, uint32_t duration)

Set the image animation duration time. unit:ms

Parameters

img -- pointer to an animation image object

void lv_animimg_set_repeat_count(lv_obj_t *img, uint16_t count)

Set the image animation reapeatly play times.

Parameters
  • img -- pointer to an animation image object

  • count -- the number of times to repeat the animation

Variables

const lv_obj_class_t lv_animimg_class
struct lv_animimg_t

Public Members

lv_img_t img
lv_anim_t anim
lv_img_dsc_t **dsc
int8_t pic_count