1# @ohos.graphics.uiEffect (Cascading Effect) (System API)
2
3The 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.
4
5- [Filter](#filter): applies a filter to a component.
6- [VisualEffect](#visualeffect): applies a visual effect to a component.
7
8> **NOTE**
9>
10> - 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.
11> - 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).
12
13## Modules to Import
14
15```ts
16import { uiEffect } from "@kit.ArkGraphics2D";
17```
18## uiEffect.createBrightnessBlender
19createBrightnessBlender(param: BrightnessBlenderParam): BrightnessBlender
20
21Creates a **BrightnessBlender** instance, which can be used to apply the brightness effect to a component.
22
23**System capability**: SystemCapability.Graphics.Drawing
24
25**System API**: This is a system API.
26
27**Parameters**
28| Name | Type                                             | Mandatory| Description                       |
29| ------ | ------------------------------------------------- | ---- | --------------------------- |
30| param  | [BrightnessBlenderParam](#brightnessblenderparam) | Yes  | Parameters that implement the brightness effect.|
31
32**Return value**
33
34| Type                                    | Description                    |
35| ---------------------------------------- | ----------------------- |
36| [BrightnessBlender ](#brightnessblender) | **BrightnessBlender** instance with the brightness effect.|
37
38**Example**
39
40```ts
41let blender : uiEffect.BrightnessBlender =
42  uiEffect.createBrightnessBlender({cubicRate:1.0, quadraticRate:1.0, linearRate:1.0, degree:1.0, saturation:1.0,
43    positiveCoefficient:[2.3, 4.5, 2.0], negativeCoefficient:[0.5, 2.0, 0.5], fraction:0.0})
44```
45
46## Filter
47A 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.
48
49### pixelStretch
50pixelStretch(stretchSizes: Array\<number\>, tileMode: TileMode): Filter
51
52Applies the pixel stretch effect onto the component.
53
54**System capability**: SystemCapability.Graphics.Drawing
55
56**System API**: This is a system API.
57
58**Parameters**
59| Name        | Type                 | Mandatory| Description                      |
60| ------------- | --------------------- | ---- | ------------------------- |
61| 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.|
62| tileMode      | [TileMode](#tilemode) | Yes  | Pixel tiling mode for pixel stretch.|
63
64
65**Return value**
66
67| Type             | Description                              |
68| ----------------- | --------------------------------- |
69| [Filter](#filter) | **Filter** instance with the pixel stretch effect.|
70
71**Example**
72
73```ts
74filter.pixelStretch([0.2, 0.2, 0.2, 0.2], uiEffect.TileMode.CLAMP)
75```
76
77### waterRipple
78waterRipple(progress: number, waveCount: number, x: number, y: number, rippleMode: WaterRippleMode): Filter
79
80Applies the ripple effect onto the component.
81
82**System capability**: SystemCapability.Graphics.Drawing
83
84**System API**: This is a system API.
85
86**Parameters**
87| Name        | Type                 | Mandatory| Description                      |
88| ------------- | --------------------- | ---- | ------------------------- |
89| 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.|
90| 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.|
91| 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.|
92| 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.|
93| rippleMode      | [WaterRippleMode](#waterripplemode) | Yes  | Scene mode of the ripple effect.|
94
95
96**Return value**
97
98| Type             | Description                              |
99| ----------------- | --------------------------------- |
100| [Filter](#filter) | **Filter** instance with the ripple effect.|
101
102**Example**
103
104```ts
105filter.waterRipple(0.5, 2, 0.5, 0.5, uiEffect.WaterRippleMode.SMALL2SMALL)
106```
107
108### flyInFlyOutEffect
109flyInFlyOutEffect(degree: number, flyMode: FlyMode): Filter
110
111Applies fly-in and fly-out animations onto the component.
112
113**System capability**: SystemCapability.Graphics.Drawing
114
115**System API**: This is a system API.
116
117**Parameters**
118| Name        | Type                 | Mandatory| Description                      |
119| ------------- | --------------------- | ---- | ------------------------- |
120| 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.|
121| 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.|
122
123
124**Return value**
125
126| Type             | Description                              |
127| ----------------- | --------------------------------- |
128| [Filter](#filter) | **Filter** instance with the fly-in and fly-out animations.|
129
130**Example**
131
132```ts
133filter.flyInFlyOutEffect(0.5, uiEffect.FlyMode.TOP)
134```
135
136### distort<sup>13+</sup>
137distort(distortionK: number): Filter
138
139Applies the lens distortion effect onto the component.
140
141**System capability**: SystemCapability.Graphics.Drawing
142
143**System API**: This is a system API.
144
145**Parameters**
146| Name        | Type                 | Mandatory| Description                      |
147| ------------- | --------------------- | ---- | ------------------------- |
148| distortionK  | number         | Yes  | Distortion coefficient, indicating the degree of lens distortion. The value range is [-1, 1]. A value less than -1 evaluates to the value **-1**. A value greater than 1 evaluates to the value **1**.|
149
150![image_Add_Distort.png](./figures/image_Add_Distort.png)
151
152The preceding figure shows the rendering results when different distortion coefficients (-1, 0, 0.5, and 1) are applied onto an **Image** component. A negative distortion value results in a barrel distortion, whereas a positive value results in a pincushion distortion. As the distortion value approaches 0, the intensity of the distortion decreases, and at exactly 0, there is no distortion effect.
153
154**Return value**
155
156| Type             | Description                              |
157| ----------------- | --------------------------------- |
158| [Filter](#filter) | **Filter** instance with lens distortion effect.|
159
160**Error codes**
161
162For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
163
164| ID| Error Message|
165| ------- | --------------------------------------------|
166| 202 | Permission verification failed. A non-system application calls a system API. |
167
168**Example**
169
170```ts
171filter.distort(-0.5)
172```
173
174## TileMode
175Enumerates the pixel tiling modes.
176
177**System capability**: SystemCapability.Graphics.Drawing
178
179**System API**: This is a system API.
180
181| Name  | Value| Description|
182| ------ | - | ---- |
183| CLAMP  | 0 | Clamp.|
184| REPEAT | 1 | Repeat.|
185| MIRROR | 2 | Mirror.|
186| DECAL  | 3 | Decal.|
187
188## WaterRippleMode
189Enumerates the scene modes of the ripple effect.
190
191**System capability**: SystemCapability.Graphics.Drawing
192
193**System API**: This is a system API.
194
195| Name  | Value| Description|
196| ------ | - | ---- |
197| SMALL2MEDIUM_RECV  | 0 | A phone taps against a 2-in-1 device (receiver).|
198| SMALL2MEDIUM_SEND  | 1 | A phone taps against a 2-in-1 device (sender).|
199| SMALL2SMALL | 2 | A phone taps against another phone.|
200
201## FlyMode
202Enumerates the scene modes of fly-in and fly-out animations.
203
204**System capability**: SystemCapability.Graphics.Drawing
205
206**System API**: This is a system API.
207
208| Name  | Value| Description|
209| ------ | - | ---- |
210| BOTTOM  | 0 | Fly-in and fly-out animations occur from the bottom of the screen.|
211| TOP  | 1 | Fly-in and fly-out animations occur from the top of the screen.|
212
213## VisualEffect
214A 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.
215
216### backgroundColorBlender
217backgroundColorBlender(blender: BrightnessBlender): VisualEffect
218
219Applies 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.
220
221**System capability**: SystemCapability.Graphics.Drawing
222
223**System API**: This is a system API.
224
225**Parameters**
226| Name | Type                                     | Mandatory| Description                      |
227| ------- | ---------------------------------------- | ---- | ------------------------- |
228| blender | [BrightnessBlender](#brightnessblender) | Yes  | Blender used to change the background color.|
229
230**Return value**
231
232| Type                         | Description                                              |
233| ----------------------------- | ------------------------------------------------- |
234| [VisualEffect](#visualeffect) | **VisualEffect** instance with the background color change effect.|
235
236**Example**
237
238```ts
239let blender : uiEffect.BrightnessBlender =
240  uiEffect.createBrightnessBlender({cubicRate:1.0, quadraticRate:1.0, linearRate:1.0, degree:1.0, saturation:1.0,
241    positiveCoefficient:[2.3, 4.5, 2.0], negativeCoefficient:[0.5, 2.0, 0.5], fraction:0.0})
242visualEffect.backgroundColorBlender(blender)
243```
244
245## Blender<sup>13+</sup>
246
247type Blender = BrightnessBlender
248
249Defines the blender type, which is used to describe blending effects.
250
251**System capability**: SystemCapability.Graphics.Drawing
252
253**System API**: This is a system API.
254
255| Type                         | Description                                              |
256| ----------------------------- | ------------------------------------------------- |
257| [BrightnessBlender](#brightnessblender) | Blender with a brightening effect.|
258
259## BrightnessBlender
260A 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.
261
262**System capability**: SystemCapability.Graphics.Drawing
263
264**System API**: This is a system API.
265
266| Name               | Type                       | Read Only| Optional| Description                                                             |
267| ------------------- | -------------------------- | ---- | ---- | ---------------------------------------------------------------- |
268| cubicRate           | number                     | No  | No  | Third-order coefficient for grayscale adjustment.<br>The value range is [-20, 20].                       |
269| quadraticRate       | number                     | No  | No  | Second-order coefficient for grayscale adjustment.<br>The value range is [-20, 20].                       |
270| linearRate          | number                     | No  | No  | Linear coefficient for grayscale adjustment.<br>The value range is [-20, 20].                       |
271| degree              | number                     | No  | No  | Grayscale adjustment ratio.<br>The value range is [-20, 20].                           |
272| saturation          | number                     | No  | No  | Reference saturation for the brightness effect.<br>The value range is [0, 20].                           |
273| 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].|
274| 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].|
275| 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. |
276
277## BrightnessBlenderParam
278Describes the parameters used for the brightness blender.
279
280**System capability**: SystemCapability.Graphics.Drawing
281
282**System API**: This is a system API.
283
284| Name               | Type                       | Read Only| Optional| Description                                                             |
285| ------------------- | -------------------------- | ---- | ---- | ---------------------------------------------------------------- |
286| cubicRate           | number                     | No  | No  | Third-order coefficient for grayscale adjustment.<br>The value range is [-20, 20].                       |
287| quadraticRate       | number                     | No  | No  | Second-order coefficient for grayscale adjustment.<br>The value range is [-20, 20].                       |
288| linearRate          | number                     | No  | No  | Linear coefficient for grayscale adjustment.<br>The value range is [-20, 20].                       |
289| degree              | number                     | No  | No  | Grayscale adjustment ratio.<br>The value range is [-20, 20].                           |
290| saturation          | number                     | No  | No  | Reference saturation for the brightness effect.<br>The value range is [0, 20].                           |
291| 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].|
292| 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].|
293| 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. |
294