• 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```ts
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**Example**
37
38```ts
39import {BusinessError} from '@ohos.base';
40async function Demo() {
41    const color : ArrayBuffer = 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.
42    let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
43    image.createPixelMap(color, opts).then((pixelMap : image.PixelMap) => {
44        console.log('Succeeded in creating pixelmap.');
45    }).catch((error : BusinessError) => {
46        console.error('Failed to create pixelmap.');
47    })
48}
49```
50
51## image.createPixelMap<sup>8+</sup>
52
53createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: AsyncCallback\<PixelMap>): void
54
55Creates a **PixelMap** object with the default BGRA_8888 format and pixel properties specified. This API uses an asynchronous callback to return the result.
56
57**System capability**: SystemCapability.Multimedia.Image.Core
58
59**Parameters**
60
61| Name  | Type                                            | Mandatory| Description                      |
62| -------- | ------------------------------------------------ | ---- | -------------------------- |
63| colors   | ArrayBuffer                                      | Yes  | Color array in BGRA_8888 format. |
64| options  | [InitializationOptions](#initializationoptions8) | Yes  | Pixel properties.                    |
65| callback | AsyncCallback\<[PixelMap](#pixelmap7)>           | Yes  | Callback used to return the **PixelMap** object.|
66
67**Example**
68
69```ts
70import {BusinessError} from '@ohos.base';
71async function Demo() {
72    const color : ArrayBuffer = 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.
73    let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
74    image.createPixelMap(color, opts, (error : BusinessError, pixelMap : image.PixelMap) => {
75        if(error) {
76            console.error('Failed to create pixelmap.');
77            return;
78        } else {
79            console.log('Succeeded in creating pixelmap.');
80        }
81    })
82}
83```
84
85## image.createPixelMapFromParcel<sup>11+</sup>
86
87createPixelMapFromParcel(sequence: rpc.MessageSequence): PixelMap
88
89Unmarshals a **MessageSequence** object to obtain a **PixelMap** object.
90
91**System capability**: SystemCapability.Multimedia.Image.Core
92
93**Parameters**
94
95| Name                | Type                                                 | Mandatory| Description                                    |
96| ---------------------- | ----------------------------------------------------- | ---- | ---------------------------------------- |
97| sequence               | [rpc.MessageSequence](js-apis-rpc.md#messagesequence9) | Yes  | **MessageSequence** object that stores the **PixelMap** information.     |
98
99**Return value**
100
101| Type                            | Description                 |
102| -------------------------------- | --------------------- |
103| [PixelMap](#pixelmap7) | Returns a **PixelMap** object if the operation is successful; throws an error otherwise.|
104
105**Error codes**
106
107For details about the error codes, see [Image Error Codes](../errorcodes/errorcode-image.md).
108
109| ID| Error Message|
110| ------- | --------------------------------------------|
111| 62980096 | If the operation failed|
112| 62980097 | If the ipc error|
113| 62980115 | Invalid input parameter|
114| 62980105 | Failed to get the data|
115| 62980177 | Abnormal API environment|
116| 62980178 | Failed to create the PixelMap|
117| 62980179 | Abnormal buffer size|
118| 62980180 | FD mapping failed|
119| 62980246 | Failed to read the PixelMap|
120
121**Example**
122
123```ts
124import image from '@ohos.multimedia.image';
125import rpc from '@ohos.rpc';
126class MySequence implements rpc.Parcelable {
127    pixel_map : image.PixelMap;
128    constructor(conPixelmap : image.PixelMap) {
129        this.pixel_map = conPixelmap;
130    }
131    marshalling(messageSequence : rpc.MessageSequence) {
132        this.pixel_map.marshalling(messageSequence);
133        return true;
134    }
135    unmarshalling(messageSequence : rpc.MessageSequence) {
136        try {
137            this.pixel_map = image.createPixelMapFromParcel(messageSequence);
138        } catch(e) {
139            console.error('createPixelMapFromParcel error: '+ e);
140            return false;
141        }
142      return true;
143    }
144}
145async function Demo() {
146   const color : ArrayBuffer = new ArrayBuffer(96);
147   let bufferArr : Uint8Array = new Uint8Array(color);
148   for (let i = 0; i < bufferArr.length; i++) {
149      bufferArr[i] = 0x80;
150   }
151   let opts : image.InitializationOptions = {
152      editable: true,
153      pixelFormat: 4,
154      size: { height: 4, width: 6 },
155      alphaType: 3
156   }
157   let pixelMap : image.PixelMap | undefined = undefined;
158   await image.createPixelMap(color, opts).then((srcPixelMap : image.PixelMap) => {
159      pixelMap = srcPixelMap;
160   })
161   if (pixelMap != undefined) {
162     // Implement serialization.
163     let parcelable : MySequence = new MySequence(pixelMap);
164     let data : rpc.MessageSequence = rpc.MessageSequence.create();
165     data.writeParcelable(parcelable);
166
167     // Deserialize to obtain data through the RPC.
168     let ret : MySequence = new MySequence(pixelMap);
169     data.readParcelable(ret);
170
171     // Obtain the PixelMap object.
172     let unmarshPixelmap = ret.pixel_map;
173   }
174}
175```
176
177## image.createPixelMapFromSurface<sup>11+</sup>
178
179Creates a **PixelMap** object from a surface ID.
180
181createPixelMapFromSurface(surfaceId: string, region: Region): Promise\<PixelMap>
182
183**System capability**: SystemCapability.Multimedia.Image.Core
184
185**Parameters**
186
187| Name                | Type                | Mandatory| Description                                    |
188| ---------------------- | -------------       | ---- | ---------------------------------------- |
189| surfaceId              | string              | Yes  | Surface ID, which is obtained from [XComponent](../arkui-ts/ts-basic-components-xcomponent.md) or [ImageReceiver](js-apis-image.md#imagereceiver9).|
190| region                 | [Region](#region7)  | Yes  | Size of the image after cropping.                        |
191
192**Return value**
193| Type                            | Description                 |
194| -------------------------------- | --------------------- |
195| Promise\<[PixelMap](#pixelmap7)> | Returns a **PixelMap** object if the operation is successful; throws an error otherwise.|
196
197**Error codes**
198
199For details about the error codes, see [Image Error Codes](../errorcodes/errorcode-image.md).
200
201| ID| Error Message|
202| ------- | --------------------------------------------|
203| 62980115 | Invalid input parameter|
204| 62980105 | Failed to get the data|
205| 62980178 | Failed to create the PixelMap|
206
207**Example**
208
209```ts
210import {BusinessError} from '@ohos.base';
211async function Demo(surfaceId: string) {
212    let region : image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } };
213    await multimedia_image.createPixelMapFromSurface(surfaceId, region).then(() => {
214        console.log('Succeeded in creating pixelmap from Surface');
215    }).catch((error : BusinessError) => {
216        console.error('Failed to create pixelmap');
217    });
218}
219```
220
221## PixelMap<sup>7+</sup>
222
223Provides 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](#imagecreatepixelmap8) 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.
224
225Since API version 11, **PixelMap** supports cross-thread calls through workers. If a **PixelMap** object is invoked by another thread through [Worker](js-apis-worker.md), all APIs of the **PixelMap** object cannot be called in the original thread. Otherwise, error 501 is reported, indicating that the server cannot complete the request.
226
227Before calling any API in **PixelMap**, you must use [image.createPixelMap](#imagecreatepixelmap8) to create a **PixelMap** object.
228
229### Attributes
230
231**System capability**: SystemCapability.Multimedia.Image.Core
232
233| Name             | Type   | Readable| Writable| Description                      |
234| -----------------| ------- | ---- | ---- | -------------------------- |
235| isEditable        | boolean | Yes  | No  | Whether the image pixel map is editable.|
236| isStrideAlignment | boolean | Yes  | No  | Whether the image memory is the DMA memory.|
237
238### readPixelsToBuffer<sup>7+</sup>
239
240readPixelsToBuffer(dst: ArrayBuffer): Promise\<void>
241
242Reads 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.
243
244**System capability**: SystemCapability.Multimedia.Image.Core
245
246**Parameters**
247
248| Name| Type       | Mandatory| Description                                                                                                 |
249| ------ | ----------- | ---- | ----------------------------------------------------------------------------------------------------- |
250| dst    | ArrayBuffer | Yes  | Buffer to which the image pixel map data will be written. The buffer size is obtained by calling [getPixelBytesNumber](#getpixelbytesnumber7).|
251
252**Return value**
253
254| Type          | Description                                           |
255| -------------- | ----------------------------------------------- |
256| Promise\<void> | Promise used to return the result. If the operation fails, an error message is returned.|
257
258**Example**
259
260```ts
261import {BusinessError} from '@ohos.base';
262async function Demo() {
263    const readBuffer : ArrayBuffer = 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.
264    pixelMap.readPixelsToBuffer(readBuffer).then(() => {
265        console.log('Succeeded in reading image pixel data.'); // Called if the condition is met.
266    }).catch((error : BusinessError) => {
267        console.error('Failed to read image pixel data.');  // Called if no condition is met.
268    })
269}
270```
271
272### readPixelsToBuffer<sup>7+</sup>
273
274readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\<void>): void
275
276Reads 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.
277
278**System capability**: SystemCapability.Multimedia.Image.Core
279
280**Parameters**
281
282| Name  | Type                | Mandatory| Description                                                                                                 |
283| -------- | -------------------- | ---- | ----------------------------------------------------------------------------------------------------- |
284| dst      | ArrayBuffer          | Yes  | Buffer to which the image pixel map data will be written. The buffer size is obtained by calling [getPixelBytesNumber](#getpixelbytesnumber7).|
285| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation fails, an error message is returned.                                                                       |
286
287**Example**
288
289```ts
290import {BusinessError} from '@ohos.base';
291async function Demo() {
292    const readBuffer : ArrayBuffer = 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.
293    pixelMap.readPixelsToBuffer(readBuffer, (err : BusinessError, res : void) => {
294        if(err) {
295            console.error('Failed to read image pixel data.');  // Called if no condition is met.
296            return;
297        } else {
298            console.log('Succeeded in reading image pixel data.'); // Called if the condition is met.
299        }
300    })
301}
302```
303
304### readPixels<sup>7+</sup>
305
306readPixels(area: PositionArea): Promise\<void>
307
308Reads image pixel map data in an area. This API uses a promise to return the result.
309
310**System capability**: SystemCapability.Multimedia.Image.Core
311
312**Parameters**
313
314| Name| Type                          | Mandatory| Description                    |
315| ------ | ------------------------------ | ---- | ------------------------ |
316| area   | [PositionArea](#positionarea7) | Yes  | Area from which the image pixel map data will be read.|
317
318**Return value**
319
320| Type          | Description                                               |
321| :------------- | :-------------------------------------------------- |
322| Promise\<void> | Promise used to return the result. If the operation fails, an error message is returned.|
323
324**Example**
325
326```ts
327import {BusinessError} from '@ohos.base';
328async function Demo() {
329    const area : image.PositionArea = {
330        pixels: new ArrayBuffer(8),
331        offset: 0,
332        stride: 8,
333        region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
334    };
335    pixelMap.readPixels(area).then(() => {
336        console.log('Succeeded in reading the image data in the area.'); // Called if the condition is met.
337    }).catch((error : BusinessError) => {
338        console.error('Failed to read the image data in the area.'); // Called if no condition is met.
339    })
340}
341```
342
343### readPixels<sup>7+</sup>
344
345readPixels(area: PositionArea, callback: AsyncCallback\<void>): void
346
347Reads image pixel map data in an area. This API uses an asynchronous callback to return the result.
348
349**System capability**: SystemCapability.Multimedia.Image.Core
350
351**Parameters**
352
353| Name  | Type                          | Mandatory| Description                          |
354| -------- | ------------------------------ | ---- | ------------------------------ |
355| area     | [PositionArea](#positionarea7) | Yes  | Area from which the image pixel map data will be read.      |
356| callback | AsyncCallback\<void>           | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
357
358**Example**
359
360```ts
361import {BusinessError} from '@ohos.base';
362async function Demo() {
363    const area : image.PositionArea = {
364        pixels: new ArrayBuffer(8),
365        offset: 0,
366        stride: 8,
367        region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
368    };
369    pixelMap.readPixels(area, (err : BusinessError) => {
370        if (err != undefined) {
371            console.error('Failed to read pixelmap from the specified area.');
372            return;
373        } else {
374            console.info('Succeeded to read pixelmap from the specified area.');
375        }
376    })
377}
378```
379
380### writePixels<sup>7+</sup>
381
382writePixels(area: PositionArea): Promise\<void>
383
384Writes image pixel map data to an area. This API uses a promise to return the result.
385
386**System capability**: SystemCapability.Multimedia.Image.Core
387
388**Parameters**
389
390| Name| Type                          | Mandatory| Description                |
391| ------ | ------------------------------ | ---- | -------------------- |
392| area   | [PositionArea](#positionarea7) | Yes  | Area to which the image pixel map data will be written.|
393
394**Return value**
395
396| Type          | Description                                               |
397| :------------- | :-------------------------------------------------- |
398| Promise\<void> | Promise used to return the result. If the operation fails, an error message is returned.|
399
400**Example**
401
402```ts
403import {BusinessError} from '@ohos.base';
404async function Demo() {
405    const area : image.PositionArea = {
406        pixels: new ArrayBuffer(8),
407        offset: 0,
408        stride: 8,
409        region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
410    };
411    let bufferArr : Uint8Array = new Uint8Array(area.pixels);
412    for (let i = 0; i < bufferArr.length; i++) {
413        bufferArr[i] = i + 1;
414    }
415    pixelMap.writePixels(area).then(() => {
416        console.info('Succeeded to write pixelmap into the specified area.');
417    }).catch((error : BusinessError) => {
418        console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`);
419    })
420}
421```
422
423### writePixels<sup>7+</sup>
424
425writePixels(area: PositionArea, callback: AsyncCallback\<void>): void
426
427Writes image pixel map data to an area. This API uses an asynchronous callback to return the result.
428
429**System capability**: SystemCapability.Multimedia.Image.Core
430
431**Parameters**
432
433| Name   | Type                          | Mandatory| Description                          |
434| --------- | ------------------------------ | ---- | ------------------------------ |
435| area      | [PositionArea](#positionarea7) | Yes  | Area to which the image pixel map data will be written.          |
436| callback  | AsyncCallback\<void>           | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
437
438**Example**
439
440```ts
441import {BusinessError} from '@ohos.base';
442async function Demo() {
443    const area : image.PositionArea = { pixels: new ArrayBuffer(8),
444        offset: 0,
445        stride: 8,
446        region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
447    };
448    let bufferArr : Uint8Array = new Uint8Array(area.pixels);
449    for (let i = 0; i < bufferArr.length; i++) {
450        bufferArr[i] = i + 1;
451    }
452    pixelMap.writePixels(area, (error : BusinessError) => {
453        if (error != undefined) {
454            console.error('Failed to write pixelmap into the specified area.');
455            return;
456        } else {
457            console.info('Succeeded to write pixelmap into the specified area.');
458        }
459    })
460}
461```
462
463### writeBufferToPixels<sup>7+</sup>
464
465writeBufferToPixels(src: ArrayBuffer): Promise\<void>
466
467Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** object. This API uses a promise to return the result.
468
469**System capability**: SystemCapability.Multimedia.Image.Core
470
471**Parameters**
472
473| Name| Type       | Mandatory| Description          |
474| ------ | ----------- | ---- | -------------- |
475| src    | ArrayBuffer | Yes  | Buffer from which the image data will be read.|
476
477**Return value**
478
479| Type          | Description                                           |
480| -------------- | ----------------------------------------------- |
481| Promise\<void> | Promise used to return the result. If the operation fails, an error message is returned.|
482
483**Example**
484
485```ts
486import {BusinessError} from '@ohos.base';
487async function Demo() {
488    const color : ArrayBuffer = 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.
489    let bufferArr : Uint8Array = new Uint8Array(color);
490    for (let i = 0; i < bufferArr.length; i++) {
491        bufferArr[i] = i + 1;
492    }
493    pixelMap.writeBufferToPixels(color).then(() => {
494        console.log("Succeeded in writing data from a buffer to a PixelMap.");
495    }).catch((error : BusinessError) => {
496        console.error("Failed to write data from a buffer to a PixelMap.");
497    })
498}
499```
500
501### writeBufferToPixels<sup>7+</sup>
502
503writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\<void>): void
504
505Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** object. This API uses an asynchronous callback to return the result.
506
507**System capability**: SystemCapability.Multimedia.Image.Core
508
509**Parameters**
510
511| Name  | Type                | Mandatory| Description                          |
512| -------- | -------------------- | ---- | ------------------------------ |
513| src      | ArrayBuffer          | Yes  | Buffer from which the image data will be read.                |
514| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
515
516**Example**
517
518```ts
519import {BusinessError} from '@ohos.base';
520async function Demo() {
521    const color : ArrayBuffer = 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.
522    let bufferArr : Uint8Array = new Uint8Array(color);
523    for (let i = 0; i < bufferArr.length; i++) {
524        bufferArr[i] = i + 1;
525    }
526    pixelMap.writeBufferToPixels(color, (err : BusinessError) => {
527        if (err != undefined) {
528            console.error("Failed to write data from a buffer to a PixelMap.");
529            return;
530        } else {
531            console.log("Succeeded in writing data from a buffer to a PixelMap.");
532        }
533    })
534}
535```
536
537### getImageInfo<sup>7+</sup>
538
539getImageInfo(): Promise\<ImageInfo>
540
541Obtains pixel map information of this image. This API uses a promise to return the result.
542
543**System capability**: SystemCapability.Multimedia.Image.Core
544
545**Return value**
546
547| Type                             | Description                                                       |
548| --------------------------------- | ----------------------------------------------------------- |
549| Promise\<[ImageInfo](#imageinfo)> | Promise used to return the pixel map information. If the operation fails, an error message is returned.|
550
551**Example**
552
553```ts
554async function Demo() {
555    pixelMap.getImageInfo().then((imageInfo : image.ImageInfo) => {
556        if (imageInfo == undefined) {
557            console.error("Failed to obtain the image pixel map information.");
558        }
559        if (imageInfo.size.height == 4 && imageInfo.size.width == 6) {
560            console.log("Succeeded in obtaining the image pixel map information.");
561        }
562    })
563}
564```
565
566### getImageInfo<sup>7+</sup>
567
568getImageInfo(callback: AsyncCallback\<ImageInfo>): void
569
570Obtains pixel map information of this image. This API uses an asynchronous callback to return the result.
571
572**System capability**: SystemCapability.Multimedia.Image.Core
573
574**Parameters**
575
576| Name  | Type                                   | Mandatory| Description                                                        |
577| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
578| callback | AsyncCallback\<[ImageInfo](#imageinfo)> | Yes  | Callback used to return the pixel map information. If the operation fails, an error message is returned.|
579
580**Example**
581
582```ts
583import {BusinessError} from '@ohos.base';
584async function Demo() {
585    pixelMap.getImageInfo((err : BusinessError, imageInfo : image.ImageInfo) => {
586        if (imageInfo == undefined) {
587            console.error("Failed to obtain the image pixel map information.");
588            return;
589        }
590        if (imageInfo.size.height == 4 && imageInfo.size.width == 6) {
591            console.log("Succeeded in obtaining the image pixel map information.");
592        }
593    })
594}
595```
596
597### getBytesNumberPerRow<sup>7+</sup>
598
599getBytesNumberPerRow(): number
600
601Obtains the number of bytes per row of this image pixel map.
602
603**System capability**: SystemCapability.Multimedia.Image.Core
604
605**Return value**
606
607| Type  | Description                |
608| ------ | -------------------- |
609| number | Number of bytes per row.|
610
611**Example**
612
613```ts
614let rowCount : number = pixelMap.getBytesNumberPerRow();
615```
616
617### getPixelBytesNumber<sup>7+</sup>
618
619getPixelBytesNumber(): number
620
621Obtains the total number of bytes of this image pixel map.
622
623**System capability**: SystemCapability.Multimedia.Image.Core
624
625**Return value**
626
627| Type  | Description                |
628| ------ | -------------------- |
629| number | Total number of bytes.|
630
631**Example**
632
633```ts
634let pixelBytesNumber : number = pixelMap.getPixelBytesNumber();
635```
636
637### getDensity<sup>9+</sup>
638
639getDensity():number
640
641Obtains the density of this image pixel map.
642
643**System capability**: SystemCapability.Multimedia.Image.Core
644
645**Return value**
646
647| Type  | Description           |
648| ------ | --------------- |
649| number | Density of the image pixel map.|
650
651**Example**
652
653```ts
654let getDensity : number = pixelMap.getDensity();
655```
656
657### opacity<sup>9+</sup>
658
659opacity(rate: number, callback: AsyncCallback\<void>): void
660
661Sets an opacity rate for this image pixel map. This API uses an asynchronous callback to return the result.
662
663**System capability**: SystemCapability.Multimedia.Image.Core
664
665**Parameters**
666
667| Name  | Type                | Mandatory| Description                          |
668| -------- | -------------------- | ---- | ------------------------------ |
669| rate     | number               | Yes  | Opacity rate to set.  |
670| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
671
672**Example**
673
674```ts
675import {BusinessError} from '@ohos.base';
676async function Demo() {
677    let rate : number = 0.5;
678    pixelMap.opacity(rate, (err : BusinessError) => {
679        if (err) {
680            console.error("Failed to set opacity.");
681            return;
682        } else {
683            console.log("Succeeded in setting opacity.");
684        }
685    })
686}
687```
688
689### opacity<sup>9+</sup>
690
691opacity(rate: number): Promise\<void>
692
693Sets an opacity rate for this image pixel map. This API uses a promise to return the result.
694
695**System capability**: SystemCapability.Multimedia.Image.Core
696
697**Parameters**
698
699| Name| Type  | Mandatory| Description                       |
700| ------ | ------ | ---- | --------------------------- |
701| rate   | number | Yes  | Opacity rate to set.|
702
703**Return value**
704
705| Type          | Description                                           |
706| -------------- | ----------------------------------------------- |
707| Promise\<void> | Promise used to return the result. If the operation fails, an error message is returned.|
708
709**Example**
710
711```ts
712import {BusinessError} from '@ohos.base';
713async function Demo() {
714    let rate : number = 0.5;
715    await pixelMap.opacity(rate).then(() => {
716        console.log('Sucessed in setting opacity.');
717    }).catch((err : BusinessError) => {
718        console.error('Failed to set opacity.');
719    })
720}
721```
722
723### createAlphaPixelmap<sup>9+</sup>
724
725createAlphaPixelmap(): Promise\<PixelMap>
726
727Creates 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.
728
729**System capability**: SystemCapability.Multimedia.Image.Core
730
731**Return value**
732
733| Type                            | Description                       |
734| -------------------------------- | --------------------------- |
735| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.|
736
737**Example**
738
739```ts
740import {BusinessError} from '@ohos.base';
741async function Demo() {
742    await pixelMap.createAlphaPixelmap().then((alphaPixelMap : image.PixelMap) => {
743        console.log('Succeeded in creating alpha pixelmap.');
744    }).catch((error : BusinessError) => {
745        console.error('Failed to create alpha pixelmap.');
746    })
747}
748```
749
750### createAlphaPixelmap<sup>9+</sup>
751
752createAlphaPixelmap(callback: AsyncCallback\<PixelMap>): void
753
754Creates 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.
755
756**System capability**: SystemCapability.Multimedia.Image.Core
757
758**Parameters**
759
760| Name  | Type                    | Mandatory| Description                    |
761| -------- | ------------------------ | ---- | ------------------------ |
762| callback | AsyncCallback\<[PixelMap](#pixelmap7)> | Yes  | Callback used to return the **PixelMap** object.|
763
764**Example**
765
766```ts
767import {BusinessError} from '@ohos.base';
768async function Demo() {
769    pixelMap.createAlphaPixelmap((err : BusinessError, alphaPixelMap : image.PixelMap) => {
770        if (alphaPixelMap == undefined) {
771            console.error('Failed to obtain new pixel map.');
772            return;
773        } else {
774            console.info('Succeed in obtaining new pixel map.');
775        }
776    })
777}
778```
779
780### scale<sup>9+</sup>
781
782scale(x: number, y: number, callback: AsyncCallback\<void>): void
783
784Scales this image based on the input scaling multiple of the width and height. This API uses an asynchronous callback to return the result.
785
786**System capability**: SystemCapability.Multimedia.Image.Core
787
788**Parameters**
789
790| Name  | Type                | Mandatory| Description                           |
791| -------- | -------------------- | ---- | ------------------------------- |
792| x        | number               | Yes  | Scaling multiple of the width.|
793| y        | number               | Yes  | Scaling multiple of the height.|
794| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation fails, an error message is returned. |
795
796**Example**
797
798```ts
799import {BusinessError} from '@ohos.base';
800async function Demo() {
801    let scaleX : number = 2.0;
802    let scaleY : number = 1.0;
803    pixelMap.scale(scaleX, scaleY, (err : BusinessError) => {
804        if (err) {
805            console.error("Failed to scale pixelmap.");
806            return;
807        } else {
808            console.log("Succeeded in scaling pixelmap.");
809        }
810    })
811}
812```
813
814### scale<sup>9+</sup>
815
816scale(x: number, y: number): Promise\<void>
817
818Scales this image based on the input scaling multiple of the width and height. This API uses a promise to return the result.
819
820**System capability**: SystemCapability.Multimedia.Image.Core
821
822**Parameters**
823
824| Name| Type  | Mandatory| Description                           |
825| ------ | ------ | ---- | ------------------------------- |
826| x      | number | Yes  | Scaling multiple of the width.|
827| y      | number | Yes  | Scaling multiple of the height.|
828
829**Return value**
830
831| Type          | Description                       |
832| -------------- | --------------------------- |
833| Promise\<void> | Promise used to return the result.|
834
835**Example**
836
837```ts
838import {BusinessError} from '@ohos.base';
839async function Demo() {
840    let scaleX : number = 2.0;
841    let scaleY : number = 1.0;
842    await pixelMap.scale(scaleX, scaleY).then(() => {
843        console.log('Sucessed in scaling pixelmap.');
844    }).catch((err : BusinessError) => {
845        console.error('Failed to scale pixelmap.');
846    })
847}
848```
849
850### translate<sup>9+</sup>
851
852translate(x: number, y: number, callback: AsyncCallback\<void>): void
853
854Translates this image based on the input coordinates. This API uses an asynchronous callback to return the result.
855
856**System capability**: SystemCapability.Multimedia.Image.Core
857
858**Parameters**
859
860| Name  | Type                | Mandatory| Description                         |
861| -------- | -------------------- | ---- | ----------------------------- |
862| x        | number               | Yes  | X coordinate to translate.                 |
863| y        | number               | Yes  | Y coordinate to translate.                 |
864| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
865
866**Example**
867
868```ts
869import {BusinessError} from '@ohos.base';
870async function Demo() {
871    let translateX : number = 50.0;
872    let translateY : number = 10.0;
873    pixelMap.translate(translateX, translateY, (err : BusinessError) => {
874        if (err) {
875            console.error("Failed to translate pixelmap.");
876            return;
877        } else {
878            console.log("Succeeded in translating pixelmap.");
879        }
880    })
881}
882```
883
884### translate<sup>9+</sup>
885
886translate(x: number, y: number): Promise\<void>
887
888Translates this image based on the input coordinates. This API uses a promise to return the result.
889
890**System capability**: SystemCapability.Multimedia.Image.Core
891
892**Parameters**
893
894| Name| Type  | Mandatory| Description       |
895| ------ | ------ | ---- | ----------- |
896| x      | number | Yes  | X coordinate to translate.|
897| y      | number | Yes  | Y coordinate to translate.|
898
899**Return value**
900
901| Type          | Description                       |
902| -------------- | --------------------------- |
903| Promise\<void> | Promise used to return the result.|
904
905**Example**
906
907```ts
908import {BusinessError} from '@ohos.base';
909async function Demo() {
910    let translateX : number = 50.0;
911    let translateY : number = 10.0;
912    await pixelMap.translate(translateX, translateY).then(() => {
913        console.log('Sucessed in translating pixelmap.');
914    }).catch((err : BusinessError) => {
915        console.error('Failed to translate pixelmap.');
916    })
917}
918```
919
920### rotate<sup>9+</sup>
921
922rotate(angle: number, callback: AsyncCallback\<void>): void
923
924Rotates this image based on the input angle. This API uses an asynchronous callback to return the result.
925
926**System capability**: SystemCapability.Multimedia.Image.Core
927
928**Parameters**
929
930| Name  | Type                | Mandatory| Description                         |
931| -------- | -------------------- | ---- | ----------------------------- |
932| angle    | number               | Yes  | Angle to rotate.             |
933| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
934
935**Example**
936
937```ts
938import {BusinessError} from '@ohos.base';
939async function Demo() {
940    let angle : number = 90.0;
941    pixelMap.rotate(angle, (err : BusinessError) => {
942        if (err != undefined) {
943            console.error("Failed to rotate pixelmap.");
944            return;
945        } else {
946            console.log("Succeeded in rotating pixelmap.");
947        }
948    })
949}
950```
951
952### rotate<sup>9+</sup>
953
954rotate(angle: number): Promise\<void>
955
956Rotates this image based on the input angle. This API uses a promise to return the result.
957
958**System capability**: SystemCapability.Multimedia.Image.Core
959
960**Parameters**
961
962| Name| Type  | Mandatory| Description                         |
963| ------ | ------ | ---- | ----------------------------- |
964| angle  | number | Yes  | Angle to rotate.             |
965
966**Return value**
967
968| Type          | Description                       |
969| -------------- | --------------------------- |
970| Promise\<void> | Promise used to return the result.|
971
972**Example**
973
974```ts
975import {BusinessError} from '@ohos.base';
976async function Demo() {
977    let angle : number = 90.0;
978    await pixelMap.rotate(angle).then(() => {
979        console.log('Sucessed in rotating pixelmap.');
980    }).catch((err : BusinessError) => {
981        console.error('Failed to rotate pixelmap.');
982    })
983}
984```
985
986### flip<sup>9+</sup>
987
988flip(horizontal: boolean, vertical: boolean, callback: AsyncCallback\<void>): void
989
990Flips this image horizontally or vertically, or both. This API uses an asynchronous callback to return the result.
991
992**System capability**: SystemCapability.Multimedia.Image.Core
993
994**Parameters**
995
996| Name    | Type                | Mandatory| Description                         |
997| ---------- | -------------------- | ---- | ----------------------------- |
998| horizontal | boolean              | Yes  | Whether to flip the image horizontally.                   |
999| vertical   | boolean              | Yes  | Whether to flip the image vertically.                   |
1000| callback   | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
1001
1002**Example**
1003
1004```ts
1005import {BusinessError} from '@ohos.base';
1006async function Demo() {
1007    let horizontal : boolean = true;
1008    let vertical : boolean = false;
1009    pixelMap.flip(horizontal, vertical, (err : BusinessError) => {
1010        if (err != undefined) {
1011            console.error("Failed to flip pixelmap.");
1012            return;
1013        } else {
1014            console.log("Succeeded in flipping pixelmap.");
1015        }
1016    })
1017}
1018```
1019
1020### flip<sup>9+</sup>
1021
1022flip(horizontal: boolean, vertical: boolean): Promise\<void>
1023
1024Flips this image horizontally or vertically, or both. This API uses a promise to return the result.
1025
1026**System capability**: SystemCapability.Multimedia.Image.Core
1027
1028**Parameters**
1029
1030| Name    | Type   | Mandatory| Description     |
1031| ---------- | ------- | ---- | --------- |
1032| horizontal | boolean | Yes  | Whether to flip the image horizontally.|
1033| vertical   | boolean | Yes  | Whether to flip the image vertically.|
1034
1035**Return value**
1036
1037| Type          | Description                       |
1038| -------------- | --------------------------- |
1039| Promise\<void> | Promise used to return the result.|
1040
1041**Example**
1042
1043```ts
1044import {BusinessError} from '@ohos.base';
1045async function Demo() {
1046    let horizontal : boolean = true;
1047    let vertical : boolean = false;
1048    await pixelMap.flip(horizontal, vertical).then(() => {
1049        console.log('Sucessed in flipping pixelmap.');
1050    }).catch((err : BusinessError) => {
1051        console.error('Failed to flip pixelmap.');
1052    })
1053}
1054```
1055
1056### crop<sup>9+</sup>
1057
1058crop(region: Region, callback: AsyncCallback\<void>): void
1059
1060Crops this image based on the input size. This API uses an asynchronous callback to return the result.
1061
1062**System capability**: SystemCapability.Multimedia.Image.Core
1063
1064**Parameters**
1065
1066| Name  | Type                | Mandatory| Description                         |
1067| -------- | -------------------- | ---- | ----------------------------- |
1068| region   | [Region](#region7)   | Yes  | Size of the image after cropping.                 |
1069| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
1070
1071**Example**
1072
1073```ts
1074import {BusinessError} from '@ohos.base';
1075async function Demo() {
1076    let region : image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } };
1077    pixelMap.crop(region, (err : BusinessError) => {
1078        if (err != undefined) {
1079            console.error("Failed to crop pixelmap.");
1080            return;
1081        } else {
1082            console.log("Succeeded in cropping pixelmap.");
1083        }
1084    })
1085}
1086```
1087
1088### crop<sup>9+</sup>
1089
1090crop(region: Region): Promise\<void>
1091
1092Crops this image based on the input size. This API uses a promise to return the result.
1093
1094**System capability**: SystemCapability.Multimedia.Image.Core
1095
1096**Parameters**
1097
1098| Name| Type              | Mandatory| Description       |
1099| ------ | ------------------ | ---- | ----------- |
1100| region | [Region](#region7) | Yes  | Size of the image after cropping.|
1101
1102**Return value**
1103
1104| Type          | Description                       |
1105| -------------- | --------------------------- |
1106| Promise\<void> | Promise used to return the result.|
1107
1108**Example**
1109
1110```ts
1111import {BusinessError} from '@ohos.base';
1112async function Demo() {
1113    let region : image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } };
1114    await pixelMap.crop(region).then(() => {
1115        console.log('Sucessed in cropping pixelmap.');
1116    }).catch((err : BusinessError) => {
1117        console.error('Failed to crop pixelmap.');
1118    });
1119}
1120```
1121
1122### getColorSpace<sup>10+</sup>
1123
1124getColorSpace(): colorSpaceManager.ColorSpaceManager
1125
1126Obtains the color space of this image.
1127
1128**System capability**: SystemCapability.Multimedia.Image.Core
1129
1130**Return value**
1131
1132| Type                               | Description            |
1133| ----------------------------------- | ---------------- |
1134| [colorSpaceManager.ColorSpaceManager](js-apis-colorSpaceManager.md#colorspacemanager) | Color space obtained.|
1135
1136**Error codes**
1137
1138For details about the error codes, see [Image Error Codes](../errorcodes/errorcode-image.md).
1139
1140| ID| Error Message|
1141| ------- | --------------------------------------------|
1142| 62980101| If the image data abnormal.            |
1143| 62980103| If the image data unsupport.             |
1144| 62980115| If the image parameter invalid.            |
1145
1146**Example**
1147
1148```ts
1149async function Demo() {
1150    let csm = pixelMap.getColorSpace();
1151}
1152```
1153
1154### setColorSpace<sup>10+</sup>
1155
1156setColorSpace(colorSpace: colorSpaceManager.ColorSpaceManager): void
1157
1158Sets the color space for this image.
1159
1160**System capability**: SystemCapability.Multimedia.Image.Core
1161
1162**Parameters**
1163
1164| Name    | Type                               | Mandatory| Description           |
1165| ---------- | ----------------------------------- | ---- | --------------- |
1166| colorSpace | [colorSpaceManager.ColorSpaceManager](js-apis-colorSpaceManager.md#colorspacemanager) | Yes  | Color space to set.|
1167
1168**Error codes**
1169
1170For details about the error codes, see [Image Error Codes](../errorcodes/errorcode-image.md).
1171
1172| ID| Error Message|
1173| ------- | --------------------------------------------|
1174| 62980111| If the operation invalid.        |
1175| 62980115| If the image parameter invalid.             |
1176
1177**Example**
1178
1179```ts
1180import colorSpaceManager from '@ohos.graphics.colorSpaceManager';
1181async function Demo() {
1182    let colorSpaceName = colorSpaceManager.ColorSpace.SRGB;
1183    let csm : colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName);
1184    pixelMap.setColorSpace(csm);
1185}
1186```
1187
1188### applyColorSpace<sup>11+</sup>
1189
1190applyColorSpace(targetColorSpace: colorSpaceManager.ColorSpaceManager, callback: AsyncCallback\<void>): void
1191
1192Performs color space conversion (CSC) on the image pixel color based on a given color space. This API uses an asynchronous callback to return the result.
1193
1194**System capability**: SystemCapability.Multimedia.Image.Core
1195
1196**Parameters**
1197
1198| Name  | Type                | Mandatory| Description                         |
1199| -------- | -------------------- | ---- | ----------------------------- |
1200| targetColorSpace | [colorSpaceManager.ColorSpaceManager](js-apis-colorSpaceManager.md#colorspacemanager) | Yes  | Target color space. SRGB, DCI_P3, DISPLAY_P3, and ADOBE_RGB_1998 are supported.|
1201| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
1202
1203**Error codes**
1204
1205For details about the error codes, see [Image Error Codes](../errorcodes/errorcode-image.md).
1206
1207| ID| Error Message|
1208| ------- | ------------------------------------------|
1209| 401 | The parameter check failed. |
1210| 62980104| Failed to initialize the internal object. |
1211| 62980108| Failed to convert the color space.       |
1212| 62980115| Invalid image parameter.            |
1213
1214**Example**
1215
1216```ts
1217import colorSpaceManager from '@ohos.graphics.colorSpaceManager';
1218import {BusinessError} from '@ohos.base'
1219
1220async function Demo() {
1221    let colorSpaceName = colorSpaceManager.ColorSpace.SRGB;
1222    let targetColorSpace : colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName);
1223    pixelmap.applyColorSpace(targetColorSpace, (err : BusinessError) => {
1224        if (err) {
1225            console.error('Failed to apply color space for pixelmap object.');
1226            return;
1227        } else {
1228            console.log('Succeeded in applying color space for pixelmap object.');
1229        }
1230    })
1231}
1232```
1233
1234### applyColorSpace<sup>11+</sup>
1235
1236applyColorSpace(targetColorSpace: colorSpaceManager.ColorSpaceManager): Promise\<void>
1237
1238Performs CSC on the image pixel color based on a given color space. This API uses a promise to return the result.
1239
1240**System capability**: SystemCapability.Multimedia.Image.Core
1241
1242**Parameters**
1243
1244| Name| Type              | Mandatory| Description       |
1245| ------ | ------------------ | ---- | ----------- |
1246| targetColorSpace | [colorSpaceManager.ColorSpaceManager](js-apis-colorSpaceManager.md#colorspacemanager) | Yes  | Target color space. SRGB, DCI_P3, DISPLAY_P3, and ADOBE_RGB_1998 are supported.|
1247
1248**Return value**
1249
1250| Type          | Description                       |
1251| -------------- | --------------------------- |
1252| Promise\<void> | Promise used to return the result.|
1253
1254**Error codes**
1255
1256For details about the error codes, see [Image Error Codes](../errorcodes/errorcode-image.md).
1257
1258| ID| Error Message|
1259| ------- | ------------------------------------------|
1260| 401 | The parameter check failed. |
1261| 62980104| Failed to initialize the internal object. |
1262| 62980108| Failed to convert the color space.       |
1263| 62980115| Invalid image parameter.            |
1264
1265**Example**
1266
1267```ts
1268import colorSpaceManager from '@ohos.graphics.colorSpaceManager';
1269import {BusinessError} from '@ohos.base'
1270
1271async function Demo() {
1272    let colorSpaceName = colorSpaceManager.ColorSpace.SRGB;
1273    let targetColorSpace : colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName);
1274    pixelmap.applyColorSpace(targetColorSpace).then(() => {
1275        console.log('Succeeded in applying color space for pixelmap object.');
1276    }).catch((error : BusinessError) => {
1277        console.error('Failed to apply color space for pixelmap object.');
1278    })
1279}
1280```
1281
1282### marshalling<sup>10+</sup>
1283
1284marshalling(sequence: rpc.MessageSequence): void
1285
1286Marshals this **PixelMap** object and writes it to a **MessageSequence** object.
1287
1288**System capability**: SystemCapability.Multimedia.Image.Core
1289
1290**Parameters**
1291
1292| Name                | Type                                                 | Mandatory| Description                                    |
1293| ---------------------- | ------------------------------------------------------ | ---- | ---------------------------------------- |
1294| sequence               | [rpc.MessageSequence](js-apis-rpc.md#messagesequence9)  | Yes  | **MessageSequence** object.                |
1295
1296**Error codes**
1297
1298For details about the error codes, see [Image Error Codes](../errorcodes/errorcode-image.md).
1299
1300| ID| Error Message|
1301| ------- | --------------------------------------------|
1302| 62980115 | Invalid image parameter.              |
1303| 62980097 | IPC error.             |
1304
1305**Example**
1306
1307```ts
1308import image from '@ohos.multimedia.image';
1309import rpc from '@ohos.rpc';
1310class MySequence implements rpc.Parcelable {
1311    pixel_map : image.PixelMap;
1312    constructor(conPixelMap : image.PixelMap) {
1313        this.pixel_map = conPixelMap;
1314    }
1315    marshalling(messageSequence : rpc.MessageSequence) {
1316        this.pixel_map.marshalling(messageSequence);
1317        console.log('marshalling');
1318        return true;
1319    }
1320    unmarshalling(messageSequence : rpc.MessageSequence) {
1321      image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}}).then((pixelParcel : image.PixelMap) => {
1322        pixelParcel.unmarshalling(messageSequence).then(async (pixelMap : image.PixelMap) => {
1323          this.pixel_map = pixelMap;
1324          await pixelMap.getImageInfo().then((imageInfo : image.ImageInfo) => {
1325            console.log("unmarshalling information h:" + imageInfo.size.height + "w:" + imageInfo.size.width);
1326          })
1327        })
1328      });
1329      return true;
1330    }
1331}
1332async function Demo() {
1333   const color : ArrayBuffer = new ArrayBuffer(96);
1334   let bufferArr : Uint8Array = new Uint8Array(color);
1335   for (let i = 0; i < bufferArr.length; i++) {
1336      bufferArr[i] = 0x80;
1337   }
1338   let opts : image.InitializationOptions = {
1339      editable: true,
1340      pixelFormat: 4,
1341      size: { height: 4, width: 6 },
1342      alphaType: 3
1343   }
1344   let pixelMap : image.PixelMap | undefined = undefined;
1345   await image.createPixelMap(color, opts).then((srcPixelMap : image.PixelMap) => {
1346      pixelMap = srcPixelMap;
1347   })
1348   if (pixelMap != undefined) {
1349     // Implement serialization.
1350     let parcelable : MySequence = new MySequence(pixelMap);
1351     let data : rpc.MessageSequence = rpc.MessageSequence.create();
1352     data.writeParcelable(parcelable);
1353
1354
1355     // Deserialize to obtain data through the RPC.
1356     let ret : MySequence = new MySequence(pixelMap);
1357     data.readParcelable(ret);
1358   }
1359}
1360```
1361
1362### unmarshalling<sup>10+</sup>
1363
1364unmarshalling(sequence: rpc.MessageSequence): Promise\<PixelMap>
1365
1366Unmarshals a **MessageSequence** object to obtain a **PixelMap** object.
1367To create a **PixelMap** object in synchronous mode, use [createPixelMapFromParcel](#imagecreatepixelmapfromparcel11).
1368
1369**System capability**: SystemCapability.Multimedia.Image.Core
1370
1371**Parameters**
1372
1373| Name                | Type                                                 | Mandatory| Description                                    |
1374| ---------------------- | ----------------------------------------------------- | ---- | ---------------------------------------- |
1375| sequence               | [rpc.MessageSequence](js-apis-rpc.md#messagesequence9) | Yes  | **MessageSequence** object that stores the **PixelMap** information.     |
1376
1377**Return value**
1378
1379| Type                            | Description                 |
1380| -------------------------------- | --------------------- |
1381| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the result. If the operation fails, an error message is returned.|
1382
1383**Error codes**
1384
1385For details about the error codes, see [Image Error Codes](../errorcodes/errorcode-image.md).
1386
1387| ID| Error Message|
1388| ------- | --------------------------------------------|
1389| 62980115 | Invalid image parameter.              |
1390| 62980097 | IPC error.              |
1391| 62980096 | The operation failed.         |
1392
1393**Example**
1394
1395```ts
1396import image from '@ohos.multimedia.image';
1397import rpc from '@ohos.rpc';
1398class MySequence implements rpc.Parcelable {
1399    pixel_map : image.PixelMap;
1400    constructor(conPixelMap : image.PixelMap) {
1401        this.pixel_map = conPixelMap;
1402    }
1403    marshalling(messageSequence : rpc.MessageSequence) {
1404        this.pixel_map.marshalling(messageSequence);
1405        console.log('marshalling');
1406        return true;
1407    }
1408    unmarshalling(messageSequence : rpc.MessageSequence) {
1409      image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}}).then((pixelParcel : image.PixelMap) => {
1410        pixelParcel.unmarshalling(messageSequence).then(async (pixelMap : image.PixelMap) => {
1411          this.pixel_map = pixelMap;
1412          await pixelMap.getImageInfo().then((imageInfo : image.ImageInfo) => {
1413            console.log("unmarshalling information h:" + imageInfo.size.height + "w:" + imageInfo.size.width);
1414          })
1415        })
1416      });
1417      return true;
1418    }
1419}
1420async function Demo() {
1421   const color : ArrayBuffer = new ArrayBuffer(96);
1422   let bufferArr : Uint8Array = new Uint8Array(color);
1423   for (let i = 0; i < bufferArr.length; i++) {
1424      bufferArr[i] = 0x80;
1425   }
1426   let opts : image.InitializationOptions = {
1427      editable: true,
1428      pixelFormat: 4,
1429      size: { height: 4, width: 6 },
1430      alphaType: 3
1431   }
1432   let pixelMap : image.PixelMap | undefined = undefined;
1433   await image.createPixelMap(color, opts).then((srcPixelMap : image.PixelMap) => {
1434      pixelMap = srcPixelMap;
1435   })
1436   if (pixelMap != undefined) {
1437     // Implement serialization.
1438     let parcelable : MySequence = new MySequence(pixelMap);
1439     let data : rpc.MessageSequence = rpc.MessageSequence.create();
1440     data.writeParcelable(parcelable);
1441
1442
1443     // Deserialize to obtain data through the RPC.
1444     let ret : MySequence = new MySequence(pixelMap);
1445     data.readParcelable(ret);
1446   }
1447}
1448```
1449
1450### release<sup>7+</sup>
1451
1452release():Promise\<void>
1453
1454Releases this **PixelMap** object. This API uses a promise to return the result.
1455
1456**System capability**: SystemCapability.Multimedia.Image.Core
1457
1458**Return value**
1459
1460| Type          | Description                           |
1461| -------------- | ------------------------------- |
1462| Promise\<void> | Promise used to return the result.|
1463
1464**Example**
1465
1466```ts
1467import {BusinessError} from '@ohos.base';
1468async function Demo() {
1469    pixelMap.release().then(() => {
1470        console.log('Succeeded in releasing pixelmap object.');
1471    }).catch((error : BusinessError) => {
1472        console.error('Failed to release pixelmap object.');
1473    })
1474}
1475```
1476
1477### release<sup>7+</sup>
1478
1479release(callback: AsyncCallback\<void>): void
1480
1481Releases this **PixelMap** object. This API uses an asynchronous callback to return the result.
1482
1483**System capability**: SystemCapability.Multimedia.Image.Core
1484
1485**Parameters**
1486
1487| Name  | Type                | Mandatory| Description              |
1488| -------- | -------------------- | ---- | ------------------ |
1489| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
1490
1491**Example**
1492
1493```ts
1494import {BusinessError} from '@ohos.base';
1495async function Demo() {
1496    pixelMap.release((err : BusinessError) => {
1497        if (err != undefined) {
1498            console.error('Failed to release pixelmap object.');
1499            return;
1500        } else {
1501            console.log('Succeeded in releasing pixelmap object.');
1502        }
1503    })
1504}
1505```
1506
1507## image.createImageSource
1508
1509createImageSource(uri: string): ImageSource
1510
1511Creates an **ImageSource** instance based on the URI.
1512
1513**System capability**: SystemCapability.Multimedia.Image.ImageSource
1514
1515**Parameters**
1516
1517| Name| Type  | Mandatory| Description                              |
1518| ------ | ------ | ---- | ---------------------------------- |
1519| 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, raw [SVG<sup>10+</sup>](#svg), and .ico<sup>11+</sup>.|
1520
1521**Return value**
1522
1523| Type                       | Description                                        |
1524| --------------------------- | -------------------------------------------- |
1525| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.|
1526
1527**Example**
1528
1529```ts
1530// Stage model
1531const context : Context = getContext(this);
1532const path : string = context.cacheDir + "/test.jpg";
1533const imageSourceApi : image.ImageSource = image.createImageSource(path);
1534```
1535
1536```ts
1537// FA model
1538import featureAbility from '@ohos.ability.featureAbility';
1539
1540const context : featureAbility.Context = featureAbility.getContext();
1541const path : string = context.getCacheDir() + "/test.jpg";
1542const imageSourceApi : image.ImageSource = image.createImageSource(path);
1543```
1544
1545## image.createImageSource<sup>9+</sup>
1546
1547createImageSource(uri: string, options: SourceOptions): ImageSource
1548
1549Creates an **ImageSource** instance based on the URI.
1550
1551**System capability**: SystemCapability.Multimedia.Image.ImageSource
1552
1553**Parameters**
1554
1555| Name | Type                           | Mandatory| Description                               |
1556| ------- | ------------------------------- | ---- | ----------------------------------- |
1557| 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, raw [SVG<sup>10+</sup>](#svg), and .ico<sup>11+</sup>.|
1558| options | [SourceOptions](#sourceoptions9) | Yes  | Image properties, including the image index and default property value.|
1559
1560**Return value**
1561
1562| Type                       | Description                                        |
1563| --------------------------- | -------------------------------------------- |
1564| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.|
1565
1566**Example**
1567
1568```ts
1569let sourceOptions : image.SourceOptions = { sourceDensity: 120 };
1570let imageSource : image.ImageSource = image.createImageSource('test.png', sourceOptions);
1571```
1572
1573## image.createImageSource<sup>7+</sup>
1574
1575createImageSource(fd: number): ImageSource
1576
1577Creates an **ImageSource** instance based on the file descriptor.
1578
1579**System capability**: SystemCapability.Multimedia.Image.ImageSource
1580
1581**Parameters**
1582
1583| Name| Type  | Mandatory| Description         |
1584| ------ | ------ | ---- | ------------- |
1585| fd     | number | Yes  | File descriptor.|
1586
1587**Return value**
1588
1589| Type                       | Description                                        |
1590| --------------------------- | -------------------------------------------- |
1591| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.|
1592
1593**Example**
1594
1595```ts
1596const imageSourceApi : image.ImageSource = image.createImageSource(0);
1597```
1598
1599## image.createImageSource<sup>9+</sup>
1600
1601createImageSource(fd: number, options: SourceOptions): ImageSource
1602
1603Creates an **ImageSource** instance based on the file descriptor.
1604
1605**System capability**: SystemCapability.Multimedia.Image.ImageSource
1606
1607**Parameters**
1608
1609| Name | Type                           | Mandatory| Description                               |
1610| ------- | ------------------------------- | ---- | ----------------------------------- |
1611| fd      | number                          | Yes  | File descriptor.                     |
1612| options | [SourceOptions](#sourceoptions9) | Yes  | Image properties, including the image index and default property value.|
1613
1614**Return value**
1615
1616| Type                       | Description                                        |
1617| --------------------------- | -------------------------------------------- |
1618| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.|
1619
1620**Example**
1621
1622```ts
1623let sourceOptions : image.SourceOptions = { sourceDensity: 120 };
1624const imageSourceApi : image.ImageSource = image.createImageSource(0, sourceOptions);
1625```
1626
1627## image.createImageSource<sup>9+</sup>
1628
1629createImageSource(buf: ArrayBuffer): ImageSource
1630
1631Creates an **ImageSource** instance based on the buffers.
1632
1633**System capability**: SystemCapability.Multimedia.Image.ImageSource
1634
1635**Parameters**
1636
1637| Name| Type       | Mandatory| Description            |
1638| ------ | ----------- | ---- | ---------------- |
1639| buf    | ArrayBuffer | Yes  | Array of image buffers.|
1640
1641**Return value**
1642
1643| Type                       | Description                                        |
1644| --------------------------- | -------------------------------------------- |
1645| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.|
1646
1647
1648**Example**
1649
1650```ts
1651const buf : ArrayBuffer = 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.
1652const imageSourceApi : image.ImageSource = image.createImageSource(buf);
1653```
1654
1655## image.createImageSource<sup>9+</sup>
1656
1657createImageSource(buf: ArrayBuffer, options: SourceOptions): ImageSource
1658
1659Creates an **ImageSource** instance based on the buffers.
1660
1661**System capability**: SystemCapability.Multimedia.Image.ImageSource
1662
1663**Parameters**
1664
1665| Name| Type                            | Mandatory| Description                                |
1666| ------ | -------------------------------- | ---- | ------------------------------------ |
1667| buf    | ArrayBuffer                      | Yes  | Array of image buffers.                    |
1668| options | [SourceOptions](#sourceoptions9) | Yes  | Image properties, including the image index and default property value.|
1669
1670**Return value**
1671
1672| Type                       | Description                                        |
1673| --------------------------- | -------------------------------------------- |
1674| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.|
1675
1676**Example**
1677
1678```ts
1679const data : ArrayBuffer= new ArrayBuffer(112);
1680let sourceOptions : image.SourceOptions = { sourceDensity: 120 };
1681const imageSourceApi : image.ImageSource = image.createImageSource(data, sourceOptions);
1682```
1683
1684## image.createImageSource<sup>11+</sup>
1685
1686createImageSource(rawfile: resourceManager.RawFileDescriptor, options?: SourceOptions): ImageSource
1687
1688Creates an **ImageSource** instance by using the raw file descriptor of the image resource file.
1689
1690**System capability**: SystemCapability.Multimedia.Image.ImageSource
1691
1692**Parameters**
1693
1694| Name| Type                            | Mandatory| Description                                |
1695| ------ | -------------------------------- | ---- | ------------------------------------ |
1696| rawfile | [resourceManager.RawFileDescriptor](js-apis-resource-manager.md#rawfiledescriptor8) | Yes| Raw file descriptor of the image resource file.|
1697| options | [SourceOptions](#sourceoptions9) | No| Image properties, including the image index and default property value.|
1698
1699**Return value**
1700
1701| Type                       | Description                                        |
1702| --------------------------- | -------------------------------------------- |
1703| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.|
1704
1705**Example**
1706
1707Stage model
1708
1709```ts
1710import resourceManager from '@ohos.resourceManager';
1711
1712// Code on the stage model
1713const context : Context = getContext(this);
1714// Obtain a resource manager.
1715const resourceMgr: resourceManager.ResourceManager = context.resourceManager;
1716resourceMgr.getRawFd('test.jpg').then((rawFileDescriptor : resourceManager.RawFileDescriptor) => {
1717    const imageSourceApi: image.ImageSource = image.createImageSource(rawFileDescriptor);
1718}).catch((error : BusinessError) => {
1719    console.error(`Failed to get RawFileDescriptor.code is ${error.code}, message is ${error.message}`);
1720})
1721```
1722
1723## image.CreateIncrementalSource<sup>9+</sup>
1724
1725CreateIncrementalSource(buf: ArrayBuffer): ImageSource
1726
1727Creates an **ImageSource** instance in incremental mode based on the buffers.
1728
1729**System capability**: SystemCapability.Multimedia.Image.ImageSource
1730
1731**Parameters**
1732
1733| Name | Type       | Mandatory| Description     |
1734| ------- | ------------| ---- | ----------|
1735| buf     | ArrayBuffer | Yes  | Incremental data.|
1736
1737**Return value**
1738
1739| Type                       | Description                             |
1740| --------------------------- | --------------------------------- |
1741| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns undefined otherwise.|
1742
1743**Example**
1744
1745```ts
1746const buf : ArrayBuffer = 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.
1747const imageSourceIncrementalSApi : image.ImageSource = image.CreateIncrementalSource(buf);
1748```
1749
1750## image.CreateIncrementalSource<sup>9+</sup>
1751
1752CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource
1753
1754Creates an **ImageSource** instance in incremental mode based on the buffers.
1755
1756**System capability**: SystemCapability.Multimedia.Image.ImageSource
1757
1758**Parameters**
1759
1760| Name | Type                           | Mandatory| Description                                |
1761| ------- | ------------------------------- | ---- | ------------------------------------ |
1762| buf     | ArrayBuffer                     | Yes  | Incremental data.                          |
1763| options | [SourceOptions](#sourceoptions9) | No  | Image properties, including the image index and default property value.|
1764
1765**Return value**
1766
1767| Type                       | Description                             |
1768| --------------------------- | --------------------------------- |
1769| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns undefined otherwise.|
1770
1771**Example**
1772
1773```ts
1774const buf : ArrayBuffer = 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.
1775const imageSourceIncrementalSApi : image.ImageSource = image.CreateIncrementalSource(buf);
1776```
1777
1778## ImageSource
1779
1780Provides APIs to obtain image information. Before calling any API in **ImageSource**, you must use [createImageSource](#imagecreateimagesource) to create an **ImageSource** instance.
1781
1782### Attributes
1783
1784**System capability**: SystemCapability.Multimedia.Image.ImageSource
1785
1786| Name            | Type          | Readable| Writable| Description                                                        |
1787| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
1788| supportedFormats | Array\<string> | Yes  | No  | Supported image formats, including PNG, JPEG, BMP, GIF, WebP, and RAW.|
1789
1790### getImageInfo
1791
1792getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void
1793
1794Obtains information about an image with the specified index. This API uses an asynchronous callback to return the result.
1795
1796**System capability**: SystemCapability.Multimedia.Image.ImageSource
1797
1798**Parameters**
1799
1800| Name  | Type                                  | Mandatory| Description                                    |
1801| -------- | -------------------------------------- | ---- | ---------------------------------------- |
1802| index    | number                                 | Yes  | Index of the image.                    |
1803| callback | AsyncCallback<[ImageInfo](#imageinfo)> | Yes  | Callback used to return the image information.|
1804
1805**Example**
1806
1807```ts
1808import {BusinessError} from '@ohos.base';
1809imageSourceApi.getImageInfo(0,(error : BusinessError, imageInfo : image.ImageInfo) => {
1810    if(error) {
1811        console.error('getImageInfo failed.');
1812    } else {
1813        console.log('getImageInfo succeeded.');
1814    }
1815})
1816```
1817
1818### getImageInfo
1819
1820getImageInfo(callback: AsyncCallback\<ImageInfo>): void
1821
1822Obtains information about this image. This API uses an asynchronous callback to return the result.
1823
1824**System capability**: SystemCapability.Multimedia.Image.ImageSource
1825
1826**Parameters**
1827
1828| Name  | Type                                  | Mandatory| Description                                    |
1829| -------- | -------------------------------------- | ---- | ---------------------------------------- |
1830| callback | AsyncCallback<[ImageInfo](#imageinfo)> | Yes  | Callback used to return the image information.|
1831
1832**Example**
1833
1834```ts
1835import {BusinessError} from '@ohos.base';
1836imageSourceApi.getImageInfo((err : BusinessError, imageInfo : image.ImageInfo) => {
1837    if (err != undefined) {
1838        console.error(`Failed to obtaining the image information.code is ${err.code}, message is ${err.message}`);
1839    } else {
1840        console.log('Succeeded in obtaining the image information.');
1841    }
1842})
1843```
1844
1845### getImageInfo
1846
1847getImageInfo(index?: number): Promise\<ImageInfo>
1848
1849Obtains information about an image with the specified index. This API uses a promise to return the result.
1850
1851**System capability**: SystemCapability.Multimedia.Image.ImageSource
1852
1853**Parameters**
1854
1855| Name| Type  | Mandatory| Description                                 |
1856| ----- | ------ | ---- | ------------------------------------- |
1857| index | number | No  | Index of the image. If this parameter is not set, the default value **0** is used.|
1858
1859**Return value**
1860
1861| Type                            | Description                  |
1862| -------------------------------- | ---------------------- |
1863| Promise<[ImageInfo](#imageinfo)> | Promise used to return the image information.|
1864
1865**Example**
1866
1867```ts
1868import {BusinessError} from '@ohos.base';
1869imageSourceApi.getImageInfo(0)
1870    .then((imageInfo : image.ImageInfo) => {
1871		console.log('Succeeded in obtaining the image information.');
1872	}).catch((error : BusinessError) => {
1873		console.error('Failed to obtain the image information.');
1874	})
1875```
1876
1877### getImageProperty<sup>11+</sup>
1878
1879getImageProperty(key:PropertyKey, options?: ImagePropertyOptions): Promise\<string>
1880
1881Obtains the value of a property with the specified index in this image. This API uses a promise to return the result. The image must be in JPEG format and contain EXIF information.
1882
1883**System capability**: SystemCapability.Multimedia.Image.ImageSource
1884
1885**Parameters**
1886
1887| Name | Type                                                | Mandatory| Description                                |
1888| ------- | ---------------------------------------------------- | ---- | ------------------------------------ |
1889| key     | [PropertyKey](#propertykey7)                                               | Yes  | Name of the property.                        |
1890| options | [ImagePropertyOptions](#imagepropertyoptions11) | No  | Image properties, including the image index and default property value.|
1891
1892**Return value**
1893
1894| Type            | Description                                                             |
1895| ---------------- | ----------------------------------------------------------------- |
1896| Promise\<string> | Promise used to return the property value. If the operation fails, the default value is returned.|
1897
1898**Error codes**
1899
1900For details about the error codes, see [Image Error Codes](../errorcodes/errorcode-image.md).
1901
1902| ID| Error Message|
1903| ------- | --------------------------------------------|
1904| 401  | The parameter check failed.              |
1905| 62980096| The operation failed.             |
1906| 62980103| The image data is not supported.            |
1907| 62980110| The image source data is incorrect.            |
1908| 62980111| The image source data is incomplete.             |
1909| 62980112| The image format does not match.             |
1910| 62980113| Unknown image format.             |
1911| 62980115| Invalid image parameter.             |
1912| 62980116| Failed to decode the image.              |
1913| 62980118| Failed to create the image plugin.           |
1914| 62980122| The image decoding header is abnormal.           |
1915| 62980123| Images in EXIF format are not supported.             |
1916| 62980135| The EXIF value is invalid.            |
1917
1918**Example**
1919
1920```ts
1921import {BusinessError} from '@ohos.base';
1922let options : image.ImagePropertyOptions = { index: 0, defaultValue: '9999' }
1923imageSourceApi.getImageProperty(image.PropertyKey.BITS_PER_SAMPLE, options)
1924.then((data : string) => {
1925    console.log('Succeeded in getting the value of the specified attribute key of the image.');
1926}).catch((error : BusinessError) => {
1927    console.error('Failed to get the value of the specified attribute key of the image.');
1928})
1929```
1930
1931### getImageProperty<sup>(deprecated)</sup>
1932
1933getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\<string>
1934
1935Obtains the value of a property with the specified index in this image. This API uses a promise to return the result. The image must be in JPEG format and contain EXIF information.
1936
1937> **NOTE**
1938>
1939> This API is deprecated since API version 11. You are advised to use [getImageProperty](#getimageproperty11).
1940
1941**System capability**: SystemCapability.Multimedia.Image.ImageSource
1942
1943**Parameters**
1944
1945| Name | Type                                                | Mandatory| Description                                |
1946| ------- | ---------------------------------------------------- | ---- | ------------------------------------ |
1947| key     | string                                               | Yes  | Name of the property.                        |
1948| options | [GetImagePropertyOptions](#getimagepropertyoptionsdeprecated) | No  | Image properties, including the image index and default property value.|
1949
1950**Return value**
1951
1952| Type            | Description                                                             |
1953| ---------------- | ----------------------------------------------------------------- |
1954| Promise\<string> | Promise used to return the property value. If the operation fails, the default value is returned.|
1955
1956**Example**
1957
1958```ts
1959import {BusinessError} from '@ohos.base';
1960imageSourceApi.getImageProperty("BitsPerSample")
1961    .then((data : string) => {
1962		console.log('Succeeded in getting the value of the specified attribute key of the image.');
1963	}).catch((error : BusinessError) => {
1964		console.error('Failed to get the value of the specified attribute key of the image.');
1965	})
1966```
1967
1968### getImageProperty<sup>(deprecated)</sup>
1969
1970getImageProperty(key:string, callback: AsyncCallback\<string>): void
1971
1972Obtains the value of a property with the specified index in this image. This API uses an asynchronous callback to return the result. The image must be in JPEG format and contain EXIF information.
1973
1974> **NOTE**
1975>
1976> This API is deprecated since API version 11. You are advised to use [getImageProperty](#getimageproperty11).
1977
1978**System capability**: SystemCapability.Multimedia.Image.ImageSource
1979
1980**Parameters**
1981
1982| Name  | Type                  | Mandatory| Description                                                        |
1983| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
1984| key      | string                 | Yes  | Name of the property.                                                |
1985| callback | AsyncCallback\<string> | Yes  | Callback used to return the property value. If the operation fails, the default value is returned.|
1986
1987**Example**
1988
1989```ts
1990import {BusinessError} from '@ohos.base';
1991imageSourceApi.getImageProperty("BitsPerSample",(error : BusinessError, data : string) => {
1992    if(error) {
1993        console.error('Failed to get the value of the specified attribute key of the image.');
1994    } else {
1995        console.log('Succeeded in getting the value of the specified attribute key of the image.');
1996    }
1997})
1998```
1999
2000### getImageProperty<sup>(deprecated)</sup>
2001
2002getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCallback\<string>): void
2003
2004Obtains the value of a property in this image. This API uses an asynchronous callback to return the result. The image must be in JPEG format and contain EXIF information.
2005
2006> **NOTE**
2007>
2008> This API is deprecated since API version 11. You are advised to use [getImageProperty](#getimageproperty11).
2009
2010**System capability**: SystemCapability.Multimedia.Image.ImageSource
2011
2012**Parameters**
2013
2014| Name  | Type                                                | Mandatory| Description                                                         |
2015| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------- |
2016| key      | string                                               | Yes  | Name of the property.                                                 |
2017| options  | [GetImagePropertyOptions](#getimagepropertyoptionsdeprecated) | Yes  | Image properties, including the image index and default property value.                         |
2018| callback | AsyncCallback\<string>                               | Yes  | Callback used to return the property value. If the operation fails, the default value is returned.|
2019
2020**Example**
2021
2022```ts
2023import {BusinessError} from '@ohos.base';
2024let property : image.GetImagePropertyOptions = { index: 0, defaultValue: '9999' }
2025imageSourceApi.getImageProperty("BitsPerSample",property,(error : BusinessError, data : string) => {
2026    if(error) {
2027        console.error('Failed to get the value of the specified attribute key of the image.');
2028    } else {
2029        console.log('Succeeded in getting the value of the specified attribute key of the image.');
2030    }
2031})
2032```
2033
2034### modifyImageProperty<sup>11+</sup>
2035
2036modifyImageProperty(key: PropertyKey, value: string): Promise\<void>
2037
2038Modifies the value of a property in this image. This API uses a promise to return the result. The image must be in JPEG format and contain EXIF information.
2039
2040**System capability**: SystemCapability.Multimedia.Image.ImageSource
2041
2042**Parameters**
2043
2044| Name | Type  | Mandatory| Description        |
2045| ------- | ------ | ---- | ------------ |
2046| key     | [PropertyKey](#propertykey7)   | Yes  | Name of the property.|
2047| value   | string | Yes  | New value of the property.    |
2048
2049**Return value**
2050
2051| Type          | Description                       |
2052| -------------- | --------------------------- |
2053| Promise\<void> | Promise used to return the result.|
2054
2055**Error codes**
2056
2057For details about the error codes, see [Image Error Codes](../errorcodes/errorcode-image.md).
2058
2059| ID| Error Message|
2060| ------- | --------------------------------------------|
2061| 401  | The parameter check failed.              |
2062| 62980123| Images in EXIF format are not supported.             |
2063| 62980133| The EXIF data is out of range.    |
2064| 62980135| The EXIF value is invalid.             |
2065| 62980146| The EXIF data failed to be written to the file.        |
2066
2067**Example**
2068
2069```ts
2070import {BusinessError} from '@ohos.base';
2071imageSourceApi.modifyImageProperty(image.PropertyKey.IMAGE_WIDTH, "120").then(() => {
2072    imageSourceApi.getImageProperty(image.PropertyKey.IMAGE_WIDTH).then((width : string) => {
2073        console.info(`ImageWidth is :${width}`);
2074    }).catch((error : BusinessError) => {
2075        console.error('Failed to get the Image Width.');
2076	})
2077}).catch((error : BusinessError) => {
2078	console.error('Failed to modify the Image Width');
2079})
2080```
2081
2082### modifyImageProperty<sup>(deprecated)</sup>
2083
2084modifyImageProperty(key: string, value: string): Promise\<void>
2085
2086Modifies the value of a property in this image. This API uses a promise to return the result. The image must be in JPEG format and contain EXIF information.
2087
2088> **NOTE**
2089>
2090> This API is deprecated since API version 11. You are advised to use [modifyImageProperty](#modifyimageproperty11).
2091
2092**System capability**: SystemCapability.Multimedia.Image.ImageSource
2093
2094**Parameters**
2095
2096| Name | Type  | Mandatory| Description        |
2097| ------- | ------ | ---- | ------------ |
2098| key     | string | Yes  | Name of the property.|
2099| value   | string | Yes  | New value of the property.    |
2100
2101**Return value**
2102
2103| Type          | Description                       |
2104| -------------- | --------------------------- |
2105| Promise\<void> | Promise used to return the result.|
2106
2107**Example**
2108
2109```ts
2110import {BusinessError} from '@ohos.base';
2111imageSourceApi.modifyImageProperty("ImageWidth", "120").then(() => {
2112    imageSourceApi.getImageProperty("ImageWidth").then((width : string) => {
2113        console.info(`ImageWidth is :${width}`);
2114    }).catch((error : BusinessError) => {
2115        console.error('Failed to get the Image Width.');
2116	})
2117}).catch((error : BusinessError) => {
2118	console.error('Failed to modify the Image Width');
2119})
2120```
2121
2122### modifyImageProperty<sup>(deprecated)</sup>
2123
2124modifyImageProperty(key: string, value: string, callback: AsyncCallback\<void>): void
2125
2126Modifies the value of a property in this image. This API uses an asynchronous callback to return the result. The image must be in JPEG format and contain EXIF information.
2127
2128> **NOTE**
2129>
2130> This API is deprecated since API version 11. You are advised to use [modifyImageProperty](#modifyimageproperty11).
2131
2132**System capability**: SystemCapability.Multimedia.Image.ImageSource
2133
2134**Parameters**
2135
2136| Name  | Type               | Mandatory| Description                          |
2137| -------- | ------------------- | ---- | ------------------------------ |
2138| key      | string              | Yes  | Name of the property.                  |
2139| value    | string              | Yes  | New value of the property.                      |
2140| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
2141
2142**Example**
2143
2144```ts
2145import {BusinessError} from '@ohos.base';
2146imageSourceApi.modifyImageProperty("ImageWidth", "120",(err : BusinessError) => {
2147    if (err != undefined) {
2148        console.error('modifyImageProperty Failed');
2149    } else {
2150        console.info('modifyImageProperty Succeeded');
2151    }
2152})
2153```
2154
2155### updateData<sup>9+</sup>
2156
2157updateData(buf: ArrayBuffer, isFinished: boolean, offset: number, length: number): Promise\<void>
2158
2159Updates incremental data. This API uses a promise to return the result.
2160
2161**System capability**: SystemCapability.Multimedia.Image.ImageSource
2162
2163**Parameters**
2164
2165| Name    | Type       | Mandatory| Description        |
2166| ---------- | ----------- | ---- | ------------ |
2167| buf        | ArrayBuffer | Yes  | Incremental data.  |
2168| isFinished | boolean     | Yes  | Whether the update is complete.|
2169| offset      | number      | Yes  | Offset for data reading.    |
2170| length     | number      | Yes  | Array length.    |
2171
2172**Return value**
2173
2174| Type          | Description                      |
2175| -------------- | -------------------------- |
2176| Promise\<void> | Promise used to return the result.|
2177
2178**Example**
2179
2180```ts
2181import {BusinessError} from '@ohos.base';
2182const array : ArrayBuffer = new ArrayBuffer(100);
2183imageSourceApi.updateData(array, false, 0, 10).then(() => {
2184    console.info('Succeeded in updating data.');
2185}).catch((err: BusinessError) => {
2186    console.error(`Failed to update data.code is ${err.code},message is ${err.message}`);
2187})
2188```
2189
2190
2191### updateData<sup>9+</sup>
2192
2193updateData(buf: ArrayBuffer, isFinished: boolean, offset: number, length: number, callback: AsyncCallback\<void>): void
2194
2195Updates incremental data. This API uses an asynchronous callback to return the result.
2196
2197**System capability**: SystemCapability.Multimedia.Image.ImageSource
2198
2199**Parameters**
2200
2201| Name    | Type               | Mandatory| Description                |
2202| ---------- | ------------------- | ---- | -------------------- |
2203| buf        | ArrayBuffer         | Yes  | Incremental data.          |
2204| isFinished | boolean             | Yes  | Whether the update is complete.        |
2205| offset      | number              | Yes  | Offset for data reading.            |
2206| length     | number              | Yes  | Array length.            |
2207| callback   | AsyncCallback\<void> | Yes  | Callback used to return the result.|
2208
2209**Example**
2210
2211```ts
2212import {BusinessError} from '@ohos.base';
2213const array : ArrayBuffer = new ArrayBuffer(100);
2214imageSourceApi.updateData(array, false, 0, 10, (err: BusinessError) => {
2215    if (err != undefined) {
2216        console.error(`Failed to update data.code is ${err.code},message is ${err.message}`);
2217    } else {
2218        console.info('Succeeded in updating data.');
2219    }
2220})
2221```
2222
2223### createPixelMap<sup>7+</sup>
2224
2225createPixelMap(options?: DecodingOptions): Promise\<PixelMap>
2226
2227Creates a **PixelMap** object based on image decoding parameters. This API uses a promise to return the result.
2228
2229**System capability**: SystemCapability.Multimedia.Image.ImageSource
2230
2231**Parameters**
2232
2233| Name | Type                                | Mandatory| Description      |
2234| ------- | ------------------------------------ | ---- | ---------- |
2235| options | [DecodingOptions](#decodingoptions7) | No  | Image decoding parameters.|
2236
2237**Return value**
2238
2239| Type                            | Description                 |
2240| -------------------------------- | --------------------- |
2241| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.|
2242
2243**Example**
2244
2245```ts
2246import {BusinessError} from '@ohos.base';
2247imageSourceApi.createPixelMap().then((pixelMap : image.PixelMap) => {
2248    console.log('Succeeded in creating pixelMap object through image decoding parameters.');
2249}).catch((error : BusinessError) => {
2250    console.error('Failed to create pixelMap object through image decoding parameters.');
2251})
2252```
2253
2254### createPixelMap<sup>7+</sup>
2255
2256createPixelMap(callback: AsyncCallback\<PixelMap>): void
2257
2258Creates a **PixelMap** object based on the default parameters. This API uses an asynchronous callback to return the result.
2259
2260**System capability**: SystemCapability.Multimedia.Image.ImageSource
2261
2262**Parameters**
2263
2264| Name    | Type                                 | Mandatory| Description                      |
2265| -------- | ------------------------------------- | ---- | -------------------------- |
2266| callback | AsyncCallback<[PixelMap](#pixelmap7)> | Yes  | Callback used to return the **PixelMap** object.|
2267
2268**Example**
2269
2270```ts
2271import {BusinessError} from '@ohos.base';
2272imageSourceApi.createPixelMap((err : BusinessError, pixelMap : image.PixelMap) => {
2273    if (err != undefined) {
2274        console.error(`Failed to create pixelMap.code is ${err.code},message is ${err.message}`);
2275    } else {
2276        console.info('Succeeded in creating pixelMap object.');
2277    }
2278})
2279```
2280
2281### createPixelMap<sup>7+</sup>
2282
2283createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): void
2284
2285Creates a **PixelMap** object based on image decoding parameters. This API uses an asynchronous callback to return the result.
2286
2287**System capability**: SystemCapability.Multimedia.Image.ImageSource
2288
2289**Parameters**
2290
2291| Name  | Type                                 | Mandatory| Description                      |
2292| -------- | ------------------------------------- | ---- | -------------------------- |
2293| options  | [DecodingOptions](#decodingoptions7)  | Yes  | Image decoding parameters.                |
2294| callback | AsyncCallback<[PixelMap](#pixelmap7)> | Yes  | Callback used to return the **PixelMap** object.|
2295
2296**Example**
2297
2298```ts
2299import {BusinessError} from '@ohos.base';
2300let decodingOptions : image.DecodingOptions = {
2301    sampleSize: 1,
2302    editable: true,
2303    desiredSize: { width: 1, height: 2 },
2304    rotate: 10,
2305    desiredPixelFormat: 3,
2306    desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 },
2307    index: 0
2308};
2309imageSourceApi.createPixelMap(decodingOptions, (err : BusinessError, pixelMap : image.PixelMap) => {
2310    if (err != undefined) {
2311        console.error(`Failed to create pixelMap.code is ${err.code},message is ${err.message}`);
2312    } else {
2313        console.log('Succeeded in creating pixelMap object.');
2314    }
2315})
2316```
2317
2318### createPixelMapList<sup>10+</sup>
2319
2320createPixelMapList(options?: DecodingOptions): Promise<Array\<PixelMap>>
2321
2322Creates an array of **PixelMap** objects based on image decoding parameters. This API uses a promise to return the result.
2323
2324**System capability**: SystemCapability.Multimedia.Image.ImageSource
2325
2326**Parameters**
2327
2328| Name  | Type                                 | Mandatory| Description                      |
2329| -------- | ------------------------------------- | ---- | -------------------------- |
2330| options  | [DecodingOptions](#decodingoptions7)  | No  | Image decoding parameters.                |
2331
2332**Return value**
2333
2334| Type                            | Description                 |
2335| -------------------------------- | --------------------- |
2336| Promise<Array<[PixelMap](#pixelmap7)>> | Promise used to return an array of **PixelMap** objects.|
2337
2338**Error codes**
2339
2340For details about the error codes, see [Image Error Codes](../errorcodes/errorcode-image.md).
2341
2342| ID| Error Message|
2343| ------- | --------------------------------------------|
2344| 62980096| The operation failed.              |
2345| 62980099 | The shared memory data is abnormal. |
2346| 62980101 | The image data is abnormal. |
2347| 62980103| The image data is not supported.             |
2348| 62980106 | The image is too large. |
2349| 62980109 | Failed to crop the image. |
2350| 62980110| The image source data is incorrect.             |
2351| 62980111| The image source data is incomplete.           |
2352| 62980112 | The image format does not match. |
2353| 62980113 | Unknown image format. |
2354| 62980115 | Invalid image parameter. |
2355| 62980116 | Failed to decode the image. |
2356| 62980118| Failed to create the image plugin.             |
2357| 62980122 | The image decoding header is abnormal. |
2358| 62980137 | Invalid media operation. |
2359| 62980173 | The DMA memory does not exist. |
2360| 62980174 | The DMA memory data is abnormal. |
2361
2362**Example**
2363
2364```ts
2365import {BusinessError} from '@ohos.base';
2366let decodeOpts: image.DecodingOptions = {
2367    sampleSize: 1,
2368    editable: true,
2369    desiredSize: { width: 198, height: 202 },
2370    rotate: 0,
2371    desiredPixelFormat: 3,
2372    index: 0,
2373};
2374imageSourceApi.createPixelMapList(decodeOpts).then((pixelMapList: Array<image.PixelMap>) => {
2375    console.log('Succeeded in creating pixelMapList object.');
2376}).catch((err: BusinessError) => {
2377    console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`);
2378})
2379```
2380
2381### createPixelMapList<sup>10+</sup>
2382
2383createPixelMapList(callback: AsyncCallback<Array\<PixelMap>>): void
2384
2385Creates an array of **PixelMap** objects based on the default parameters. This API uses an asynchronous callback to return the result.
2386
2387**System capability**: SystemCapability.Multimedia.Image.ImageSource
2388
2389**Parameters**
2390
2391| Name    | Type                                 | Mandatory| Description                      |
2392| -------- | ------------------------------------- | ---- | -------------------------- |
2393| callback | AsyncCallback<Array<[PixelMap](#pixelmap7)>> | Yes  | Callback used to return an array of **PixelMap** objects.|
2394
2395**Error codes**
2396
2397For details about the error codes, see [Image Error Codes](../errorcodes/errorcode-image.md).
2398
2399| ID| Error Message|
2400| ------- | --------------------------------------------|
2401| 62980096 | The operation failed.             |
2402| 62980099 | The shared memory data is abnormal.  |
2403| 62980101 | The image data is abnormal.          |
2404| 62980103 | The image data is not supported.         |
2405| 62980106 | The image is too large.              |
2406| 62980109 | Failed to crop the image.            |
2407| 62980110 | The image source data is incorrect.      |
2408| 62980111 | The image source data is incomplete. |
2409| 62980112 | The image format does not match.       |
2410| 62980113 | Unknown image format.        |
2411| 62980115 | Invalid image parameter.      |
2412| 62980116 | Failed to decode the image.         |
2413| 62980118 | Failed to create the image plugin.   |
2414| 62980122 | The image decoding header is abnormal.   |
2415| 62980137 | Invalid media operation.     |
2416| 62980173 | The DMA memory does not exist.        |
2417| 62980174 | The DMA memory data is abnormal.    |
2418
2419**Example**
2420
2421```ts
2422import {BusinessError} from '@ohos.base';
2423imageSourceApi.createPixelMapList((err: BusinessError, pixelMapList: Array<image.PixelMap>) => {
2424    if (err != undefined) {
2425        console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`);
2426    } else {
2427        console.info('Succeeded in creating pixelMapList object.');
2428    }
2429})
2430```
2431
2432### createPixelMapList<sup>10+</sup>
2433
2434createPixelMapList(options: DecodingOptions, callback: AsyncCallback<Array\<PixelMap>>): void
2435
2436Creates an array of **PixelMap** objects based on image decoding parameters. This API uses an asynchronous callback to return the result.
2437
2438**System capability**: SystemCapability.Multimedia.Image.ImageSource
2439
2440**Parameters**
2441
2442| Name  | Type                | Mandatory| Description                              |
2443| -------- | -------------------- | ---- | ---------------------------------- |
2444| options | [DecodingOptions](#decodingoptions7) | Yes| Image decoding parameters.|
2445| callback | AsyncCallback<Array<[PixelMap](#pixelmap7)>> | Yes  | Callback used to return an array of **PixelMap** objects.|
2446
2447**Error codes**
2448
2449For details about the error codes, see [Image Error Codes](../errorcodes/errorcode-image.md).
2450
2451| ID| Error Message|
2452| ------- | --------------------------------------------|
2453| 62980096 | The operation failed.            |
2454| 62980099 | The shared memory data is abnormal.  |
2455| 62980101 | The image data is abnormal.         |
2456| 62980103 | The image data is not supported.        |
2457| 62980106 | The image is too large.              |
2458| 62980109 | Failed to crop the image.           |
2459| 62980110 | The image source data is incorrect.      |
2460| 62980111 | The image source data is incomplete. |
2461| 62980112 | The image format does not match.        |
2462| 62980113 | Unknown image format.         |
2463| 62980115 | Invalid image parameter.      |
2464| 62980116 | Failed to decode the image.         |
2465| 62980118 | Failed to create the image plugin.  |
2466| 62980122 | The image decoding header is abnormal.   |
2467| 62980137 | Invalid media operation.      |
2468| 62980173 | The DMA memory does not exist.         |
2469| 62980174 | The DMA memory data is abnormal.     |
2470
2471**Example**
2472
2473```ts
2474import {BusinessError} from '@ohos.base';
2475let decodeOpts : image.DecodingOptions = {
2476    sampleSize: 1,
2477    editable: true,
2478    desiredSize: { width: 198, height: 202 },
2479    rotate: 0,
2480    desiredPixelFormat: 3,
2481    index: 0,
2482};
2483imageSourceApi.createPixelMapList(decodeOpts, (err: BusinessError, pixelMapList: Array<image.PixelMap>) => {
2484    if (err != undefined) {
2485        console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`);
2486    } else {
2487        console.log('Succeeded in creating pixelMapList object.');
2488    }
2489})
2490```
2491
2492### getDelayTimeList<sup>10+</sup>
2493
2494getDelayTimeList(callback: AsyncCallback<Array\<number>>): void
2495
2496Obtains an array of delay times. This API uses an asynchronous callback to return the result. It is used only for GIF images.
2497
2498**System capability**: SystemCapability.Multimedia.Image.ImageSource
2499
2500**Parameters**
2501
2502| Name  | Type                | Mandatory| Description                              |
2503| -------- | -------------------- | ---- | ---------------------------------- |
2504| callback | AsyncCallback<Array\<number>> | Yes  | Callback used to return an array of delay times.|
2505
2506**Error codes**
2507
2508For details about the error codes, see [Image Error Codes](../errorcodes/errorcode-image.md).
2509
2510| ID| Error Message|
2511| ------- | --------------------------------------------|
2512| 62980096| The operation failed.              |
2513| 62980110| The image source data is incorrect.             |
2514| 62980111| The image source data is incomplete.            |
2515| 62980112 | The image format does not match. |
2516| 62980113| Unknown image format. |
2517| 62980115 | Invalid image parameter. |
2518| 62980116| Failed to decode the image. |
2519| 62980118| Failed to create the image plugin. |
2520| 62980122| The image decoding header is abnormal. |
2521| 62980137 | Invalid media operation. |
2522| 62980149 | Invalid media parameter. |
2523
2524**Example**
2525
2526```ts
2527import {BusinessError} from '@ohos.base';
2528imageSourceApi.getDelayTimeList((err: BusinessError, delayTimes: Array<number>) => {
2529    if (err != undefined) {
2530        console.error(`Failed to get delayTimes object.code is ${err.code},message is ${err.message}`);
2531    } else {
2532        console.log('Succeeded in delayTimes object.');
2533    }
2534})
2535```
2536
2537### getDelayTimeList<sup>10+</sup>
2538
2539getDelayTimeList(): Promise<Array\<number>>
2540
2541Obtains an array of delay times. This API uses a promise to return the result. It is used only for GIF images.
2542
2543**System capability**: SystemCapability.Multimedia.Image.ImageSource
2544
2545**Return value**
2546
2547| Type          | Description                       |
2548| -------------- | --------------------------- |
2549| Promise<Array\<number>> | Promise used to return an array of delay times.|
2550
2551**Error codes**
2552
2553For details about the error codes, see [Image Error Codes](../errorcodes/errorcode-image.md).
2554
2555| ID| Error Message|
2556| ------- | --------------------------------------------|
2557| 62980096 | The operation failed.             |
2558| 62980110 | The image source data is incorrect.      |
2559| 62980111 | The image source data is incomplete. |
2560| 62980112 | The image format does not match.        |
2561| 62980113 | Unknown image format.         |
2562| 62980115 | Invalid image parameter.      |
2563| 62980116 | Failed to decode the image.          |
2564| 62980118 | Failed to create the image plugin.  |
2565| 62980122 | The image decoding header is abnormal.   |
2566| 62980137 | Invalid media operation.      |
2567| 62980149 | Invalid media parameter.      |
2568
2569**Example**
2570
2571```ts
2572import {BusinessError} from '@ohos.base';
2573imageSourceApi.getDelayTimeList().then((delayTimes : Array<number>) => {
2574    console.log('Succeeded in delayTimes object.');
2575}).catch((err: BusinessError) => {
2576    console.error(`Failed to get delayTimes object.code is ${err.code},message is ${err.message}`);
2577})
2578```
2579
2580### getFrameCount<sup>10+</sup>
2581
2582getFrameCount(callback: AsyncCallback\<number>): void
2583
2584Obtains the number of frames. This API uses an asynchronous callback to return the result.
2585
2586**System capability**: SystemCapability.Multimedia.Image.ImageSource
2587
2588**Parameters**
2589
2590| Name  | Type                | Mandatory| Description                              |
2591| -------- | -------------------- | ---- | ---------------------------------- |
2592| callback | AsyncCallback\<number> | Yes  | Callback used to return the number of frames.|
2593
2594**Error codes**
2595
2596For details about the error codes, see [Image Error Codes](../errorcodes/errorcode-image.md).
2597
2598| ID| Error Message|
2599| ------- | --------------------------------------------|
2600| 62980096| The operation failed.              |
2601| 62980110| The image source data is incorrect. |
2602| 62980111| The image source data is incomplete. |
2603| 62980112| The image format does not match. |
2604| 62980113| Unknown image format. |
2605| 62980115| Invalid image parameter. |
2606| 62980116| Failed to decode the image. |
2607| 62980118| Failed to create the image plugin. |
2608| 62980122| The image decoding header is abnormal. |
2609| 62980137| Invalid media operation. |
2610
2611**Example**
2612
2613```ts
2614import {BusinessError} from '@ohos.base';
2615imageSourceApi.getFrameCount((err: BusinessError, frameCount: number) => {
2616    if (err != undefined) {
2617        console.error(`Failed to get frame count.code is ${err.code},message is ${err.message}`);
2618    } else {
2619        console.log('Succeeded in getting frame count.');
2620    }
2621})
2622```
2623
2624### getFrameCount<sup>10+</sup>
2625
2626getFrameCount(): Promise\<number>
2627
2628Obtains the number of frames. This API uses a promise to return the result.
2629
2630**System capability**: SystemCapability.Multimedia.Image.ImageSource
2631
2632**Return value**
2633
2634| Type          | Description                       |
2635| -------------- | --------------------------- |
2636| Promise\<number> | Promise used to return the number of frames.|
2637
2638**Error codes**
2639
2640For details about the error codes, see [Image Error Codes](../errorcodes/errorcode-image.md).
2641
2642| ID| Error Message|
2643| ------- | --------------------------------------------|
2644| 62980096 | The operation failed.             |
2645| 62980110 | The image source data is incorrect.      |
2646| 62980111 | The image source data is incomplete. |
2647| 62980112 | The image format does not match.        |
2648| 62980113 | Unknown image format.         |
2649| 62980115 | Invalid image parameter.      |
2650| 62980116 | Failed to decode the image.          |
2651| 62980118 | Failed to create the image plugin.   |
2652| 62980122 | The image decoding header is abnormal.  |
2653| 62980137 | Invalid media operation.      |
2654
2655**Example**
2656
2657```ts
2658import {BusinessError} from '@ohos.base';
2659imageSourceApi.getFrameCount().then((frameCount: number) => {
2660    console.log('Succeeded in getting frame count.');
2661}).catch((err : BusinessError) => {
2662    console.error(`Failed to get frame count.code is ${err.code},message is ${err.message}`);
2663})
2664```
2665
2666### release
2667
2668release(callback: AsyncCallback\<void>): void
2669
2670Releases this **ImageSource** instance. This API uses an asynchronous callback to return the result.
2671
2672**System capability**: SystemCapability.Multimedia.Image.ImageSource
2673
2674**Parameters**
2675
2676| Name  | Type                | Mandatory| Description                              |
2677| -------- | -------------------- | ---- | ---------------------------------- |
2678| callback | AsyncCallback\<void> | Yes  | Callback invoked for instance release. If the operation fails, an error message is returned.|
2679
2680**Example**
2681
2682```ts
2683import {BusinessError} from '@ohos.base';
2684imageSourceApi.release((err : BusinessError) => {
2685    if (err != undefined) {
2686        console.error('Failed to release the image source instance.');
2687    } else {
2688        console.log('Succeeded in releasing the image source instance.');
2689    }
2690})
2691```
2692
2693### release
2694
2695release(): Promise\<void>
2696
2697Releases this **ImageSource** instance. This API uses a promise to return the result.
2698
2699**System capability**: SystemCapability.Multimedia.Image.ImageSource
2700
2701**Return value**
2702
2703| Type          | Description                       |
2704| -------------- | --------------------------- |
2705| Promise\<void> | Promise used to return the result.|
2706
2707**Example**
2708
2709```ts
2710import {BusinessError} from '@ohos.base';
2711imageSourceApi.release().then(()=>{
2712    console.log('Succeeded in releasing the image source instance.');
2713}).catch((error : BusinessError) => {
2714    console.error('Failed to release the image source instance.');
2715})
2716```
2717
2718## image.createImagePacker
2719
2720createImagePacker(): ImagePacker
2721
2722Creates an **ImagePacker** instance.
2723
2724**System capability**: SystemCapability.Multimedia.Image.ImagePacker
2725
2726**Return value**
2727
2728| Type                       | Description                 |
2729| --------------------------- | --------------------- |
2730| [ImagePacker](#imagepacker) | **ImagePacker** instance created.|
2731
2732**Example**
2733
2734```ts
2735const imagePackerApi : image.ImagePacker = image.createImagePacker();
2736```
2737
2738## ImagePacker
2739
2740Provides APIs to pack images. Before calling any API in **ImagePacker**, you must use [createImagePacker](#imagecreateimagepacker) to create an **ImagePacker** instance. The image formats JPEG, WebP, and PNG are supported.
2741
2742### Attributes
2743
2744**System capability**: SystemCapability.Multimedia.Image.ImagePacker
2745
2746| Name            | Type          | Readable| Writable| Description                      |
2747| ---------------- | -------------- | ---- | ---- | -------------------------- |
2748| supportedFormats | Array\<string> | Yes  | No  | Supported image formats, which can be JPEG, WebP, and PNG.|
2749
2750### packing
2751
2752packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void
2753
2754Packs an image. This API uses an asynchronous callback to return the result.
2755
2756**System capability**: SystemCapability.Multimedia.Image.ImagePacker
2757
2758**Parameters**
2759
2760| Name  | Type                              | Mandatory| Description                              |
2761| -------- | ---------------------------------- | ---- | ---------------------------------- |
2762| source   | [ImageSource](#imagesource)        | Yes  | Image to pack.                    |
2763| option   | [PackingOption](#packingoption)    | Yes  | Option for image packing.                     |
2764| callback | AsyncCallback\<ArrayBuffer>        | Yes  | Callback used to return the packed data.|
2765
2766**Example**
2767
2768```ts
2769import {BusinessError} from '@ohos.base';
2770const imageSourceApi : image.ImageSource = image.createImageSource(0);
2771let packOpts : image.PackingOption = { format:"image/jpeg", quality:98 };
2772imagePackerApi.packing(imageSourceApi, packOpts, (err : BusinessError, data : ArrayBuffer) => {
2773    if(err) {
2774        console.error('packing failed.');
2775    } else {
2776        console.log('packing succeeded.');
2777    }
2778})
2779```
2780
2781### packing
2782
2783packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer>
2784
2785Packs an image. This API uses a promise to return the result.
2786
2787**System capability**: SystemCapability.Multimedia.Image.ImagePacker
2788
2789**Parameters**
2790
2791| Name| Type                           | Mandatory| Description          |
2792| ------ | ------------------------------- | ---- | -------------- |
2793| source | [ImageSource](#imagesource)     | Yes  | Image to pack.|
2794| option | [PackingOption](#packingoption) | Yes  | Option for image packing.|
2795
2796**Return value**
2797
2798| Type                        | Description                                         |
2799| ---------------------------- | --------------------------------------------- |
2800| Promise\<ArrayBuffer>        | Promise used to return the packed data.|
2801
2802**Example**
2803
2804```ts
2805import {BusinessError} from '@ohos.base';
2806const imageSourceApi : image.ImageSource = image.createImageSource(0);
2807let packOpts : image.PackingOption = { format:"image/jpeg", quality:98 }
2808imagePackerApi.packing(imageSourceApi, packOpts)
2809    .then( (data : ArrayBuffer) => {
2810        console.log('packing succeeded.');
2811	}).catch((error : BusinessError) => {
2812	    console.error('packing failed.');
2813	})
2814```
2815
2816### packing<sup>8+</sup>
2817
2818packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void
2819
2820Packs an image. This API uses an asynchronous callback to return the result.
2821
2822**System capability**: SystemCapability.Multimedia.Image.ImagePacker
2823
2824**Parameters**
2825
2826| Name  | Type                           | Mandatory| Description                              |
2827| -------- | ------------------------------- | ---- | ---------------------------------- |
2828| source   | [PixelMap](#pixelmap7)           | Yes  | **PixelMap** object to pack.              |
2829| option   | [PackingOption](#packingoption) | Yes  | Option for image packing.                    |
2830| callback | AsyncCallback\<ArrayBuffer>     | Yes  | Callback used to return the packed data.|
2831
2832**Example**
2833
2834```ts
2835import {BusinessError} from '@ohos.base';
2836const color : ArrayBuffer = 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.
2837let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
2838image.createPixelMap(color, opts).then((pixelMap : image.PixelMap) => {
2839    let packOpts : image.PackingOption = { format:"image/jpeg", quality:98 }
2840    imagePackerApi.packing(pixelMap, packOpts, (err : BusinessError, data : ArrayBuffer) => {
2841        console.log('Succeeded in packing the image.');
2842    })
2843}).catch((error : BusinessError) => {
2844	console.error('createPixelMap failed.');
2845})
2846```
2847
2848### packing<sup>8+</sup>
2849
2850packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer>
2851
2852Packs an image. This API uses a promise to return the result.
2853
2854**System capability**: SystemCapability.Multimedia.Image.ImagePacker
2855
2856**Parameters**
2857
2858| Name| Type                           | Mandatory| Description              |
2859| ------ | ------------------------------- | ---- | ------------------ |
2860| source | [PixelMap](#pixelmap7)           | Yes  | **PixelMap** object to pack.|
2861| option | [PackingOption](#packingoption) | Yes  | Option for image packing.    |
2862
2863**Return value**
2864
2865| Type                 | Description                                        |
2866| --------------------- | -------------------------------------------- |
2867| Promise\<ArrayBuffer> | Promise used to return the packed data.|
2868
2869**Example**
2870
2871```ts
2872import {BusinessError} from '@ohos.base';
2873const color : ArrayBuffer = 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.
2874let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
2875image.createPixelMap(color, opts).then((pixelMap : image.PixelMap) => {
2876    let packOpts : image.PackingOption = { format:"image/jpeg", quality:98 }
2877    imagePackerApi.packing(pixelMap, packOpts)
2878        .then( (data : ArrayBuffer) => {
2879            console.log('Succeeded in packing the image.');
2880        }).catch((error : BusinessError) => {
2881            console.error('Failed to pack the image..');
2882        })
2883}).catch((error : BusinessError) => {
2884	console.error('createPixelMap failed.');
2885})
2886```
2887
2888### release
2889
2890release(callback: AsyncCallback\<void>): void
2891
2892Releases this **ImagePacker** instance. This API uses an asynchronous callback to return the result.
2893
2894**System capability**: SystemCapability.Multimedia.Image.ImagePacker
2895
2896**Parameters**
2897
2898| Name  | Type                | Mandatory| Description                          |
2899| -------- | -------------------- | ---- | ------------------------------ |
2900| callback | AsyncCallback\<void> | Yes  | Callback invoked for instance release. If the operation fails, an error message is returned.|
2901
2902**Example**
2903
2904```ts
2905import {BusinessError} from '@ohos.base';
2906imagePackerApi.release((err : BusinessError)=>{
2907    if (err != undefined) {
2908        console.error('Failed to release image packaging.');
2909    } else {
2910        console.log('Succeeded in releasing image packaging.');
2911    }
2912})
2913```
2914
2915### release
2916
2917release(): Promise\<void>
2918
2919Releases this **ImagePacker** instance. This API uses a promise to return the result.
2920
2921**System capability**: SystemCapability.Multimedia.Image.ImagePacker
2922
2923**Return value**
2924
2925| Type          | Description                                                  |
2926| -------------- | ------------------------------------------------------ |
2927| Promise\<void> | Promise used to return the instance release result. If the operation fails, an error message is returned.|
2928
2929**Example**
2930
2931```ts
2932import {BusinessError} from '@ohos.base';
2933imagePackerApi.release().then(()=>{
2934    console.log('Succeeded in releasing image packaging.');
2935}).catch((error : BusinessError)=>{
2936    console.error('Failed to release image packaging.');
2937})
2938```
2939
2940### packToFile<sup>11+</sup>
2941
2942packToFile(source: ImageSource, fd: number, options: PackingOption, callback: AsyncCallback\<void>): void
2943
2944Encodes an **ImageSource** instance and packs it into a file. This API uses an asynchronous callback to return the result.
2945
2946**System capability**: SystemCapability.Multimedia.Image.ImagePacker
2947
2948**Parameters**
2949
2950| Name  | Type                           | Mandatory| Description                          |
2951| -------- | ------------------------------- | ---- | ------------------------------ |
2952| source   | [ImageSource](#imagesource)     | Yes  | Image to pack.                |
2953| fd       | number                          | Yes  | File descriptor.                  |
2954| options   | [PackingOption](#packingoption) | Yes  | Option for image packing.                |
2955| callback | AsyncCallback\<void>            | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
2956
2957**Example**
2958
2959```ts
2960import {BusinessError} from '@ohos.base'
2961import fs from '@ohos.file.fs'
2962
2963const context : Context = getContext(this);
2964const path : string = context.filesDir + "/test.png";
2965const imageSourceApi : image.ImageSource = image.createImageSource(path);
2966let packOpts : image.PackingOption = { format: "image/jpeg", quality: 98 };
2967const filePath : string = context.cacheDir + "/image_source.jpg";
2968let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
2969const imagePackerApi : image.ImagePacker = image.createImagePacker();
2970imagePackerApi.packToFile(imageSourceApi, file.fd, packOpts, (err : BusinessError) => {
2971    if(err) {
2972        console.error('packToFile failed.');
2973    } else {
2974        console.log('packToFile succeeded.');
2975    }
2976})
2977```
2978
2979### packToFile<sup>11+</sup>
2980
2981packToFile (source: ImageSource, fd: number, options: PackingOption): Promise\<void>
2982
2983Encodes an **ImageSource** instance and packs it into a file. This API uses a promise to return the result.
2984
2985**System capability**: SystemCapability.Multimedia.Image.ImagePacker
2986
2987**Parameters**
2988
2989| Name| Type                           | Mandatory| Description          |
2990| ------ | ------------------------------- | ---- | -------------- |
2991| source | [ImageSource](#imagesource)     | Yes  | Image to pack.|
2992| fd     | number                          | Yes  | File descriptor.  |
2993| options | [PackingOption](#packingoption) | Yes  | Option for image packing.|
2994
2995**Return value**
2996
2997| Type          | Description                             |
2998| -------------- | --------------------------------- |
2999| Promise\<void> | Promise used to return the result. If the operation fails, an error message is returned.|
3000
3001**Example**
3002
3003```ts
3004import {BusinessError} from '@ohos.base'
3005import fs from '@ohos.file.fs'
3006
3007const context : Context = getContext(this);
3008const path : string = context.filesDir + "/test.png";
3009const imageSourceApi : image.ImageSource = image.createImageSource(path);
3010let packOpts : image.PackingOption = { format: "image/jpeg", quality: 98 };
3011const filePath : string = context.cacheDir + "/image_source.jpg";
3012let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
3013const imagePackerApi : image.ImagePacker = image.createImagePacker();
3014imagePackerApi.packToFile(imageSourceApi, file.fd, packOpts).then(()=>{
3015    console.log('Succeeded in packToFile.');
3016}).catch((error : BusinessError)=>{
3017    console.log('Failed to packToFile.');
3018})
3019```
3020
3021### packToFile<sup>11+</sup>
3022
3023packToFile (source: PixelMap, fd: number, options: PackingOption,  callback: AsyncCallback\<void>): void;
3024
3025Encodes a **PixelMap** instance and packs it into a file. This API uses an asynchronous callback to return the result.
3026
3027**System capability**: SystemCapability.Multimedia.Image.ImagePacker
3028
3029**Parameters**
3030
3031| Name  | Type                           | Mandatory| Description                          |
3032| -------- | ------------------------------- | ---- | ------------------------------ |
3033| source   | [PixelMap](#pixelmap7)          | Yes  | **PixelMap** object to pack.          |
3034| fd       | number                          | Yes  | File descriptor.                  |
3035| options   | [PackingOption](#packingoption) | Yes  | Option for image packing.                |
3036| callback | AsyncCallback\<void>            | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
3037
3038**Example**
3039
3040```ts
3041import {BusinessError} from '@ohos.base'
3042import fs from '@ohos.file.fs'
3043
3044const color : ArrayBuffer = 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.
3045let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
3046const context : Context = getContext(this);
3047const path : string = context.cacheDir + "/pixel_map.jpg";
3048image.createPixelMap(color, opts).then((pixelmap : image.PixelMap) => {
3049    let packOpts : image.PackingOption = { format: "image/jpeg", quality: 98 }
3050    let file = fs.openSync(path, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
3051    const imagePackerApi : image.ImagePacker = image.createImagePacker();
3052    imagePackerApi.packToFile(pixelmap, file.fd, packOpts, (err : BusinessError) => {
3053        if(err) {
3054            console.error('packToFile failed.');
3055        } else {
3056            console.log('packToFile succeeded.');
3057        }
3058    })
3059})
3060```
3061
3062### packToFile<sup>11+</sup>
3063
3064packToFile (source: PixelMap, fd: number, options: PackingOption): Promise\<void>
3065
3066Encodes a **PixelMap** instance and packs it into a file. This API uses a promise to return the result.
3067
3068**System capability**: SystemCapability.Multimedia.Image.ImagePacker
3069
3070**Parameters**
3071
3072| Name| Type                           | Mandatory| Description                |
3073| ------ | ------------------------------- | ---- | -------------------- |
3074| source | [PixelMap](#pixelmap7)          | Yes  | **PixelMap** object to pack.|
3075| fd     | number                          | Yes  | File descriptor.        |
3076| options | [PackingOption](#packingoption) | Yes  | Option for image packing.      |
3077
3078**Return value**
3079
3080| Type          | Description                             |
3081| -------------- | --------------------------------- |
3082| Promise\<void> | Promise used to return the result. If the operation fails, an error message is returned.|
3083
3084**Example**
3085
3086```ts
3087import {BusinessError} from '@ohos.base'
3088import fs from '@ohos.file.fs'
3089
3090const color : ArrayBuffer = 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.
3091let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
3092const context : Context = getContext(this);
3093const path : string = context.cacheDir + "/pixel_map.jpg";
3094image.createPixelMap(color, opts).then((pixelmap : image.PixelMap) => {
3095    let packOpts : image.PackingOption = { format: "image/jpeg", quality: 98 }
3096    let file = fs.openSync(path, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
3097    const imagePackerApi : image.ImagePacker = image.createImagePacker();
3098    imagePackerApi.packToFile(pixelmap, file.fd, packOpts)
3099        .then(() => {
3100            console.log('Succeeded in packToFile.');
3101        }).catch((error : BusinessError) => {
3102            console.log('Failed to packToFile.');
3103        })
3104})
3105```
3106
3107## image.createImageReceiver<sup>11+</sup>
3108
3109createImageReceiver(size: Size, format: ImageFormat, capacity: number): ImageReceiver
3110
3111Creates an **ImageReceiver** instance by specifying the image size, format, and capacity.
3112
3113**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
3114
3115**Parameters**
3116
3117| Name  | Type  | Mandatory| Description                  |
3118| -------- | ------ | ---- | ---------------------- |
3119| size    | [Size](#size)  | Yes  | Default size of the image.      |
3120| format   | [ImageFormat](#imageformat9) | Yes  | Image format, which is a constant of [ImageFormat](#imageformat9). (Currently, only **ImageFormat:JPEG** is supported.)            |
3121| capacity | number | Yes  | Maximum number of images that can be accessed at the same time.|
3122
3123**Return value**
3124
3125| Type                            | Description                                   |
3126| -------------------------------- | --------------------------------------- |
3127| [ImageReceiver](#imagereceiver9) | Returns an **ImageReceiver** instance if the operation is successful.|
3128
3129**Error codes**
3130
3131For details about the error codes, see [Image Error Codes](../errorcodes/errorcode-image.md).
3132
3133| ID| Error Message|
3134| ------- | --------------------------------------------|
3135| 401| The parameter check failed.            |
3136
3137**Example**
3138
3139```ts
3140let size:image.Size = {
3141    height: 8192,
3142    width: 8
3143}
3144let receiver : image.ImageReceiver = image.createImageReceiver(size, image.ImageFormat.JPEG, 8);
3145```
3146
3147## image.createImageReceiver<sup>(deprecated)</sup>
3148
3149createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver
3150
3151Creates an **ImageReceiver** instance by specifying the image width, height, format, and capacity.
3152
3153> **NOTE**
3154>
3155> This API is deprecated since API version 11. You are advised to use [createImageReceiver](#imagecreateimagereceiver11).
3156
3157**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
3158
3159**Parameters**
3160
3161| Name  | Type  | Mandatory| Description                  |
3162| -------- | ------ | ---- | ---------------------- |
3163| width    | number | Yes  | Default image width.      |
3164| height   | number | Yes  | Default image height.      |
3165| format   | number | Yes  | Image format, which is a constant of [ImageFormat](#imageformat9). (Currently, only **ImageFormat:JPEG** is supported.) |
3166| capacity | number | Yes  | Maximum number of images that can be accessed at the same time.|
3167
3168**Return value**
3169
3170| Type                            | Description                                   |
3171| -------------------------------- | --------------------------------------- |
3172| [ImageReceiver](#imagereceiver9) | Returns an **ImageReceiver** instance if the operation is successful.|
3173
3174**Example**
3175
3176```ts
3177let receiver : image.ImageReceiver = image.createImageReceiver(8192, 8, image.ImageFormat.JPEG, 8);
3178```
3179
3180## ImageReceiver<sup>9+</sup>
3181
3182Provides APIs to obtain the surface ID of a component, read the latest image, read the next image, and release the **ImageReceiver** instance.
3183
3184Before calling any APIs in **ImageReceiver**, you must create an **ImageReceiver** instance.
3185
3186### Attributes
3187
3188**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
3189
3190| Name    | Type                        | Readable| Writable| Description              |
3191| -------- | ---------------------------- | ---- | ---- | ------------------ |
3192| size     | [Size](#size)                | Yes  | No  | Image size.        |
3193| capacity | number                       | Yes  | No  | Maximum number of images that can be accessed at the same time.|
3194| format   | [ImageFormat](#imageformat9) | Yes  | No  | Image format.        |
3195
3196### getReceivingSurfaceId<sup>9+</sup>
3197
3198getReceivingSurfaceId(callback: AsyncCallback\<string>): void
3199
3200Obtains a surface ID for the camera or other components. This API uses an asynchronous callback to return the result.
3201
3202**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
3203
3204**Parameters**
3205
3206| Name  | Type                  | Mandatory| Description                      |
3207| -------- | ---------------------- | ---- | -------------------------- |
3208| callback | AsyncCallback\<string> | Yes  | Callback used to return the surface ID.|
3209
3210**Example**
3211
3212```ts
3213import {BusinessError} from '@ohos.base';
3214receiver.getReceivingSurfaceId((err : BusinessError, id : string) => {
3215    if(err) {
3216        console.error('getReceivingSurfaceId failed.');
3217    } else {
3218        console.log('getReceivingSurfaceId succeeded.');
3219    }
3220});
3221```
3222
3223### getReceivingSurfaceId<sup>9+</sup>
3224
3225getReceivingSurfaceId(): Promise\<string>
3226
3227Obtains a surface ID for the camera or other components. This API uses a promise to return the result.
3228
3229**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
3230
3231**Return value**
3232
3233| Type            | Description                |
3234| ---------------- | -------------------- |
3235| Promise\<string> | Promise used to return the surface ID.|
3236
3237**Example**
3238
3239```ts
3240import {BusinessError} from '@ohos.base';
3241receiver.getReceivingSurfaceId().then( (id : string) => {
3242    console.log('getReceivingSurfaceId succeeded.');
3243}).catch((error : BusinessError) => {
3244    console.error('getReceivingSurfaceId failed.');
3245})
3246```
3247
3248### readLatestImage<sup>9+</sup>
3249
3250readLatestImage(callback: AsyncCallback\<Image>): void
3251
3252Reads the latest image from the **ImageReceiver** instance. This API uses an asynchronous callback to return the result.
3253
3254**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
3255
3256**Parameters**
3257
3258| Name    | Type                           | Mandatory| Description                    |
3259| -------- | ------------------------------- | ---- | ------------------------ |
3260| callback | AsyncCallback<[Image](#image9)> | Yes  | Callback used to return the latest image.|
3261
3262**Example**
3263
3264```ts
3265import {BusinessError} from '@ohos.base';
3266receiver.readLatestImage((err : BusinessError, img : image.Image) => {
3267    if(err) {
3268        console.error('readLatestImage failed.');
3269    } else {
3270        console.log('readLatestImage succeeded.');
3271    }
3272});
3273```
3274
3275### readLatestImage<sup>9+</sup>
3276
3277readLatestImage(): Promise\<Image>
3278
3279Reads the latest image from the **ImageReceiver** instance. This API uses a promise to return the result.
3280
3281**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
3282
3283**Return value**
3284
3285| Type                     | Description              |
3286| ------------------------- | ------------------ |
3287| Promise<[Image](#image9)> | Promise used to return the latest image.|
3288
3289**Example**
3290
3291```ts
3292import {BusinessError} from '@ohos.base';
3293receiver.readLatestImage().then((img : image.Image) => {
3294    console.log('readLatestImage succeeded.');
3295}).catch((error : BusinessError) => {
3296    console.error('readLatestImage failed.');
3297})
3298```
3299
3300### readNextImage<sup>9+</sup>
3301
3302readNextImage(callback: AsyncCallback\<Image>): void
3303
3304Reads the next image from the **ImageReceiver** instance. This API uses an asynchronous callback to return the result.
3305
3306**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
3307
3308**Parameters**
3309
3310| Name  | Type                           | Mandatory| Description                      |
3311| -------- | ------------------------------- | ---- | -------------------------- |
3312| callback | AsyncCallback<[Image](#image9)> | Yes  | Callback used to return the next image.|
3313
3314**Example**
3315
3316```ts
3317import {BusinessError} from '@ohos.base';
3318receiver.readNextImage((err : BusinessError, img : image.Image) => {
3319    if(err) {
3320        console.error('readNextImage failed.');
3321    } else {
3322        console.log('readNextImage succeeded.');
3323    }
3324});
3325```
3326
3327### readNextImage<sup>9+</sup>
3328
3329readNextImage(): Promise\<Image>
3330
3331Reads the next image from the **ImageReceiver** instance. This API uses a promise to return the result.
3332
3333**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
3334
3335**Return value**
3336
3337| Type                     | Description                |
3338| ------------------------- | -------------------- |
3339| Promise<[Image](#image9)> | Promise used to return the next image.|
3340
3341**Example**
3342
3343```ts
3344import {BusinessError} from '@ohos.base';
3345receiver.readNextImage().then((img : image.Image) => {
3346    console.log('readNextImage succeeded.');
3347}).catch((error : BusinessError) => {
3348    console.error('readNextImage failed.');
3349})
3350```
3351
3352### on<sup>9+</sup>
3353
3354on(type: 'imageArrival', callback: AsyncCallback\<void>): void
3355
3356Listens for image arrival events.
3357
3358**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
3359
3360**Parameters**
3361
3362| Name  | Type                | Mandatory| Description                                                  |
3363| -------- | -------------------- | ---- | ------------------------------------------------------ |
3364| type     | string               | Yes  | Type of event to listen for. The value is fixed at **imageArrival**, which is triggered when an image is received.|
3365| callback | AsyncCallback\<void> | Yes  | Callback invoked for the event.                                      |
3366
3367**Example**
3368
3369```ts
3370receiver.on('imageArrival', () => {
3371    // image arrival, do something.
3372})
3373```
3374
3375### release<sup>9+</sup>
3376
3377release(callback: AsyncCallback\<void>): void
3378
3379Releases this **ImageReceiver** instance. This API uses an asynchronous callback to return the result.
3380
3381**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
3382
3383**Parameters**
3384
3385| Name  | Type                | Mandatory| Description                    |
3386| -------- | -------------------- | ---- | ------------------------ |
3387| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
3388
3389**Example**
3390
3391```ts
3392import {BusinessError} from '@ohos.base'
3393receiver.release((err : BusinessError) => {
3394    if(err) {
3395        console.error('release ImageReceiver failed.');
3396    } else {
3397        console.log('release ImageReceiver succeeded.');
3398    }
3399})
3400```
3401
3402### release<sup>9+</sup>
3403
3404release(): Promise\<void>
3405
3406Releases this **ImageReceiver** instance. This API uses a promise to return the result.
3407
3408**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
3409
3410**Return value**
3411
3412| Type          | Description              |
3413| -------------- | ------------------ |
3414| Promise\<void> | Promise used to return the result.|
3415
3416**Example**
3417
3418```ts
3419import {BusinessError} from '@ohos.base';
3420receiver.release().then(() => {
3421    console.log('release succeeded.');
3422}).catch((error : BusinessError) => {
3423    console.error('release failed.');
3424})
3425```
3426
3427## image.createImageCreator<sup>11+</sup>
3428
3429createImageCreator(size: Size, format: ImageFormat, capacity: number): ImageCreator
3430
3431Creates an **ImageCreator** instance by specifying the image size, format, and capacity.
3432
3433**System capability**: SystemCapability.Multimedia.Image.ImageCreator
3434
3435**Parameters**
3436
3437| Name  | Type  | Mandatory| Description                  |
3438| -------- | ------ | ---- | ---------------------- |
3439| size    | [Size](#size)  | Yes  | Default size of the image.      |
3440| format   | [ImageFormat](#imageformat9) | Yes  | Image format, for example, YCBCR_422_SP or JPEG.            |
3441| capacity | number | Yes  | Maximum number of images that can be accessed at the same time.|
3442
3443**Return value**
3444
3445| Type                          | Description                                   |
3446| ------------------------------ | --------------------------------------- |
3447| [ImageCreator](#imagecreator9) | Returns an **ImageCreator** instance if the operation is successful.|
3448
3449
3450**Error codes**
3451
3452For details about the error codes, see [Image Error Codes](../errorcodes/errorcode-image.md).
3453
3454| ID| Error Message|
3455| ------- | --------------------------------------------|
3456| 401| The parameter check failed.            |
3457
3458**Example**
3459
3460```ts
3461let size:image.Size = {
3462    height: 8192,
3463    width: 8
3464}
3465let creator : image.ImageCreator = image.createImageCreator(size, image.ImageFormat.JPEG, 8);
3466```
3467
3468## image.createImageCreator<sup>(deprecated)</sup>
3469
3470createImageCreator(width: number, height: number, format: number, capacity: number): ImageCreator
3471
3472Creates an **ImageCreator** instance by specifying the image width, height, format, and capacity.
3473
3474> **NOTE**
3475>
3476> This API is deprecated since API version 11. You are advised to use [createImageCreator](#imagecreateimagecreator11).
3477
3478**System capability**: SystemCapability.Multimedia.Image.ImageCreator
3479
3480**Parameters**
3481
3482| Name  | Type  | Mandatory| Description                  |
3483| -------- | ------ | ---- | ---------------------- |
3484| width    | number | Yes  | Default image width.      |
3485| height   | number | Yes  | Default image height.      |
3486| format   | number | Yes  | Image format, for example, YCBCR_422_SP or JPEG.            |
3487| capacity | number | Yes  | Maximum number of images that can be accessed at the same time.|
3488
3489**Return value**
3490
3491| Type                          | Description                                   |
3492| ------------------------------ | --------------------------------------- |
3493| [ImageCreator](#imagecreator9) | Returns an **ImageCreator** instance if the operation is successful.|
3494
3495**Example**
3496
3497```ts
3498let creator : image.ImageCreator = image.createImageCreator(8192, 8, image.ImageFormat.JPEG, 8);
3499```
3500
3501## ImageCreator<sup>9+</sup>
3502
3503Provides APIs for applications to request an image native data area and compile native image data.
3504Before calling any APIs in **ImageCreator**, you must create an [ImageCreator](#imagecreator9) instance. **ImageCreator** does not support multiple threads.
3505
3506### Attributes
3507
3508**System capability**: SystemCapability.Multimedia.Image.ImageCreator
3509
3510| Name    | Type                        | Readable| Writable| Description              |
3511| -------- | ---------------------------- | ---- | ---- | ------------------ |
3512| capacity | number                       | Yes  | No  | Maximum number of images that can be accessed at the same time.|
3513| format   | [ImageFormat](#imageformat9) | Yes  | No  | Image format.        |
3514
3515### dequeueImage<sup>9+</sup>
3516
3517dequeueImage(callback: AsyncCallback\<Image>): void
3518
3519Obtains an image buffer from the idle queue and writes image data into it. This API uses an asynchronous callback to return the result.
3520
3521**System capability**: SystemCapability.Multimedia.Image.ImageCreator
3522
3523**Parameters**
3524
3525| Name       | Type                                   | Mandatory| Description                |
3526| ------------- | ---------------------------------------| ---- | -------------------- |
3527| callback      | AsyncCallback\<[Image](#image9)>                   | Yes  | Callback used to return the drawn image.|
3528
3529**Example**
3530
3531```ts
3532import {BusinessError} from '@ohos.base';
3533creator.dequeueImage((err : BusinessError, img : image.Image) => {
3534    if (err) {
3535        console.error('dequeueImage failed.');
3536    } else {
3537        console.info('dequeueImage succeeded.');
3538    }
3539});
3540```
3541
3542### dequeueImage<sup>9+</sup>
3543
3544dequeueImage(): Promise\<Image>
3545
3546Obtains an image buffer from the idle queue and writes image data into it. This API uses a promise to return the result.
3547
3548**System capability**: SystemCapability.Multimedia.Image.ImageCreator
3549
3550**Return value**
3551
3552| Type            | Description          |
3553| --------------- | ------------- |
3554| Promise\<[Image](#image9)> | Promise used to return the drawn image.|
3555
3556**Example**
3557
3558```ts
3559import {BusinessError} from '@ohos.base';
3560creator.dequeueImage().then((img : image.Image) => {
3561    console.info('dequeueImage succeeded.');
3562}).catch((error : BusinessError) => {
3563    console.error('dequeueImage failed: ' + error);
3564})
3565```
3566
3567### queueImage<sup>9+</sup>
3568
3569queueImage(interface: Image, callback: AsyncCallback\<void>): void
3570
3571Places the drawn image in the dirty queue. This API uses an asynchronous callback to return the result.
3572
3573**System capability**: SystemCapability.Multimedia.Image.ImageCreator
3574
3575**Parameters**
3576
3577| Name       | Type                    | Mandatory| Description                |
3578| ------------- | -------------------------| ---- | -------------------- |
3579| interface     | [Image](#image9)                    | Yes  | Drawn image.|
3580| callback      | AsyncCallback\<void>     | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
3581
3582**Example**
3583
3584```ts
3585import {BusinessError} from '@ohos.base';
3586creator.dequeueImage().then((img : image.Image) => {
3587    // Draw the image.
3588    img.getComponent(4).then( (component : image.Component) => {
3589        let bufferArr : Uint8Array = new Uint8Array(component.byteBuffer);
3590        for (let i = 0; i < bufferArr.length; i += 4) {
3591            bufferArr[i] = 0; //B
3592            bufferArr[i + 1] = 0; //G
3593            bufferArr[i + 2] = 255; //R
3594            bufferArr[i + 3] = 255; //A
3595        }
3596    })
3597    creator.queueImage(img, (err : BusinessError) => {
3598        if (err) {
3599            console.error('queueImage failed: ' + err);
3600        } else {
3601            console.info('queueImage succeeded');
3602        }
3603    })
3604})
3605
3606```
3607
3608### queueImage<sup>9+</sup>
3609
3610queueImage(interface: Image): Promise\<void>
3611
3612Places the drawn image in the dirty queue. This API uses a promise to return the result.
3613
3614**System capability**: SystemCapability.Multimedia.Image.ImageCreator
3615
3616**Parameters**
3617
3618| Name         | Type    | Mandatory| Description               |
3619| ------------- | --------| ---- | ------------------- |
3620| interface     | [Image](#image9)   | Yes  | Drawn image.|
3621
3622**Return value**
3623
3624| Type           | Description          |
3625| -------------- | ------------- |
3626| Promise\<void> | Promise used to return the result. If the operation fails, an error message is returned.|
3627
3628**Example**
3629
3630```ts
3631import {BusinessError} from '@ohos.base';
3632creator.dequeueImage().then((img : image.Image) => {
3633    // Draw the image.
3634    img.getComponent(4).then((component : image.Component) => {
3635        let bufferArr : Uint8Array = new Uint8Array(component.byteBuffer);
3636        for (let i = 0; i < bufferArr.length; i += 4) {
3637            bufferArr[i] = 0; //B
3638            bufferArr[i + 1] = 0; //G
3639            bufferArr[i + 2] = 255; //R
3640            bufferArr[i + 3] = 255; //A
3641        }
3642    })
3643    creator.queueImage(img).then(() => {
3644        console.info('queueImage succeeded.');
3645    }).catch((error : BusinessError) => {
3646        console.error('queueImage failed: ' + error);
3647    })
3648})
3649
3650```
3651
3652### on<sup>9+</sup>
3653
3654on(type: 'imageRelease', callback: AsyncCallback\<void>): void
3655
3656Listens for image release events. This API uses an asynchronous callback to return the result.
3657
3658**System capability**: SystemCapability.Multimedia.Image.ImageCreator
3659
3660**Parameters**
3661
3662| Name       | Type                    | Mandatory| Description                |
3663| ------------- | -------------------------| ---- | -------------------- |
3664| type          | string                   | Yes  | Type of event, which is **'imageRelease'**.|
3665| callback      | AsyncCallback\<void>     | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
3666
3667**Example**
3668
3669```ts
3670import {BusinessError} from '@ohos.base';
3671creator.on('imageRelease', (err : BusinessError) => {
3672    if (err) {
3673        console.error('on faild' + err);
3674    } else {
3675        console.info('on succeeded');
3676    }
3677})
3678```
3679
3680### release<sup>9+</sup>
3681
3682release(callback: AsyncCallback\<void>): void
3683
3684Releases this **ImageCreator** instance. This API uses an asynchronous callback to return the result.
3685
3686**System capability**: SystemCapability.Multimedia.Image.ImageCreator
3687
3688**Parameters**
3689
3690| Name          | Type                    | Mandatory| Description                |
3691| ------------- | -------------------------| ---- | -------------------- |
3692| callback      | AsyncCallback\<void>     | Yes  | Callback used to return the result. If the operation fails, an error message is returned.|
3693
3694**Example**
3695
3696```ts
3697import {BusinessError} from '@ohos.base';
3698creator.release((err : BusinessError) => {
3699    if (err) {
3700        console.error('release failed: ' + err);
3701    } else {
3702        console.info('release succeeded');
3703    }
3704});
3705```
3706### release<sup>9+</sup>
3707
3708release(): Promise\<void>
3709
3710Releases this **ImageCreator** instance. This API uses a promise to return the result.
3711
3712**System capability**: SystemCapability.Multimedia.Image.ImageCreator
3713
3714**Return value**
3715
3716| Type           | Description          |
3717| -------------- | ------------- |
3718| Promise\<void> | Promise used to return the result. If the operation fails, an error message is returned.|
3719
3720**Example**
3721
3722```ts
3723import {BusinessError} from '@ohos.base';
3724creator.release().then(() => {
3725    console.info('release succeeded');
3726}).catch((error : BusinessError) => {
3727    console.error('release failed');
3728})
3729```
3730
3731## Image<sup>9+</sup>
3732
3733Provides 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.
3734
3735### Attributes
3736
3737**System capability**: SystemCapability.Multimedia.Image.Core
3738
3739| Name    | Type              | Readable| Writable| Description                                              |
3740| -------- | ------------------ | ---- | ---- | -------------------------------------------------- |
3741| clipRect | [Region](#region7) | Yes  | Yes  | Image area to be cropped.                                |
3742| size     | [Size](#size)      | Yes  | No  | Image size.                                        |
3743| format   | number             | Yes  | No  | Image format. For details, see [PixelMapFormat](#pixelmapformat7).|
3744
3745### getComponent<sup>9+</sup>
3746
3747getComponent(componentType: ComponentType, callback: AsyncCallback\<Component>): void
3748
3749Obtains the component buffer from the **Image** instance based on the color component type. This API uses an asynchronous callback to return the result.
3750
3751**System capability**: SystemCapability.Multimedia.Image.Core
3752
3753**Parameters**
3754
3755| Name       | Type                                   | Mandatory| Description                |
3756| ------------- | --------------------------------------- | ---- | -------------------- |
3757| componentType | [ComponentType](#componenttype9)        | Yes  | Color component type of the image.    |
3758| callback      | AsyncCallback<[Component](#component9)> | Yes  | Callback used to return the component buffer.|
3759
3760**Example**
3761
3762```ts
3763import {BusinessError} from '@ohos.base';
3764img.getComponent(4, (err : BusinessError, component : image.Component) => {
3765    if(err) {
3766        console.error('getComponent failed.');
3767    } else {
3768        console.log('getComponent succeeded.');
3769    }
3770})
3771```
3772
3773### getComponent<sup>9+</sup>
3774
3775getComponent(componentType: ComponentType): Promise\<Component>
3776
3777Obtains the component buffer from the **Image** instance based on the color component type. This API uses a promise to return the result.
3778
3779**System capability**: SystemCapability.Multimedia.Image.Core
3780
3781**Parameters**
3782
3783| Name       | Type                            | Mandatory| Description            |
3784| ------------- | -------------------------------- | ---- | ---------------- |
3785| componentType | [ComponentType](#componenttype9) | Yes  | Color component type of the image.|
3786
3787**Return value**
3788
3789| Type                             | Description                             |
3790| --------------------------------- | --------------------------------- |
3791| Promise<[Component](#component9)> | Promise used to return the component buffer.|
3792
3793**Example**
3794
3795```ts
3796img.getComponent(4).then((component : image.Component) => {
3797    console.log('getComponent succeeded.');
3798}).catch((error : BusinessError) => {
3799    console.error('getComponent failed');
3800})
3801```
3802
3803### release<sup>9+</sup>
3804
3805release(callback: AsyncCallback\<void>): void
3806
3807Releases this **Image** instance. This API uses an asynchronous callback to return the result.
3808
3809The corresponding resources must be released before another image arrives.
3810
3811**System capability**: SystemCapability.Multimedia.Image.Core
3812
3813**Parameters**
3814
3815| Name  | Type                | Mandatory| Description          |
3816| -------- | -------------------- | ---- | -------------- |
3817| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
3818
3819**Example**
3820
3821```ts
3822import {BusinessError} from '@ohos.base';
3823img.release((err : BusinessError) =>{
3824    if (err != undefined) {
3825        console.error('Failed to release the image source instance.');
3826    } else {
3827        console.log('Succeeded in releasing the image source instance.');
3828    }
3829})
3830```
3831
3832### release<sup>9+</sup>
3833
3834release(): Promise\<void>
3835
3836Releases this **Image** instance. This API uses a promise to return the result.
3837
3838The corresponding resources must be released before another image arrives.
3839
3840**System capability**: SystemCapability.Multimedia.Image.Core
3841
3842**Return value**
3843
3844| Type          | Description                 |
3845| -------------- | --------------------- |
3846| Promise\<void> | Promise used to return the result.|
3847
3848**Example**
3849
3850```ts
3851import {BusinessError} from '@ohos.base';
3852img.release().then(() =>{
3853    console.log('release succeeded.');
3854}).catch((error : BusinessError) => {
3855    console.error('release failed.');
3856})
3857```
3858
3859## PositionArea<sup>7+</sup>
3860
3861Describes area information in an image.
3862
3863**System capability**: SystemCapability.Multimedia.Image.Core
3864
3865| Name  | Type              | Readable| Writable| Description                                                        |
3866| ------ | ------------------ | ---- | ---- | ------------------------------------------------------------ |
3867| pixels | ArrayBuffer        | Yes  | Yes  | Pixels of the image.                                                      |
3868| offset | number             | Yes  | Yes  | Offset for data reading.                                                    |
3869| stride | number             | Yes  | Yes  | 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.                  |
3870| region | [Region](#region7) | Yes  | Yes  | 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.|
3871
3872## ImageInfo
3873
3874Describes image information.
3875
3876**System capability**: SystemCapability.Multimedia.Image.Core
3877
3878| Name| Type         | Readable| Writable| Description      |
3879| ---- | ------------- | ---- | ---- | ---------- |
3880| size | [Size](#size) | Yes  | Yes  | Image size.|
3881| density<sup>9+</sup> | number | Yes  | Yes  | Pixel density, in ppi.|
3882| stride<sup>11+</sup> | number | Yes  | Yes  | Number of bytes from one row of pixels in memory to the next row of pixels in memory.stride >= region.size.width*4  |
3883
3884## Size
3885
3886Describes the size of an image.
3887
3888**System capability**: SystemCapability.Multimedia.Image.Core
3889
3890| Name  | Type  | Readable| Writable| Description          |
3891| ------ | ------ | ---- | ---- | -------------- |
3892| height | number | Yes  | Yes  | Image height.|
3893| width  | number | Yes  | Yes  | Image width.|
3894
3895## PixelMapFormat<sup>7+</sup>
3896
3897Enumerates the pixel formats of images.
3898
3899**System capability**: SystemCapability.Multimedia.Image.Core
3900
3901| Name                  |   Value  | Description             |
3902| ---------------------- | ------ | ----------------- |
3903| UNKNOWN                | 0      | Unknown format.       |
3904| RGB_565                | 2      | RGB_565.    |
3905| RGBA_8888              | 3      | RGBA_8888.|
3906| BGRA_8888<sup>9+</sup> | 4      | BGRA_8888.|
3907| RGB_888<sup>9+</sup>   | 5      | RGB_888.  |
3908| ALPHA_8<sup>9+</sup>   | 6      | ALPHA_8.  |
3909| RGBA_F16<sup>9+</sup>  | 7      | RGBA_F16. |
3910| NV21<sup>9+</sup>      | 8      | NV21.     |
3911| NV12<sup>9+</sup>      | 9      | NV12.     |
3912
3913## AlphaType<sup>9+</sup>
3914
3915Enumerates the alpha types of images.
3916
3917**System capability**: SystemCapability.Multimedia.Image.Core
3918
3919| Name    |   Value  | Description                   |
3920| -------- | ------ | ----------------------- |
3921| UNKNOWN  | 0      | Unknown alpha type.           |
3922| OPAQUE   | 1      | There is no alpha or the image is opaque.|
3923| PREMUL   | 2      | Premultiplied alpha.        |
3924| UNPREMUL | 3      | Unpremultiplied alpha, that is, straight alpha.      |
3925
3926## ScaleMode<sup>9+</sup>
3927
3928Enumerates the scale modes of images.
3929
3930**System capability**: SystemCapability.Multimedia.Image.Core
3931
3932| Name           |   Value  | Description                                              |
3933| --------------- | ------ | -------------------------------------------------- |
3934| CENTER_CROP     | 1      | Scales the image so that it fills the requested bounds of the target and crops the extra.|
3935| FIT_TARGET_SIZE | 0      | Reduces the image size to the dimensions of the target.                          |
3936
3937## SourceOptions<sup>9+</sup>
3938
3939Defines image source initialization options.
3940
3941**System capability**: SystemCapability.Multimedia.Image.Core
3942
3943| Name             | Type                              | Readable| Writable| Description              |
3944| ----------------- | ---------------------------------- | ---- | ---- | ------------------ |
3945| sourceDensity     | number                             | Yes  | Yes  | Density of the image source.|
3946| sourcePixelFormat | [PixelMapFormat](#pixelmapformat7) | Yes  | Yes  | Pixel format of the image source.    |
3947| sourceSize        | [Size](#size)                      | Yes  | Yes  | Pixel size of the image source.    |
3948
3949
3950## InitializationOptions<sup>8+</sup>
3951
3952Defines pixel map initialization options.
3953
3954**System capability**: SystemCapability.Multimedia.Image.Core
3955
3956| Name                    | Type                              | Readable| Writable| Description          |
3957| ------------------------ | ---------------------------------- | ---- | ---- | -------------- |
3958| alphaType<sup>9+</sup>   | [AlphaType](#alphatype9)           | Yes  | Yes  | Alpha type.      |
3959| editable                 | boolean                            | Yes  | Yes  | Whether the image is editable.  |
3960| pixelFormat              | [PixelMapFormat](#pixelmapformat7) | Yes  | Yes  | Pixel map format.    |
3961| scaleMode<sup>9+</sup>   | [ScaleMode](#scalemode9)           | Yes  | Yes  | Scale mode.      |
3962| size                     | [Size](#size)                      | Yes  | Yes  | Image size.|
3963
3964## DecodingOptions<sup>7+</sup>
3965
3966Defines image decoding options.
3967
3968**System capability**: SystemCapability.Multimedia.Image.ImageSource
3969
3970| Name              | Type                              | Readable| Writable| Description            |
3971| ------------------ | ---------------------------------- | ---- | ---- | ---------------- |
3972| sampleSize         | number                             | Yes  | Yes  | Thumbnail sampling size. Currently, this option can only be set to **1**.|
3973| rotate             | number                             | Yes  | Yes  | Rotation angle.      |
3974| editable           | boolean                            | Yes  | Yes  | Whether the image is editable. If this option is set to **false**, the image cannot be edited again, and operations such as cropping will fail. |
3975| desiredSize        | [Size](#size)                      | Yes  | Yes  | Expected output size.  |
3976| desiredRegion      | [Region](#region7)                 | Yes  | Yes  | Region to decode.      |
3977| desiredPixelFormat | [PixelMapFormat](#pixelmapformat7) | Yes  | Yes  | Pixel map format for decoding.|
3978| index              | number                             | Yes  | Yes  | Index of the image to decode.  |
3979| fitDensity<sup>9+</sup> | number                        | Yes  | Yes  | Image pixel density, in ppi.  |
3980| desiredColorSpace<sup>11+</sup> | [colorSpaceManager.ColorSpaceManager](js-apis-colorSpaceManager.md#colorspacemanager) | Yes  | Yes  | Target color space.|
3981
3982## Region<sup>7+</sup>
3983
3984Describes region information.
3985
3986**System capability**: SystemCapability.Multimedia.Image.Core
3987
3988| Name| Type         | Readable| Writable| Description        |
3989| ---- | ------------- | ---- | ---- | ------------ |
3990| size | [Size](#size) | Yes  | Yes  | Region size.  |
3991| x    | number        | Yes  | Yes  | X coordinate to translate.|
3992| y    | number        | Yes  | Yes  | Y coordinate of the region.|
3993
3994## PackingOption
3995
3996Defines the option for image packing.
3997
3998**System capability**: SystemCapability.Multimedia.Image.ImagePacker
3999
4000| Name   | Type  | Readable| Writable| Description                                               |
4001| ------- | ------ | ---- | ---- | --------------------------------------------------- |
4002| format  | string | Yes  | Yes  | Format of the packed image.<br>Currently, only JPG, WebP, and PNG are supported.|
4003| quality | number | Yes  | Yes  | Quality of the output image in JPEG encoding. The value ranges from 0 to 100.|
4004| bufferSize<sup>9+</sup> | number | Yes  | Yes  | Size of the buffer for receiving the encoded data, in bytes. The default value is 10 MB. The value of **bufferSize** must be greater than the size of the encoded image.|
4005
4006## ImagePropertyOptions<sup>11+</sup>
4007
4008Describes image properties.
4009
4010**System capability**: SystemCapability.Multimedia.Image.ImageSource
4011
4012| Name        | Type  | Readable| Writable| Description        |
4013| ------------ | ------ | ---- | ---- | ------------ |
4014| index        | number | Yes  | Yes  | Index of the image.  |
4015| defaultValue | string | Yes  | Yes  | Default property value.|
4016
4017## GetImagePropertyOptions<sup>(deprecated)</sup>
4018
4019Describes image properties.
4020
4021> **NOTE**
4022>
4023> This API is deprecated since API version 11. You are advised to use [ImagePropertyOptions](#imagepropertyoptions11).
4024
4025**System capability**: SystemCapability.Multimedia.Image.ImageSource
4026
4027| Name        | Type  | Readable| Writable| Description        |
4028| ------------ | ------ | ---- | ---- | ------------ |
4029| index        | number | Yes  | Yes  | Index of the image.  |
4030| defaultValue | string | Yes  | Yes  | Default property value.|
4031
4032## PropertyKey<sup>7+</sup>
4033
4034Describes the exchangeable image file format (EXIF) data of an image.
4035
4036**System capability**: SystemCapability.Multimedia.Image.Core
4037
4038| Name             |   Value                   | Description                    |
4039| ----------------- | ----------------------- | ------------------------ |
4040| BITS_PER_SAMPLE                           | "BitsPerSample"              | Number of bits per pixel.                           |
4041| ORIENTATION                               | "Orientation"                | Image orientation.                                 |
4042| IMAGE_LENGTH                              | "ImageLength"                | Image length.                                 |
4043| IMAGE_WIDTH                               | "ImageWidth"                 | Image width.                                 |
4044| GPS_LATITUDE                              | "GPSLatitude"                | Image latitude.                                 |
4045| GPS_LONGITUDE                             | "GPSLongitude"               | Image longitude.                                 |
4046| GPS_LATITUDE_REF                          | "GPSLatitudeRef"             | Latitude reference, for example, N or S.                       |
4047| GPS_LONGITUDE_REF                         | "GPSLongitudeRef"            | Longitude reference, for example, W or E.                       |
4048| DATE_TIME_ORIGINAL<sup>9+</sup>           | "DateTimeOriginal"           | Shooting time, for example, 2022:09:06 15:48:00.        |
4049| EXPOSURE_TIME<sup>9+</sup>                | "ExposureTime"               | Exposure time, for example, 1/33 sec.                   |
4050| SCENE_TYPE<sup>9+</sup>                   | "SceneType"                  | Shooting scene type, for example, portrait, scenery, motion, and night.|
4051| ISO_SPEED_RATINGS<sup>9+</sup>            | "ISOSpeedRatings"            | ISO sensitivity or ISO speed, for example, 400.                       |
4052| F_NUMBER<sup>9+</sup>                     | "FNumber"                    | Aperture, for example, f/1.8.                        |
4053| DATE_TIME<sup>10+</sup>                   | "DateTime"                   | Date and time.                                 |
4054| GPS_TIME_STAMP<sup>10+</sup>              | "GPSTimeStamp"               | GPS timestamp.                                  |
4055| GPS_DATE_STAMP<sup>10+</sup>              | "GPSDateStamp"               | GPS date stamp.                                  |
4056| IMAGE_DESCRIPTION<sup>10+</sup>           | "ImageDescription"           | Image description.                               |
4057| MAKE<sup>10+</sup>                        | "Make"                       | Manufacturer.                                     |
4058| MODEL<sup>10+</sup>                       | "Model"                      | Device model.                                   |
4059| PHOTO_MODE<sup>10+</sup>                  | "PhotoMode "                 | Photographing mode.                                   |
4060| SENSITIVITY_TYPE<sup>10+</sup>            | "SensitivityType"            | Sensitivity type.                                 |
4061| STANDARD_OUTPUT_SENSITIVITY<sup>10+</sup> | "StandardOutputSensitivity"  | Standard output sensitivity.                             |
4062| RECOMMENDED_EXPOSURE_INDEX<sup>10+</sup>  | "RecommendedExposureIndex"   | Recommended exposure index.                               |
4063| ISO_SPEED<sup>10+</sup>                   | "ISOSpeedRatings"            | ISO speed.                                |
4064| APERTURE_VALUE<sup>10+</sup>              | "ApertureValue"              | Aperture value.                                     |
4065| EXPOSURE_BIAS_VALUE<sup>10+</sup>         | "ExposureBiasValue"          | Exposure bias value.                                 |
4066| METERING_MODE<sup>10+</sup>               | "MeteringMode"               | Metering mode.                                   |
4067| LIGHT_SOURCE<sup>10+</sup>                | "LightSource"                | Light source.                                       |
4068| FLASH <sup>10+</sup>                      | "Flash"                      | Flash status.                      |
4069| FOCAL_LENGTH <sup>10+</sup>               | "FocalLength"                | Focal length.                                       |
4070| USER_COMMENT <sup>10+</sup>               | "UserComment"                | User comment.                                   |
4071| PIXEL_X_DIMENSION <sup>10+</sup>          | "PixelXDimension"            | Pixel X dimension.                                  |
4072| PIXEL_Y_DIMENSION<sup>10+</sup>           | "PixelYDimension"            | Pixel Y dimension.                                  |
4073| WHITE_BALANCE <sup>10+</sup>              | "WhiteBalance"               | White balance.                                     |
4074| FOCAL_LENGTH_IN_35_MM_FILM <sup>10+</sup> | "FocalLengthIn35mmFilm"      | Focal length in 35mm film.                             |
4075| CAPTURE_MODE <sup>10+</sup>               | "HwMnoteCaptureMode"         | Capture mode. Currently, this attribute is read-only.                 |
4076| PHYSICAL_APERTURE <sup>10+</sup>          | "HwMnotePhysicalAperture"    | Physical aperture. Currently, this attribute is read-only.       |
4077| ROLL_ANGLE <sup>11+</sup>                 | "HwMnoteRollAngle"           | Rolling angle. Currently, this attribute is read-only.                 |
4078| PITCH_ANGLE<sup>11+</sup>                | "HwMnotePitchAngle"          | Pitch angle. Currently, this attribute is read-only.                 |
4079| SCENE_FOOD_CONF<sup>11+</sup>             | "HwMnoteSceneFoodConf"       | Photographing scene: food. Currently, this attribute is read-only.           |
4080| SCENE_STAGE_CONF<sup>11+</sup>           | "HwMnoteSceneStageConf"     | Photographing scene: stage. Currently, this attribute is read-only.           |
4081| SCENE_BLUE_SKY_CONF<sup>11+</sup>       | "HwMnoteSceneBlueSkyConf"    | Photographing scene: blue sky. Currently, this attribute is read-only.           |
4082| SCENE_GREEN_PLANT_CONF<sup>11+</sup>      | "HwMnoteSceneGreenPlantConf" | Photographing scene: green plants. Currently, this attribute is read-only.      |
4083| SCENE_BEACH_CONF<sup>11+</sup>            | "HwMnoteSceneBeachConf"      | Photographing scene: beach. Currently, this attribute is read-only.           |
4084| SCENE_SNOW_CONF<sup>11+</sup>             | "HwMnoteSceneSnowConf"       | Photographing scene: snow. Currently, this attribute is read-only.           |
4085| SCENE_SUNSET_CONF<sup>11+</sup>           | "HwMnoteSceneSunsetConf"     | Photographing scene: sunset. Currently, this attribute is read-only.           |
4086| SCENE_FLOWERS_CONF<sup>11+</sup>          | "HwMnoteSceneFlowersConf"    | Photographing scene: flowers. Currently, this attribute is read-only.             |
4087| SCENE_NIGHT_CONF<sup>11+</sup>            | "HwMnoteSceneNightConf"      | Photographing scene: night. Currently, this attribute is read-only.           |
4088| SCENE_TEXT_CONF<sup>11+</sup>             | "HwMnoteSceneTextConf"       | Photographing scene: text. Currently, this attribute is read-only.           |
4089| FACE_COUNT<sup>11+</sup>                  | "HwMnoteFaceCount"           | Number of faces. Currently, this attribute is read-only.                 |
4090| FOCUS_MODE<sup>11+</sup>                  | "HwMnoteFocusMode"           | Focus mode. Currently, this attribute is read-only.                 |
4091
4092## ImageFormat<sup>9+</sup>
4093
4094Enumerates the image formats.
4095
4096**System capability**: SystemCapability.Multimedia.Image.Core
4097
4098| Name        |   Value  | Description                |
4099| ------------ | ------ | -------------------- |
4100| YCBCR_422_SP | 1000   | YCBCR422 semi-planar format.|
4101| JPEG         | 2000   | JPEG encoding format.      |
4102
4103## ComponentType<sup>9+</sup>
4104
4105Enumerates the color component types of images.
4106
4107**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
4108
4109| Name |   Value  | Description       |
4110| ----- | ------ | ----------- |
4111| YUV_Y | 1      | Luminance component. |
4112| YUV_U | 2      | Chrominance component. |
4113| YUV_V | 3      | Chrominance component. |
4114| JPEG  | 4      | JPEG type.|
4115
4116## Component<sup>9+</sup>
4117
4118Describes the color components of an image.
4119
4120**System capability**: SystemCapability.Multimedia.Image.Core
4121
4122| Name         | Type                            | Readable| Writable| Description        |
4123| ------------- | -------------------------------- | ---- | ---- | ------------ |
4124| componentType | [ComponentType](#componenttype9) | Yes  | No  | Color component type.  |
4125| rowStride     | number                           | Yes  | No  | Row stride.      |
4126| pixelStride   | number                           | Yes  | No  | Pixel stride.  |
4127| byteBuffer    | ArrayBuffer                      | Yes  | No  | Component buffer.|
4128
4129## Supplementary Information
4130### SVG Tags
4131
4132The SVG tags are supported since API version 10. The used version is (SVG) 1.1. Currently, the following tags are supported:
4133- a
4134- circla
4135- clipPath
4136- defs
4137- ellipse
4138- feBlend
4139- feColorMatrix
4140- feComposite
4141- feDiffuseLighting
4142- feDisplacementMap
4143- feDistantLight
4144- feFlood
4145- feGaussianBlur
4146- feImage
4147- feMorphology
4148- feOffset
4149- fePointLight
4150- feSpecularLighting
4151- feSpotLight
4152- feTurbulence
4153- filter
4154- g
4155- image
4156- line
4157- linearGradient
4158- mask
4159- path
4160- pattern
4161- polygon
4162- polyline
4163- radialGradient
4164- rect
4165- stop
4166- svg
4167- text
4168- textPath
4169- tspan
4170- use
4171