• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.multimedia.image (Image Processing)
2
3The **Image** module provides APIs for image processing. You can use the APIs to create a **PixelMap** object with specified properties or read image pixel data (even in an area).
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11```js
12import image from '@ohos.multimedia.image';
13```
14
15## image.createPixelMap<sup>8+</sup>
16
17createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<PixelMap>
18
19Creates a **PixelMap** object with the default BGRA_8888 format and pixel properties specified. This API uses a promise to return the result.
20
21**System capability**: SystemCapability.Multimedia.Image.Core
22
23**Parameters**
24
25| Name | Type                                            | Mandatory| Description                                                            |
26| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- |
27| colors  | ArrayBuffer                                      | Yes  | Color array in BGRA_8888 format.                                       |
28| options | [InitializationOptions](#initializationoptions8) | Yes  | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.|
29
30**Return value**
31
32| Type                            | Description                                                                   |
33| -------------------------------- | ----------------------------------------------------------------------- |
34| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.<br>If the size of the created pixel map exceeds that of the original image, the pixel map size of the original image is returned.|
35
36
37**Example**
38
39```js
40const color = new ArrayBuffer(96);  // 96 is the size of the pixel map buffer to create. The value is calculated as follows: height x width x 4.
41let bufferArr = new Uint8Array(color);
42let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
43image.createPixelMap(color, opts).then((pixelmap) => {
44    console.log('Succeeded in creating pixelmap.');
45}).catch(error => {
46    console.log('Failed to create pixelmap.');
47})
48```
49
50## image.createPixelMap<sup>8+</sup>
51
52createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: AsyncCallback\<PixelMap>): void
53
54Creates a **PixelMap** object with the default BGRA_8888 format and pixel properties specified. This API uses an asynchronous callback to return the result.
55
56**System capability**: SystemCapability.Multimedia.Image.Core
57
58**Parameters**
59
60| Name  | Type                                            | Mandatory| Description                      |
61| -------- | ------------------------------------------------ | ---- | -------------------------- |
62| colors   | ArrayBuffer                                      | Yes  | Color array in BGRA_8888 format. |
63| options  | [InitializationOptions](#initializationoptions8) | Yes  | Pixel properties.                    |
64| callback | AsyncCallback\<[PixelMap](#pixelmap7)>           | Yes  | Callback used to return the **PixelMap** object.|
65
66**Example**
67
68```js
69const color = new ArrayBuffer(96);  // 96 is the size of the pixel map buffer to create. The value is calculated as follows: height x width x 4.
70let bufferArr = new Uint8Array(color);
71let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
72image.createPixelMap(color, opts, (error, pixelmap) => {
73    if(error) {
74        console.log('Failed to create pixelmap.');
75    } else {
76        console.log('Succeeded in creating pixelmap.');
77    }
78})
79```
80
81## PixelMap<sup>7+</sup>
82
83Provides APIs to read or write image pixel map data and obtain image pixel map information. Before calling any API in **PixelMap**, you must use **createPixelMap** to create a **PixelMap** object. Currently, the maximum size of a serialized pixel map is 128 MB. A larger size will cause a display failure. The size is calculated as follows: Width * Height * Number of bytes occupied by each pixel.
84
85### Attributes
86
87**System capability**: SystemCapability.Multimedia.Image.Core
88
89| Name      | Type   | Readable| Writable| Description                      |
90| ---------- | ------- | ---- | ---- | -------------------------- |
91| isEditable | boolean | Yes  | No  | Whether the image pixel map is editable.|
92
93### readPixelsToBuffer<sup>7+</sup>
94
95readPixelsToBuffer(dst: ArrayBuffer): Promise\<void>
96
97Reads data of this pixel map and writes the data to an **ArrayBuffer**. This API uses a promise to return the result. If this pixel map is created in the BGRA_8888 format, the data read is the same as the original data.
98
99**System capability**: SystemCapability.Multimedia.Image.Core
100
101**Parameters**
102
103| Name| Type       | Mandatory| Description                                                                                                 |
104| ------ | ----------- | ---- | ----------------------------------------------------------------------------------------------------- |
105| dst    | ArrayBuffer | Yes  | Buffer to which the image pixel map data will be written. The buffer size is obtained by calling **getPixelBytesNumber**.|
106
107**Return value**
108
109| Type          | Description                                           |
110| -------------- | ----------------------------------------------- |
111| Promise\<void> | Promise used to return the result. If the operation fails, an error message is returned.|
112
113**Example**
114
115```js
116const readBuffer = new ArrayBuffer(96);  // 96 is the size of the pixel map buffer to create. The value is calculated as follows: height x width x 4.
117pixelmap.readPixelsToBuffer(readBuffer).then(() => {
118    console.log('Succeeded in reading image pixel data.'); // Called if the condition is met.
119}).catch(error => {
120    console.log('Failed to read image pixel data.');  // Called if no condition is met.
121})
122```
123
124### readPixelsToBuffer<sup>7+</sup>
125
126readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\<void>): void
127
128Reads data of this pixel map and writes the data to an **ArrayBuffer**. This API uses an asynchronous callback to return the result. If this pixel map is created in the BGRA_8888 format, the data read is the same as the original data.
129
130**System capability**: SystemCapability.Multimedia.Image.Core
131
132**Parameters**
133
134| Name  | Type                | Mandatory| Description                                                                                                 |
135| -------- | -------------------- | ---- | ----------------------------------------------------------------------------------------------------- |
136| dst      | ArrayBuffer          | Yes  | Buffer to which the image pixel map data will be written. The buffer size is obtained by calling **getPixelBytesNumber**.|
137| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation fails, an error message is returned.                                                                       |
138
139**Example**
140
141```js
142const readBuffer = new ArrayBuffer(96);  // 96 is the size of the pixel map buffer to create. The value is calculated as follows: height x width x 4.
143pixelmap.readPixelsToBuffer(readBuffer, (err, res) => {
144    if(err) {
145        console.log('Failed to read image pixel data.');  // Called if no condition is met.
146    } else {
147        console.log('Succeeded in reading image pixel data.'); // Called if the condition is met.
148    }
149})
150```
151
152### readPixels<sup>7+</sup>
153
154readPixels(area: PositionArea): Promise\<void>
155
156Reads image pixel map data in an area. This API uses a promise to return the data read.
157
158**System capability**: SystemCapability.Multimedia.Image.Core
159
160**Parameters**
161
162| Name| Type                          | Mandatory| Description                    |
163| ------ | ------------------------------ | ---- | ------------------------ |
164| area   | [PositionArea](#positionarea7) | Yes  | Area from which the image pixel map data will be read.|
165
166**Return value**
167
168| Type          | Description                                               |
169| :------------- | :-------------------------------------------------- |
170| Promise\<void> | Promise used to return the result. If the operation fails, an error message is returned.|
171
172**Example**
173
174```js
175const area = {
176    pixels: new ArrayBuffer(8),
177    offset: 0,
178    stride: 8,
179    region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
180}
181pixelmap.readPixels(area).then(() => {
182    console.log('Succeeded in reading the image data in the area.'); // Called if the condition is met.
183}).catch(error => {
184    console.log('Failed to read the image data in the area.'); // Called if no condition is met.
185})
186```
187
188### readPixels<sup>7+</sup>
189
190readPixels(area: PositionArea, callback: AsyncCallback\<void>): void
191
192Reads image pixel map data in an area. This API uses an asynchronous callback to return the data read.
193
194**System capability**: SystemCapability.Multimedia.Image.Core
195
196**Parameters**
197
198| Name  | Type                          | Mandatory| Description                          |
199| -------- | ------------------------------ | ---- | ------------------------------ |
200| area     | [PositionArea](#positionarea7) | Yes  | Area from which the image pixel map data will be read.      |
201| callback | AsyncCallback\<void>           | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
202
203**Example**
204
205```js
206const color = new ArrayBuffer(96);  // 96 is the size of the pixel map buffer to create. The value is calculated as follows: height x width x 4.
207let bufferArr = new Uint8Array(color);
208let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
209image.createPixelMap(color, opts, (err, pixelmap) => {
210    if(pixelmap == undefined){
211        console.info('createPixelMap failed.');
212    } else {
213        const area = { pixels: new ArrayBuffer(8),
214            offset: 0,
215            stride: 8,
216            region: { size: { height: 1, width: 2 }, x: 0, y: 0 }};
217        pixelmap.readPixels(area, () => {
218            console.info('readPixels success');
219        })
220    }
221})
222```
223
224### writePixels<sup>7+</sup>
225
226writePixels(area: PositionArea): Promise\<void>
227
228Writes image pixel map data to an area. This API uses a promise to return the operation result.
229
230**System capability**: SystemCapability.Multimedia.Image.Core
231
232**Parameters**
233
234| Name| Type                          | Mandatory| Description                |
235| ------ | ------------------------------ | ---- | -------------------- |
236| area   | [PositionArea](#positionarea7) | Yes  | Area to which the image pixel map data will be written.|
237
238**Return value**
239
240| Type          | Description                                               |
241| :------------- | :-------------------------------------------------- |
242| Promise\<void> | Promise used to return the result. If the operation fails, an error message is returned.|
243
244**Example**
245
246```js
247const color = new ArrayBuffer(96);  // 96 is the size of the pixel map buffer to create. The value is calculated as follows: height x width x 4.
248let bufferArr = new Uint8Array(color);
249let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
250image.createPixelMap(color, opts)
251    .then( pixelmap => {
252        if (pixelmap == undefined) {
253            console.info('createPixelMap failed.');
254        }
255        const area = { pixels: new ArrayBuffer(8),
256            offset: 0,
257            stride: 8,
258            region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
259        }
260        let bufferArr = new Uint8Array(area.pixels);
261        for (var i = 0; i < bufferArr.length; i++) {
262            bufferArr[i] = i + 1;
263        }
264
265        pixelmap.writePixels(area).then(() => {
266		    console.info('Succeeded to write pixelmap into the specified area.');
267        })
268    }).catch(error => {
269        console.log('error: ' + error);
270    })
271```
272
273### writePixels<sup>7+</sup>
274
275writePixels(area: PositionArea, callback: AsyncCallback\<void>): void
276
277Writes image pixel map data to an area. This API uses an asynchronous callback to return the operation result.
278
279**System capability**: SystemCapability.Multimedia.Image.Core
280
281**Parameters**
282
283| Name   | Type                          | Mandatory| Description                          |
284| --------- | ------------------------------ | ---- | ------------------------------ |
285| area      | [PositionArea](#positionarea7) | Yes  | Area to which the image pixel map data will be written.          |
286| callback  | AsyncCallback\<void>           | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
287
288**Example**
289
290```js
291const area = { pixels: new ArrayBuffer(8),
292    offset: 0,
293    stride: 8,
294    region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
295}
296let bufferArr = new Uint8Array(area.pixels);
297for (var i = 0; i < bufferArr.length; i++) {
298    bufferArr[i] = i + 1;
299}
300pixelmap.writePixels(area, (error) => {
301    if (error != undefined) {
302		console.info('Failed to write pixelmap into the specified area.');
303	} else {
304		console.info('Succeeded to write pixelmap into the specified area.');
305	}
306})
307```
308
309### writeBufferToPixels<sup>7+</sup>
310
311writeBufferToPixels(src: ArrayBuffer): Promise\<void>
312
313Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** object. This API uses a promise to return the result.
314
315**System capability**: SystemCapability.Multimedia.Image.Core
316
317**Parameters**
318
319| Name| Type       | Mandatory| Description          |
320| ------ | ----------- | ---- | -------------- |
321| src    | ArrayBuffer | Yes  | Buffer from which the image data will be read.|
322
323**Return value**
324
325| Type          | Description                                           |
326| -------------- | ----------------------------------------------- |
327| Promise\<void> | Promise used to return the result. If the operation fails, an error message is returned.|
328
329**Example**
330
331```js
332const color = new ArrayBuffer(96);  // 96 is the size of the pixel map buffer to create. The value is calculated as follows: height x width x 4.
333let bufferArr = new Uint8Array(color);
334for (var i = 0; i < bufferArr.length; i++) {
335    bufferArr[i] = i + 1;
336}
337pixelmap.writeBufferToPixels(color).then(() => {
338    console.log("Succeeded in writing data from a buffer to a PixelMap.");
339}).catch((err) => {
340    console.error("Failed to write data from a buffer to a PixelMap.");
341})
342```
343
344### writeBufferToPixels<sup>7+</sup>
345
346writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\<void>): void
347
348Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** object. This API uses an asynchronous callback to return the result.
349
350**System capability**: SystemCapability.Multimedia.Image.Core
351
352**Parameters**
353
354| Name  | Type                | Mandatory| Description                          |
355| -------- | -------------------- | ---- | ------------------------------ |
356| src      | ArrayBuffer          | Yes  | Buffer from which the image data will be read.                |
357| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
358
359**Example**
360
361```js
362const color = new ArrayBuffer(96);  // 96 is the size of the pixel map buffer to create. The value is calculated as follows: height x width x 4.
363let bufferArr = new Uint8Array(color);
364for (var i = 0; i < bufferArr.length; i++) {
365    bufferArr[i] = i + 1;
366}
367pixelmap.writeBufferToPixels(color, function(err) {
368    if (err) {
369        console.error("Failed to write data from a buffer to a PixelMap.");
370        return;
371    } else {
372		console.log("Succeeded in writing data from a buffer to a PixelMap.");
373	}
374});
375```
376
377### getImageInfo<sup>7+</sup>
378
379getImageInfo(): Promise\<ImageInfo>
380
381Obtains pixel map information of this image. This API uses a promise to return the information.
382
383**System capability**: SystemCapability.Multimedia.Image.Core
384
385**Return value**
386
387| Type                             | Description                                                       |
388| --------------------------------- | ----------------------------------------------------------- |
389| Promise\<[ImageInfo](#imageinfo)> | Promise used to return the pixel map information. If the operation fails, an error message is returned.|
390
391**Example**
392
393```js
394const color = new ArrayBuffer(96);  // 96 is the size of the pixel map buffer to create. The value is calculated as follows: height x width x 4.
395let opts = { editable: true, pixelFormat: 2, size: { height: 6, width: 8 } }
396image.createPixelMap(color, opts).then(pixelmap => {
397    if (pixelmap == undefined) {
398        console.error("Failed to obtain the image pixel map information.");
399    }
400    pixelmap.getImageInfo().then(imageInfo => {
401        if (imageInfo == undefined) {
402            console.error("Failed to obtain the image pixel map information.");
403        }
404        if (imageInfo.size.height == 4 && imageInfo.size.width == 6) {
405            console.log("Succeeded in obtaining the image pixel map information.");
406        }
407    })
408})
409```
410
411### getImageInfo<sup>7+</sup>
412
413getImageInfo(callback: AsyncCallback\<ImageInfo>): void
414
415Obtains pixel map information of this image. This API uses an asynchronous callback to return the information.
416
417**System capability**: SystemCapability.Multimedia.Image.Core
418
419**Parameters**
420
421| Name  | Type                                   | Mandatory| Description                                                        |
422| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
423| callback | AsyncCallback\<[ImageInfo](#imageinfo)> | Yes  | Callback used to return the pixel map information. If the operation fails, an error message is returned.|
424
425**Example**
426
427```js
428const color = new ArrayBuffer(96);  // 96 is the size of the pixel map buffer to create. The value is calculated as follows: height x width x 4.
429let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
430image.createPixelMap(color, opts, (err, pixelmap) => {
431    if (pixelmap == undefined) {
432        console.error("Failed to obtain the image pixel map information.");
433    }
434    pixelmap.getImageInfo((err, imageInfo) => {
435        if (imageInfo == undefined) {
436            console.error("Failed to obtain the image pixel map information.");
437        }
438        if (imageInfo.size.height == 4 && imageInfo.size.width == 6) {
439            console.log("Succeeded in obtaining the image pixel map information.");
440        }
441    })
442})
443```
444
445### getBytesNumberPerRow<sup>7+</sup>
446
447getBytesNumberPerRow(): number
448
449Obtains the number of bytes per row of this image pixel map.
450
451**System capability**: SystemCapability.Multimedia.Image.Core
452
453**Return value**
454
455| Type  | Description                |
456| ------ | -------------------- |
457| number | Number of bytes per row.|
458
459**Example**
460
461```js
462const color = new ArrayBuffer(96);  // 96 is the size of the pixel map buffer to create. The value is calculated as follows: height x width x 4.
463let bufferArr = new Uint8Array(color);
464let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
465image.createPixelMap(color, opts, (err,pixelmap) => {
466    let rowCount = pixelmap.getBytesNumberPerRow();
467})
468```
469
470### getPixelBytesNumber<sup>7+</sup>
471
472getPixelBytesNumber(): number
473
474Obtains the total number of bytes of this image pixel map.
475
476**System capability**: SystemCapability.Multimedia.Image.Core
477
478**Return value**
479
480| Type  | Description                |
481| ------ | -------------------- |
482| number | Total number of bytes.|
483
484**Example**
485
486```js
487let pixelBytesNumber = pixelmap.getPixelBytesNumber();
488```
489
490### getDensity<sup>9+</sup>
491
492getDensity():number
493
494Obtains the density of this image pixel map.
495
496**System capability**: SystemCapability.Multimedia.Image.Core
497
498**Return value**
499
500| Type  | Description           |
501| ------ | --------------- |
502| number | Density of the image pixel map.|
503
504**Example**
505
506```js
507let getDensity = pixelmap.getDensity();
508```
509
510### opacity<sup>9+</sup>
511
512opacity(rate: number, callback: AsyncCallback\<void>): void
513
514Sets an opacity rate for this image pixel map. This API uses an asynchronous callback to return the result.
515
516**System capability**: SystemCapability.Multimedia.Image.Core
517
518**Parameters**
519
520| Name  | Type                | Mandatory| Description                          |
521| -------- | -------------------- | ---- | ------------------------------ |
522| rate     | number               | Yes  | Opacity rate to set. The value ranges from 0 to 1.  |
523| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
524
525**Example**
526
527```js
528var rate = 0.5;
529pixelmap.opacity(rate, (err) => {
530	if (err) {
531        console.error("Failed to set opacity.");
532        return;
533    } else {
534        console.log("Succeeded in setting opacity.");
535	}
536})
537```
538
539### opacity<sup>9+</sup>
540
541opacity(rate: number): Promise\<void>
542
543Sets an opacity rate for this image pixel map. This API uses a promise to return the result.
544
545**System capability**: SystemCapability.Multimedia.Image.Core
546
547**Parameters**
548
549| Name| Type  | Mandatory| Description                       |
550| ------ | ------ | ---- | --------------------------- |
551| rate   | number | Yes  | Opacity rate to set. The value ranges from 0 to 1.|
552
553**Return value**
554
555| Type          | Description                                           |
556| -------------- | ----------------------------------------------- |
557| Promise\<void> | Promise used to return the result. If the operation fails, an error message is returned.|
558
559**Example**
560
561```js
562async function Demo() {
563    await pixelmap.opacity(0.5);
564}
565```
566
567### createAlphaPixelmap<sup>9+</sup>
568
569createAlphaPixelmap(): Promise\<PixelMap>
570
571Creates a **PixelMap** object that contains only the alpha channel information. This object can be used for the shadow effect. This API uses a promise to return the result.
572
573**System capability**: SystemCapability.Multimedia.Image.Core
574
575**Return value**
576
577| Type                            | Description                       |
578| -------------------------------- | --------------------------- |
579| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.|
580
581**Example**
582
583```js
584async function Demo() {
585    await pixelmap.createAlphaPixelmap();
586}
587```
588
589### createAlphaPixelmap<sup>9+</sup>
590
591createAlphaPixelmap(callback: AsyncCallback\<PixelMap>): void
592
593Creates a **PixelMap** object that contains only the alpha channel information. This object can be used for the shadow effect. This API uses an asynchronous callback to return the result.
594
595**System capability**: SystemCapability.Multimedia.Image.Core
596
597**Parameters**
598
599| Name  | Type                    | Mandatory| Description                    |
600| -------- | ------------------------ | ---- | ------------------------ |
601| callback | AsyncCallback\<PixelMap> | Yes  | Callback used to return the **PixelMap** object.|
602
603**Example**
604
605```js
606pixelmap.createAlphaPixelmap((err, alphaPixelMap) => {
607    if (alphaPixelMap == undefined) {
608        console.info('Failed to obtain new pixel map.');
609    } else {
610        console.info('Succeed in obtaining new pixel map.');
611    }
612})
613```
614
615### scale<sup>9+</sup>
616
617scale(x: number, y: number, callback: AsyncCallback\<void>): void
618
619Scales this image based on the input width and height. This API uses an asynchronous callback to return the result.
620
621**System capability**: SystemCapability.Multimedia.Image.Core
622
623**Parameters**
624
625| Name  | Type                | Mandatory| Description                           |
626| -------- | -------------------- | ---- | ------------------------------- |
627| x        | number               | Yes  | Scaling ratio of the width.|
628| y        | number               | Yes  | Scaling ratio of the height.|
629| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation fails, an error message is returned. |
630
631**Example**
632
633```js
634async function Demo() {
635	await pixelmap.scale(2.0, 1.0);
636}
637```
638
639### scale<sup>9+</sup>
640
641scale(x: number, y: number): Promise\<void>
642
643Scales this image based on the input width and height. This API uses a promise to return the result.
644
645**System capability**: SystemCapability.Multimedia.Image.Core
646
647**Parameters**
648
649| Name| Type  | Mandatory| Description                           |
650| ------ | ------ | ---- | ------------------------------- |
651| x      | number | Yes  | Scaling ratio of the width.|
652| y      | number | Yes  | Scaling ratio of the height.|
653
654**Return value**
655
656| Type          | Description                       |
657| -------------- | --------------------------- |
658| Promise\<void> | Promise used to return the result.|
659
660**Example**
661
662```js
663async function Demo() {
664	await pixelmap.scale(2.0, 1.0);
665}
666```
667
668### translate<sup>9+</sup>
669
670translate(x: number, y: number, callback: AsyncCallback\<void>): void
671
672Translates this image based on the input coordinates. This API uses an asynchronous callback to return the result.
673
674**System capability**: SystemCapability.Multimedia.Image.Core
675
676**Parameters**
677
678| Name  | Type                | Mandatory| Description                         |
679| -------- | -------------------- | ---- | ----------------------------- |
680| x        | number               | Yes  | X coordinate to translate.                 |
681| y        | number               | Yes  | Y coordinate to translate.                 |
682| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
683
684**Example**
685
686```js
687async function Demo() {
688	await pixelmap.translate(3.0, 1.0);
689}
690```
691
692### translate<sup>9+</sup>
693
694translate(x: number, y: number): Promise\<void>
695
696Translates this image based on the input coordinates. This API uses a promise to return the result.
697
698**System capability**: SystemCapability.Multimedia.Image.Core
699
700**Parameters**
701
702| Name| Type  | Mandatory| Description       |
703| ------ | ------ | ---- | ----------- |
704| x      | number | Yes  | X coordinate to translate.|
705| y      | number | Yes  | Y coordinate to translate.|
706
707**Return value**
708
709| Type          | Description                       |
710| -------------- | --------------------------- |
711| Promise\<void> | Promise used to return the result.|
712
713**Example**
714
715```js
716async function Demo() {
717	await pixelmap.translate(3.0, 1.0);
718}
719```
720
721### rotate<sup>9+</sup>
722
723rotate(angle: number, callback: AsyncCallback\<void>): void
724
725Rotates this image based on the input angle. This API uses an asynchronous callback to return the result.
726
727**System capability**: SystemCapability.Multimedia.Image.Core
728
729**Parameters**
730
731| Name  | Type                | Mandatory| Description                         |
732| -------- | -------------------- | ---- | ----------------------------- |
733| angle    | number               | Yes  | Angle to rotate.             |
734| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
735
736**Example**
737
738```js
739var angle = 90.0;
740pixelmap.rotate(angle, (err) => {
741	if (err) {
742        console.error("Failed to set rotation.");
743        return;
744    } else {
745        console.log("Succeeded in setting rotation.");
746	}
747})
748```
749
750### rotate<sup>9+</sup>
751
752rotate(angle: number): Promise\<void>
753
754Rotates this image based on the input angle. This API uses a promise to return the result.
755
756**System capability**: SystemCapability.Multimedia.Image.Core
757
758**Parameters**
759
760| Name| Type  | Mandatory| Description                         |
761| ------ | ------ | ---- | ----------------------------- |
762| angle  | number | Yes  | Angle to rotate.             |
763
764**Return value**
765
766| Type          | Description                       |
767| -------------- | --------------------------- |
768| Promise\<void> | Promise used to return the result.|
769
770**Example**
771
772```js
773async function Demo() {
774	await pixelmap.rotate(90.0);
775}
776```
777
778### flip<sup>9+</sup>
779
780flip(horizontal: boolean, vertical: boolean, callback: AsyncCallback\<void>): void
781
782Flips this image horizontally or vertically, or both. This API uses an asynchronous callback to return the result.
783
784**System capability**: SystemCapability.Multimedia.Image.Core
785
786**Parameters**
787
788| Name    | Type                | Mandatory| Description                         |
789| ---------- | -------------------- | ---- | ----------------------------- |
790| horizontal | boolean              | Yes  | Whether to flip the image horizontally.                   |
791| vertical   | boolean              | Yes  | Whether to flip the image vertically.                   |
792| callback   | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
793
794**Example**
795
796```js
797async function Demo() {
798	await pixelmap.flip(false, true);
799}
800```
801
802### flip<sup>9+</sup>
803
804flip(horizontal: boolean, vertical: boolean): Promise\<void>
805
806Flips this image horizontally or vertically, or both. This API uses a promise to return the result.
807
808**System capability**: SystemCapability.Multimedia.Image.Core
809
810**Parameters**
811
812| Name    | Type   | Mandatory| Description     |
813| ---------- | ------- | ---- | --------- |
814| horizontal | boolean | Yes  | Whether to flip the image horizontally.|
815| vertical   | boolean | Yes  | Whether to flip the image vertically.|
816
817**Return value**
818
819| Type          | Description                       |
820| -------------- | --------------------------- |
821| Promise\<void> | Promise used to return the result.|
822
823**Example**
824
825```js
826async function Demo() {
827	await pixelmap.flip(false, true);
828}
829```
830
831### crop<sup>9+</sup>
832
833crop(region: Region, callback: AsyncCallback\<void>): void
834
835Crops this image based on the input size. This API uses an asynchronous callback to return the result.
836
837**System capability**: SystemCapability.Multimedia.Image.Core
838
839**Parameters**
840
841| Name  | Type                | Mandatory| Description                         |
842| -------- | -------------------- | ---- | ----------------------------- |
843| region   | [Region](#region7)   | Yes  | Size of the image after cropping.                 |
844| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
845
846**Example**
847
848```js
849async function Demo() {
850	await pixelmap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } });
851}
852```
853
854### crop<sup>9+</sup>
855
856crop(region: Region): Promise\<void>
857
858Crops this image based on the input size. This API uses a promise to return the result.
859
860**System capability**: SystemCapability.Multimedia.Image.Core
861
862**Parameters**
863
864| Name| Type              | Mandatory| Description       |
865| ------ | ------------------ | ---- | ----------- |
866| region | [Region](#region7) | Yes  | Size of the image after cropping.|
867
868**Return value**
869
870| Type          | Description                       |
871| -------------- | --------------------------- |
872| Promise\<void> | Promise used to return the result.|
873
874**Example**
875
876```js
877async function Demo() {
878	await pixelmap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } });
879}
880```
881
882### release<sup>7+</sup>
883
884release():Promise\<void>
885
886Releases this **PixelMap** object. This API uses a promise to return the result.
887
888**System capability**: SystemCapability.Multimedia.Image.Core
889
890**Return value**
891
892| Type          | Description                           |
893| -------------- | ------------------------------- |
894| Promise\<void> | Promise used to return the result.|
895
896**Example**
897
898```js
899pixelmap.release().then(() => {
900	console.log('Succeeded in releasing pixelmap object.');
901}).catch(error => {
902	console.log('Failed to release pixelmap object.');
903})
904```
905
906### release<sup>7+</sup>
907
908release(callback: AsyncCallback\<void>): void
909
910Releases this **PixelMap** object. This API uses an asynchronous callback to return the result.
911
912**System capability**: SystemCapability.Multimedia.Image.Core
913
914**Parameters**
915
916| Name  | Type                | Mandatory| Description              |
917| -------- | -------------------- | ---- | ------------------ |
918| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
919
920**Example**
921
922```js
923pixelmap.release(() => {
924    console.log('Succeeded in releasing pixelmap object.');
925})
926```
927
928## image.createImageSource
929
930createImageSource(uri: string): ImageSource
931
932Creates an **ImageSource** instance based on the URI.
933
934**System capability**: SystemCapability.Multimedia.Image.ImageSource
935
936**Parameters**
937
938| Name| Type  | Mandatory| Description                              |
939| ------ | ------ | ---- | ---------------------------------- |
940| uri    | string | Yes  | Image path. Currently, only the application sandbox path is supported.<br>Currently, the following formats are supported: JPG, PNG, GIF, BMP, Webp, and RAW.|
941
942**Return value**
943
944| Type                       | Description                                        |
945| --------------------------- | -------------------------------------------- |
946| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.|
947
948**Example**
949
950```js
951// Stage model
952const context = getContext(this);
953const path = context.cacheDir() + "/test.jpg";
954const imageSourceApi = image.createImageSource(path);
955```
956
957```js
958// FA model
959import featureAbility from '@ohos.ability.featureAbility';
960
961const context = featureAbility.getContext();
962const path = context.getCacheDir() + "/test.jpg";
963const imageSourceApi = image.createImageSource(path);
964```
965
966## image.createImageSource<sup>9+</sup>
967
968createImageSource(uri: string, options: SourceOptions): ImageSource
969
970Creates an **ImageSource** instance based on the URI.
971
972**System capability**: SystemCapability.Multimedia.Image.ImageSource
973
974**Parameters**
975
976| Name | Type                           | Mandatory| Description                               |
977| ------- | ------------------------------- | ---- | ----------------------------------- |
978| uri     | string                          | Yes  | Image path. Currently, only the application sandbox path is supported.<br>Currently, the following formats are supported: JPG, PNG, GIF, BMP, Webp, and RAW.|
979| options | [SourceOptions](#sourceoptions9) | Yes  | Image properties, including the image index and default property value.|
980
981**Return value**
982
983| Type                       | Description                                        |
984| --------------------------- | -------------------------------------------- |
985| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.|
986
987**Example**
988
989```js
990var sourceOptions = { sourceDensity: 120 };
991let imageSource = image.createImageSource('test.png', sourceOptions);
992```
993
994## image.createImageSource<sup>7+</sup>
995
996createImageSource(fd: number): ImageSource
997
998Creates an **ImageSource** instance based on the file descriptor.
999
1000**System capability**: SystemCapability.Multimedia.Image.ImageSource
1001
1002**Parameters**
1003
1004| Name| Type  | Mandatory| Description         |
1005| ------ | ------ | ---- | ------------- |
1006| fd     | number | Yes  | File descriptor.|
1007
1008**Return value**
1009
1010| Type                       | Description                                        |
1011| --------------------------- | -------------------------------------------- |
1012| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.|
1013
1014**Example**
1015
1016```js
1017const imageSourceApi = image.createImageSource(0);
1018```
1019
1020## image.createImageSource<sup>9+</sup>
1021
1022createImageSource(fd: number, options: SourceOptions): ImageSource
1023
1024Creates an **ImageSource** instance based on the file descriptor.
1025
1026**System capability**: SystemCapability.Multimedia.Image.ImageSource
1027
1028**Parameters**
1029
1030| Name | Type                           | Mandatory| Description                               |
1031| ------- | ------------------------------- | ---- | ----------------------------------- |
1032| fd      | number                          | Yes  | File descriptor.                     |
1033| options | [SourceOptions](#sourceoptions9) | Yes  | Image properties, including the image index and default property value.|
1034
1035**Return value**
1036
1037| Type                       | Description                                        |
1038| --------------------------- | -------------------------------------------- |
1039| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.|
1040
1041**Example**
1042
1043```js
1044var sourceOptions = { sourceDensity: 120 };
1045const imageSourceApi = image.createImageSource(0, sourceOptions);
1046```
1047
1048## image.createImageSource<sup>9+</sup>
1049
1050createImageSource(buf: ArrayBuffer): ImageSource
1051
1052Creates an **ImageSource** instance based on the buffers.
1053
1054**System capability**: SystemCapability.Multimedia.Image.ImageSource
1055
1056**Parameters**
1057
1058| Name| Type       | Mandatory| Description            |
1059| ------ | ----------- | ---- | ---------------- |
1060| buf    | ArrayBuffer | Yes  | Array of image buffers.|
1061
1062**Example**
1063
1064```js
1065const buf = new ArrayBuffer(96);  // 96 is the size of the pixel map buffer to create. The value is calculated as follows: height x width x 4.
1066const imageSourceApi = image.createImageSource(buf);
1067```
1068
1069## image.createImageSource<sup>9+</sup>
1070
1071createImageSource(buf: ArrayBuffer, options: SourceOptions): ImageSource
1072
1073Creates an **ImageSource** instance based on the buffers.
1074
1075**System capability**: SystemCapability.Multimedia.Image.ImageSource
1076
1077**Parameters**
1078
1079| Name| Type                            | Mandatory| Description                                |
1080| ------ | -------------------------------- | ---- | ------------------------------------ |
1081| buf    | ArrayBuffer                      | Yes  | Array of image buffers.                    |
1082| options | [SourceOptions](#sourceoptions9) | Yes  | Image properties, including the image index and default property value.|
1083
1084**Return value**
1085
1086| Type                       | Description                                        |
1087| --------------------------- | -------------------------------------------- |
1088| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.|
1089
1090**Example**
1091
1092```js
1093const data = new ArrayBuffer(112);
1094const imageSourceApi = image.createImageSource(data);
1095```
1096
1097## image.CreateIncrementalSource<sup>9+</sup>
1098
1099CreateIncrementalSource(buf: ArrayBuffer): ImageSource
1100
1101Creates an **ImageSource** instance in incremental mode based on the buffers.
1102
1103**System capability**: SystemCapability.Multimedia.Image.ImageSource
1104
1105**Parameters**
1106
1107| Name | Type       | Mandatory| Description     |
1108| ------- | ------------| ---- | ----------|
1109| buf     | ArrayBuffer | Yes  | Incremental data.|
1110
1111**Return value**
1112
1113| Type                       | Description                             |
1114| --------------------------- | --------------------------------- |
1115| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns undefined otherwise.|
1116
1117**Example**
1118
1119```js
1120const buf = new ArrayBuffer(96);  // 96 is the size of the pixel map buffer to create. The value is calculated as follows: height x width x 4.
1121const imageSourceIncrementalSApi = image.CreateIncrementalSource(buf);
1122```
1123
1124## image.CreateIncrementalSource<sup>9+</sup>
1125
1126CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource
1127
1128Creates an **ImageSource** instance in incremental mode based on the buffers.
1129
1130**System capability**: SystemCapability.Multimedia.Image.ImageSource
1131
1132**Parameters**
1133
1134| Name | Type                           | Mandatory| Description                                |
1135| ------- | ------------------------------- | ---- | ------------------------------------ |
1136| buf     | ArrayBuffer                     | Yes  | Incremental data.                          |
1137| options | [SourceOptions](#sourceoptions9) | No  | Image properties, including the image index and default property value.|
1138
1139**Return value**
1140
1141| Type                       | Description                             |
1142| --------------------------- | --------------------------------- |
1143| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns undefined otherwise.|
1144
1145**Example**
1146
1147```js
1148const buf = new ArrayBuffer(96);  // 96 is the size of the pixel map buffer to create. The value is calculated as follows: height x width x 4.
1149const imageSourceIncrementalSApi = image.CreateIncrementalSource(buf);
1150```
1151
1152## ImageSource
1153
1154Provides APIs to obtain image information. Before calling any API in **ImageSource**, you must use **createImageSource** to create an **ImageSource** instance.
1155
1156### Attributes
1157
1158**System capability**: SystemCapability.Multimedia.Image.ImageSource
1159
1160| Name            | Type          | Readable| Writable| Description                                                        |
1161| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
1162| supportedFormats | Array\<string> | Yes  | No  | Supported image formats, including PNG, JPEG, BMP, GIF, WebP, and RAW.|
1163
1164### getImageInfo
1165
1166getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void
1167
1168Obtains information about an image with the specified index. This API uses an asynchronous callback to return the information.
1169
1170**System capability**: SystemCapability.Multimedia.Image.ImageSource
1171
1172**Parameters**
1173
1174| Name  | Type                                  | Mandatory| Description                                    |
1175| -------- | -------------------------------------- | ---- | ---------------------------------------- |
1176| index    | number                                 | Yes  | Index of the image.                    |
1177| callback | AsyncCallback<[ImageInfo](#imageinfo)> | Yes  | Callback used to return the image information.|
1178
1179**Example**
1180
1181```js
1182imageSourceApi.getImageInfo(0,(error, imageInfo) => {
1183    if(error) {
1184        console.log('getImageInfo failed.');
1185    } else {
1186        console.log('getImageInfo succeeded.');
1187    }
1188})
1189```
1190
1191### getImageInfo
1192
1193getImageInfo(callback: AsyncCallback\<ImageInfo>): void
1194
1195Obtains information about this image. This API uses an asynchronous callback to return the information.
1196
1197**System capability**: SystemCapability.Multimedia.Image.ImageSource
1198
1199**Parameters**
1200
1201| Name  | Type                                  | Mandatory| Description                                    |
1202| -------- | -------------------------------------- | ---- | ---------------------------------------- |
1203| callback | AsyncCallback<[ImageInfo](#imageinfo)> | Yes  | Callback used to return the image information.|
1204
1205**Example**
1206
1207```js
1208imageSourceApi.getImageInfo(imageInfo => {
1209    console.log('Succeeded in obtaining the image information.');
1210})
1211```
1212
1213### getImageInfo
1214
1215getImageInfo(index?: number): Promise\<ImageInfo>
1216
1217Obtains information about an image with the specified index. This API uses a promise to return the image information.
1218
1219**System capability**: SystemCapability.Multimedia.Image.ImageSource
1220
1221**Parameters**
1222
1223| Name| Type  | Mandatory| Description                                 |
1224| ----- | ------ | ---- | ------------------------------------- |
1225| index | number | No  | Index of the image. If this parameter is not set, the default value **0** is used.|
1226
1227**Return value**
1228
1229| Type                            | Description                  |
1230| -------------------------------- | ---------------------- |
1231| Promise<[ImageInfo](#imageinfo)> | Promise used to return the image information.|
1232
1233**Example**
1234
1235```js
1236imageSourceApi.getImageInfo(0)
1237    .then(imageInfo => {
1238		console.log('Succeeded in obtaining the image information.');
1239	}).catch(error => {
1240		console.log('Failed to obtain the image information.');
1241	})
1242```
1243
1244### getImageProperty<sup>7+</sup>
1245
1246getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\<string>
1247
1248Obtains the value of a property with the specified index in this image. This API uses a promise to return the result.
1249
1250**System capability**: SystemCapability.Multimedia.Image.ImageSource
1251
1252 **Parameters**
1253
1254| Name | Type                                                | Mandatory| Description                                |
1255| ------- | ---------------------------------------------------- | ---- | ------------------------------------ |
1256| key     | string                                               | Yes  | Name of the property.                        |
1257| options | [GetImagePropertyOptions](#getimagepropertyoptions7) | No  | Image properties, including the image index and default property value.|
1258
1259**Return value**
1260
1261| Type            | Description                                                             |
1262| ---------------- | ----------------------------------------------------------------- |
1263| Promise\<string> | Promise used to return the property value. If the operation fails, the default value is returned.|
1264
1265**Example**
1266
1267```js
1268imageSourceApi.getImageProperty("BitsPerSample")
1269    .then(data => {
1270		console.log('Succeeded in getting the value of the specified attribute key of the image.');
1271	})
1272```
1273
1274### getImageProperty<sup>7+</sup>
1275
1276getImageProperty(key:string, callback: AsyncCallback\<string>): void
1277
1278Obtains the value of a property with the specified index in this image. This API uses an asynchronous callback to return the result.
1279
1280**System capability**: SystemCapability.Multimedia.Image.ImageSource
1281
1282 **Parameters**
1283
1284| Name  | Type                  | Mandatory| Description                                                        |
1285| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
1286| key      | string                 | Yes  | Name of the property.                                                |
1287| callback | AsyncCallback\<string> | Yes  | Callback used to return the property value. If the operation fails, the default value is returned.|
1288
1289**Example**
1290
1291```js
1292imageSourceApi.getImageProperty("BitsPerSample",(error,data) => {
1293    if(error) {
1294        console.log('Failed to get the value of the specified attribute key of the image.');
1295    } else {
1296        console.log('Succeeded in getting the value of the specified attribute key of the image.');
1297    }
1298})
1299```
1300
1301### getImageProperty<sup>7+</sup>
1302
1303getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCallback\<string>): void
1304
1305Obtains the value of a property in this image. This API uses an asynchronous callback to return the property value in a string.
1306
1307**System capability**: SystemCapability.Multimedia.Image.ImageSource
1308
1309**Parameters**
1310
1311| Name  | Type                                                | Mandatory| Description                                                         |
1312| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------- |
1313| key      | string                                               | Yes  | Name of the property.                                                 |
1314| options  | [GetImagePropertyOptions](#getimagepropertyoptions7) | Yes  | Image properties, including the image index and default property value.                         |
1315| callback | AsyncCallback\<string>                               | Yes  | Callback used to return the property value. If the operation fails, the default value is returned.|
1316
1317**Example**
1318
1319```js
1320let property = { index: 0, defaultValue: '9999' }
1321imageSourceApi.getImageProperty("BitsPerSample",property,(error,data) => {
1322    if(error) {
1323        console.log('Failed to get the value of the specified attribute key of the image.');
1324    } else {
1325        console.log('Succeeded in getting the value of the specified attribute key of the image.');
1326    }
1327})
1328```
1329
1330### modifyImageProperty<sup>9+</sup>
1331
1332modifyImageProperty(key: string, value: string): Promise\<void>
1333
1334Modifies the value of a property in this image. This API uses a promise to return the result.
1335
1336**System capability**: SystemCapability.Multimedia.Image.ImageSource
1337
1338**Parameters**
1339
1340| Name | Type  | Mandatory| Description        |
1341| ------- | ------ | ---- | ------------ |
1342| key     | string | Yes  | Name of the property.|
1343| value   | string | Yes  | New value of the property.    |
1344
1345**Return value**
1346
1347| Type          | Description                       |
1348| -------------- | --------------------------- |
1349| Promise\<void> | Promise used to return the result.|
1350
1351**Example**
1352
1353```js
1354imageSourceApi.modifyImageProperty("ImageWidth", "120").then(() => {
1355    const w = imageSourceApi.getImageProperty("ImageWidth")
1356    console.info('w', w);
1357})
1358```
1359
1360### modifyImageProperty<sup>9+</sup>
1361
1362modifyImageProperty(key: string, value: string, callback: AsyncCallback\<void>): void
1363
1364Modifies the value of a property in this image. This API uses an asynchronous callback to return the result.
1365
1366**System capability**: SystemCapability.Multimedia.Image.ImageSource
1367
1368**Parameters**
1369
1370| Name  | Type               | Mandatory| Description                          |
1371| -------- | ------------------- | ---- | ------------------------------ |
1372| key      | string              | Yes  | Name of the property.                  |
1373| value    | string              | Yes  | New value of the property.                      |
1374| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
1375
1376**Example**
1377
1378```js
1379imageSourceApi.modifyImageProperty("ImageWidth", "120",() => {})
1380```
1381
1382### updateData<sup>9+</sup>
1383
1384updateData(buf: ArrayBuffer, isFinished: boolean, value: number, length: number): Promise\<void>
1385
1386Updates incremental data. This API uses a promise to return the result.
1387
1388**System capability**: SystemCapability.Multimedia.Image.ImageSource
1389
1390**Parameters**
1391
1392| Name    | Type       | Mandatory| Description        |
1393| ---------- | ----------- | ---- | ------------ |
1394| buf        | ArrayBuffer | Yes  | Incremental data.  |
1395| isFinished | boolean     | Yes  | Whether the update is complete.|
1396| value      | number      | Yes  | Offset for data reading.    |
1397| length     | number      | Yes  | Array length.    |
1398
1399**Return value**
1400
1401| Type          | Description                      |
1402| -------------- | -------------------------- |
1403| Promise\<void> | Promise used to return the result.|
1404
1405**Example**
1406
1407```js
1408const array = new ArrayBuffer(100);
1409imageSourceApi.updateData(array, false, 0, 10).then(data => {
1410    console.info('Succeeded in updating data.');
1411})
1412```
1413
1414
1415### updateData<sup>9+</sup>
1416
1417updateData(buf: ArrayBuffer, isFinished: boolean, value: number, length: number, callback: AsyncCallback\<void>): void
1418
1419Updates incremental data. This API uses an asynchronous callback to return the result.
1420
1421**System capability**: SystemCapability.Multimedia.Image.ImageSource
1422
1423**Parameters**
1424
1425| Name    | Type               | Mandatory| Description                |
1426| ---------- | ------------------- | ---- | -------------------- |
1427| buf        | ArrayBuffer         | Yes  | Incremental data.          |
1428| isFinished | boolean             | Yes  | Whether the update is complete.        |
1429| value      | number              | Yes  | Offset for data reading.            |
1430| length     | number              | Yes  | Array length.            |
1431| callback   | AsyncCallback\<void> | Yes  | Callback used to return the result.|
1432
1433**Example**
1434
1435```js
1436const array = new ArrayBuffer(100);
1437imageSourceApi.updateData(array, false, 0, 10,(error,data )=> {
1438    if(data !== undefined){
1439        console.info('Succeeded in updating data.');
1440    }
1441})
1442```
1443
1444### createPixelMap<sup>7+</sup>
1445
1446createPixelMap(options?: DecodingOptions): Promise\<PixelMap>
1447
1448Creates a **PixelMap** object based on image decoding parameters. This API uses a promise to return the result.
1449
1450**System capability**: SystemCapability.Multimedia.Image.ImageSource
1451
1452**Parameters**
1453
1454| Name | Type                                | Mandatory| Description      |
1455| ------- | ------------------------------------ | ---- | ---------- |
1456| options | [DecodingOptions](#decodingoptions7) | No  | Image decoding parameters.|
1457
1458**Return value**
1459
1460| Type                            | Description                 |
1461| -------------------------------- | --------------------- |
1462| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.|
1463
1464**Example**
1465
1466```js
1467imageSourceApi.createPixelMap().then(pixelmap => {
1468    console.log('Succeeded in creating pixelmap object through image decoding parameters.');
1469}).catch(error => {
1470    console.log('Failed to create pixelmap object through image decoding parameters.');
1471})
1472```
1473
1474### createPixelMap<sup>7+</sup>
1475
1476createPixelMap(callback: AsyncCallback\<PixelMap>): void
1477
1478Creates a **PixelMap** object based on the default parameters. This API uses an asynchronous callback to return the result.
1479
1480**System capability**: SystemCapability.Multimedia.Image.ImageSource
1481
1482**Parameters**
1483
1484| Name    | Type                                 | Mandatory| Description                      |
1485| -------- | ------------------------------------- | ---- | -------------------------- |
1486| callback | AsyncCallback<[PixelMap](#pixelmap7)> | Yes  | Callback used to return the **PixelMap** object.|
1487
1488**Example**
1489
1490```js
1491imageSourceApi.createPixelMap((err, pixelmap) => {
1492                    console.info('Succeeded in creating pixelmap object.');
1493                })
1494```
1495
1496### createPixelMap<sup>7+</sup>
1497
1498createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): void
1499
1500Creates a **PixelMap** object based on image decoding parameters. This API uses an asynchronous callback to return the result.
1501
1502**System capability**: SystemCapability.Multimedia.Image.ImageSource
1503
1504**Parameters**
1505
1506| Name  | Type                                 | Mandatory| Description                      |
1507| -------- | ------------------------------------- | ---- | -------------------------- |
1508| options  | [DecodingOptions](#decodingoptions7)  | Yes  | Image decoding parameters.                |
1509| callback | AsyncCallback<[PixelMap](#pixelmap7)> | Yes  | Callback used to return the **PixelMap** object.|
1510
1511**Example**
1512
1513```js
1514let decodingOptions = {
1515    sampleSize: 1,
1516    editable: true,
1517    desiredSize: { width: 1, height: 2 },
1518    rotate: 10,
1519    desiredPixelFormat: 3,
1520    desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 },
1521    index: 0
1522};
1523imageSourceApi.createPixelMap(decodingOptions, pixelmap => {
1524    console.log('Succeeded in creating pixelmap object.');
1525})
1526```
1527
1528### release
1529
1530release(callback: AsyncCallback\<void>): void
1531
1532Releases this **ImageSource** instance. This API uses an asynchronous callback to return the result.
1533
1534**System capability**: SystemCapability.Multimedia.Image.ImageSource
1535
1536**Parameters**
1537
1538| Name  | Type                | Mandatory| Description                              |
1539| -------- | -------------------- | ---- | ---------------------------------- |
1540| callback | AsyncCallback\<void> | Yes  | Callback invoked for instance release. If the operation fails, an error message is returned.|
1541
1542**Example**
1543
1544```js
1545imageSourceApi.release(() => {
1546    console.log('release succeeded.');
1547})
1548```
1549
1550### release
1551
1552release(): Promise\<void>
1553
1554Releases this **ImageSource** instance. This API uses a promise to return the result.
1555
1556**System capability**: SystemCapability.Multimedia.Image.ImageSource
1557
1558**Return value**
1559
1560| Type          | Description                       |
1561| -------------- | --------------------------- |
1562| Promise\<void> | Promise used to return the result.|
1563
1564**Example**
1565
1566```js
1567imageSourceApi.release().then(()=>{
1568    console.log('Succeeded in releasing the image source instance.');
1569}).catch(error => {
1570    console.log('Failed to release the image source instance.');
1571})
1572```
1573
1574## image.createImagePacker
1575
1576createImagePacker(): ImagePacker
1577
1578Creates an **ImagePacker** instance.
1579
1580**System capability**: SystemCapability.Multimedia.Image.ImagePacker
1581
1582**Return value**
1583
1584| Type                       | Description                 |
1585| --------------------------- | --------------------- |
1586| [ImagePacker](#imagepacker) | **ImagePacker** instance created.|
1587
1588**Example**
1589
1590```js
1591const imagePackerApi = image.createImagePacker();
1592```
1593
1594## ImagePacker
1595
1596Provides APIs to pack images. Before calling any API in **ImagePacker**, you must use **createImagePacker** to create an **ImagePacker** instance. The image formats JPEG and WebP are supported.
1597
1598### Attributes
1599
1600**System capability**: SystemCapability.Multimedia.Image.ImagePacker
1601
1602| Name            | Type          | Readable| Writable| Description                      |
1603| ---------------- | -------------- | ---- | ---- | -------------------------- |
1604| supportedFormats | Array\<string> | Yes  | No  | Supported image format, which can be jpeg.|
1605
1606### packing
1607
1608packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void
1609
1610Packs an image. This API uses an asynchronous callback to return the result.
1611
1612**System capability**: SystemCapability.Multimedia.Image.ImagePacker
1613
1614**Parameters**
1615
1616| Name  | Type                              | Mandatory| Description                              |
1617| -------- | ---------------------------------- | ---- | ---------------------------------- |
1618| source   | [ImageSource](#imagesource)        | Yes  | Image to pack.                    |
1619| option   | [PackingOption](#packingoption)    | Yes  | Option for image packing.                     |
1620| callback | AsyncCallback\<ArrayBuffer>        | Yes  | Callback used to return the packed data.|
1621
1622**Example**
1623
1624```js
1625const imageSourceApi = image.createImageSource(0);
1626let packOpts = { format:"image/jpeg", quality:98 };
1627imagePackerApi.packing(imageSourceApi, packOpts, data => {})
1628```
1629
1630### packing
1631
1632packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer>
1633
1634Packs an image. This API uses a promise to return the result.
1635
1636**System capability**: SystemCapability.Multimedia.Image.ImagePacker
1637
1638**Parameters**
1639
1640| Name| Type                           | Mandatory| Description          |
1641| ------ | ------------------------------- | ---- | -------------- |
1642| source | [ImageSource](#imagesource)     | Yes  | Image to pack.|
1643| option | [PackingOption](#packingoption) | Yes  | Option for image packing.|
1644
1645**Return value**
1646
1647| Type                        | Description                                         |
1648| ---------------------------- | --------------------------------------------- |
1649| Promise\<ArrayBuffer>        | Promise used to return the packed data.|
1650
1651**Example**
1652
1653```js
1654const imageSourceApi = image.createImageSource(0);
1655let packOpts = { format:"image/jpeg", quality:98 }
1656imagePackerApi.packing(imageSourceApi, packOpts)
1657    .then( data => {
1658        console.log('packing succeeded.');
1659	}).catch(error => {
1660	    console.log('packing failed.');
1661	})
1662```
1663
1664### packing<sup>8+</sup>
1665
1666packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void
1667
1668Packs an image. This API uses an asynchronous callback to return the result.
1669
1670**System capability**: SystemCapability.Multimedia.Image.ImagePacker
1671
1672**Parameters**
1673
1674| Name  | Type                           | Mandatory| Description                              |
1675| -------- | ------------------------------- | ---- | ---------------------------------- |
1676| source   | [PixelMap](#pixelmap)           | Yes  | **PixelMap** object to pack.              |
1677| option   | [PackingOption](#packingoption) | Yes  | Option for image packing.                    |
1678| callback | AsyncCallback\<ArrayBuffer>     | Yes  | Callback used to return the packed data.|
1679
1680**Example**
1681
1682```js
1683const color = new ArrayBuffer(96);  // 96 is the size of the pixel map buffer to create. The value is calculated as follows: height x width x 4.
1684let bufferArr = new Uint8Array(color);
1685let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
1686image.createPixelMap(color, opts).then((pixelmap) => {
1687    let packOpts = { format:"image/jpeg", quality:98 }
1688    imagePackerApi.packing(pixelmap, packOpts, data => {
1689        console.log('Succeeded in packing the image.');
1690    })
1691})
1692```
1693
1694### packing<sup>8+</sup>
1695
1696packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer>
1697
1698Packs an image. This API uses a promise to return the result.
1699
1700**System capability**: SystemCapability.Multimedia.Image.ImagePacker
1701
1702**Parameters**
1703
1704| Name| Type                           | Mandatory| Description              |
1705| ------ | ------------------------------- | ---- | ------------------ |
1706| source | [PixelMap](#pixelmap)           | Yes  | **PixelMap** object to pack.|
1707| option | [PackingOption](#packingoption) | Yes  | Option for image packing.    |
1708
1709**Return value**
1710
1711| Type                 | Description                                        |
1712| --------------------- | -------------------------------------------- |
1713| Promise\<ArrayBuffer> | Promise used to return the packed data.|
1714
1715**Example**
1716
1717```js
1718const color = new ArrayBuffer(96);  // 96 is the size of the pixel map buffer to create. The value is calculated as follows: height x width x 4.
1719let bufferArr = new Uint8Array(color);
1720let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
1721image.createPixelMap(color, opts).then((pixelmap) => {
1722    let packOpts = { format:"image/jpeg", quality:98 }
1723    imagePackerApi.packing(pixelmap, packOpts)
1724        .then( data => {
1725            console.log('Succeeded in packing the image.');
1726        }).catch(error => {
1727            console.log('Failed to pack the image..');
1728        })
1729})
1730```
1731
1732### release
1733
1734release(callback: AsyncCallback\<void>): void
1735
1736Releases this **ImagePacker** instance. This API uses an asynchronous callback to return the result.
1737
1738**System capability**: SystemCapability.Multimedia.Image.ImagePacker
1739
1740**Parameters**
1741
1742| Name  | Type                | Mandatory| Description                          |
1743| -------- | -------------------- | ---- | ------------------------------ |
1744| callback | AsyncCallback\<void> | Yes  | Callback invoked for instance release. If the operation fails, an error message is returned.|
1745
1746**Example**
1747
1748```js
1749imagePackerApi.release(()=>{
1750    console.log('Succeeded in releasing image packaging.');
1751})
1752```
1753
1754### release
1755
1756release(): Promise\<void>
1757
1758Releases this **ImagePacker** instance. This API uses a promise to return the result.
1759
1760**System capability**: SystemCapability.Multimedia.Image.ImagePacker
1761
1762**Return value**
1763
1764| Type          | Description                                                  |
1765| -------------- | ------------------------------------------------------ |
1766| Promise\<void> | Promise used to return the instance release result. If the operation fails, an error message is returned.|
1767
1768**Example**
1769
1770```js
1771imagePackerApi.release().then(()=>{
1772    console.log('Succeeded in releasing image packaging.');
1773}).catch((error)=>{
1774    console.log('Failed to release image packaging.');
1775})
1776```
1777
1778## image.createImageReceiver<sup>9+</sup>
1779
1780createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver
1781
1782Creates an **ImageReceiver** instance by specifying the image width, height, format, and capacity.
1783
1784**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
1785
1786**Parameters**
1787
1788| Name  | Type  | Mandatory| Description                  |
1789| -------- | ------ | ---- | ---------------------- |
1790| width    | number | Yes  | Default image width.      |
1791| height   | number | Yes  | Default image height.      |
1792| format   | number | Yes  | Image format, which is a constant of [ImageFormat](#imageformat9). (Only ImageFormat:JPEG and 4 are supported.) |
1793| capacity | number | Yes  | Maximum number of images that can be accessed at the same time.|
1794
1795**Return value**
1796
1797| Type                            | Description                                   |
1798| -------------------------------- | --------------------------------------- |
1799| [ImageReceiver](#imagereceiver9) | Returns an **ImageReceiver** instance if the operation is successful.|
1800
1801**Example**
1802
1803```js
1804var receiver = image.createImageReceiver(8192, 8, 2000, 8);
1805```
1806
1807## ImageReceiver<sup>9+</sup>
1808
1809Provides APIs to obtain the surface ID of a component, read the latest image, read the next image, and release the **ImageReceiver** instance.
1810
1811Before calling any APIs in **ImageReceiver**, you must create an **ImageReceiver** instance.
1812
1813### Attributes
1814
1815**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
1816
1817| Name    | Type                        | Readable| Writable| Description              |
1818| -------- | ---------------------------- | ---- | ---- | ------------------ |
1819| size     | [Size](#size)                | Yes  | No  | Image size.        |
1820| capacity | number                       | Yes  | No  | Maximum number of images that can be accessed at the same time.|
1821| format   | [ImageFormat](#imageformat9) | Yes  | No  | Image format.        |
1822
1823### getReceivingSurfaceId<sup>9+</sup>
1824
1825getReceivingSurfaceId(callback: AsyncCallback\<string>): void
1826
1827Obtains a surface ID for the camera or other components. This API uses an asynchronous callback to return the result.
1828
1829**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
1830
1831**Parameters**
1832
1833| Name  | Type                  | Mandatory| Description                      |
1834| -------- | ---------------------- | ---- | -------------------------- |
1835| callback | AsyncCallback\<string> | Yes  | Callback used to return the surface ID.|
1836
1837**Example**
1838
1839```js
1840receiver.getReceivingSurfaceId((err, id) => {
1841    if(err) {
1842        console.log('getReceivingSurfaceId failed.');
1843    } else {
1844        console.log('getReceivingSurfaceId succeeded.');
1845    }
1846});
1847```
1848
1849### getReceivingSurfaceId<sup>9+</sup>
1850
1851getReceivingSurfaceId(): Promise\<string>
1852
1853Obtains a surface ID for the camera or other components. This API uses a promise to return the result.
1854
1855**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
1856
1857**Return value**
1858
1859| Type            | Description                |
1860| ---------------- | -------------------- |
1861| Promise\<string> | Promise used to return the surface ID.|
1862
1863**Example**
1864
1865```js
1866receiver.getReceivingSurfaceId().then( id => {
1867    console.log('getReceivingSurfaceId succeeded.');
1868}).catch(error => {
1869    console.log('getReceivingSurfaceId failed.');
1870})
1871```
1872
1873### readLatestImage<sup>9+</sup>
1874
1875readLatestImage(callback: AsyncCallback\<Image>): void
1876
1877Reads the latest image from the **ImageReceiver** instance. This API uses an asynchronous callback to return the result.
1878
1879**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
1880
1881**Parameters**
1882
1883| Name    | Type                           | Mandatory| Description                    |
1884| -------- | ------------------------------- | ---- | ------------------------ |
1885| callback | AsyncCallback<[Image](#image9)> | Yes  | Callback used to return the latest image.|
1886
1887**Example**
1888
1889```js
1890receiver.readLatestImage((err, img) => {
1891    if(err) {
1892        console.log('readLatestImage failed.');
1893    } else {
1894        console.log('readLatestImage succeeded.');
1895    }
1896});
1897```
1898
1899### readLatestImage<sup>9+</sup>
1900
1901readLatestImage(): Promise\<Image>
1902
1903Reads the latest image from the **ImageReceiver** instance. This API uses a promise to return the result.
1904
1905**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
1906
1907**Return value**
1908
1909| Type                     | Description              |
1910| ------------------------- | ------------------ |
1911| Promise<[Image](#image9)> | Promise used to return the latest image.|
1912
1913**Example**
1914
1915```js
1916receiver.readLatestImage().then(img => {
1917    console.log('readLatestImage succeeded.');
1918}).catch(error => {
1919    console.log('readLatestImage failed.');
1920})
1921```
1922
1923### readNextImage<sup>9+</sup>
1924
1925readNextImage(callback: AsyncCallback\<Image>): void
1926
1927Reads the next image from the **ImageReceiver** instance. This API uses an asynchronous callback to return the result.
1928
1929**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
1930
1931**Parameters**
1932
1933| Name  | Type                           | Mandatory| Description                      |
1934| -------- | ------------------------------- | ---- | -------------------------- |
1935| callback | AsyncCallback<[Image](#image9)> | Yes  | Callback used to return the next image.|
1936
1937**Example**
1938
1939```js
1940receiver.readNextImage((err, img) => {
1941    if(err) {
1942        console.log('readNextImage failed.');
1943    } else {
1944        console.log('readNextImage succeeded.');
1945    }
1946});
1947```
1948
1949### readNextImage<sup>9+</sup>
1950
1951readNextImage(): Promise\<Image>
1952
1953Reads the next image from the **ImageReceiver** instance. This API uses a promise to return the result.
1954
1955**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
1956
1957**Return value**
1958
1959| Type                     | Description                |
1960| ------------------------- | -------------------- |
1961| Promise<[Image](#image9)> | Promise used to return the next image.|
1962
1963**Example**
1964
1965```js
1966receiver.readNextImage().then(img => {
1967    console.log('readNextImage succeeded.');
1968}).catch(error => {
1969    console.log('readNextImage failed.');
1970})
1971```
1972
1973### on<sup>9+</sup>
1974
1975on(type: 'imageArrival', callback: AsyncCallback\<void>): void
1976
1977Listens for image arrival events.
1978
1979**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
1980
1981**Parameters**
1982
1983| Name  | Type                | Mandatory| Description                                                  |
1984| -------- | -------------------- | ---- | ------------------------------------------------------ |
1985| type     | string               | Yes  | Type of event to listen for. The value is fixed at **imageArrival**, which is triggered when an image is received.|
1986| callback | AsyncCallback\<void> | Yes  | Callback invoked for the event.                                      |
1987
1988**Example**
1989
1990```js
1991receiver.on('imageArrival', () => {})
1992```
1993
1994### release<sup>9+</sup>
1995
1996release(callback: AsyncCallback\<void>): void
1997
1998Releases this **ImageReceiver** instance. This API uses an asynchronous callback to return the result.
1999
2000**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
2001
2002**Parameters**
2003
2004| Name  | Type                | Mandatory| Description                    |
2005| -------- | -------------------- | ---- | ------------------------ |
2006| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
2007
2008**Example**
2009
2010```js
2011receiver.release(() => {})
2012```
2013
2014### release<sup>9+</sup>
2015
2016release(): Promise\<void>
2017
2018Releases this **ImageReceiver** instance. This API uses a promise to return the result.
2019
2020**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
2021
2022**Return value**
2023
2024| Type          | Description              |
2025| -------------- | ------------------ |
2026| Promise\<void> | Promise used to return the result.|
2027
2028**Example**
2029
2030```js
2031receiver.release().then(() => {
2032    console.log('release succeeded.');
2033}).catch(error => {
2034    console.log('release failed.');
2035})
2036```
2037
2038## image.createImageCreator<sup>9+</sup>
2039
2040createImageCreator(width: number, height: number, format: number, capacity: number): ImageCreator
2041
2042Creates an **ImageCreator** instance by specifying the image width, height, format, and capacity.
2043
2044**System capability**: SystemCapability.Multimedia.Image.ImageCreator
2045
2046**Parameters**
2047
2048| Name  | Type  | Mandatory| Description                  |
2049| -------- | ------ | ---- | ---------------------- |
2050| width    | number | Yes  | Default image width.      |
2051| height   | number | Yes  | Default image height.      |
2052| format   | number | Yes  | Image format, for example, YCBCR_422_SP or JPEG.            |
2053| capacity | number | Yes  | Maximum number of images that can be accessed at the same time.|
2054
2055**Return value**
2056
2057| Type                          | Description                                   |
2058| ------------------------------ | --------------------------------------- |
2059| [ImageCreator](#imagecreator9) | Returns an **ImageCreator** instance if the operation is successful.|
2060
2061**Example**
2062
2063```js
2064var creator = image.createImageCreator(8192, 8, 4, 8);
2065```
2066
2067## ImageCreator<sup>9+</sup>
2068
2069Provides APIs for applications to request an image native data area and compile native image data.
2070Before calling any APIs in **ImageCreator**, you must create an **ImageCreator** instance.
2071
2072### Attributes
2073
2074**System capability**: SystemCapability.Multimedia.Image.ImageCreator
2075
2076| Name    | Type                        | Readable| Writable| Description              |
2077| -------- | ---------------------------- | ---- | ---- | ------------------ |
2078| capacity | number                       | Yes  | No  | Maximum number of images that can be accessed at the same time.|
2079| format   | [ImageFormat](#imageformat9) | Yes  | No  | Image format.        |
2080
2081### dequeueImage<sup>9+</sup>
2082
2083dequeueImage(callback: AsyncCallback\<Image>): void
2084
2085Obtains an image buffer from the idle queue and writes image data into it. This API uses an asynchronous callback to return the result.
2086
2087**System capability**: SystemCapability.Multimedia.Image.ImageCreator
2088
2089**Parameters**
2090
2091| Name       | Type                                   | Mandatory| Description                |
2092| ------------- | ---------------------------------------| ---- | -------------------- |
2093| callback      | AsyncCallback\<Image>                   | Yes  | Callback used to return the drawn image.|
2094
2095**Example**
2096
2097```js
2098creator.dequeueImage((err, img) => {
2099    if (err) {
2100        console.info('dequeueImage failed.');
2101    }
2102    console.info('dequeueImage succeeded.');
2103});
2104```
2105
2106### dequeueImage<sup>9+</sup>
2107
2108dequeueImage(): Promise\<Image>
2109
2110Obtains an image buffer from the idle queue and writes image data into it. This API uses a promise to return the result.
2111
2112**System capability**: SystemCapability.Multimedia.Image.ImageCreator
2113
2114**Return value**
2115
2116| Type            | Description          |
2117| --------------- | ------------- |
2118| Promise\<Image> | Promise used to return the drawn image.|
2119
2120**Example**
2121
2122```js
2123creator.dequeueImage().then(img => {
2124    console.info('dequeueImage succeeded.');
2125}).catch(error => {
2126    console.log('dequeueImage failed: ' + error);
2127})
2128```
2129
2130### queueImage<sup>9+</sup>
2131
2132queueImage(interface: Image, callback: AsyncCallback\<void>): void
2133
2134Places the drawn image in the dirty queue. This API uses an asynchronous callback to return the result.
2135
2136**System capability**: SystemCapability.Multimedia.Image.ImageCreator
2137
2138**Parameters**
2139
2140| Name       | Type                    | Mandatory| Description                |
2141| ------------- | -------------------------| ---- | -------------------- |
2142| interface     | Image                    | Yes  | Drawn image.|
2143| callback      | AsyncCallback\<void>     | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
2144
2145**Example**
2146
2147```js
2148creator.dequeueImage().then(img => {
2149    // Draw the image.
2150    img.getComponent(4).then(component => {
2151        var bufferArr = new Uint8Array(component.byteBuffer);
2152        for (var i = 0; i < bufferArr.length; i += 4) {
2153            bufferArr[i] = 0; //B
2154            bufferArr[i + 1] = 0; //G
2155            bufferArr[i + 2] = 255; //R
2156            bufferArr[i + 3] = 255; //A
2157        }
2158    })
2159    creator.queueImage(img, (err) => {
2160        if (err) {
2161            console.info('queueImage failed: ' + err);
2162        }
2163        console.info('queueImage succeeded');
2164    })
2165})
2166
2167```
2168
2169### queueImage<sup>9+</sup>
2170
2171queueImage(interface: Image): Promise\<void>
2172
2173Places the drawn image in the dirty queue. This API uses a promise to return the result.
2174
2175**System capability**: SystemCapability.Multimedia.Image.ImageCreator
2176
2177**Parameters**
2178
2179| Name         | Type    | Mandatory| Description               |
2180| ------------- | --------| ---- | ------------------- |
2181| interface     | Image   | Yes  | Drawn image.|
2182
2183**Return value**
2184
2185| Type           | Description          |
2186| -------------- | ------------- |
2187| Promise\<void> | Promise used to return the result. If the operation fails, an error message is returned.|
2188
2189**Example**
2190
2191```js
2192creator.dequeueImage().then(img => {
2193    // Draw the image.
2194    img.getComponent(4).then(component => {
2195        var bufferArr = new Uint8Array(component.byteBuffer);
2196        for (var i = 0; i < bufferArr.length; i += 4) {
2197            bufferArr[i] = 0; //B
2198            bufferArr[i + 1] = 0; //G
2199            bufferArr[i + 2] = 255; //R
2200            bufferArr[i + 3] = 255; //A
2201        }
2202    })
2203    creator.queueImage(img).then(() => {
2204        console.info('queueImage succeeded.');
2205    }).catch(error => {
2206        console.info('queueImage failed: ' + error);
2207    })
2208})
2209
2210```
2211
2212### on<sup>9+</sup>
2213
2214on(type: 'imageRelease', callback: AsyncCallback\<void>): void
2215
2216Listens for image release events. This API uses an asynchronous callback to return the result.
2217
2218**System capability**: SystemCapability.Multimedia.Image.ImageCreator
2219
2220**Parameters**
2221
2222| Name       | Type                    | Mandatory| Description                |
2223| ------------- | -------------------------| ---- | -------------------- |
2224| type          | string                   | Yes  | Type of event, which is **'imageRelease'**.|
2225| callback      | AsyncCallback\<void>     | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
2226
2227**Example**
2228
2229```js
2230creator.on('imageRelease', (err) => {
2231    if (err) {
2232        console.info('on faild' + err);
2233    }
2234    console.info('on succeeded');
2235})
2236```
2237
2238### release<sup>9+</sup>
2239
2240release(callback: AsyncCallback\<void>): void
2241
2242Releases this **ImageCreator** instance. This API uses an asynchronous callback to return the result.
2243
2244**System capability**: SystemCapability.Multimedia.Image.ImageCreator
2245
2246**Parameters**
2247
2248| Name          | Type                    | Mandatory| Description                |
2249| ------------- | -------------------------| ---- | -------------------- |
2250| callback      | AsyncCallback\<void>     | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
2251
2252**Example**
2253
2254```js
2255creator.release((err) => {
2256    if (err) {
2257        console.info('release failed: ' + err);
2258    }
2259    console.info('release succeeded');
2260});
2261```
2262### release<sup>9+</sup>
2263
2264release(): Promise\<void>
2265
2266Releases this **ImageCreator** instance. This API uses a promise to return the result.
2267
2268**System capability**: SystemCapability.Multimedia.Image.ImageCreator
2269
2270**Return value**
2271
2272| Type           | Description          |
2273| -------------- | ------------- |
2274| Promise\<void> | Promise used to return the result. If the operation fails, an error message is returned.|
2275
2276**Example**
2277
2278```js
2279creator.release().then(() => {
2280    console.info('release succeeded');
2281}).catch(error => {
2282    console.info('release failed');
2283})
2284```
2285
2286## Image<sup>9+</sup>
2287
2288Provides APIs for basic image operations, including obtaining image information and reading and writing image data. An **Image** instance is returned when [readNextImage](#readnextimage9) and [readLatestImage](#readlatestimage9) are called.
2289
2290### Attributes
2291
2292**System capability**: SystemCapability.Multimedia.Image.Core
2293
2294| Name    | Type              | Readable| Writable| Description                                              |
2295| -------- | ------------------ | ---- | ---- | -------------------------------------------------- |
2296| clipRect | [Region](#region7) | Yes  | Yes  | Image area to be cropped.                                |
2297| size     | [Size](#size)      | Yes  | No  | Image size.                                        |
2298| format   | number             | Yes  | No  | Image format. For details, see [PixelMapFormat](#pixelmapformat7).|
2299
2300### getComponent<sup>9+</sup>
2301
2302getComponent(componentType: ComponentType, callback: AsyncCallback\<Component>): void
2303
2304Obtains the component buffer from the **Image** instance based on the color component type. This API uses an asynchronous callback to return the result.
2305
2306**System capability**: SystemCapability.Multimedia.Image.Core
2307
2308**Parameters**
2309
2310| Name       | Type                                   | Mandatory| Description                |
2311| ------------- | --------------------------------------- | ---- | -------------------- |
2312| componentType | [ComponentType](#componenttype9)        | Yes  | Color component type of the image.    |
2313| callback      | AsyncCallback<[Component](#component9)> | Yes  | Callback used to return the component buffer.|
2314
2315**Example**
2316
2317```js
2318img.getComponent(4, (err, component) => {
2319    if(err) {
2320        console.log('getComponent failed.');
2321    } else {
2322        console.log('getComponent succeeded.');
2323    }
2324})
2325```
2326
2327### getComponent<sup>9+</sup>
2328
2329getComponent(componentType: ComponentType): Promise\<Component>
2330
2331Obtains the component buffer from the **Image** instance based on the color component type. This API uses a promise to return the result.
2332
2333**System capability**: SystemCapability.Multimedia.Image.Core
2334
2335**Parameters**
2336
2337| Name       | Type                            | Mandatory| Description            |
2338| ------------- | -------------------------------- | ---- | ---------------- |
2339| componentType | [ComponentType](#componenttype9) | Yes  | Color component type of the image.|
2340
2341**Return value**
2342
2343| Type                             | Description                             |
2344| --------------------------------- | --------------------------------- |
2345| Promise<[Component](#component9)> | Promise used to return the component buffer.|
2346
2347**Example**
2348
2349```js
2350img.getComponent(4).then(component => { })
2351```
2352
2353### release<sup>9+</sup>
2354
2355release(callback: AsyncCallback\<void>): void
2356
2357Releases this **Image** instance. This API uses an asynchronous callback to return the result.
2358
2359The corresponding resources must be released before another image arrives.
2360
2361**System capability**: SystemCapability.Multimedia.Image.Core
2362
2363**Parameters**
2364
2365| Name  | Type                | Mandatory| Description          |
2366| -------- | -------------------- | ---- | -------------- |
2367| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
2368
2369**Example**
2370
2371```js
2372img.release(() =>{
2373    console.log('release succeeded.');
2374})
2375```
2376
2377### release<sup>9+</sup>
2378
2379release(): Promise\<void>
2380
2381Releases this **Image** instance. This API uses a promise to return the result.
2382
2383The corresponding resources must be released before another image arrives.
2384
2385**System capability**: SystemCapability.Multimedia.Image.Core
2386
2387**Return value**
2388
2389| Type          | Description                 |
2390| -------------- | --------------------- |
2391| Promise\<void> | Promise used to return the result.|
2392
2393**Example**
2394
2395```js
2396img.release().then(() =>{
2397    console.log('release succeeded.');
2398}).catch(error => {
2399    console.log('release failed.');
2400})
2401```
2402
2403## PositionArea<sup>7+</sup>
2404
2405Describes area information in an image.
2406
2407**System capability**: SystemCapability.Multimedia.Image.Core
2408
2409| Name  | Type              | Readable| Writable| Description                                                        |
2410| ------ | ------------------ | ---- | ---- | ------------------------------------------------------------ |
2411| pixels | ArrayBuffer        | Yes  | No  | Pixels of the image.                                                      |
2412| offset | number             | Yes  | No  | Offset for data reading.                                                    |
2413| stride | number             | Yes  | No  | Number of bytes from one row of pixels in memory to the next row of pixels in memory. The value of **stride** must be greater than or equal to the value of **region.size.width** multiplied by 4.                  |
2414| region | [Region](#region7) | Yes  | No  | Region to read or write. The width of the region to write plus the X coordinate cannot be greater than the width of the original image. The height of the region to write plus the Y coordinate cannot be greater than the height of the original image.|
2415
2416## ImageInfo
2417
2418Describes image information.
2419
2420**System capability**: SystemCapability.Multimedia.Image.Core
2421
2422| Name| Type         | Readable| Writable| Description      |
2423| ---- | ------------- | ---- | ---- | ---------- |
2424| size | [Size](#size) | Yes  | Yes  | Image size.|
2425| density<sup>9+</sup> | number | Yes  | Yes  | Pixel density, in ppi.|
2426
2427## Size
2428
2429Describes the size of an image.
2430
2431**System capability**: SystemCapability.Multimedia.Image.Core
2432
2433| Name  | Type  | Readable| Writable| Description          |
2434| ------ | ------ | ---- | ---- | -------------- |
2435| height | number | Yes  | Yes  | Image height.|
2436| width  | number | Yes  | Yes  | Image width.|
2437
2438## PixelMapFormat<sup>7+</sup>
2439
2440Enumerates the pixel formats of images.
2441
2442**System capability**: SystemCapability.Multimedia.Image.Core
2443
2444| Name                  |   Value  | Description             |
2445| ---------------------- | ------ | ----------------- |
2446| UNKNOWN                | 0      | Unknown format.       |
2447| RGB_565                | 2      | RGB_565.    |
2448| RGBA_8888              | 3      | RGBA_8888.|
2449| BGRA_8888<sup>9+</sup> | 4      | BGRA_8888.|
2450| RGB_888<sup>9+</sup>   | 5      | RGB_888.  |
2451| ALPHA_8<sup>9+</sup>   | 6      | ALPHA_8.  |
2452| RGBA_F16<sup>9+</sup>  | 7      | RGBA_F16. |
2453| NV21<sup>9+</sup>      | 8      | NV21.     |
2454| NV12<sup>9+</sup>      | 9      | NV12.     |
2455
2456## AlphaType<sup>9+</sup>
2457
2458Enumerates the alpha types of images.
2459
2460**System capability**: SystemCapability.Multimedia.Image.Core
2461
2462| Name    |   Value  | Description                   |
2463| -------- | ------ | ----------------------- |
2464| UNKNOWN  | 0      | Unknown alpha type.           |
2465| OPAQUE   | 1      | There is no alpha or the image is opaque.|
2466| PREMUL   | 2      | Premultiplied alpha.        |
2467| UNPREMUL | 3      | Unpremultiplied alpha, that is, straight alpha.      |
2468
2469## ScaleMode<sup>9+</sup>
2470
2471Enumerates the scale modes of images.
2472
2473**System capability**: SystemCapability.Multimedia.Image.Core
2474
2475| Name           |   Value  | Description                                              |
2476| --------------- | ------ | -------------------------------------------------- |
2477| CENTER_CROP     | 1      | Scales the image so that it fills the requested bounds of the target and crops the extra.|
2478| FIT_TARGET_SIZE | 0      | Reduces the image size to the dimensions of the target.                          |
2479
2480## SourceOptions<sup>9+</sup>
2481
2482Defines image source initialization options.
2483
2484**System capability**: SystemCapability.Multimedia.Image.Core
2485
2486| Name             | Type                              | Readable| Writable| Description              |
2487| ----------------- | ---------------------------------- | ---- | ---- | ------------------ |
2488| sourceDensity     | number                             | Yes  | Yes  | Density of the image source.|
2489| sourcePixelFormat | [PixelMapFormat](#pixelmapformat7) | Yes  | Yes  | Pixel format of the image source.    |
2490| sourceSize        | [Size](#size)                      | Yes  | Yes  | Pixel size of the image source.    |
2491
2492
2493## InitializationOptions<sup>8+</sup>
2494
2495Defines pixel map initialization options.
2496
2497**System capability**: SystemCapability.Multimedia.Image.Core
2498
2499| Name                    | Type                              | Readable| Writable| Description          |
2500| ------------------------ | ---------------------------------- | ---- | ---- | -------------- |
2501| alphaType<sup>9+</sup>   | [AlphaType](#alphatype9)           | Yes  | Yes  | Alpha type.      |
2502| editable                 | boolean                            | Yes  | Yes  | Whether the image is editable.  |
2503| pixelFormat              | [PixelMapFormat](#pixelmapformat7) | Yes  | Yes  | Pixel map format.    |
2504| scaleMode<sup>9+</sup>   | [ScaleMode](#scalemode9)           | Yes  | Yes  | Scale mode.      |
2505| size                     | [Size](#size)                      | Yes  | Yes  | Image size.|
2506
2507## DecodingOptions<sup>7+</sup>
2508
2509Defines image decoding options.
2510
2511**System capability**: SystemCapability.Multimedia.Image.ImageSource
2512
2513| Name              | Type                              | Readable| Writable| Description            |
2514| ------------------ | ---------------------------------- | ---- | ---- | ---------------- |
2515| sampleSize         | number                             | Yes  | Yes  | Thumbnail sampling size.|
2516| rotate             | number                             | Yes  | Yes  | Rotation angle.      |
2517| editable           | boolean                            | Yes  | Yes  | Whether the image is editable.    |
2518| desiredSize        | [Size](#size)                      | Yes  | Yes  | Expected output size.  |
2519| desiredRegion      | [Region](#region7)                 | Yes  | Yes  | Region to decode.      |
2520| desiredPixelFormat | [PixelMapFormat](#pixelmapformat7) | Yes  | Yes  | Pixel map format for decoding.|
2521| index              | number                             | Yes  | Yes  | Index of the image to decode.  |
2522| fitDensity<sup>9+</sup> | number                        | Yes  | Yes  | Image pixel density, in ppi.  |
2523
2524## Region<sup>7+</sup>
2525
2526Describes region information.
2527
2528**System capability**: SystemCapability.Multimedia.Image.Core
2529
2530| Name| Type         | Readable| Writable| Description        |
2531| ---- | ------------- | ---- | ---- | ------------ |
2532| size | [Size](#size) | Yes  | Yes  | Region size.  |
2533| x    | number        | Yes  | Yes  | X coordinate to translate.|
2534| y    | number        | Yes  | Yes  | Y coordinate of the region.|
2535
2536## PackingOption
2537
2538Defines the option for image packing.
2539
2540**System capability**: SystemCapability.Multimedia.Image.ImagePacker
2541
2542| Name   | Type  | Readable| Writable| Description                                               |
2543| ------- | ------ | ---- | ---- | --------------------------------------------------- |
2544| format  | string | Yes  | Yes  | Format of the packed image.<br>Only the JPG and WebP formats are supported.|
2545| quality | number | Yes  | Yes  | Quality of the output image in JPEG encoding. The value ranges from 1 to 100.|
2546| bufferSize<sup>9+</sup> | number | Yes  | Yes  | Buffer size, which is used to set the image size. The default value is 10 MB.|
2547
2548## GetImagePropertyOptions<sup>7+</sup>
2549
2550Describes image properties.
2551
2552**System capability**: SystemCapability.Multimedia.Image.ImageSource
2553
2554| Name        | Type  | Readable| Writable| Description        |
2555| ------------ | ------ | ---- | ---- | ------------ |
2556| index        | number | Yes  | Yes  | Index of an image.  |
2557| defaultValue | string | Yes  | Yes  | Default property value.|
2558
2559## PropertyKey<sup>7+</sup>
2560
2561Describes the exchangeable image file format (EXIF) data of an image.
2562
2563**System capability**: SystemCapability.Multimedia.Image.Core
2564
2565| Name             |   Value                   | Description                    |
2566| ----------------- | ----------------------- | ------------------------ |
2567| BITS_PER_SAMPLE   | "BitsPerSample"         | Number of bits per pixel.        |
2568| ORIENTATION       | "Orientation"           | Image orientation.              |
2569| IMAGE_LENGTH      | "ImageLength"           | Image length.              |
2570| IMAGE_WIDTH       | "ImageWidth"            | Image width.              |
2571| GPS_LATITUDE      | "GPSLatitude"           | Image latitude.              |
2572| GPS_LONGITUDE     | "GPSLongitude"          | Image longitude.              |
2573| GPS_LATITUDE_REF  | "GPSLatitudeRef"        | Latitude reference, for example, N or S.   |
2574| GPS_LONGITUDE_REF | "GPSLongitudeRef"       | Longitude reference, for example, W or E.   |
2575| DATE_TIME_ORIGINAL<sup>9+</sup> | "DateTimeOriginal" | Shooting time, for example, 2022:09:06 15:48:00.    |
2576| EXPOSURE_TIME<sup>9+</sup>      | "ExposureTime"     | Exposure time, for example, 1/33 sec.|
2577| SCENE_TYPE<sup>9+</sup>         | "SceneType"        | Shooting scene type, for example, portrait, scenery, motion, and night.    |
2578| ISO_SPEED_RATINGS<sup>9+</sup>  | "ISOSpeedRatings"  | ISO sensitivity or ISO speed, for example, 400.    |
2579| F_NUMBER<sup>9+</sup>           | "FNumber"          | Aperture, for example, f/1.8.    |
2580
2581
2582## ImageFormat<sup>9+</sup>
2583
2584Enumerates the image formats.
2585
2586**System capability**: SystemCapability.Multimedia.Image.Core
2587
2588| Name        |   Value  | Description                |
2589| ------------ | ------ | -------------------- |
2590| YCBCR_422_SP | 1000   | YCBCR422 semi-planar format.|
2591| JPEG         | 2000   | JPEG encoding format.      |
2592
2593## ComponentType<sup>9+</sup>
2594
2595Enumerates the color component types of images.
2596
2597**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
2598
2599| Name |   Value  | Description       |
2600| ----- | ------ | ----------- |
2601| YUV_Y | 1      | Luminance component. |
2602| YUV_U | 2      | Chrominance component. |
2603| YUV_V | 3      | Chrominance component. |
2604| JPEG  | 4      | JPEG type.|
2605
2606## Component<sup>9+</sup>
2607
2608Describes the color components of an image.
2609
2610**System capability**: SystemCapability.Multimedia.Image.Core
2611
2612| Name         | Type                            | Readable| Writable| Description        |
2613| ------------- | -------------------------------- | ---- | ---- | ------------ |
2614| componentType | [ComponentType](#componenttype9) | Yes  | No  | Color component type.  |
2615| rowStride     | number                           | Yes  | No  | Row stride.      |
2616| pixelStride   | number                           | Yes  | No  | Pixel stride.  |
2617| byteBuffer    | ArrayBuffer                      | Yes  | No  | Component buffer.|
2618
2619## ResponseCode
2620
2621Enumerates the response codes returned upon build errors.
2622
2623| Name                               | Value      | Description                                               |
2624| ----------------------------------- | -------- | --------------------------------------------------- |
2625| ERR_MEDIA_INVALID_VALUE             | -1       | Invalid value.                                         |
2626| SUCCESS                             | 0        | Operation successful.                                         |
2627| ERROR                               | 62980096 | Operation failed.                                         |
2628| ERR_IPC                             | 62980097 | IPC error.                                          |
2629| ERR_SHAMEM_NOT_EXIST                | 62980098 | The shared memory does not exist.                                     |
2630| ERR_SHAMEM_DATA_ABNORMAL            | 62980099 | The shared memory is abnormal.                                     |
2631| ERR_IMAGE_DECODE_ABNORMAL           | 62980100 | An error occurs during image decoding.                                     |
2632| ERR_IMAGE_DATA_ABNORMAL             | 62980101 | The input image data is incorrect.                                 |
2633| ERR_IMAGE_MALLOC_ABNORMAL           | 62980102 | An error occurs during image memory allocation.                                   |
2634| ERR_IMAGE_DATA_UNSUPPORT            | 62980103 | Unsupported image type.                                   |
2635| ERR_IMAGE_INIT_ABNORMAL             | 62980104 | An error occurs during image initialization.                                   |
2636| ERR_IMAGE_GET_DATA_ABNORMAL         | 62980105 | An error occurs during image data retrieval.                                 |
2637| ERR_IMAGE_TOO_LARGE                 | 62980106 | The image data is too large.                                     |
2638| ERR_IMAGE_TRANSFORM                 | 62980107 | An error occurs during image transformation.                                     |
2639| ERR_IMAGE_COLOR_CONVERT             | 62980108 | An error occurs during image color conversion.                                 |
2640| ERR_IMAGE_CROP                      | 62980109 | An error occurs during image cropping.                                         |
2641| ERR_IMAGE_SOURCE_DATA               | 62980110 | The image source data is incorrect.                                   |
2642| ERR_IMAGE_SOURCE_DATA_INCOMPLETE    | 62980111 | The image source data is incomplete.                                 |
2643| ERR_IMAGE_MISMATCHED_FORMAT         | 62980112 | The image formats do not match.                                   |
2644| ERR_IMAGE_UNKNOWN_FORMAT            | 62980113 | Unknown image format.                                     |
2645| ERR_IMAGE_SOURCE_UNRESOLVED         | 62980114 | The image source is not parsed.                                     |
2646| ERR_IMAGE_INVALID_PARAMETER         | 62980115 | Invalid image parameter.                                     |
2647| ERR_IMAGE_DECODE_FAILED             | 62980116 | Decoding failed.                                         |
2648| ERR_IMAGE_PLUGIN_REGISTER_FAILED    | 62980117 | Failed to register the plug-in.                                     |
2649| ERR_IMAGE_PLUGIN_CREATE_FAILED      | 62980118 | Failed to create the plug-in.                                     |
2650| ERR_IMAGE_ENCODE_FAILED             | 62980119 | Failed to encode the image.                                     |
2651| ERR_IMAGE_ADD_PIXEL_MAP_FAILED      | 62980120 | Failed to add the image pixel map.                             |
2652| ERR_IMAGE_HW_DECODE_UNSUPPORT       | 62980121 | Unsupported image hardware decoding.                               |
2653| ERR_IMAGE_DECODE_HEAD_ABNORMAL      | 62980122 | The image decoding header is incorrect.                                   |
2654| ERR_IMAGE_DECODE_EXIF_UNSUPPORT     | 62980123 | EXIF decoding is not supported.                             |
2655| ERR_IMAGE_PROPERTY_NOT_EXIST        | 62980124 | The image property does not exist. The error codes for the image start from 150.|
2656| ERR_IMAGE_READ_PIXELMAP_FAILED      | 62980246 | Failed to read the pixel map.                                 |
2657| ERR_IMAGE_WRITE_PIXELMAP_FAILED     | 62980247 | Failed to write the pixel map.                                 |
2658| ERR_IMAGE_PIXELMAP_NOT_ALLOW_MODIFY | 62980248 | Modification to the pixel map is not allowed.                               |
2659| ERR_IMAGE_CONFIG_FAILED             | 62980259 | The configuration is incorrect.                                         |
2660