1e41f4b71Sopenharmony_ci# ImageAnimator 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **ImageAnimator** component enables images to be played a frame-by-frame basis. The list of images to be played as well as the duration of each image can be configured. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## Child Components 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ciNot supported 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci## APIs 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ciImageAnimator() 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 10. 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci## Attributes 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ciIn addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported. 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci### images 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ciimages(value: Array<ImageFrameInfo>) 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ciSets the image frame information. Dynamic update is not supported. 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 10. 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci**Parameters** 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 43e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------ | ---- | ------------------------------------------------------------ | 44e41f4b71Sopenharmony_ci| value | Array<[ImageFrameInfo](#imageframeinfo)> | Yes | Image frame information. The information of each frame includes the image path, image size, image position, and image playback duration. For details, see **ImageFrameInfo**.<br>Default value: **[]** | 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci### state 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_cistate(value: AnimationStatus) 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ciSets the playback state of the animation. 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 10. 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci**Parameters** 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 61e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 62e41f4b71Sopenharmony_ci| value | [AnimationStatus](ts-appendix-enums.md#animationstatus) | Yes | Playback state of the animation. The default state is **Initial**.<br>Default value: **AnimationStatus.Initial** | 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci### duration 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ciduration(value: number) 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ciSets the playback duration. This attribute does not take effect when a separate duration is set for any of the image frames. 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 10. 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci**Parameters** 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 79e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ | 80e41f4b71Sopenharmony_ci| value | number | Yes | Playback duration.<br>If the value is **0**, no image is played.<br>The value change takes effect only at the start of the next cycle.<br>Unit: ms<br>Default value: **1000** | 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci### reverse 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_cireverse(value: boolean) 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ciSets the playback direction. 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 10. 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci**Parameters** 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 97e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------------------------------ | 98e41f4b71Sopenharmony_ci| value | boolean | Yes | Playback direction.<br>The value **false** indicates that images are played from the first one to the last one, and **true** indicates that images are played from the last one to the first one.<br>Default value: **false** | 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci### fixedSize 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_cifixedSize(value: boolean) 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ciSets whether the image size is fixed at the component size. 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 10. 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci**Parameters** 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 115e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------------------------------ | 116e41f4b71Sopenharmony_ci| value | boolean | Yes | Whether the image size is fixed at the component size.<br> **true**: The image size is fixed at the component size. In this case, the width, height, top, and left attributes of the image are invalid.<br> **false**: The width, height, top, and left attributes of each image must be set separately.<br>Default value: **true** | 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci### preDecode<sup>(deprecated)</sup> 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_cipreDecode(value: number) 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ciSets the number of images to be pre-decoded. 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ciThis API is deprecated since API version 9. 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 10. 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci**Parameters** 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 133e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ | 134e41f4b71Sopenharmony_ci| value | number | Yes | Number of images to be pre-decoded. For example, the value **2** indicates that two images following the currently playing one are pre-decoded.<br>Default value: **0** | 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ci### fillMode 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_cifillMode(value: FillMode) 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ciSets the status before and after execution of the animation in the current playback direction. The status after execution of the animation is jointly determined by the **fillMode** and **reverse** attributes. For example, if **fillMode** is set to **Forwards**, the target will retain the state defined by the last keyframe encountered during execution. In this case, if **reverse** is set to **false**, the target will retain the state defined by the last keyframe encountered in the forward direction, that is, the last image; if **reverse** is set to **true**, the target will retain the state defined by the last keyframe encountered in the backward direction, that is, the first image. 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 10. 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ci**Parameters** 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 151e41f4b71Sopenharmony_ci| ------ | ----------------------------------------- | ---- | ------------------------------------------------------------ | 152e41f4b71Sopenharmony_ci| value | [FillMode](ts-appendix-enums.md#fillmode) | Yes | Status before and after execution of the animation in the current playback direction.<br>Default value: **FillMode.Forwards** | 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci### iterations 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ciiterations(value: number) 157e41f4b71Sopenharmony_ci 158e41f4b71Sopenharmony_ciSets the number of times that the animation is played. 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ci**Parameters** 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 167e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------ | 168e41f4b71Sopenharmony_ci| value | number | Yes | Number of times that the animation is played. By default, the animation is played once. The value **-1** indicates that the animation is played for an unlimited number of times.<br>Default value: **1** | 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ci## ImageFrameInfo 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 175e41f4b71Sopenharmony_ci| -------- | -------------- | -------- | -------- | 176e41f4b71Sopenharmony_ci| src | string \| [Resource](ts-types.md#resource)<sup>9+</sup> \| [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7)<sup>12+</sup> | Yes | Image path. The image format can be .svg, .png, or .jpg. The [Resource](ts-types.md#resource) type is supported since API version 9, and the [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7) type is supported since API version 12.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 10.| 177e41f4b71Sopenharmony_ci| width | number \| string | No | Image width.<br>Default value: **0**<br>Since API version 10, this API is supported in ArkTS widgets. | 178e41f4b71Sopenharmony_ci| height | number \| string | No | Image height.<br>Default value: **0**<br>Since API version 10, this API is supported in ArkTS widgets. | 179e41f4b71Sopenharmony_ci| top | number \| string | No | Vertical coordinate of the image relative to the upper left corner of the widget<br>Default value: **0**<br>Since API version 10, this API is supported in ArkTS widgets. | 180e41f4b71Sopenharmony_ci| left | number \| string | No | Horizontal coordinate of the image relative to the upper left corner of the widget<br>Default value: **0**<br>Since API version 10, this API is supported in ArkTS widgets. | 181e41f4b71Sopenharmony_ci| duration | number | No | Playback duration of each image frame, in milliseconds.<br>Default value: **0** | 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ci## Events 184e41f4b71Sopenharmony_ci 185e41f4b71Sopenharmony_ciIn addition to the [universal events](ts-universal-events-click.md), the following events are supported. 186e41f4b71Sopenharmony_ci 187e41f4b71Sopenharmony_ci### onStart 188e41f4b71Sopenharmony_ci 189e41f4b71Sopenharmony_cionStart(event: () => void) 190e41f4b71Sopenharmony_ci 191e41f4b71Sopenharmony_ciTriggered when the animation starts to play. 192e41f4b71Sopenharmony_ci 193e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 10. 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_ci### onPause 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_cionPause(event: () => void) 202e41f4b71Sopenharmony_ci 203e41f4b71Sopenharmony_ciTriggered when the animation playback is paused. 204e41f4b71Sopenharmony_ci 205e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 10. 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 208e41f4b71Sopenharmony_ci 209e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_ci### onRepeat 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_cionRepeat(event: () => void) 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ciTriggered when the animation playback is repeated. 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci### onCancel 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_cionCancel(event: () => void) 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ciTriggered when the animation playback returns to the initial state. 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 10. 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci### onFinish 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_cionFinish(event: () => void) 236e41f4b71Sopenharmony_ci 237e41f4b71Sopenharmony_ciTriggered when the animation playback is complete or stopped. 238e41f4b71Sopenharmony_ci 239e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 10. 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 242e41f4b71Sopenharmony_ci 243e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 244e41f4b71Sopenharmony_ci 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci## Example 247e41f4b71Sopenharmony_ci 248e41f4b71Sopenharmony_ci### Playing an Animation of the Resource Type 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ci```ts 251e41f4b71Sopenharmony_ci// xxx.ets 252e41f4b71Sopenharmony_ci@Entry 253e41f4b71Sopenharmony_ci@Component 254e41f4b71Sopenharmony_cistruct ImageAnimatorExample { 255e41f4b71Sopenharmony_ci @State state: AnimationStatus = AnimationStatus.Initial 256e41f4b71Sopenharmony_ci @State reverse: boolean = false 257e41f4b71Sopenharmony_ci @State iterations: number = 1 258e41f4b71Sopenharmony_ci 259e41f4b71Sopenharmony_ci build() { 260e41f4b71Sopenharmony_ci Column({ space: 10 }) { 261e41f4b71Sopenharmony_ci ImageAnimator() 262e41f4b71Sopenharmony_ci .images([ 263e41f4b71Sopenharmony_ci { 264e41f4b71Sopenharmony_ci src: $r('app.media.img1') 265e41f4b71Sopenharmony_ci }, 266e41f4b71Sopenharmony_ci { 267e41f4b71Sopenharmony_ci src: $r('app.media.img2') 268e41f4b71Sopenharmony_ci }, 269e41f4b71Sopenharmony_ci { 270e41f4b71Sopenharmony_ci src: $r('app.media.img3') 271e41f4b71Sopenharmony_ci }, 272e41f4b71Sopenharmony_ci { 273e41f4b71Sopenharmony_ci src: $r('app.media.img4') 274e41f4b71Sopenharmony_ci } 275e41f4b71Sopenharmony_ci ]) 276e41f4b71Sopenharmony_ci .duration(2000) 277e41f4b71Sopenharmony_ci .state(this.state).reverse(this.reverse) 278e41f4b71Sopenharmony_ci .fillMode(FillMode.None).iterations(this.iterations).width(340).height(240) 279e41f4b71Sopenharmony_ci .margin({ top: 100 }) 280e41f4b71Sopenharmony_ci .onStart(() => { 281e41f4b71Sopenharmony_ci console.info('Start') 282e41f4b71Sopenharmony_ci }) 283e41f4b71Sopenharmony_ci .onPause(() => { 284e41f4b71Sopenharmony_ci console.info('Pause') 285e41f4b71Sopenharmony_ci }) 286e41f4b71Sopenharmony_ci .onRepeat(() => { 287e41f4b71Sopenharmony_ci console.info('Repeat') 288e41f4b71Sopenharmony_ci }) 289e41f4b71Sopenharmony_ci .onCancel(() => { 290e41f4b71Sopenharmony_ci console.info('Cancel') 291e41f4b71Sopenharmony_ci }) 292e41f4b71Sopenharmony_ci .onFinish(() => { 293e41f4b71Sopenharmony_ci console.info('Finish') 294e41f4b71Sopenharmony_ci this.state = AnimationStatus.Stopped 295e41f4b71Sopenharmony_ci }) 296e41f4b71Sopenharmony_ci Row() { 297e41f4b71Sopenharmony_ci Button('start').width(100).padding(5).onClick(() => { 298e41f4b71Sopenharmony_ci this.state = AnimationStatus.Running 299e41f4b71Sopenharmony_ci }).margin(5) 300e41f4b71Sopenharmony_ci Button('pause').width(100).padding(5).onClick(() => { 301e41f4b71Sopenharmony_ci this.state = AnimationStatus.Paused // Display the image of the current frame. 302e41f4b71Sopenharmony_ci }).margin(5) 303e41f4b71Sopenharmony_ci Button('stop').width(100).padding(5).onClick(() => { 304e41f4b71Sopenharmony_ci this.state = AnimationStatus.Stopped // Display the image of the initial frame. 305e41f4b71Sopenharmony_ci }).margin(5) 306e41f4b71Sopenharmony_ci } 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ci Row() { 309e41f4b71Sopenharmony_ci Button('reverse').width(100).padding(5).onClick(() => { 310e41f4b71Sopenharmony_ci this.reverse = !this.reverse 311e41f4b71Sopenharmony_ci }).margin(5) 312e41f4b71Sopenharmony_ci Button('once').width(100).padding(5).onClick(() => { 313e41f4b71Sopenharmony_ci this.iterations = 1 314e41f4b71Sopenharmony_ci }).margin(5) 315e41f4b71Sopenharmony_ci Button('infinite').width(100).padding(5).onClick(() => { 316e41f4b71Sopenharmony_ci this.iterations = -1 // The animation is played for an unlimited number of times. 317e41f4b71Sopenharmony_ci }).margin(5) 318e41f4b71Sopenharmony_ci } 319e41f4b71Sopenharmony_ci }.width('100%').height('100%') 320e41f4b71Sopenharmony_ci } 321e41f4b71Sopenharmony_ci} 322e41f4b71Sopenharmony_ci``` 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ci### Playing an Animation of the PixelMap Type 325e41f4b71Sopenharmony_ci 326e41f4b71Sopenharmony_ci```ts 327e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit' 328e41f4b71Sopenharmony_ci 329e41f4b71Sopenharmony_ci@Entry 330e41f4b71Sopenharmony_ci@Component 331e41f4b71Sopenharmony_cistruct ImageAnimatorExample { 332e41f4b71Sopenharmony_ci imagePixelMap: Array<PixelMap> = [] 333e41f4b71Sopenharmony_ci @State state: AnimationStatus = AnimationStatus.Initial 334e41f4b71Sopenharmony_ci @State reverse: boolean = false 335e41f4b71Sopenharmony_ci @State iterations: number = 1 336e41f4b71Sopenharmony_ci @State images:Array<ImageFrameInfo> = [] 337e41f4b71Sopenharmony_ci async aboutToAppear() { 338e41f4b71Sopenharmony_ci this.imagePixelMap.push(await this.getPixmapFromMedia($r('app.media.icon'))) 339e41f4b71Sopenharmony_ci this.images.push({src:this.imagePixelMap[0]}) 340e41f4b71Sopenharmony_ci } 341e41f4b71Sopenharmony_ci build() { 342e41f4b71Sopenharmony_ci Column({ space: 10 }) { 343e41f4b71Sopenharmony_ci ImageAnimator() 344e41f4b71Sopenharmony_ci .images(this.images) 345e41f4b71Sopenharmony_ci .duration(2000) 346e41f4b71Sopenharmony_ci .state(this.state).reverse(this.reverse) 347e41f4b71Sopenharmony_ci .fillMode(FillMode.None).iterations(this.iterations).width(340).height(240) 348e41f4b71Sopenharmony_ci .margin({ top: 100 }) 349e41f4b71Sopenharmony_ci .onStart(() => { 350e41f4b71Sopenharmony_ci console.info('Start') 351e41f4b71Sopenharmony_ci }) 352e41f4b71Sopenharmony_ci .onPause(() => { 353e41f4b71Sopenharmony_ci console.info('Pause') 354e41f4b71Sopenharmony_ci }) 355e41f4b71Sopenharmony_ci .onRepeat(() => { 356e41f4b71Sopenharmony_ci console.info('Repeat') 357e41f4b71Sopenharmony_ci }) 358e41f4b71Sopenharmony_ci .onCancel(() => { 359e41f4b71Sopenharmony_ci console.info('Cancel') 360e41f4b71Sopenharmony_ci }) 361e41f4b71Sopenharmony_ci .onFinish(() => { 362e41f4b71Sopenharmony_ci console.info('Finish') 363e41f4b71Sopenharmony_ci this.state = AnimationStatus.Stopped 364e41f4b71Sopenharmony_ci }) 365e41f4b71Sopenharmony_ci Row() { 366e41f4b71Sopenharmony_ci Button('start').width(100).padding(5).onClick(() => { 367e41f4b71Sopenharmony_ci this.state = AnimationStatus.Running 368e41f4b71Sopenharmony_ci }).margin(5) 369e41f4b71Sopenharmony_ci Button('pause').width(100).padding(5).onClick(() => { 370e41f4b71Sopenharmony_ci this.state = AnimationStatus.Paused // Display the image of the current frame. 371e41f4b71Sopenharmony_ci }).margin(5) 372e41f4b71Sopenharmony_ci Button('stop').width(100).padding(5).onClick(() => { 373e41f4b71Sopenharmony_ci this.state = AnimationStatus.Stopped // Display the image of the initial frame. 374e41f4b71Sopenharmony_ci }).margin(5) 375e41f4b71Sopenharmony_ci } 376e41f4b71Sopenharmony_ci Row() { 377e41f4b71Sopenharmony_ci Button('reverse').width(100).padding(5).onClick(() => { 378e41f4b71Sopenharmony_ci this.reverse = !this.reverse 379e41f4b71Sopenharmony_ci }).margin(5) 380e41f4b71Sopenharmony_ci Button('once').width(100).padding(5).onClick(() => { 381e41f4b71Sopenharmony_ci this.iterations = 1 382e41f4b71Sopenharmony_ci }).margin(5) 383e41f4b71Sopenharmony_ci Button('infinite').width(100).padding(5).onClick(() => { 384e41f4b71Sopenharmony_ci this.iterations = -1 // The animation is played for an unlimited number of times. 385e41f4b71Sopenharmony_ci }).margin(5) 386e41f4b71Sopenharmony_ci } 387e41f4b71Sopenharmony_ci }.width('100%').height('100%') 388e41f4b71Sopenharmony_ci } 389e41f4b71Sopenharmony_ci 390e41f4b71Sopenharmony_ci private async getPixmapFromMedia(resource: Resource) { 391e41f4b71Sopenharmony_ci let unit8Array = await getContext(this)?.resourceManager?.getMediaContent({ 392e41f4b71Sopenharmony_ci bundleName: resource.bundleName, 393e41f4b71Sopenharmony_ci moduleName: resource.moduleName, 394e41f4b71Sopenharmony_ci id: resource.id 395e41f4b71Sopenharmony_ci }) 396e41f4b71Sopenharmony_ci let imageSource = image.createImageSource(unit8Array.buffer.slice(0, unit8Array.buffer.byteLength)) 397e41f4b71Sopenharmony_ci let createPixelMap: image.PixelMap = await imageSource.createPixelMap({ 398e41f4b71Sopenharmony_ci desiredPixelFormat: image.PixelMapFormat.RGBA_8888 399e41f4b71Sopenharmony_ci }) 400e41f4b71Sopenharmony_ci await imageSource.release() 401e41f4b71Sopenharmony_ci return createPixelMap 402e41f4b71Sopenharmony_ci } 403e41f4b71Sopenharmony_ci} 404e41f4b71Sopenharmony_ci``` 405e41f4b71Sopenharmony_ci 406e41f4b71Sopenharmony_ci 407