openharmony 鸿蒙 js-apis-uiEffect-sys

2025-06-12 浏览 (1)

@ohos.graphics.uiEffect (Cascading Effect) (System API)

The 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.

  • Filter: applies a filter to a component.
  • VisualEffect: applies a visual effect to a component.

NOTE

  • 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.
  • This topic describes only system APIs provided by the module. For details about its public APIs, see ohos.graphics.uiEffect (Cascading Effect).

Modules to Import

import { uiEffect } from "@kit.ArkGraphics2D";

uiEffect.createBrightnessBlender

createBrightnessBlender(param: BrightnessBlenderParam): BrightnessBlender

Creates a BrightnessBlender instance, which can be used to apply the brightness effect to a component.

System capability: SystemCapability.Graphics.Drawing

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
paramBrightnessBlenderParamYesParameters that implement the brightness effect.

Return value

TypeDescription
BrightnessBlender BrightnessBlender instance with the brightness effect.

Example

let blender : uiEffect.BrightnessBlender =
  uiEffect.createBrightnessBlender({cubicRate:1.0, quadraticRate:1.0, linearRate:1.0, degree:1.0, saturation:1.0,
    positiveCoefficient:[2.3, 4.5, 2.0], negativeCoefficient:[0.5, 2.0, 0.5], fraction:0.0})

Filter

A class that can apply a filter to a component. Before calling any API in Filter, you must use createFilter to create a Filter instance.

pixelStretch

pixelStretch(stretchSizes: Array<number>, tileMode: TileMode): Filter

Applies the pixel stretch effect onto the component.

System capability: SystemCapability.Graphics.Drawing

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
stretchSizesArray<number>YesRatio based on which the pixels grow towards the top, bottom, left, and right edges. The value range is [-1, 1].
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:
The values for the four directions must be all positive or all negative.
tileModeTileModeYesPixel tiling mode for pixel stretch.

Return value

TypeDescription
FilterFilter instance with the pixel stretch effect.

Example

filter.pixelStretch([0.2, 0.2, 0.2, 0.2], uiEffect.TileMode.CLAMP)

waterRipple

waterRipple(progress: number, waveCount: number, x: number, y: number, rippleMode: WaterRippleMode): Filter

Applies the ripple effect onto the component.

System capability: SystemCapability.Graphics.Drawing

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
progressnumberYesProgress of the ripple. The value range is [0, 1].
The closer the value is to 1, the more fully the ripple effect is displayed.
If a value outside this range is provided, no ripple effect will be displayed.
waveCountnumberYesNumber of ripples that form when the ripple effect. The value range is [1, 3].
The value must be an integer. Ripples will not be displayed if a floating point number or a value outside this range is provided.
xnumberYesX coordinate on the screen that marks the center of the ripple when the ripple effect is initially triggered.
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).
A negative number indicates that the center of the ripple is located to the left of the screen's center.
ynumberYesY coordinate on the screen that marks the center of the ripple when the ripple effect is initially triggered.
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).
A negative number indicates that the center of the ripple is located above the screen's center.
rippleModeWaterRippleModeYesScene mode of the ripple effect.

Return value

TypeDescription
FilterFilter instance with the ripple effect.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
202Permission verification failed. A non-system application calls a system API.

Example

filter.waterRipple(0.5, 2, 0.5, 0.5, uiEffect.WaterRippleMode.SMALL2SMALL)

flyInFlyOutEffect

flyInFlyOutEffect(degree: number, flyMode: FlyMode): Filter

Applies fly-in and fly-out animations onto the component.

System capability: SystemCapability.Graphics.Drawing

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
degreenumberYesDegree of control over deformation of the fly-in and fly-out animations. The value range is [0, 1].
A value closer to 1 results in more obvious deformation.
If a value outside this range is provided, no fly-in and fly-out animations will be displayed.
flyModeFlyModeYesScene mode of the fly-in and fly-out animations.
BOTTOM means that the fly-in and fly-out animations occur from the bottom of the screen,
and TOP means that the fly-in and fly-out animations occur from the top of the screen.

Return value

TypeDescription
FilterFilter instance with the fly-in and fly-out animations.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
202Permission verification failed. A non-system application calls a system API.

Example

filter.flyInFlyOutEffect(0.5, uiEffect.FlyMode.TOP)

distort13+

distort(distortionK: number): Filter

Applies the lens distortion effect onto the component.

System capability: SystemCapability.Graphics.Drawing

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
distortionKnumberYesDistortion 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.

image_Add_Distort.png

The 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.

Return value

TypeDescription
FilterFilter instance with lens distortion effect.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
202Permission verification failed. A non-system application calls a system API.

Example

filter.distort(-0.5)

TileMode

Enumerates the pixel tiling modes.

System capability: SystemCapability.Graphics.Drawing

System API: This is a system API.

