1e41f4b71Sopenharmony_ci# Motion Blur 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciYou can apply a motion blur effect to a component being scaled or moved. This effect must be used together with the **onFinish** parameter of **AnimateParam**. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 12. Updates will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## motionBlur 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_cimotionBlur(value: MotionBlurOptions) 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ciApply a motion blur effect to the component being scaled or moved. 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci1. Do not use this API in intra-component transitions, shared element transitions, implicit element transitions, or particle animations. Doing so may cause unexpected results. 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci2. The **radius** parameter of **motionBlur** must be set to **0** for the initial state. Otherwise, there may be unexpected results during a cold start. 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci3. This API must be used together with the **onFinish** parameter of **AnimateParam**. Its **radius** parameter must be set to **0** when the animation ends; otherwise, there may be unexpected results. 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci4. When using this API, do not frequently change the blur radius of the same component; otherwise, there may be unexpected results. For example, if you frequently click the image in the example, the blur effect may not work sometimes. 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci5. To avoid unexpected results, make sure the coordinates of the motion blur anchor point are the same as those of the animation scaling anchor point. 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci6. To avoid unexpected results, set the blur radius to a value less than 1. 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci**Parameters** 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 31e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 32e41f4b71Sopenharmony_ci| value | [MotionBlurOptions](#motionbluroptions) | Yes | Motion blur options.| 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci## MotionBlurOptions 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 37e41f4b71Sopenharmony_ci| ------------- | ----------------------------------------------------------- | ----- | ------------------------------------------------------------ | 38e41f4b71Sopenharmony_ci| radius | number | Yes | Blur radius. The value range is [0.0, ∞). You are advised to set it to a value less than 1.0.| 39e41f4b71Sopenharmony_ci| anchor | [MotionBlurAnchor](#motionbluranchor) | Yes | Coordinates of the motion blur anchor point. They must be the same as those of the animation scaling anchor point.| 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci## MotionBlurAnchor 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 44e41f4b71Sopenharmony_ci| ------------- | ----------------------------------------------------------- | ----- | ------------------------------------------------------------ | 45e41f4b71Sopenharmony_ci| x | number | Yes | X-coordinate of the anchor point. The value range is [0.0, 1.0].| 46e41f4b71Sopenharmony_ci| y | number | Yes | Y-coordinate of the anchor point. The value range is [0.0, 1.0].| 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci## Example 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ciThis example demonstrates how to apply a motion blur effect. 51e41f4b71Sopenharmony_ci```ts 52e41f4b71Sopenharmony_ci// xxx.ets 53e41f4b71Sopenharmony_ciimport curves from '@ohos.curves'; 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci@Entry 56e41f4b71Sopenharmony_ci@Component 57e41f4b71Sopenharmony_cistruct motionBlurTest { 58e41f4b71Sopenharmony_ci @State widthSize: number = 400 59e41f4b71Sopenharmony_ci @State heightSize: number = 320 60e41f4b71Sopenharmony_ci @State flag: boolean = true 61e41f4b71Sopenharmony_ci @State radius: number = 0 62e41f4b71Sopenharmony_ci @State x: number = 0 63e41f4b71Sopenharmony_ci @State y: number = 0 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci build() { 66e41f4b71Sopenharmony_ci Column() { 67e41f4b71Sopenharmony_ci Column() { 68e41f4b71Sopenharmony_ci Image($r('app.media.testImg')) 69e41f4b71Sopenharmony_ci .width(this.widthSize) 70e41f4b71Sopenharmony_ci .height(this.heightSize) 71e41f4b71Sopenharmony_ci .onClick(() => { 72e41f4b71Sopenharmony_ci this.radius = 5; 73e41f4b71Sopenharmony_ci this.x = 0.5; 74e41f4b71Sopenharmony_ci this.y = 0.5; 75e41f4b71Sopenharmony_ci if (this.flag) { 76e41f4b71Sopenharmony_ci this.widthSize = 100; 77e41f4b71Sopenharmony_ci this.heightSize = 80; 78e41f4b71Sopenharmony_ci } else { 79e41f4b71Sopenharmony_ci this.widthSize = 400; 80e41f4b71Sopenharmony_ci this.heightSize = 320; 81e41f4b71Sopenharmony_ci } 82e41f4b71Sopenharmony_ci this.flag = !this.flag; 83e41f4b71Sopenharmony_ci }) 84e41f4b71Sopenharmony_ci .animation({ 85e41f4b71Sopenharmony_ci duration: 2000, 86e41f4b71Sopenharmony_ci curve: curves.springCurve(10, 1, 228, 30), 87e41f4b71Sopenharmony_ci onFinish: () => { 88e41f4b71Sopenharmony_ci this.radius = 0; 89e41f4b71Sopenharmony_ci } 90e41f4b71Sopenharmony_ci }) 91e41f4b71Sopenharmony_ci .motionBlur({ radius: this.radius, anchor: { x: this.x, y: this.y } }) 92e41f4b71Sopenharmony_ci } 93e41f4b71Sopenharmony_ci }.width('100%').margin({ top: 5 }) 94e41f4b71Sopenharmony_ci } 95e41f4b71Sopenharmony_ci} 96e41f4b71Sopenharmony_ci``` 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci 99