1e41f4b71Sopenharmony_ci# @ohos.graphics.uiEffect (Cascading Effect) (System API)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe uiEffect module provides basic capabilities to apply an effect, for example, blur, pixel stretch, and brightness, to a component. Effects are classified into filters and visual effects. Effects of the same category can be cascaded in an effect instance of the corresponding category. In actual development, the blur effect can be used for background blurring, and the brightness effect can be used for screen-on display.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci- [Filter](#filter): applies a filter to a component.
6e41f4b71Sopenharmony_ci- [VisualEffect](#visualeffect): applies a visual effect to a component.
7e41f4b71Sopenharmony_ci
8e41f4b71Sopenharmony_ci> **NOTE**
9e41f4b71Sopenharmony_ci> 
10e41f4b71Sopenharmony_ci> - The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.
11e41f4b71Sopenharmony_ci> - This topic describes only system APIs provided by the module. For details about its public APIs, see [ohos.graphics.uiEffect (Cascading Effect)](js-apis-uiEffect.md).
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## Modules to Import
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci```ts
16e41f4b71Sopenharmony_ciimport { uiEffect } from "@kit.ArkGraphics2D";
17e41f4b71Sopenharmony_ci```
18e41f4b71Sopenharmony_ci## uiEffect.createBrightnessBlender
19e41f4b71Sopenharmony_cicreateBrightnessBlender(param: BrightnessBlenderParam): BrightnessBlender
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ciCreates a **BrightnessBlender** instance, which can be used to apply the brightness effect to a component.
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**System API**: This is a system API.
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**Parameters**
28e41f4b71Sopenharmony_ci| Name | Type                                             | Mandatory| Description                       |
29e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------- | ---- | --------------------------- |
30e41f4b71Sopenharmony_ci| param  | [BrightnessBlenderParam](#brightnessblenderparam) | Yes  | Parameters that implement the brightness effect.|
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci**Return value**
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci| Type                                    | Description                    |
35e41f4b71Sopenharmony_ci| ---------------------------------------- | ----------------------- |
36e41f4b71Sopenharmony_ci| [BrightnessBlender ](#brightnessblender) | **BrightnessBlender** instance with the brightness effect.|
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci**Example**
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci```ts
41e41f4b71Sopenharmony_cilet blender : uiEffect.BrightnessBlender =
42e41f4b71Sopenharmony_ci  uiEffect.createBrightnessBlender({cubicRate:1.0, quadraticRate:1.0, linearRate:1.0, degree:1.0, saturation:1.0,
43e41f4b71Sopenharmony_ci    positiveCoefficient:[2.3, 4.5, 2.0], negativeCoefficient:[0.5, 2.0, 0.5], fraction:0.0})
44e41f4b71Sopenharmony_ci```
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci## Filter
47e41f4b71Sopenharmony_ciA class that can apply a filter to a component. Before calling any API in **Filter**, you must use [createFilter](js-apis-uiEffect.md#uieffectcreatefilter) to create a **Filter** instance.
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci### pixelStretch
50e41f4b71Sopenharmony_cipixelStretch(stretchSizes: Array\<number\>, tileMode: TileMode): Filter
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ciApplies the pixel stretch effect to the component.
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci**System API**: This is a system API.
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci**Parameters**
59e41f4b71Sopenharmony_ci| Name        | Type                 | Mandatory| Description                      |
60e41f4b71Sopenharmony_ci| ------------- | --------------------- | ---- | ------------------------- |
61e41f4b71Sopenharmony_ci| stretchSizes  | Array\<number\>         | Yes  | Ratio based on which the pixels grow towards the top, bottom, left, and right edges. The value range is [-1, 1].<br>A positive value indicates outward stretching, and the upper, lower, left, and right edges are filled with edge pixels of the specified original image ratio. A negative value indicates inward stretching, but the image size remains unchanged:<br>The values for the four directions must be all positive or all negative.|
62e41f4b71Sopenharmony_ci| tileMode      | [TileMode](#tilemode) | Yes  | Pixel tiling mode for pixel stretch.|
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci**Return value**
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci| Type             | Description                              |
68e41f4b71Sopenharmony_ci| ----------------- | --------------------------------- |
69e41f4b71Sopenharmony_ci| [Filter](#filter) | **Filter** instance with the pixel stretch effect.|
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci**Example**
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci```ts
74e41f4b71Sopenharmony_cifilter.pixelStretch([0.2, 0.2, 0.2, 0.2], uiEffect.TileMode.CLAMP)
75e41f4b71Sopenharmony_ci```
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci### waterRipple
78e41f4b71Sopenharmony_ciwaterRipple(progress: number, waveCount: number, x: number, y: number, rippleMode: WaterRippleMode): Filter
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ciApplies the ripple effect to the component.
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci**System API**: This is a system API.
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci**Parameters**
87e41f4b71Sopenharmony_ci| Name        | Type                 | Mandatory| Description                      |
88e41f4b71Sopenharmony_ci| ------------- | --------------------- | ---- | ------------------------- |
89e41f4b71Sopenharmony_ci| progress  | number         | Yes  | Progress of the ripple. The value range is [0, 1].<br>The closer the value is to 1, the more fully the ripple effect is displayed.<br>If a value outside this range is provided, no ripple effect will be displayed.|
90e41f4b71Sopenharmony_ci| waveCount      | number | Yes  | Number of ripples that form when the ripple effect. The value range is [1, 3].<br>The value must be an integer. Ripples will not be displayed if a floating point number or a value outside this range is provided.|
91e41f4b71Sopenharmony_ci| x      | number | Yes  | X coordinate on the screen that marks the center of the ripple when the ripple effect is initially triggered.<br>The ripples are normalized across the screen, with the coordinates of the upper left corner set to (0, 0) and the upper right corner set to (1, 0).<br>A negative number indicates that the center of the ripple is located to the left of the screen's center.|
92e41f4b71Sopenharmony_ci| y      | number | Yes  | Y coordinate on the screen that marks the center of the ripple when the ripple effect is initially triggered.<br>The ripples are normalized across the screen, with the coordinates of the upper left corner set to (0, 0) and the lower left corner set to (0, 1).<br>A negative number indicates that the center of the ripple is located above the screen's center.|
93e41f4b71Sopenharmony_ci| rippleMode      | [WaterRippleMode](#waterripplemode) | Yes  | Scene mode of the ripple effect.|
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci**Return value**
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci| Type             | Description                              |
99e41f4b71Sopenharmony_ci| ----------------- | --------------------------------- |
100e41f4b71Sopenharmony_ci| [Filter](#filter) | **Filter** instance with the ripple effect.|
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci**Example**
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci```ts
105e41f4b71Sopenharmony_cifilter.waterRipple(0.5, 2, 0.5, 0.5, uiEffect.WaterRippleMode.SMALL2SMALL)
106e41f4b71Sopenharmony_ci```
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci### flyInFlyOutEffect
109e41f4b71Sopenharmony_ciflyInFlyOutEffect(degree: number, flyMode: FlyMode): Filter
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ciAdds fly-in and fly-out animations to the component.
112e41f4b71Sopenharmony_ci
113e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci**System API**: This is a system API.
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ci**Parameters**
118e41f4b71Sopenharmony_ci| Name        | Type                 | Mandatory| Description                      |
119e41f4b71Sopenharmony_ci| ------------- | --------------------- | ---- | ------------------------- |
120e41f4b71Sopenharmony_ci| degree  | number         | Yes  | Degree of control over deformation of the fly-in and fly-out animations. The value range is [0, 1].<br>A value closer to 1 results in more obvious deformation.<br>If a value outside this range is provided, no fly-in and fly-out animations will be displayed.|
121e41f4b71Sopenharmony_ci| flyMode      | [FlyMode](#flymode) | Yes  | Scene mode of the fly-in and fly-out animations.<br>**BOTTOM** means that the fly-in and fly-out animations occur from the bottom of the screen,<br>and **TOP** means that the fly-in and fly-out animations occur from the top of the screen.|
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci**Return value**
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci| Type             | Description                              |
127e41f4b71Sopenharmony_ci| ----------------- | --------------------------------- |
128e41f4b71Sopenharmony_ci| [Filter](#filter) | **Filter** instance with the fly-in and fly-out animations.|
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci**Example**
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci```ts
133e41f4b71Sopenharmony_cifilter.flyInFlyOutEffect(0.5, uiEffect.FlyMode.TOP)
134e41f4b71Sopenharmony_ci```
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci## TileMode
137e41f4b71Sopenharmony_ciEnumerates the pixel tiling modes.
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
140e41f4b71Sopenharmony_ci
141e41f4b71Sopenharmony_ci**System API**: This is a system API.
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ci| Name  | Value| Description|
144e41f4b71Sopenharmony_ci| ------ | - | ---- |
145e41f4b71Sopenharmony_ci| CLAMP  | 0 | Clamp.|
146e41f4b71Sopenharmony_ci| REPEAT | 1 | Repeat.|
147e41f4b71Sopenharmony_ci| MIRROR | 2 | Mirror.|
148e41f4b71Sopenharmony_ci| DECAL  | 3 | Decal.|
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_ci## WaterRippleMode
151e41f4b71Sopenharmony_ciEnumerates the scene modes of the ripple effect.
152e41f4b71Sopenharmony_ci
153e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ci**System API**: This is a system API.
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_ci| Name  | Value| Description|
158e41f4b71Sopenharmony_ci| ------ | - | ---- |
159e41f4b71Sopenharmony_ci| SMALL2MEDIUM_RECV  | 0 | A phone taps against a 2-in-1 device (receiver).|
160e41f4b71Sopenharmony_ci| SMALL2MEDIUM_SEND  | 1 | A phone taps against a 2-in-1 device (sender).|
161e41f4b71Sopenharmony_ci| SMALL2SMALL | 2 | A phone taps against another phone.|
162e41f4b71Sopenharmony_ci
163e41f4b71Sopenharmony_ci## FlyMode
164e41f4b71Sopenharmony_ciEnumerates the scene modes of fly-in and fly-out animations.
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci**System API**: This is a system API.
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci| Name  | Value| Description|
171e41f4b71Sopenharmony_ci| ------ | - | ---- |
172e41f4b71Sopenharmony_ci| BOTTOM  | 0 | Fly-in and fly-out animations occur from the bottom of the screen.|
173e41f4b71Sopenharmony_ci| TOP  | 1 | Fly-in and fly-out animations occur from the top of the screen.|
174e41f4b71Sopenharmony_ci
175e41f4b71Sopenharmony_ci## VisualEffect
176e41f4b71Sopenharmony_ciA class that can apply a visual effect to a component. Before calling any API in **VisualEffect**, you must use [createEffect](js-apis-uiEffect.md#uieffectcreateeffect) to create a **VisualEffect** instance.
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci### backgroundColorBlender
179e41f4b71Sopenharmony_cibackgroundColorBlender(blender: BrightnessBlender): VisualEffect
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_ciApplies a blender to the component to change the background color of the component. The change effect is determined by the input. Currently, only the brightness blender is supported.
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
184e41f4b71Sopenharmony_ci
185e41f4b71Sopenharmony_ci**System API**: This is a system API.
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ci**Parameters**
188e41f4b71Sopenharmony_ci| Name | Type                                     | Mandatory| Description                      |
189e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ------------------------- |
190e41f4b71Sopenharmony_ci| blender | [BrightnessBlender](#brightnessblender) | Yes  | Blender used to change the background color.|
191e41f4b71Sopenharmony_ci
192e41f4b71Sopenharmony_ci**Return value**
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_ci| Type                         | Description                                              |
195e41f4b71Sopenharmony_ci| ----------------------------- | ------------------------------------------------- |
196e41f4b71Sopenharmony_ci| [VisualEffect](#visualeffect) | **VisualEffect** instance with the background color change effect.|
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_ci**Example**
199e41f4b71Sopenharmony_ci
200e41f4b71Sopenharmony_ci```ts
201e41f4b71Sopenharmony_cilet blender : uiEffect.BrightnessBlender =
202e41f4b71Sopenharmony_ci  uiEffect.createBrightnessBlender({cubicRate:1.0, quadraticRate:1.0, linearRate:1.0, degree:1.0, saturation:1.0,
203e41f4b71Sopenharmony_ci    positiveCoefficient:[2.3, 4.5, 2.0], negativeCoefficient:[0.5, 2.0, 0.5], fraction:0.0})
204e41f4b71Sopenharmony_civisualEffect.backgroundColorBlender(blender)
205e41f4b71Sopenharmony_ci```
206e41f4b71Sopenharmony_ci
207e41f4b71Sopenharmony_ci## Blender<sup>13+</sup>
208e41f4b71Sopenharmony_ci
209e41f4b71Sopenharmony_citype Blender = BrightnessBlender
210e41f4b71Sopenharmony_ci
211e41f4b71Sopenharmony_ciDefines the blender type, which is used to describe blending effects.
212e41f4b71Sopenharmony_ci
213e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
214e41f4b71Sopenharmony_ci
215e41f4b71Sopenharmony_ci**System API**: This is a system API.
216e41f4b71Sopenharmony_ci
217e41f4b71Sopenharmony_ci| Type                         | Description                                              |
218e41f4b71Sopenharmony_ci| ----------------------------- | ------------------------------------------------- |
219e41f4b71Sopenharmony_ci| [BrightnessBlender](#brightnessblender) | Blender with a brightening effect.|
220e41f4b71Sopenharmony_ci
221e41f4b71Sopenharmony_ci## BrightnessBlender
222e41f4b71Sopenharmony_ciA blender that can apply the brightness effect to a component. Before calling any API in **BrightnessBlender**, you must use [createBrightnessBlender](#uieffectcreatebrightnessblender) to create a **BrightnessBlender** instance.
223e41f4b71Sopenharmony_ci
224e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
225e41f4b71Sopenharmony_ci
226e41f4b71Sopenharmony_ci**System API**: This is a system API.
227e41f4b71Sopenharmony_ci
228e41f4b71Sopenharmony_ci| Name               | Type                       | Read Only| Optional| Description                                                             |
229e41f4b71Sopenharmony_ci| ------------------- | -------------------------- | ---- | ---- | ---------------------------------------------------------------- |
230e41f4b71Sopenharmony_ci| cubicRate           | number                     | No  | No  | Third-order coefficient for grayscale adjustment.<br>The value range is [-20, 20].                       |
231e41f4b71Sopenharmony_ci| quadraticRate       | number                     | No  | No  | Second-order coefficient for grayscale adjustment.<br>The value range is [-20, 20].                       |
232e41f4b71Sopenharmony_ci| linearRate          | number                     | No  | No  | Linear coefficient for grayscale adjustment.<br>The value range is [-20, 20].                       |
233e41f4b71Sopenharmony_ci| degree              | number                     | No  | No  | Grayscale adjustment ratio.<br>The value range is [-20, 20].                           |
234e41f4b71Sopenharmony_ci| saturation          | number                     | No  | No  | Reference saturation for the brightness effect.<br>The value range is [0, 20].                           |
235e41f4b71Sopenharmony_ci| positiveCoefficient | [number, number, number]   | No  | No  | RGB positive adjustment parameter based on the reference saturation.<br>The value range of each number is [-20, 20].|
236e41f4b71Sopenharmony_ci| negativeCoefficient | [number, number, number]   | No  | No  | RGB negative adjustment parameter based on the reference saturation.<br>The value range of each number is [-20, 20].|
237e41f4b71Sopenharmony_ci| fraction            | number                     | No  | No  | Blending ratio of the brightness effect.<br>The value range is [0, 1]. A value beyond the boundary will be automatically truncated during implementation. |
238e41f4b71Sopenharmony_ci
239e41f4b71Sopenharmony_ci## BrightnessBlenderParam
240e41f4b71Sopenharmony_ciDescribes the parameters used for the brightness blender.
241e41f4b71Sopenharmony_ci
242e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
243e41f4b71Sopenharmony_ci
244e41f4b71Sopenharmony_ci**System API**: This is a system API.
245e41f4b71Sopenharmony_ci
246e41f4b71Sopenharmony_ci| Name               | Type                       | Read Only| Optional| Description                                                             |
247e41f4b71Sopenharmony_ci| ------------------- | -------------------------- | ---- | ---- | ---------------------------------------------------------------- |
248e41f4b71Sopenharmony_ci| cubicRate           | number                     | No  | No  | Third-order coefficient for grayscale adjustment.<br>The value range is [-20, 20].                       |
249e41f4b71Sopenharmony_ci| quadraticRate       | number                     | No  | No  | Second-order coefficient for grayscale adjustment.<br>The value range is [-20, 20].                       |
250e41f4b71Sopenharmony_ci| linearRate          | number                     | No  | No  | Linear coefficient for grayscale adjustment.<br>The value range is [-20, 20].                       |
251e41f4b71Sopenharmony_ci| degree              | number                     | No  | No  | Grayscale adjustment ratio.<br>The value range is [-20, 20].                           |
252e41f4b71Sopenharmony_ci| saturation          | number                     | No  | No  | Reference saturation for the brightness effect.<br>The value range is [0, 20].                           |
253e41f4b71Sopenharmony_ci| positiveCoefficient | [number, number, number]   | No  | No  | RGB positive adjustment parameter based on the reference saturation.<br>The value range of each number is [-20, 20].|
254e41f4b71Sopenharmony_ci| negativeCoefficient | [number, number, number]   | No  | No  | RGB negative adjustment parameter based on the reference saturation.<br>The value range of each number is [-20, 20].|
255e41f4b71Sopenharmony_ci| fraction            | number                     | No  | No  | Blending ratio of the brightness effect.<br>The value range is [0, 1]. A value beyond the boundary will be automatically truncated during implementation. |
256