NameValueDescription
CLAMP0Clamp.
REPEAT1Repeat.
MIRROR2Mirror.
DECAL3Decal.

WaterRippleMode

Enumerates the scene modes of the ripple effect.

System capability: SystemCapability.Graphics.Drawing

System API: This is a system API.

NameValueDescription
SMALL2MEDIUM_RECV0A phone taps against a 2-in-1 device (receiver).
SMALL2MEDIUM_SEND1A phone taps against a 2-in-1 device (sender).
SMALL2SMALL2A phone taps against another phone.

FlyMode

Enumerates the scene modes of fly-in and fly-out animations.

System capability: SystemCapability.Graphics.Drawing

System API: This is a system API.

NameValueDescription
BOTTOM0Fly-in and fly-out animations occur from the bottom of the screen.
TOP1Fly-in and fly-out animations occur from the top of the screen.

VisualEffect

A class that can apply a visual effect to a component. Before calling any API in VisualEffect, you must use createEffect to create a VisualEffect instance.

backgroundColorBlender

backgroundColorBlender(blender: BrightnessBlender): VisualEffect

Applies 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.

System capability: SystemCapability.Graphics.Drawing

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
blenderBrightnessBlenderYesBlender used to change the background color.

Return value

TypeDescription
VisualEffectVisualEffect instance with the background color change effect.

Example

let blender : uiEffect.BrightnessBlender =
  uiEffect.createBrightnessBlender({cubicRate:1.0, quadraticRate:1.0, linearRate:1.0, degree:1.0, saturation:1.0,
    positiveCoefficient:[2.3, 4.5, 2.0], negativeCoefficient:[0.5, 2.0, 0.5], fraction:0.0})
visualEffect.backgroundColorBlender(blender)

Blender13+

type Blender = BrightnessBlender

Defines the blender type, which is used to describe blending effects.

System capability: SystemCapability.Graphics.Drawing

System API: This is a system API.

TypeDescription
BrightnessBlenderBlender with a brightening effect.

BrightnessBlender

A blender that can apply the brightness effect to a component. Before calling any API in BrightnessBlender, you must use createBrightnessBlender to create a BrightnessBlender instance.

System capability: SystemCapability.Graphics.Drawing

System API: This is a system API.

NameTypeRead OnlyOptionalDescription
cubicRatenumberNoNoThird-order coefficient for grayscale adjustment.
The value range is [-20, 20].
quadraticRatenumberNoNoSecond-order coefficient for grayscale adjustment.
The value range is [-20, 20].
linearRatenumberNoNoLinear coefficient for grayscale adjustment.
The value range is [-20, 20].
degreenumberNoNoGrayscale adjustment ratio.
The value range is [-20, 20].
saturationnumberNoNoReference saturation for the brightness effect.
The value range is [0, 20].
positiveCoefficient[number, number, number]NoNoRGB positive adjustment parameter based on the reference saturation.
The value range of each number is [-20, 20].
negativeCoefficient[number, number, number]NoNoRGB negative adjustment parameter based on the reference saturation.
The value range of each number is [-20, 20].
fractionnumberNoNoBlending ratio of the brightness effect.
The value range is [0, 1]. A value beyond the boundary will be automatically truncated during implementation.

BrightnessBlenderParam

Describes the parameters used for the brightness blender.

System capability: SystemCapability.Graphics.Drawing

System API: This is a system API.

NameTypeRead OnlyOptionalDescription
cubicRatenumberNoNoThird-order coefficient for grayscale adjustment.
The value range is [-20, 20].
quadraticRatenumberNoNoSecond-order coefficient for grayscale adjustment.
The value range is [-20, 20].
linearRatenumberNoNoLinear coefficient for grayscale adjustment.
The value range is [-20, 20].
degreenumberNoNoGrayscale adjustment ratio.
The value range is [-20, 20].
saturationnumberNoNoReference saturation for the brightness effect.
The value range is [0, 20].
positiveCoefficient[number, number, number]NoNoRGB positive adjustment parameter based on the reference saturation.
The value range of each number is [-20, 20].
negativeCoefficient[number, number, number]NoNoRGB negative adjustment parameter based on the reference saturation.
The value range of each number is [-20, 20].
fractionnumberNoNoBlending ratio of the brightness effect.
The value range is [0, 1]. A value beyond the boundary will be automatically truncated during implementation.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArkGraphics 2D

harmony 鸿蒙BufferHandle

harmony 鸿蒙ColorSpacePrimaries

harmony 鸿蒙DisplaySoloist_ExpectedRateRange

harmony 鸿蒙_drawing

harmony 鸿蒙NativeColorSpaceManager

harmony 鸿蒙NativeDisplaySoloist

harmony 鸿蒙NativeVsync

harmony 鸿蒙NativeWindow

harmony 鸿蒙OH_Drawing_BitmapFormat

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/g9y5vl