1e41f4b71Sopenharmony_ci# @ohos.effectKit (Image Effects)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **EffectKit** module provides basic image processing capabilities, including brightness adjustment, blurring, grayscale adjustment, and color picker.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ciThis module provides the following classes:
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci- [Filter](#filter): a class that adds a specified effect to the image source.
8e41f4b71Sopenharmony_ci- [Color](#color): a class used to store the color picked.
9e41f4b71Sopenharmony_ci- [ColorPicker](#colorpicker): a smart color picker.
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci> **NOTE**
12e41f4b71Sopenharmony_ci> 
13e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## Modules to Import
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci```ts
18e41f4b71Sopenharmony_ciimport { effectKit } from "@kit.ArkGraphics2D";
19e41f4b71Sopenharmony_ci```
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci## effectKit.createEffect
22e41f4b71Sopenharmony_cicreateEffect(source: image.PixelMap): Filter
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ciCreates a **Filter** instance based on a pixel map.
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Image.Core
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci**Parameters**
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci| Name   | Type              | Mandatory | Description    |
35e41f4b71Sopenharmony_ci| ------- | ----------------- | ---- | -------- |
36e41f4b71Sopenharmony_ci| source  | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes  | **PixelMap** instance created by the image module. An instance can be obtained by decoding an image or directly created. For details, see [Image Overview](../../media/image/image-overview.md).  |
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci**Return value**
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci| Type                            | Description          |
41e41f4b71Sopenharmony_ci| -------------------------------- | -------------- |
42e41f4b71Sopenharmony_ci| [Filter](#filter) | Head node of the filter linked list without any effect. If the operation fails, **null** is returned. |
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci**Example**
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci```ts
47e41f4b71Sopenharmony_ciimport { image } from "@kit.ImageKit";
48e41f4b71Sopenharmony_ciimport { effectKit } from "@kit.ArkGraphics2D";
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ciconst color = new ArrayBuffer(96);
51e41f4b71Sopenharmony_cilet opts : image.InitializationOptions = {
52e41f4b71Sopenharmony_ci  editable: true,
53e41f4b71Sopenharmony_ci  pixelFormat: 3,
54e41f4b71Sopenharmony_ci  size: {
55e41f4b71Sopenharmony_ci    height: 4,
56e41f4b71Sopenharmony_ci    width: 6
57e41f4b71Sopenharmony_ci  }
58e41f4b71Sopenharmony_ci}
59e41f4b71Sopenharmony_ciimage.createPixelMap(color, opts).then((pixelMap) => {
60e41f4b71Sopenharmony_ci  let headFilter = effectKit.createEffect(pixelMap);
61e41f4b71Sopenharmony_ci})
62e41f4b71Sopenharmony_ci```
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci## effectKit.createColorPicker
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_cicreateColorPicker(source: image.PixelMap): Promise\<ColorPicker>
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ciCreates a **ColorPicker** instance based on a pixel map. This API uses a promise to return the result.
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Image.Core
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci**Parameters**
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci| Name    | Type        | Mandatory | Description                      |
79e41f4b71Sopenharmony_ci| -------- | ----------- | ---- | -------------------------- |
80e41f4b71Sopenharmony_ci| source   | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes  |  **PixelMap** instance created by the image module. An instance can be obtained by decoding an image or directly created. For details, see [Image Overview](../../media/image/image-overview.md). |
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci**Return value**
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci| Type                  | Description          |
85e41f4b71Sopenharmony_ci| ---------------------- | -------------- |
86e41f4b71Sopenharmony_ci| Promise\<[ColorPicker](#colorpicker)>  | Promise used to return the **ColorPicker** instance created. |
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci**Error codes**
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci| ID | Error Message                       |
93e41f4b71Sopenharmony_ci| -------- | ------------------------------ |
94e41f4b71Sopenharmony_ci| 401      | Input parameter error.             |
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci**Example**
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci```ts
99e41f4b71Sopenharmony_ciimport { image } from "@kit.ImageKit";
100e41f4b71Sopenharmony_ciimport { effectKit } from "@kit.ArkGraphics2D";
101e41f4b71Sopenharmony_ciimport { BusinessError } from "@kit.BasicServicesKit";
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ciconst color = new ArrayBuffer(96);
104e41f4b71Sopenharmony_cilet opts : image.InitializationOptions = {
105e41f4b71Sopenharmony_ci  editable: true,
106e41f4b71Sopenharmony_ci  pixelFormat: 3,
107e41f4b71Sopenharmony_ci  size: {
108e41f4b71Sopenharmony_ci    height: 4,
109e41f4b71Sopenharmony_ci    width: 6
110e41f4b71Sopenharmony_ci  }
111e41f4b71Sopenharmony_ci}
112e41f4b71Sopenharmony_ci
113e41f4b71Sopenharmony_ciimage.createPixelMap(color, opts).then((pixelMap) => {
114e41f4b71Sopenharmony_ci  effectKit.createColorPicker(pixelMap).then(colorPicker => {
115e41f4b71Sopenharmony_ci    console.info("color picker=" + colorPicker);
116e41f4b71Sopenharmony_ci  }).catch( (reason : BusinessError) => {
117e41f4b71Sopenharmony_ci    console.error("error=" + reason.message);
118e41f4b71Sopenharmony_ci  })
119e41f4b71Sopenharmony_ci})
120e41f4b71Sopenharmony_ci```
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci## effectKit.createColorPicker<sup>10+</sup>
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_cicreateColorPicker(source: image.PixelMap, region: Array\<number>): Promise\<ColorPicker>
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ciCreates a **ColorPicker** instance for the selected region based on a pixel map. This API uses a promise to return the result.
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Image.Core
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci**Parameters**
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci| Name    | Type        | Mandatory | Description                      |
137e41f4b71Sopenharmony_ci| -------- | ----------- | ---- | -------------------------- |
138e41f4b71Sopenharmony_ci| source   | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes  |  **PixelMap** instance created by the image module. An instance can be obtained by decoding an image or directly created. For details, see [Image Overview](../../media/image/image-overview.md). |
139e41f4b71Sopenharmony_ci| region   | Array\<number> | Yes  |  Region of the image from which the color is picked.<br>The array consists of four elements, representing the left, top, right, and bottom positions of the image, respectively. The value of each element must be in the range [0, 1]. The leftmost and topmost positions of the image correspond to 0, and the rightmost and bottom positions correspond to 1. In the array, the third element must be greater than the first element, and the fourth element must be greater than the second element.|
140e41f4b71Sopenharmony_ci
141e41f4b71Sopenharmony_ci**Return value**
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ci| Type                  | Description          |
144e41f4b71Sopenharmony_ci| ---------------------- | -------------- |
145e41f4b71Sopenharmony_ci| Promise\<[ColorPicker](#colorpicker)>  | Promise used to return the **ColorPicker** instance created. |
146e41f4b71Sopenharmony_ci
147e41f4b71Sopenharmony_ci**Error codes**
148e41f4b71Sopenharmony_ci
149e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
150e41f4b71Sopenharmony_ci
151e41f4b71Sopenharmony_ci| ID | Error Message                       |
152e41f4b71Sopenharmony_ci| -------- | ------------------------------ |
153e41f4b71Sopenharmony_ci| 401      | Input parameter error.             |
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ci**Example**
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_ci```ts
158e41f4b71Sopenharmony_ciimport { image } from "@kit.ImageKit";
159e41f4b71Sopenharmony_ciimport { effectKit } from "@kit.ArkGraphics2D";
160e41f4b71Sopenharmony_ciimport { BusinessError } from "@kit.BasicServicesKit";
161e41f4b71Sopenharmony_ci
162e41f4b71Sopenharmony_ciconst color = new ArrayBuffer(96);
163e41f4b71Sopenharmony_cilet opts : image.InitializationOptions = {
164e41f4b71Sopenharmony_ci  editable: true,
165e41f4b71Sopenharmony_ci  pixelFormat: 3,
166e41f4b71Sopenharmony_ci  size: {
167e41f4b71Sopenharmony_ci    height: 4,
168e41f4b71Sopenharmony_ci    width: 6
169e41f4b71Sopenharmony_ci  }
170e41f4b71Sopenharmony_ci}
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ciimage.createPixelMap(color, opts).then((pixelMap) => {
173e41f4b71Sopenharmony_ci  effectKit.createColorPicker(pixelMap, [0, 0, 1, 1]).then(colorPicker => {
174e41f4b71Sopenharmony_ci    console.info("color picker=" + colorPicker);
175e41f4b71Sopenharmony_ci  }).catch( (reason : BusinessError) => {
176e41f4b71Sopenharmony_ci    console.error("error=" + reason.message);
177e41f4b71Sopenharmony_ci  })
178e41f4b71Sopenharmony_ci})
179e41f4b71Sopenharmony_ci```
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_ci## effectKit.createColorPicker
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_cicreateColorPicker(source: image.PixelMap, callback: AsyncCallback\<ColorPicker>): void
184e41f4b71Sopenharmony_ci
185e41f4b71Sopenharmony_ciCreates a **ColorPicker** instance based on a pixel map. This API uses an asynchronous callback to return the result.
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
188e41f4b71Sopenharmony_ci
189e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
190e41f4b71Sopenharmony_ci
191e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Image.Core
192e41f4b71Sopenharmony_ci
193e41f4b71Sopenharmony_ci**Parameters**
194e41f4b71Sopenharmony_ci
195e41f4b71Sopenharmony_ci| Name    | Type               | Mandatory | Description                      |
196e41f4b71Sopenharmony_ci| -------- | ------------------ | ---- | -------------------------- |
197e41f4b71Sopenharmony_ci| source   | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes |**PixelMap** instance created by the image module. An instance can be obtained by decoding an image or directly created. For details, see [Image Overview](../../media/image/image-overview.md). |
198e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[ColorPicker](#colorpicker)> | Yes | Callback used to return the **ColorPicker** instance created. |
199e41f4b71Sopenharmony_ci
200e41f4b71Sopenharmony_ci**Error codes**
201e41f4b71Sopenharmony_ci
202e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
203e41f4b71Sopenharmony_ci
204e41f4b71Sopenharmony_ci| ID | Error Message                       |
205e41f4b71Sopenharmony_ci| -------- | ------------------------------ |
206e41f4b71Sopenharmony_ci| 401      | Input parameter error.             |
207e41f4b71Sopenharmony_ci
208e41f4b71Sopenharmony_ci**Example**
209e41f4b71Sopenharmony_ci
210e41f4b71Sopenharmony_ci```ts
211e41f4b71Sopenharmony_ciimport { image } from "@kit.ImageKit";
212e41f4b71Sopenharmony_ciimport { effectKit } from "@kit.ArkGraphics2D";
213e41f4b71Sopenharmony_ci
214e41f4b71Sopenharmony_ciconst color = new ArrayBuffer(96);
215e41f4b71Sopenharmony_cilet opts : image.InitializationOptions = {
216e41f4b71Sopenharmony_ci  editable: true,
217e41f4b71Sopenharmony_ci  pixelFormat: 3,
218e41f4b71Sopenharmony_ci  size: {
219e41f4b71Sopenharmony_ci    height: 4,
220e41f4b71Sopenharmony_ci    width: 6
221e41f4b71Sopenharmony_ci  }
222e41f4b71Sopenharmony_ci}
223e41f4b71Sopenharmony_ciimage.createPixelMap(color, opts).then((pixelMap) => {
224e41f4b71Sopenharmony_ci  effectKit.createColorPicker(pixelMap, (error, colorPicker) => {
225e41f4b71Sopenharmony_ci    if (error) {
226e41f4b71Sopenharmony_ci      console.error('Failed to create color picker.');
227e41f4b71Sopenharmony_ci    } else {
228e41f4b71Sopenharmony_ci      console.info('Succeeded in creating color picker.');
229e41f4b71Sopenharmony_ci    }
230e41f4b71Sopenharmony_ci  })
231e41f4b71Sopenharmony_ci})
232e41f4b71Sopenharmony_ci```
233e41f4b71Sopenharmony_ci
234e41f4b71Sopenharmony_ci## effectKit.createColorPicker<sup>10+</sup>
235e41f4b71Sopenharmony_ci
236e41f4b71Sopenharmony_cicreateColorPicker(source: image.PixelMap, region:Array\<number>, callback: AsyncCallback\<ColorPicker>): void
237e41f4b71Sopenharmony_ci
238e41f4b71Sopenharmony_ciCreates a **ColorPicker** instance for the selected region based on a pixel map. This API uses an asynchronous callback to return the result.
239e41f4b71Sopenharmony_ci
240e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
241e41f4b71Sopenharmony_ci
242e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
243e41f4b71Sopenharmony_ci
244e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Image.Core
245e41f4b71Sopenharmony_ci
246e41f4b71Sopenharmony_ci**Parameters**
247e41f4b71Sopenharmony_ci
248e41f4b71Sopenharmony_ci| Name    | Type               | Mandatory | Description                      |
249e41f4b71Sopenharmony_ci| -------- | ------------------ | ---- | -------------------------- |
250e41f4b71Sopenharmony_ci| source   | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes |**PixelMap** instance created by the image module. An instance can be obtained by decoding an image or directly created. For details, see [Image Overview](../../media/image/image-overview.md). |
251e41f4b71Sopenharmony_ci| region   | Array\<number> | Yes  |  Region of the image from which the color is picked.<br>The array consists of four elements, representing the left, top, right, and bottom positions of the image, respectively. The value of each element must be in the range [0, 1]. The leftmost and topmost positions of the image correspond to 0, and the rightmost and bottom positions correspond to 1. In the array, the third element must be greater than the first element, and the fourth element must be greater than the second element.|
252e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[ColorPicker](#colorpicker)> | Yes | Callback used to return the **ColorPicker** instance created. |
253e41f4b71Sopenharmony_ci
254e41f4b71Sopenharmony_ci**Error codes**
255e41f4b71Sopenharmony_ci
256e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
257e41f4b71Sopenharmony_ci
258e41f4b71Sopenharmony_ci| ID | Error Message                       |
259e41f4b71Sopenharmony_ci| -------- | ------------------------------ |
260e41f4b71Sopenharmony_ci| 401      | Input parameter error.             |
261e41f4b71Sopenharmony_ci
262e41f4b71Sopenharmony_ci**Example**
263e41f4b71Sopenharmony_ci
264e41f4b71Sopenharmony_ci```ts
265e41f4b71Sopenharmony_ciimport { image } from "@kit.ImageKit";
266e41f4b71Sopenharmony_ciimport { effectKit } from "@kit.ArkGraphics2D";
267e41f4b71Sopenharmony_ci
268e41f4b71Sopenharmony_ciconst color = new ArrayBuffer(96);
269e41f4b71Sopenharmony_cilet opts : image.InitializationOptions = {
270e41f4b71Sopenharmony_ci  editable: true,
271e41f4b71Sopenharmony_ci  pixelFormat: 3,
272e41f4b71Sopenharmony_ci  size: {
273e41f4b71Sopenharmony_ci    height: 4,
274e41f4b71Sopenharmony_ci    width: 6
275e41f4b71Sopenharmony_ci  }
276e41f4b71Sopenharmony_ci}
277e41f4b71Sopenharmony_ciimage.createPixelMap(color, opts).then((pixelMap) => {
278e41f4b71Sopenharmony_ci  effectKit.createColorPicker(pixelMap, [0, 0, 1, 1], (error, colorPicker) => {
279e41f4b71Sopenharmony_ci    if (error) {
280e41f4b71Sopenharmony_ci      console.error('Failed to create color picker.');
281e41f4b71Sopenharmony_ci    } else {
282e41f4b71Sopenharmony_ci      console.info('Succeeded in creating color picker.');
283e41f4b71Sopenharmony_ci    }
284e41f4b71Sopenharmony_ci  })
285e41f4b71Sopenharmony_ci})
286e41f4b71Sopenharmony_ci```
287e41f4b71Sopenharmony_ci
288e41f4b71Sopenharmony_ci## Color
289e41f4b71Sopenharmony_ci
290e41f4b71Sopenharmony_ciA class that stores the color picked.
291e41f4b71Sopenharmony_ci
292e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
293e41f4b71Sopenharmony_ci
294e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
295e41f4b71Sopenharmony_ci
296e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Image.Core
297e41f4b71Sopenharmony_ci
298e41f4b71Sopenharmony_ci| Name  | Type  | Readable | Writable | Description             |
299e41f4b71Sopenharmony_ci| ------ | ----- | ---- | ---- | ---------------- |
300e41f4b71Sopenharmony_ci| red   | number | Yes  | No  | Value of the red component. The value range is [0x0, 0xFF].          |
301e41f4b71Sopenharmony_ci| green | number | Yes  | No  | Value of the green component. The value range is [0x0, 0xFF].          |
302e41f4b71Sopenharmony_ci| blue  | number | Yes  | No  | Value of the blue component. The value range is [0x0, 0xFF].          |
303e41f4b71Sopenharmony_ci| alpha | number | Yes  | No  | Value of the alpha component. The value range is [0x0, 0xFF].      |
304e41f4b71Sopenharmony_ci
305e41f4b71Sopenharmony_ci## ColorPicker
306e41f4b71Sopenharmony_ci
307e41f4b71Sopenharmony_ciA class used to obtain the color from an image. Before calling any method of **ColorPicker**, use [createColorPicker](#effectkitcreatecolorpicker) to create a **ColorPicker** instance.
308e41f4b71Sopenharmony_ci
309e41f4b71Sopenharmony_ci### getMainColor
310e41f4b71Sopenharmony_ci
311e41f4b71Sopenharmony_cigetMainColor(): Promise\<Color>
312e41f4b71Sopenharmony_ci
313e41f4b71Sopenharmony_ciObtains the main color from the image and writes the result to a [Color](#color) instance. This API uses a promise to return the result.
314e41f4b71Sopenharmony_ci
315e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
316e41f4b71Sopenharmony_ci
317e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
318e41f4b71Sopenharmony_ci
319e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Image.Core
320e41f4b71Sopenharmony_ci
321e41f4b71Sopenharmony_ci**Return value**
322e41f4b71Sopenharmony_ci
323e41f4b71Sopenharmony_ci| Type          | Description                                           |
324e41f4b71Sopenharmony_ci| :------------- | :---------------------------------------------- |
325e41f4b71Sopenharmony_ci| Promise\<[Color](#color)> | Promise used to return the color value of the main color. If the operation fails, an error message is returned. |
326e41f4b71Sopenharmony_ci
327e41f4b71Sopenharmony_ci**Example**
328e41f4b71Sopenharmony_ci
329e41f4b71Sopenharmony_ci```ts
330e41f4b71Sopenharmony_ciimport { image } from "@kit.ImageKit";
331e41f4b71Sopenharmony_ciimport { effectKit } from "@kit.ArkGraphics2D";
332e41f4b71Sopenharmony_ci
333e41f4b71Sopenharmony_ciconst color = new ArrayBuffer(96);
334e41f4b71Sopenharmony_cilet opts: image.InitializationOptions = {
335e41f4b71Sopenharmony_ci  editable: true,
336e41f4b71Sopenharmony_ci  pixelFormat: 3,
337e41f4b71Sopenharmony_ci  size: {
338e41f4b71Sopenharmony_ci    height: 4,
339e41f4b71Sopenharmony_ci    width: 6
340e41f4b71Sopenharmony_ci  }
341e41f4b71Sopenharmony_ci}
342e41f4b71Sopenharmony_ciimage.createPixelMap(color, opts).then((pixelMap) => {
343e41f4b71Sopenharmony_ci  effectKit.createColorPicker(pixelMap, (error, colorPicker) => {
344e41f4b71Sopenharmony_ci    if (error) {
345e41f4b71Sopenharmony_ci      console.error('Failed to create color picker.');
346e41f4b71Sopenharmony_ci     } else {
347e41f4b71Sopenharmony_ci       console.info('Succeeded in creating color picker.');
348e41f4b71Sopenharmony_ci       colorPicker.getMainColor().then(color => {
349e41f4b71Sopenharmony_ci        console.info('Succeeded in getting main color.');
350e41f4b71Sopenharmony_ci         console.info(`color[ARGB]=${color.alpha},${color.red},${color.green},${color.blue}`);
351e41f4b71Sopenharmony_ci      })
352e41f4b71Sopenharmony_ci    }
353e41f4b71Sopenharmony_ci  })
354e41f4b71Sopenharmony_ci})
355e41f4b71Sopenharmony_ci```
356e41f4b71Sopenharmony_ci
357e41f4b71Sopenharmony_ci### getMainColorSync
358e41f4b71Sopenharmony_ci
359e41f4b71Sopenharmony_cigetMainColorSync(): Color
360e41f4b71Sopenharmony_ci
361e41f4b71Sopenharmony_ciObtains the main color from the image and writes the result to a [Color](#color) instance. This API returns the result synchronously.
362e41f4b71Sopenharmony_ci
363e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
364e41f4b71Sopenharmony_ci
365e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
366e41f4b71Sopenharmony_ci
367e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Image.Core
368e41f4b71Sopenharmony_ci
369e41f4b71Sopenharmony_ci**Return value**
370e41f4b71Sopenharmony_ci
371e41f4b71Sopenharmony_ci| Type    | Description                                 |
372e41f4b71Sopenharmony_ci| :------- | :----------------------------------- |
373e41f4b71Sopenharmony_ci| [Color](#color)    | Color value of the main color. If the operation fails, **null** is returned. |
374e41f4b71Sopenharmony_ci
375e41f4b71Sopenharmony_ci**Example**
376e41f4b71Sopenharmony_ci
377e41f4b71Sopenharmony_ci```ts
378e41f4b71Sopenharmony_ciimport { image } from "@kit.ImageKit";
379e41f4b71Sopenharmony_ciimport { effectKit } from "@kit.ArkGraphics2D";
380e41f4b71Sopenharmony_ci
381e41f4b71Sopenharmony_ciconst color = new ArrayBuffer(96);
382e41f4b71Sopenharmony_cilet opts : image.InitializationOptions = {
383e41f4b71Sopenharmony_ci  editable: true,
384e41f4b71Sopenharmony_ci  pixelFormat: 3,
385e41f4b71Sopenharmony_ci  size: {
386e41f4b71Sopenharmony_ci    height: 4,
387e41f4b71Sopenharmony_ci    width: 6
388e41f4b71Sopenharmony_ci  }
389e41f4b71Sopenharmony_ci}
390e41f4b71Sopenharmony_ciimage.createPixelMap(color, opts).then((pixelMap) => {
391e41f4b71Sopenharmony_ci  effectKit.createColorPicker(pixelMap, (error, colorPicker) => {
392e41f4b71Sopenharmony_ci    if (error) {
393e41f4b71Sopenharmony_ci      console.error('Failed to create color picker.');
394e41f4b71Sopenharmony_ci    } else {
395e41f4b71Sopenharmony_ci      console.info('Succeeded in creating color picker.');
396e41f4b71Sopenharmony_ci      let color = colorPicker.getMainColorSync();
397e41f4b71Sopenharmony_ci      console.info('get main color =' + color);
398e41f4b71Sopenharmony_ci    }
399e41f4b71Sopenharmony_ci  })
400e41f4b71Sopenharmony_ci})
401e41f4b71Sopenharmony_ci```
402e41f4b71Sopenharmony_ci![image_Main_Color.png](figures/image_Main_Color.png)
403e41f4b71Sopenharmony_ci
404e41f4b71Sopenharmony_ci### getLargestProportionColor<sup>10+</sup>
405e41f4b71Sopenharmony_ci
406e41f4b71Sopenharmony_cigetLargestProportionColor(): Color
407e41f4b71Sopenharmony_ci
408e41f4b71Sopenharmony_ciObtains the color with the largest proportion from the image and writes the result to a [Color](#color) instance. This API returns the result synchronously.
409e41f4b71Sopenharmony_ci
410e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
411e41f4b71Sopenharmony_ci
412e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
413e41f4b71Sopenharmony_ci
414e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Image.Core
415e41f4b71Sopenharmony_ci
416e41f4b71Sopenharmony_ci**Return value**
417e41f4b71Sopenharmony_ci
418e41f4b71Sopenharmony_ci| Type          | Description                                           |
419e41f4b71Sopenharmony_ci| :------------- | :---------------------------------------------- |
420e41f4b71Sopenharmony_ci| [Color](#color)       | Color value of the color with the largest proportion. If the operation fails, **null** is returned. |
421e41f4b71Sopenharmony_ci
422e41f4b71Sopenharmony_ci**Example**
423e41f4b71Sopenharmony_ci
424e41f4b71Sopenharmony_ci```ts
425e41f4b71Sopenharmony_ciimport { image } from "@kit.ImageKit";
426e41f4b71Sopenharmony_ciimport { effectKit } from "@kit.ArkGraphics2D";
427e41f4b71Sopenharmony_ci
428e41f4b71Sopenharmony_ciconst color = new ArrayBuffer(96);
429e41f4b71Sopenharmony_cilet opts : image.InitializationOptions = {
430e41f4b71Sopenharmony_ci  editable: true,
431e41f4b71Sopenharmony_ci  pixelFormat: 3,
432e41f4b71Sopenharmony_ci  size: {
433e41f4b71Sopenharmony_ci    height: 4,
434e41f4b71Sopenharmony_ci    width: 6
435e41f4b71Sopenharmony_ci  }
436e41f4b71Sopenharmony_ci}
437e41f4b71Sopenharmony_ciimage.createPixelMap(color, opts).then((pixelMap) => {
438e41f4b71Sopenharmony_ci  effectKit.createColorPicker(pixelMap, (error, colorPicker) => {
439e41f4b71Sopenharmony_ci    if (error) {
440e41f4b71Sopenharmony_ci      console.error('Failed to create color picker.');
441e41f4b71Sopenharmony_ci    } else {
442e41f4b71Sopenharmony_ci      console.info('Succeeded in creating color picker.');
443e41f4b71Sopenharmony_ci      let color = colorPicker.getLargestProportionColor();
444e41f4b71Sopenharmony_ci      console.info('get largest proportion color =' + color);
445e41f4b71Sopenharmony_ci    }
446e41f4b71Sopenharmony_ci  })
447e41f4b71Sopenharmony_ci})
448e41f4b71Sopenharmony_ci```
449e41f4b71Sopenharmony_ci![image_Largest_Proportion_Color.png](figures/image_Largest_Proportion_Color.png)
450e41f4b71Sopenharmony_ci
451e41f4b71Sopenharmony_ci### getTopProportionColors<sup>12+</sup>
452e41f4b71Sopenharmony_ci
453e41f4b71Sopenharmony_cigetTopProportionColors(colorCount: number): Array<Color | null>
454e41f4b71Sopenharmony_ci
455e41f4b71Sopenharmony_ciObtains a given number of colors with the top proportions in the image. This API returns the result synchronously.
456e41f4b71Sopenharmony_ci
457e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
458e41f4b71Sopenharmony_ci
459e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
460e41f4b71Sopenharmony_ci
461e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Image.Core
462e41f4b71Sopenharmony_ci
463e41f4b71Sopenharmony_ci**Parameters**
464e41f4b71Sopenharmony_ci| Name     | Type  | Mandatory | Description             |
465e41f4b71Sopenharmony_ci| ---------- | ------ | ---- | ------------------------------------------- |
466e41f4b71Sopenharmony_ci| colorCount | number | Yes  | Number of colors to obtain. The value range is [1, 10]. If a non-integer is passed in, the value will be rounded down.  |
467e41f4b71Sopenharmony_ci
468e41f4b71Sopenharmony_ci**Return value**
469e41f4b71Sopenharmony_ci
470e41f4b71Sopenharmony_ci| Type                                    | Description                                           |
471e41f4b71Sopenharmony_ci| :--------------------------------------- | :---------------------------------------------- |
472e41f4b71Sopenharmony_ci| Array<[Color](#color) \| null> | Array of colors, sorted by proportion.<br>- If the number of colors obtained is less than the value of **colorCount**, the array size is the actual number obtained.<br>- If the color fails to be obtained, an empty array is returned.<br>- If the value of **colorCount** is less than 1, **[null]** is returned.<br>- If the value of **colorCount** is greater than 10, an array holding the first 10 colors with the top proportions is returned. |
473e41f4b71Sopenharmony_ci
474e41f4b71Sopenharmony_ci**Example**
475e41f4b71Sopenharmony_ci
476e41f4b71Sopenharmony_ci```js
477e41f4b71Sopenharmony_ciimport { image } from "@kit.ImageKit";
478e41f4b71Sopenharmony_ciimport { effectKit } from "@kit.ArkGraphics2D";
479e41f4b71Sopenharmony_ci
480e41f4b71Sopenharmony_ciconst color = new ArrayBuffer(96);
481e41f4b71Sopenharmony_cilet opts : image.InitializationOptions = {
482e41f4b71Sopenharmony_ci  editable: true,
483e41f4b71Sopenharmony_ci  pixelFormat: 3,
484e41f4b71Sopenharmony_ci  size: {
485e41f4b71Sopenharmony_ci    height: 4,
486e41f4b71Sopenharmony_ci    width: 6
487e41f4b71Sopenharmony_ci  }
488e41f4b71Sopenharmony_ci}
489e41f4b71Sopenharmony_ciimage.createPixelMap(color, opts).then((pixelMap) => {
490e41f4b71Sopenharmony_ci  effectKit.createColorPicker(pixelMap, (error, colorPicker) => {
491e41f4b71Sopenharmony_ci    if (error) {
492e41f4b71Sopenharmony_ci      console.error('Failed to create color picker.');
493e41f4b71Sopenharmony_ci    } else {
494e41f4b71Sopenharmony_ci      console.info('Succeeded in creating color picker.');
495e41f4b71Sopenharmony_ci      let colors = colorPicker.getTopProportionColors(2);
496e41f4b71Sopenharmony_ci      for(let index = 0; index < colors.length; index++) {
497e41f4b71Sopenharmony_ci        if (colors[index]) {
498e41f4b71Sopenharmony_ci          console.info('get top proportion colors: index ' + index + ', color ' + colors[index]);
499e41f4b71Sopenharmony_ci        }
500e41f4b71Sopenharmony_ci      }
501e41f4b71Sopenharmony_ci    }
502e41f4b71Sopenharmony_ci  })
503e41f4b71Sopenharmony_ci})
504e41f4b71Sopenharmony_ci```
505e41f4b71Sopenharmony_ci![image_Largest_Proportion_Color.png](figures/image_Top_Proportion_Colors.png)
506e41f4b71Sopenharmony_ci
507e41f4b71Sopenharmony_ci### getHighestSaturationColor<sup>10+</sup>
508e41f4b71Sopenharmony_ci
509e41f4b71Sopenharmony_cigetHighestSaturationColor(): Color
510e41f4b71Sopenharmony_ci
511e41f4b71Sopenharmony_ciObtains the color with the highest saturation from the image and writes the result to a [Color](#color) instance. This API returns the result synchronously.
512e41f4b71Sopenharmony_ci
513e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
514e41f4b71Sopenharmony_ci
515e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
516e41f4b71Sopenharmony_ci
517e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Image.Core
518e41f4b71Sopenharmony_ci
519e41f4b71Sopenharmony_ci**Return value**
520e41f4b71Sopenharmony_ci
521e41f4b71Sopenharmony_ci| Type          | Description                                           |
522e41f4b71Sopenharmony_ci| :------------- | :---------------------------------------------- |
523e41f4b71Sopenharmony_ci| [Color](#color)       | Color value of the color with the highest saturation. If the operation fails, **null** is returned. |
524e41f4b71Sopenharmony_ci
525e41f4b71Sopenharmony_ci**Example**
526e41f4b71Sopenharmony_ci
527e41f4b71Sopenharmony_ci```ts
528e41f4b71Sopenharmony_ciimport { image } from "@kit.ImageKit";
529e41f4b71Sopenharmony_ciimport { effectKit } from "@kit.ArkGraphics2D";
530e41f4b71Sopenharmony_ci
531e41f4b71Sopenharmony_ciconst color = new ArrayBuffer(96);
532e41f4b71Sopenharmony_cilet opts: image.InitializationOptions = {
533e41f4b71Sopenharmony_ci  editable: true,
534e41f4b71Sopenharmony_ci  pixelFormat: 3,
535e41f4b71Sopenharmony_ci  size: {
536e41f4b71Sopenharmony_ci    height: 4,
537e41f4b71Sopenharmony_ci    width: 6
538e41f4b71Sopenharmony_ci  }
539e41f4b71Sopenharmony_ci}
540e41f4b71Sopenharmony_ciimage.createPixelMap(color, opts).then((pixelMap) => {
541e41f4b71Sopenharmony_ci  effectKit.createColorPicker(pixelMap, (error, colorPicker) => {
542e41f4b71Sopenharmony_ci    if (error) {
543e41f4b71Sopenharmony_ci      console.error('Failed to create color picker.');
544e41f4b71Sopenharmony_ci    } else {
545e41f4b71Sopenharmony_ci      console.info('Succeeded in creating color picker.');
546e41f4b71Sopenharmony_ci      let color = colorPicker.getHighestSaturationColor();
547e41f4b71Sopenharmony_ci      console.info('get highest saturation color =' + color);
548e41f4b71Sopenharmony_ci    }
549e41f4b71Sopenharmony_ci  })
550e41f4b71Sopenharmony_ci})
551e41f4b71Sopenharmony_ci```
552e41f4b71Sopenharmony_ci![image_Highest_Saturation_Color.png](figures/image_Highest_Saturation_Color.png)
553e41f4b71Sopenharmony_ci
554e41f4b71Sopenharmony_ci### getAverageColor<sup>10+</sup>
555e41f4b71Sopenharmony_ci
556e41f4b71Sopenharmony_cigetAverageColor(): Color
557e41f4b71Sopenharmony_ci
558e41f4b71Sopenharmony_ciObtains the average color from the image and writes the result to a [Color](#color) instance. This API returns the result synchronously.
559e41f4b71Sopenharmony_ci
560e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
561e41f4b71Sopenharmony_ci
562e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
563e41f4b71Sopenharmony_ci
564e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Image.Core
565e41f4b71Sopenharmony_ci
566e41f4b71Sopenharmony_ci**Return value**
567e41f4b71Sopenharmony_ci
568e41f4b71Sopenharmony_ci| Type          | Description                                           |
569e41f4b71Sopenharmony_ci| :------------- | :---------------------------------------------- |
570e41f4b71Sopenharmony_ci| [Color](#color)       | Average color value. If the operation fails, **null** is returned. |
571e41f4b71Sopenharmony_ci
572e41f4b71Sopenharmony_ci**Example**
573e41f4b71Sopenharmony_ci
574e41f4b71Sopenharmony_ci```ts
575e41f4b71Sopenharmony_ciimport { image } from "@kit.ImageKit";
576e41f4b71Sopenharmony_ciimport { effectKit } from "@kit.ArkGraphics2D";
577e41f4b71Sopenharmony_ci
578e41f4b71Sopenharmony_ciconst color = new ArrayBuffer(96);
579e41f4b71Sopenharmony_cilet opts: image.InitializationOptions = {
580e41f4b71Sopenharmony_ci  editable: true,
581e41f4b71Sopenharmony_ci  pixelFormat: 3,
582e41f4b71Sopenharmony_ci  size: {
583e41f4b71Sopenharmony_ci    height: 4,
584e41f4b71Sopenharmony_ci    width: 6
585e41f4b71Sopenharmony_ci  }
586e41f4b71Sopenharmony_ci}
587e41f4b71Sopenharmony_ciimage.createPixelMap(color, opts).then((pixelMap) => {
588e41f4b71Sopenharmony_ci  effectKit.createColorPicker(pixelMap, (error, colorPicker) => {
589e41f4b71Sopenharmony_ci    if (error) {
590e41f4b71Sopenharmony_ci      console.error('Failed to create color picker.');
591e41f4b71Sopenharmony_ci    } else {
592e41f4b71Sopenharmony_ci      console.info('Succeeded in creating color picker.');
593e41f4b71Sopenharmony_ci      let color = colorPicker.getAverageColor();
594e41f4b71Sopenharmony_ci      console.info('get average color =' + color);
595e41f4b71Sopenharmony_ci    }
596e41f4b71Sopenharmony_ci  })
597e41f4b71Sopenharmony_ci})
598e41f4b71Sopenharmony_ci```
599e41f4b71Sopenharmony_ci![image_Average_Color.png](figures/image_Average_Color.png)
600e41f4b71Sopenharmony_ci
601e41f4b71Sopenharmony_ci### isBlackOrWhiteOrGrayColor<sup>10+</sup>
602e41f4b71Sopenharmony_ci
603e41f4b71Sopenharmony_ciisBlackOrWhiteOrGrayColor(color: number): boolean
604e41f4b71Sopenharmony_ci
605e41f4b71Sopenharmony_ciChecks whether a color is black, white, and gray.
606e41f4b71Sopenharmony_ci
607e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
608e41f4b71Sopenharmony_ci
609e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
610e41f4b71Sopenharmony_ci
611e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Image.Core
612e41f4b71Sopenharmony_ci
613e41f4b71Sopenharmony_ci**Parameters**
614e41f4b71Sopenharmony_ci
615e41f4b71Sopenharmony_ci| Name    | Type        | Mandatory | Description                      |
616e41f4b71Sopenharmony_ci| -------- | ----------- | ---- | -------------------------- |
617e41f4b71Sopenharmony_ci| color| number | Yes  |  Color to check. The value range is [0x0, 0xFFFFFFFF]. |
618e41f4b71Sopenharmony_ci
619e41f4b71Sopenharmony_ci**Return value**
620e41f4b71Sopenharmony_ci
621e41f4b71Sopenharmony_ci| Type          | Description                                           |
622e41f4b71Sopenharmony_ci| :------------- | :---------------------------------------------- |
623e41f4b71Sopenharmony_ci| boolean              | Returns **true** if the image is black, white, and gray; returns **false** otherwise. |
624e41f4b71Sopenharmony_ci
625e41f4b71Sopenharmony_ci**Example**
626e41f4b71Sopenharmony_ci
627e41f4b71Sopenharmony_ci```ts
628e41f4b71Sopenharmony_ciimport { image } from "@kit.ImageKit";
629e41f4b71Sopenharmony_ciimport { effectKit } from "@kit.ArkGraphics2D";
630e41f4b71Sopenharmony_ci
631e41f4b71Sopenharmony_ciconst color = new ArrayBuffer(96);
632e41f4b71Sopenharmony_cilet opts: image.InitializationOptions = {
633e41f4b71Sopenharmony_ci  editable: true,
634e41f4b71Sopenharmony_ci  pixelFormat: 3,
635e41f4b71Sopenharmony_ci  size: {
636e41f4b71Sopenharmony_ci    height: 4,
637e41f4b71Sopenharmony_ci    width: 6
638e41f4b71Sopenharmony_ci  }
639e41f4b71Sopenharmony_ci}
640e41f4b71Sopenharmony_ciimage.createPixelMap(color, opts).then((pixelMap) => {
641e41f4b71Sopenharmony_ci  effectKit.createColorPicker(pixelMap, (error, colorPicker) => {
642e41f4b71Sopenharmony_ci    if (error) {
643e41f4b71Sopenharmony_ci      console.error('Failed to create color picker.');
644e41f4b71Sopenharmony_ci    } else {
645e41f4b71Sopenharmony_ci      console.info('Succeeded in creating color picker.');
646e41f4b71Sopenharmony_ci      let bJudge = colorPicker.isBlackOrWhiteOrGrayColor(0xFFFFFFFF);
647e41f4b71Sopenharmony_ci      console.info('is black or white or gray color[bool](white) =' + bJudge);
648e41f4b71Sopenharmony_ci    }
649e41f4b71Sopenharmony_ci  })
650e41f4b71Sopenharmony_ci})
651e41f4b71Sopenharmony_ci```
652e41f4b71Sopenharmony_ci
653e41f4b71Sopenharmony_ci## Filter
654e41f4b71Sopenharmony_ci
655e41f4b71Sopenharmony_ciA class used to add a specified effect to an image. Before calling any method of **Filter**, use [createEffect](#effectkitcreateeffect) to create a **Filter** instance.
656e41f4b71Sopenharmony_ci
657e41f4b71Sopenharmony_ci### blur
658e41f4b71Sopenharmony_ci
659e41f4b71Sopenharmony_ciblur(radius: number): Filter
660e41f4b71Sopenharmony_ci
661e41f4b71Sopenharmony_ciAdds the blur effect to the filter linked list, and returns the head node of the linked list.
662e41f4b71Sopenharmony_ci
663e41f4b71Sopenharmony_ci>  **NOTE**
664e41f4b71Sopenharmony_ci>
665e41f4b71Sopenharmony_ci>  This API provides the blur effect for static images. To provide the real-time blur effect for components, use [dynamic blur](../../ui/arkts-blur-effect.md).
666e41f4b71Sopenharmony_ci
667e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
668e41f4b71Sopenharmony_ci
669e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
670e41f4b71Sopenharmony_ci
671e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Image.Core
672e41f4b71Sopenharmony_ci
673e41f4b71Sopenharmony_ci**Parameters**
674e41f4b71Sopenharmony_ci
675e41f4b71Sopenharmony_ci| Name | Type       | Mandatory | Description                                                        |
676e41f4b71Sopenharmony_ci| ------ | ----------- | ---- | ------------------------------------------------------------ |
677e41f4b71Sopenharmony_ci|  radius   | number | Yes  | Blur radius, in pixels. The blur effect is proportional to the configured value. A larger value indicates a more obvious effect. |
678e41f4b71Sopenharmony_ci
679e41f4b71Sopenharmony_ci**Return value**
680e41f4b71Sopenharmony_ci
681e41f4b71Sopenharmony_ci| Type          | Description                                           |
682e41f4b71Sopenharmony_ci| :------------- | :---------------------------------------------- |
683e41f4b71Sopenharmony_ci| [Filter](#filter) | Final image effect. |
684e41f4b71Sopenharmony_ci
685e41f4b71Sopenharmony_ci**Example**
686e41f4b71Sopenharmony_ci
687e41f4b71Sopenharmony_ci```ts
688e41f4b71Sopenharmony_ciimport { image } from "@kit.ImageKit";
689e41f4b71Sopenharmony_ciimport { effectKit } from "@kit.ArkGraphics2D";
690e41f4b71Sopenharmony_ci
691e41f4b71Sopenharmony_ciconst color = new ArrayBuffer(96);
692e41f4b71Sopenharmony_cilet opts : image.InitializationOptions = {
693e41f4b71Sopenharmony_ci  editable: true,
694e41f4b71Sopenharmony_ci  pixelFormat: 3,
695e41f4b71Sopenharmony_ci  size: {
696e41f4b71Sopenharmony_ci    height: 4,
697e41f4b71Sopenharmony_ci    width: 6
698e41f4b71Sopenharmony_ci  }
699e41f4b71Sopenharmony_ci};
700e41f4b71Sopenharmony_ciimage.createPixelMap(color, opts).then((pixelMap) => {
701e41f4b71Sopenharmony_ci  let radius = 5;
702e41f4b71Sopenharmony_ci  let headFilter = effectKit.createEffect(pixelMap);
703e41f4b71Sopenharmony_ci  if (headFilter != null) {
704e41f4b71Sopenharmony_ci    headFilter.blur(radius);
705e41f4b71Sopenharmony_ci  }
706e41f4b71Sopenharmony_ci})
707e41f4b71Sopenharmony_ci```
708e41f4b71Sopenharmony_ci![image_Add_Blur.png](figures/image_Add_Blur.png)
709e41f4b71Sopenharmony_ci
710e41f4b71Sopenharmony_ci### invert<sup>12+</sup>
711e41f4b71Sopenharmony_ci
712e41f4b71Sopenharmony_ciinvert(): Filter
713e41f4b71Sopenharmony_ci
714e41f4b71Sopenharmony_ciAdds the inversion effect to the filter linked list, and returns the head node of the linked list.
715e41f4b71Sopenharmony_ci
716e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Image.Core
717e41f4b71Sopenharmony_ci
718e41f4b71Sopenharmony_ci**Return value**
719e41f4b71Sopenharmony_ci
720e41f4b71Sopenharmony_ci| Type          | Description                                           |
721e41f4b71Sopenharmony_ci| :------------- | :---------------------------------------------- |
722e41f4b71Sopenharmony_ci| [Filter](#filter) | Final image effect. |
723e41f4b71Sopenharmony_ci
724e41f4b71Sopenharmony_ci**Example**
725e41f4b71Sopenharmony_ci
726e41f4b71Sopenharmony_ci```ts
727e41f4b71Sopenharmony_ciimport { image } from "@kit.ImageKit";
728e41f4b71Sopenharmony_ciimport { effectKit } from "@kit.ArkGraphics2D";
729e41f4b71Sopenharmony_ci
730e41f4b71Sopenharmony_ciconst color = new ArrayBuffer(96);
731e41f4b71Sopenharmony_cilet opts : image.InitializationOptions = {
732e41f4b71Sopenharmony_ci  editable: true,
733e41f4b71Sopenharmony_ci  pixelFormat: 3,
734e41f4b71Sopenharmony_ci  size: {
735e41f4b71Sopenharmony_ci    height: 4,
736e41f4b71Sopenharmony_ci    width: 6
737e41f4b71Sopenharmony_ci  }
738e41f4b71Sopenharmony_ci};
739e41f4b71Sopenharmony_ciimage.createPixelMap(color, opts).then((pixelMap) => {
740e41f4b71Sopenharmony_ci  let headFilter = effectKit.createEffect(pixelMap);
741e41f4b71Sopenharmony_ci  if (headFilter != null) {
742e41f4b71Sopenharmony_ci    headFilter.invert();
743e41f4b71Sopenharmony_ci  }
744e41f4b71Sopenharmony_ci})
745e41f4b71Sopenharmony_ci```
746e41f4b71Sopenharmony_ci![image_Add_Invert.png](figures/image_Add_Invert.png)
747e41f4b71Sopenharmony_ci
748e41f4b71Sopenharmony_ci### setColorMatrix<sup>12+</sup>
749e41f4b71Sopenharmony_ci
750e41f4b71Sopenharmony_cisetColorMatrix(colorMatrix: Array\<number>): Filter
751e41f4b71Sopenharmony_ci
752e41f4b71Sopenharmony_ciAdds a custom effect to the filter linked list, and returns the head node of the linked list.
753e41f4b71Sopenharmony_ci
754e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Image.Core
755e41f4b71Sopenharmony_ci
756e41f4b71Sopenharmony_ci**Parameters**
757e41f4b71Sopenharmony_ci
758e41f4b71Sopenharmony_ci| Name | Type       | Mandatory | Description                                                        |
759e41f4b71Sopenharmony_ci| ------ | ----------- | ---- | ------------------------------------------------------------ |
760e41f4b71Sopenharmony_ci|  colorMatrix  |   Array\<number> | Yes  | Custom color matrix.<br>A 5 x 4 matrix can be created. The value range of the matrix element is [0, 1], where **0** indicates that the color channel is not involved in the calculation, and **1** indicates that the color channel is involved in the calculation and retains the original weight. |
761e41f4b71Sopenharmony_ci
762e41f4b71Sopenharmony_ci**Return value**
763e41f4b71Sopenharmony_ci
764e41f4b71Sopenharmony_ci| Type          | Description                                           |
765e41f4b71Sopenharmony_ci| :------------- | :---------------------------------------------- |
766e41f4b71Sopenharmony_ci| [Filter](#filter) | Final image effect. |
767e41f4b71Sopenharmony_ci
768e41f4b71Sopenharmony_ci**Error codes**
769e41f4b71Sopenharmony_ci
770e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
771e41f4b71Sopenharmony_ci
772e41f4b71Sopenharmony_ci| ID | Error Message                       |
773e41f4b71Sopenharmony_ci| -------- | ------------------------------ |
774e41f4b71Sopenharmony_ci| 401      | Input parameter error.             |
775e41f4b71Sopenharmony_ci
776e41f4b71Sopenharmony_ci**Example**
777e41f4b71Sopenharmony_ci
778e41f4b71Sopenharmony_ci```ts
779e41f4b71Sopenharmony_ciimport { image } from "@kit.ImageKit";
780e41f4b71Sopenharmony_ciimport { effectKit } from "@kit.ArkGraphics2D";
781e41f4b71Sopenharmony_ci
782e41f4b71Sopenharmony_ciconst color = new ArrayBuffer(96);
783e41f4b71Sopenharmony_cilet opts : image.InitializationOptions = {
784e41f4b71Sopenharmony_ci  editable: true,
785e41f4b71Sopenharmony_ci  pixelFormat: 3,
786e41f4b71Sopenharmony_ci  size: {
787e41f4b71Sopenharmony_ci    height: 4,
788e41f4b71Sopenharmony_ci    width: 6
789e41f4b71Sopenharmony_ci  }
790e41f4b71Sopenharmony_ci};
791e41f4b71Sopenharmony_ciimage.createPixelMap(color, opts).then((pixelMap) => {
792e41f4b71Sopenharmony_ci  let colorMatrix:Array<number> = [
793e41f4b71Sopenharmony_ci    0.2126,0.7152,0.0722,0,0,
794e41f4b71Sopenharmony_ci    0.2126,0.7152,0.0722,0,0,
795e41f4b71Sopenharmony_ci    0.2126,0.7152,0.0722,0,0,
796e41f4b71Sopenharmony_ci    0,0,0,1,0
797e41f4b71Sopenharmony_ci  ];
798e41f4b71Sopenharmony_ci  let headFilter = effectKit.createEffect(pixelMap);
799e41f4b71Sopenharmony_ci  if (headFilter != null) {
800e41f4b71Sopenharmony_ci    headFilter.setColorMatrix(colorMatrix);
801e41f4b71Sopenharmony_ci  }
802e41f4b71Sopenharmony_ci})
803e41f4b71Sopenharmony_ci```
804e41f4b71Sopenharmony_ci
805e41f4b71Sopenharmony_ci### brightness
806e41f4b71Sopenharmony_ci
807e41f4b71Sopenharmony_cibrightness(bright: number): Filter
808e41f4b71Sopenharmony_ci
809e41f4b71Sopenharmony_ciAdds the brightness effect to the filter linked list, and returns the head node of the linked list.
810e41f4b71Sopenharmony_ci
811e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
812e41f4b71Sopenharmony_ci
813e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
814e41f4b71Sopenharmony_ci
815e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Image.Core
816e41f4b71Sopenharmony_ci
817e41f4b71Sopenharmony_ci**Parameters**
818e41f4b71Sopenharmony_ci
819e41f4b71Sopenharmony_ci| Name | Type       | Mandatory | Description                                                        |
820e41f4b71Sopenharmony_ci| ------ | ----------- | ---- | ------------------------------------------------------------ |
821e41f4b71Sopenharmony_ci|  bright   | number | Yes  | Brightness value, ranging from 0 to 1. When the value is **0**, the image brightness remains unchanged. |
822e41f4b71Sopenharmony_ci
823e41f4b71Sopenharmony_ci**Return value**
824e41f4b71Sopenharmony_ci
825e41f4b71Sopenharmony_ci| Type          | Description                                           |
826e41f4b71Sopenharmony_ci| :------------- | :---------------------------------------------- |
827e41f4b71Sopenharmony_ci| [Filter](#filter) | Final image effect. |
828e41f4b71Sopenharmony_ci
829e41f4b71Sopenharmony_ci**Example**
830e41f4b71Sopenharmony_ci
831e41f4b71Sopenharmony_ci```ts
832e41f4b71Sopenharmony_ciimport { image } from "@kit.ImageKit";
833e41f4b71Sopenharmony_ciimport { effectKit } from "@kit.ArkGraphics2D";
834e41f4b71Sopenharmony_ci
835e41f4b71Sopenharmony_ciconst color = new ArrayBuffer(96);
836e41f4b71Sopenharmony_cilet opts : image.InitializationOptions = {
837e41f4b71Sopenharmony_ci  editable: true,
838e41f4b71Sopenharmony_ci  pixelFormat: 3,
839e41f4b71Sopenharmony_ci  size: {
840e41f4b71Sopenharmony_ci    height: 4,
841e41f4b71Sopenharmony_ci    width: 6
842e41f4b71Sopenharmony_ci  }
843e41f4b71Sopenharmony_ci};
844e41f4b71Sopenharmony_ciimage.createPixelMap(color, opts).then((pixelMap) => {
845e41f4b71Sopenharmony_ci  let bright = 0.5;
846e41f4b71Sopenharmony_ci  let headFilter = effectKit.createEffect(pixelMap);
847e41f4b71Sopenharmony_ci  if (headFilter != null) {
848e41f4b71Sopenharmony_ci    headFilter.brightness(bright);
849e41f4b71Sopenharmony_ci  }
850e41f4b71Sopenharmony_ci})
851e41f4b71Sopenharmony_ci```
852e41f4b71Sopenharmony_ci![image_Add_Brightness.png](figures/image_Add_Brightness.png)
853e41f4b71Sopenharmony_ci
854e41f4b71Sopenharmony_ci### grayscale
855e41f4b71Sopenharmony_ci
856e41f4b71Sopenharmony_cigrayscale(): Filter
857e41f4b71Sopenharmony_ci
858e41f4b71Sopenharmony_ciAdds the grayscale effect to the filter linked list, and returns the head node of the linked list.
859e41f4b71Sopenharmony_ci
860e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
861e41f4b71Sopenharmony_ci
862e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
863e41f4b71Sopenharmony_ci
864e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Image.Core
865e41f4b71Sopenharmony_ci
866e41f4b71Sopenharmony_ci**Return value**
867e41f4b71Sopenharmony_ci
868e41f4b71Sopenharmony_ci| Type          | Description                                           |
869e41f4b71Sopenharmony_ci| :------------- | :---------------------------------------------- |
870e41f4b71Sopenharmony_ci| [Filter](#filter) | Final image effect. |
871e41f4b71Sopenharmony_ci
872e41f4b71Sopenharmony_ci**Example**
873e41f4b71Sopenharmony_ci
874e41f4b71Sopenharmony_ci```ts
875e41f4b71Sopenharmony_ciimport { image } from "@kit.ImageKit";
876e41f4b71Sopenharmony_ciimport { effectKit } from "@kit.ArkGraphics2D";
877e41f4b71Sopenharmony_ci
878e41f4b71Sopenharmony_ciconst color = new ArrayBuffer(96);
879e41f4b71Sopenharmony_cilet opts : image.InitializationOptions = {
880e41f4b71Sopenharmony_ci  editable: true,
881e41f4b71Sopenharmony_ci  pixelFormat: 3,
882e41f4b71Sopenharmony_ci  size: {
883e41f4b71Sopenharmony_ci    height: 4,
884e41f4b71Sopenharmony_ci    width: 6
885e41f4b71Sopenharmony_ci  }
886e41f4b71Sopenharmony_ci};
887e41f4b71Sopenharmony_ciimage.createPixelMap(color, opts).then((pixelMap) => {
888e41f4b71Sopenharmony_ci  let headFilter = effectKit.createEffect(pixelMap);
889e41f4b71Sopenharmony_ci  if (headFilter != null) {
890e41f4b71Sopenharmony_ci    headFilter.grayscale();
891e41f4b71Sopenharmony_ci  }
892e41f4b71Sopenharmony_ci})
893e41f4b71Sopenharmony_ci```
894e41f4b71Sopenharmony_ci![image_Add_Grayscale.png](figures/image_Add_Grayscale.png)
895e41f4b71Sopenharmony_ci
896e41f4b71Sopenharmony_ci### getEffectPixelMap<sup>11+</sup>
897e41f4b71Sopenharmony_ci
898e41f4b71Sopenharmony_cigetEffectPixelMap(): Promise<image.PixelMap>
899e41f4b71Sopenharmony_ci
900e41f4b71Sopenharmony_ciObtains **image.PixelMap** of the source image to which the filter linked list is added. This API uses a promise to return the result.
901e41f4b71Sopenharmony_ci
902e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
903e41f4b71Sopenharmony_ci
904e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
905e41f4b71Sopenharmony_ci
906e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Image.Core
907e41f4b71Sopenharmony_ci
908e41f4b71Sopenharmony_ci**Return value**
909e41f4b71Sopenharmony_ci
910e41f4b71Sopenharmony_ci| Type                  | Description          |
911e41f4b71Sopenharmony_ci| ---------------------- | -------------- |
912e41f4b71Sopenharmony_ci| Promise\<image.PixelMap>  | Promise used to return **image.PixelMap** of the source image. |
913e41f4b71Sopenharmony_ci
914e41f4b71Sopenharmony_ci
915e41f4b71Sopenharmony_ci**Example**
916e41f4b71Sopenharmony_ci
917e41f4b71Sopenharmony_ci```ts
918e41f4b71Sopenharmony_ciimport { image } from "@kit.ImageKit";
919e41f4b71Sopenharmony_ciimport { effectKit } from "@kit.ArkGraphics2D";
920e41f4b71Sopenharmony_ci
921e41f4b71Sopenharmony_ciconst color = new ArrayBuffer(96);
922e41f4b71Sopenharmony_cilet opts : image.InitializationOptions = {
923e41f4b71Sopenharmony_ci  editable: true,
924e41f4b71Sopenharmony_ci  pixelFormat: 3,
925e41f4b71Sopenharmony_ci  size: {
926e41f4b71Sopenharmony_ci    height: 4,
927e41f4b71Sopenharmony_ci    width: 6
928e41f4b71Sopenharmony_ci  }
929e41f4b71Sopenharmony_ci};
930e41f4b71Sopenharmony_ciimage.createPixelMap(color, opts).then((pixelMap) => {
931e41f4b71Sopenharmony_ci  effectKit.createEffect(pixelMap).grayscale().getEffectPixelMap().then(data => {
932e41f4b71Sopenharmony_ci    console.info('getPixelBytesNumber = ', data.getPixelBytesNumber());
933e41f4b71Sopenharmony_ci  })
934e41f4b71Sopenharmony_ci})
935e41f4b71Sopenharmony_ci```
936e41f4b71Sopenharmony_ci
937e41f4b71Sopenharmony_ci### getPixelMap<sup>(deprecated)</sup>
938e41f4b71Sopenharmony_ci
939e41f4b71Sopenharmony_cigetPixelMap(): image.PixelMap
940e41f4b71Sopenharmony_ci
941e41f4b71Sopenharmony_ciObtains **image.PixelMap** of the source image to which the filter linked list is added.
942e41f4b71Sopenharmony_ci
943e41f4b71Sopenharmony_ci> **NOTE**
944e41f4b71Sopenharmony_ci>
945e41f4b71Sopenharmony_ci> This API is supported since API version 9 and deprecated since API version 11. You are advised to use [getEffectPixelMap](#geteffectpixelmap11) instead.
946e41f4b71Sopenharmony_ci
947e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Image.Core
948e41f4b71Sopenharmony_ci
949e41f4b71Sopenharmony_ci**Return value**
950e41f4b71Sopenharmony_ci
951e41f4b71Sopenharmony_ci| Type          | Description                                           |
952e41f4b71Sopenharmony_ci| :------------- | :---------------------------------------------- |
953e41f4b71Sopenharmony_ci| [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | **image.PixelMap** of the source image. |
954e41f4b71Sopenharmony_ci
955e41f4b71Sopenharmony_ci**Example**
956e41f4b71Sopenharmony_ci
957e41f4b71Sopenharmony_ci```ts
958e41f4b71Sopenharmony_ciimport { image } from "@kit.ImageKit";
959e41f4b71Sopenharmony_ciimport { effectKit } from "@kit.ArkGraphics2D";
960e41f4b71Sopenharmony_ci
961e41f4b71Sopenharmony_ciconst color = new ArrayBuffer(96);
962e41f4b71Sopenharmony_cilet opts : image.InitializationOptions = {
963e41f4b71Sopenharmony_ci  editable: true,
964e41f4b71Sopenharmony_ci  pixelFormat: 3,
965e41f4b71Sopenharmony_ci  size: {
966e41f4b71Sopenharmony_ci    height: 4,
967e41f4b71Sopenharmony_ci    width: 6
968e41f4b71Sopenharmony_ci  }
969e41f4b71Sopenharmony_ci};
970e41f4b71Sopenharmony_ciimage.createPixelMap(color, opts).then((pixelMap) => {
971e41f4b71Sopenharmony_ci  let pixel = effectKit.createEffect(pixelMap).grayscale().getPixelMap();
972e41f4b71Sopenharmony_ci  console.info('getPixelBytesNumber = ', pixel.getPixelBytesNumber());
973e41f4b71Sopenharmony_ci})
974e41f4b71Sopenharmony_ci```
975