1e41f4b71Sopenharmony_ci# @ohos.graphics.uiEffect (效果级联)(系统接口) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci本模块提供组件效果的一些基础能力,包括模糊、边缘像素扩展、提亮等。效果被分为Filter和VisualEffect大类,同类效果可以级联在一个效果大类的实例下。在实际开发中,模糊可用于背景虚化,提亮可用于亮屏显示等。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci- [Filter](#filter):用于添加指定Filter效果到组件上。 6e41f4b71Sopenharmony_ci- [VisualEffect](#visualeffect):用于添加指定VisualEffect效果到组件上。 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci> **说明:** 9e41f4b71Sopenharmony_ci> 10e41f4b71Sopenharmony_ci> - 本模块首批接口从API version 12开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 11e41f4b71Sopenharmony_ci> - 页面仅包含本模块的系统接口,其他公开接口参见[ohos.graphics.uiEffect (效果级联)](js-apis-uiEffect.md)。 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci## 导入模块 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_ci创建BrightnessBlender实例用于给组件添加提亮效果。 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Graphics.Drawing 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci**参数:** 28e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 29e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------- | ---- | --------------------------- | 30e41f4b71Sopenharmony_ci| param | [BrightnessBlenderParam](#brightnessblenderparam) | 是 | 实现提亮效果的参数。 | 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci**返回值:** 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci| 类型 | 说明 | 35e41f4b71Sopenharmony_ci| ---------------------------------------- | ----------------------- | 36e41f4b71Sopenharmony_ci| [BrightnessBlender ](#brightnessblender) | 返回设置了提亮效果参数的BrightnessBlender。 | 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci**示例:** 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_ciFilter效果类,用于将相应的效果添加到指定的组件上。在调用Filter的方法前,需要先通过[createFilter](js-apis-uiEffect.md#uieffectcreatefilter)创建一个Filter实例。 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci### pixelStretch 50e41f4b71Sopenharmony_cipixelStretch(stretchSizes: Array\<number\>, tileMode: TileMode): Filter 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci将边缘像素扩展效果添加至组件上。 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Graphics.Drawing 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci**参数:** 59e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 60e41f4b71Sopenharmony_ci| ------------- | --------------------- | ---- | ------------------------- | 61e41f4b71Sopenharmony_ci| stretchSizes | Array\<number\> | 是 | 上下左右四个方向边缘像素扩展的百分比比例,取值范围为[-1, 1]。<br/>正值表示向外扩展,上下左右四个方向分别用指定原图比例的边缘像素填充。负值表示内缩,但是最终图像大小不变。<br/>注意四个方向对应的参数需统一为非正值或非负值。| 62e41f4b71Sopenharmony_ci| tileMode | [TileMode](#tilemode) | 是 | 边缘像素扩展的像素填充模式。 | 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci**返回值:** 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci| 类型 | 说明 | 68e41f4b71Sopenharmony_ci| ----------------- | --------------------------------- | 69e41f4b71Sopenharmony_ci| [Filter](#filter) | 返回挂载了边缘像素扩展效果的Filter。 | 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci**示例:** 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_ci将水波纹效果添加至组件上。 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Graphics.Drawing 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci**参数:** 87e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 88e41f4b71Sopenharmony_ci| ------------- | --------------------- | ---- | ------------------------- | 89e41f4b71Sopenharmony_ci| progress | number | 是 | 表示水波纹的进度,取值范围为[0, 1]。<br/>水波纹进度越趋向于1,水波纹展示越完全。<br/>超出取值范围水波纹不会出现效果。| 90e41f4b71Sopenharmony_ci| waveCount | number | 是 | 水波纹波动时波纹的个数,取值范围为[1, 3]。<br/>水波纹的个数只能取整数,如果为浮点数或超出取值范围,水波纹不会出现效果。 | 91e41f4b71Sopenharmony_ci| x | number | 是 | 水波纹中心在屏幕中第一次出现的x轴位置。<br/>水波纹对屏幕进行归一化处理,左上角的坐标为(0, 0),右上角坐标为(1, 0)。<br/>当x取值为负值时,代表在屏幕左侧。| 92e41f4b71Sopenharmony_ci| y | number | 是 | 水波纹中心在屏幕中第一次出现的y轴位置。<br/>水波纹对屏幕进行归一化处理,左上角的坐标为(0, 0),左下角坐标为(0, 1)。<br/>当y取值为负值时,代表在屏幕上方。 | 93e41f4b71Sopenharmony_ci| rippleMode | [WaterRippleMode](#waterripplemode) | 是 | 水波纹的场景模式。| 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci**返回值:** 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci| 类型 | 说明 | 99e41f4b71Sopenharmony_ci| ----------------- | --------------------------------- | 100e41f4b71Sopenharmony_ci| [Filter](#filter) | 返回挂载了水波纹效果的Filter。 | 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci**示例:** 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_ci将飞入飞出形变效果添加至组件上。 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Graphics.Drawing 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci**参数:** 118e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 119e41f4b71Sopenharmony_ci| ------------- | --------------------- | ---- | ------------------------- | 120e41f4b71Sopenharmony_ci| degree | number | 是 | 表示控制飞入飞出形变的程度,取值范围为[0, 1]。<br/>越靠近1,变形程度越明显。<br/>超出取值范围形变不会出现效果。| 121e41f4b71Sopenharmony_ci| flyMode | [FlyMode](#flymode) | 是 | 飞入飞出的场景模式。<br/>BOTTOM表示从设备底部飞入飞出形变场景。<br/>TOP表示从设备顶部飞入飞出形变场景。 | 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci**返回值:** 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci| 类型 | 说明 | 127e41f4b71Sopenharmony_ci| ----------------- | --------------------------------- | 128e41f4b71Sopenharmony_ci| [Filter](#filter) | 返回挂载了飞入飞出形变效果的Filter。 | 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci**示例:** 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci```ts 133e41f4b71Sopenharmony_cifilter.flyInFlyOutEffect(0.5, uiEffect.FlyMode.TOP) 134e41f4b71Sopenharmony_ci``` 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ci## TileMode 137e41f4b71Sopenharmony_ci像素填充模式枚举。 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Graphics.Drawing 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 144e41f4b71Sopenharmony_ci| ------ | - | ---- | 145e41f4b71Sopenharmony_ci| CLAMP | 0 | 截断。 | 146e41f4b71Sopenharmony_ci| REPEAT | 1 | 重复。 | 147e41f4b71Sopenharmony_ci| MIRROR | 2 | 镜像。 | 148e41f4b71Sopenharmony_ci| DECAL | 3 | 透明。 | 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci## WaterRippleMode 151e41f4b71Sopenharmony_ci水波纹场景模式枚举。 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Graphics.Drawing 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 158e41f4b71Sopenharmony_ci| ------ | - | ---- | 159e41f4b71Sopenharmony_ci| SMALL2MEDIUM_RECV | 0 | 手机碰2in1设备(接收端)。 | 160e41f4b71Sopenharmony_ci| SMALL2MEDIUM_SEND | 1 | 手机碰2in1设备(发送端)。 | 161e41f4b71Sopenharmony_ci| SMALL2SMALL | 2 | 手机碰手机。 | 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci## FlyMode 164e41f4b71Sopenharmony_ci飞入飞出形变场景模式枚举。 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Graphics.Drawing 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 171e41f4b71Sopenharmony_ci| ------ | - | ---- | 172e41f4b71Sopenharmony_ci| BOTTOM | 0 | 从底部进行飞入飞出形变。 | 173e41f4b71Sopenharmony_ci| TOP | 1 | 从顶部进行飞入飞出形变。 | 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci## VisualEffect 176e41f4b71Sopenharmony_ciVisualEffect效果类,用于将相应的效果添加到指定的组件上。在调用VisualEffect的方法前,需要先通过[createEffect](js-apis-uiEffect.md#uieffectcreateeffect)创建一个VisualEffect实例。 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci### backgroundColorBlender 179e41f4b71Sopenharmony_cibackgroundColorBlender(blender: BrightnessBlender): VisualEffect 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ci将混合器添加至组件上以改变组件背景颜色,具体的更改效果由输入决定,目前仅支持提亮混合器。 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Graphics.Drawing 184e41f4b71Sopenharmony_ci 185e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 186e41f4b71Sopenharmony_ci 187e41f4b71Sopenharmony_ci**参数:** 188e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 189e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ------------------------- | 190e41f4b71Sopenharmony_ci| blender | [BrightnessBlender](#brightnessblender) | 是 | 用于混合背景颜色的blender。 | 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci**返回值:** 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci| 类型 | 说明 | 195e41f4b71Sopenharmony_ci| ----------------------------- | ------------------------------------------------- | 196e41f4b71Sopenharmony_ci| [VisualEffect](#visualeffect) | 返回添加了背景颜色更改效果的VisualEffect。 | 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci**示例:** 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_ci混合器类型,用于描述混合效果。 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Graphics.Drawing 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ci| 类型 | 说明 | 218e41f4b71Sopenharmony_ci| ----------------------------- | ------------------------------------------------- | 219e41f4b71Sopenharmony_ci| [BrightnessBlender](#brightnessblender) | 具有提亮效果的混合器。 | 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci## BrightnessBlender 222e41f4b71Sopenharmony_ci提亮混合器,用于将提亮效果添加到指定的组件上。在调用BrightnessBlender前,需要先通过[createBrightnessBlender](#uieffectcreatebrightnessblender)创建一个BrightnessBlender实例。 223e41f4b71Sopenharmony_ci 224e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Graphics.Drawing 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 227e41f4b71Sopenharmony_ci 228e41f4b71Sopenharmony_ci| 名称 | 类型 | 只读 | 可选 | 说明 | 229e41f4b71Sopenharmony_ci| ------------------- | -------------------------- | ---- | ---- | ---------------------------------------------------------------- | 230e41f4b71Sopenharmony_ci| cubicRate | number | 否 | 否 | 灰度调整的三阶系数。<br/>取值范围[-20, 20]。 | 231e41f4b71Sopenharmony_ci| quadraticRate | number | 否 | 否 | 灰度调整的二阶系数。<br/>取值范围[-20, 20]。 | 232e41f4b71Sopenharmony_ci| linearRate | number | 否 | 否 | 灰度调整的线性系数。<br/>取值范围[-20, 20]。 | 233e41f4b71Sopenharmony_ci| degree | number | 否 | 否 | 灰度调整的比例。<br/>取值范围[-20, 20]。 | 234e41f4b71Sopenharmony_ci| saturation | number | 否 | 否 | 提亮的基准饱和度。<br/>取值范围[0, 20]。 | 235e41f4b71Sopenharmony_ci| positiveCoefficient | [number, number, number] | 否 | 否 | 基于基准饱和度的RGB正向调整参数。<br/>每个number的取值范围[-20, 20]。 | 236e41f4b71Sopenharmony_ci| negativeCoefficient | [number, number, number] | 否 | 否 | 基于基准饱和度的RGB负向调整参数。<br/>每个number的取值范围[-20, 20]。 | 237e41f4b71Sopenharmony_ci| fraction | number | 否 | 否 | 提亮效果的混合比例。<br/>取值范围[0, 1],超出边界会在实现时自动截断。 | 238e41f4b71Sopenharmony_ci 239e41f4b71Sopenharmony_ci## BrightnessBlenderParam 240e41f4b71Sopenharmony_ciBrightnessBlender参数列表。 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Graphics.Drawing 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci| 名称 | 类型 | 只读 | 可选 | 说明 | 247e41f4b71Sopenharmony_ci| ------------------- | -------------------------- | ---- | ---- | ---------------------------------------------------------------- | 248e41f4b71Sopenharmony_ci| cubicRate | number | 否 | 否 | 灰度调整的三阶系数。<br/>取值范围[-20, 20]。 | 249e41f4b71Sopenharmony_ci| quadraticRate | number | 否 | 否 | 灰度调整的二阶系数。<br/>取值范围[-20, 20]。 | 250e41f4b71Sopenharmony_ci| linearRate | number | 否 | 否 | 灰度调整的线性系数。<br/>取值范围[-20, 20]。 | 251e41f4b71Sopenharmony_ci| degree | number | 否 | 否 | 灰度调整的比例。<br/>取值范围[-20, 20]。 | 252e41f4b71Sopenharmony_ci| saturation | number | 否 | 否 | 提亮的基准饱和度。<br/>取值范围[0, 20]。 | 253e41f4b71Sopenharmony_ci| positiveCoefficient | [number, number, number] | 否 | 否 | 基于基准饱和度的RGB正向调整参数。<br/>每个number的取值范围[-20, 20]。 | 254e41f4b71Sopenharmony_ci| negativeCoefficient | [number, number, number] | 否 | 否 | 基于基准饱和度的RGB负向调整参数。<br/>每个number的取值范围[-20, 20]。 | 255e41f4b71Sopenharmony_ci| fraction | number | 否 | 否 | 提亮效果的混合比例。<br/>取值范围[0, 1],超出边界会在实现时自动截断。 |