openharmony 鸿蒙 arkts-apis-graphics-drawing-ShadowLayer

2026-08-25 浏览 (1)

Class (ShadowLayer)

Implements a shadow layer.

NOTE

  • The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version.

  • The initial APIs of this class are supported since API version 12.

  • This module uses the physical pixel unit, px.

  • This module operates under a single-threaded model. The caller needs to manage thread safety and context state transitions.

Modules to Import

import { drawing } from '@kit.ArkGraphics2D';

create12+

static create(blurRadius: number, x: number, y: number, color: common2D.Color): ShadowLayer

Creates a ShadowLayer object.

System capability: SystemCapability.Graphics.Drawing

Parameters

NameTypeMandatoryDescription
blurRadiusnumberYesRadius of the shadow layer. The value must be a floating point number greater than 0.
xnumberYesOffset on the X axis. The value is a floating point number.
ynumberYesOffset on the Y axis. The value is a floating point number.
colorcommon2D.ColorYesColor in ARGB format. The value of each color channel is an integer ranging from 0 to 255.

Returns

TypeDescription
ShadowLayerShadowLayer object created.

Error codes

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

IDError Message
401Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed.

Example

import { RenderNode } from '@kit.ArkUI';
import { common2D, drawing } from '@kit.ArkGraphics2D';

class DrawingRenderNode extends RenderNode {
  draw(context : DrawContext) {
    const canvas = context.canvas;
    let color : common2D.Color = {alpha: 0xFF, red: 0x00, green: 0xFF, blue: 0x00};
    let shadowLayer = drawing.ShadowLayer.create(3, -3, 3, color);
  }
}

create18+

static create(blurRadius: number, x: number, y: number, color: common2D.Color|number): ShadowLayer

Creates a ShadowLayer object.

System capability: SystemCapability.Graphics.Drawing

Parameters

NameTypeMandatoryDescription
blurRadiusnumberYesRadius of the shadow layer. The value must be a floating point number greater than 0.
xnumberYesOffset on the X axis. The value is a floating point number.
ynumberYesOffset on the Y axis. The value is a floating point number.
colorcommon2D.Color |numberYesColor, represented by an unsigned integer in hexadecimal ARGB format.

Returns

TypeDescription
ShadowLayerShadowLayer object created.

Error codes

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

IDError Message
401Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed.

Example

import { RenderNode } from '@kit.ArkUI';
import { drawing } from '@kit.ArkGraphics2D';

class DrawingRenderNode extends RenderNode {
  draw(context : DrawContext) {
    const canvas = context.canvas;
    let shadowLayer = drawing.ShadowLayer.create(3, -3, 3, 0xff00ff00);
  }
}

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-drawing-gpu-context-h

openharmony 鸿蒙 capi-drawing-nativepixelmap-

openharmony 鸿蒙 capi-nativevsync-oh-nativevsync-expectedraterange

openharmony 鸿蒙 capi-drawing-oh-drawing-brush

openharmony 鸿蒙 capi-drawing-oh-drawing-image-info

openharmony 鸿蒙 capi-drawing-text-linetypography-h

openharmony 鸿蒙 capi-oh-nativeimage-oh-nativeimage

openharmony 鸿蒙 capi-drawing-typeface-h

openharmony 鸿蒙 capi-drawing-brush-h

openharmony 鸿蒙 capi-nativewindow

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