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 pixels of an image (or even in a region of an image). 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> - Since API version 12, the APIs of this module are supported in ArkTS widgets. 10 11## Modules to Import 12 13```ts 14import { image } from '@kit.ImageKit'; 15``` 16 17## image.createPixelMap<sup>8+</sup> 18 19createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<PixelMap> 20 21Creates a **PixelMap** object with the default BGRA_8888 format and specified pixel properties. This API uses a promise to return the result. 22 23**System capability**: SystemCapability.Multimedia.Image.Core 24 25**Parameters** 26 27| Name | Type | Mandatory| Description | 28| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 29| colors | ArrayBuffer | Yes | Color array in BGRA_8888 format. | 30| options | [InitializationOptions](#initializationoptions8) | Yes | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.| 31 32**Return value** 33 34| Type | Description | 35| -------------------------------- | ----------------------------------------------------------------------- | 36| 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.| 37 38**Example** 39 40```ts 41import { BusinessError } from '@kit.BasicServicesKit'; 42 43async function Demo() { 44 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. 45 let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } 46 image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => { 47 console.info('Succeeded in creating pixelmap.'); 48 }).catch((error: BusinessError) => { 49 console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`); 50 }) 51} 52``` 53 54## image.createPixelMap<sup>8+</sup> 55 56createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: AsyncCallback\<PixelMap>): void 57 58Creates a **PixelMap** object with the default BGRA_8888 format and specified pixel properties. This API uses an asynchronous callback to return the result. 59 60**System capability**: SystemCapability.Multimedia.Image.Core 61 62**Parameters** 63 64| Name | Type | Mandatory| Description | 65| -------- | ------------------------------------------------ | ---- | -------------------------- | 66| colors | ArrayBuffer | Yes | Color array in BGRA_8888 format. | 67| options | [InitializationOptions](#initializationoptions8) | Yes | Pixel properties. | 68| callback | AsyncCallback\<[PixelMap](#pixelmap7)> | Yes | Callback used to return the result. If the operation is successful, **err** is undefined and **data** is the **PixelMap** object obtained; otherwise, **err** is an error object.| 69 70**Example** 71 72```ts 73import { BusinessError } from '@kit.BasicServicesKit'; 74 75async function Demo() { 76 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. 77 let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } 78 image.createPixelMap(color, opts, (error: BusinessError, pixelMap: image.PixelMap) => { 79 if(error) { 80 console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`); 81 return; 82 } else { 83 console.info('Succeeded in creating pixelmap.'); 84 } 85 }) 86} 87``` 88 89## image.createPixelMapFromParcel<sup>11+</sup> 90 91createPixelMapFromParcel(sequence: rpc.MessageSequence): PixelMap 92 93Creates a **PixelMap** object from a **MessageSequence** object. 94 95**System capability**: SystemCapability.Multimedia.Image.Core 96 97**Parameters** 98 99| Name | Type | Mandatory| Description | 100| ---------------------- | ----------------------------------------------------- | ---- | ---------------------------------------- | 101| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | Yes | **MessageSequence** object that stores the **PixelMap** information. | 102 103**Return value** 104 105| Type | Description | 106| -------------------------------- | --------------------- | 107| [PixelMap](#pixelmap7) | Returns a **PixelMap** object if the operation is successful; throws an error otherwise.| 108 109**Error codes** 110 111For details about the error codes, see [Image Error Codes](errorcode-image.md). 112 113| ID| Error Message| 114| ------- | --------------------------------------------| 115| 62980096 | Operation failed| 116| 62980097 | IPC error.| 117| 62980115 | Invalid input parameter| 118| 62980105 | Failed to get the data| 119| 62980177 | Abnormal API environment| 120| 62980178 | Failed to create the PixelMap| 121| 62980179 | Abnormal buffer size| 122| 62980180 | FD mapping failed| 123| 62980246 | Failed to read the PixelMap| 124 125**Example** 126 127```ts 128import { image } from '@kit.ImageKit'; 129import { rpc } from '@kit.IPCKit'; 130import { BusinessError } from '@kit.BasicServicesKit'; 131 132class MySequence implements rpc.Parcelable { 133 pixel_map: image.PixelMap; 134 constructor(conPixelmap: image.PixelMap) { 135 this.pixel_map = conPixelmap; 136 } 137 marshalling(messageSequence: rpc.MessageSequence) { 138 this.pixel_map.marshalling(messageSequence); 139 return true; 140 } 141 unmarshalling(messageSequence: rpc.MessageSequence) { 142 try { 143 this.pixel_map = image.createPixelMapFromParcel(messageSequence); 144 } catch(e) { 145 let error = e as BusinessError; 146 console.error(`createPixelMapFromParcel error. code is ${error.code}, message is ${error.message}`); 147 return false; 148 } 149 return true; 150 } 151} 152async function Demo() { 153 const color: ArrayBuffer = new ArrayBuffer(96); 154 let bufferArr: Uint8Array = new Uint8Array(color); 155 for (let i = 0; i < bufferArr.length; i++) { 156 bufferArr[i] = 0x80; 157 } 158 let opts: image.InitializationOptions = { 159 editable: true, 160 pixelFormat: 4, 161 size: { height: 4, width: 6 }, 162 alphaType: 3 163 } 164 let pixelMap: image.PixelMap | undefined = undefined; 165 image.createPixelMap(color, opts).then((srcPixelMap: image.PixelMap) => { 166 pixelMap = srcPixelMap; 167 }) 168 if (pixelMap != undefined) { 169 // Implement serialization. 170 let parcelable: MySequence = new MySequence(pixelMap); 171 let data: rpc.MessageSequence = rpc.MessageSequence.create(); 172 data.writeParcelable(parcelable); 173 174 // Implement deserialization to obtain data through the RPC. 175 let ret: MySequence = new MySequence(pixelMap); 176 data.readParcelable(ret); 177 178 // Obtain the PixelMap object. 179 let unmarshPixelmap = ret.pixel_map; 180 } 181} 182``` 183 184## image.createPixelMapFromSurface<sup>11+</sup> 185 186createPixelMapFromSurface(surfaceId: string, region: Region): Promise\<PixelMap> 187 188Creates a **PixelMap** object from a surface ID. This API uses a promise to return the result. 189 190**System capability**: SystemCapability.Multimedia.Image.Core 191 192**Parameters** 193 194| Name | Type | Mandatory| Description | 195| ---------------------- | ------------- | ---- | ---------------------------------------- | 196| surfaceId | string | Yes | Surface ID, which is obtained from [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md).| 197| region | [Region](#region7) | Yes | Size of the image. | 198 199**Return value** 200| Type | Description | 201| -------------------------------- | --------------------- | 202| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.| 203 204**Error codes** 205 206For details about the error codes, see [Image Error Codes](errorcode-image.md). 207 208| ID| Error Message| 209| ------- | --------------------------------------------| 210| 62980115 | If the image parameter invalid.| 211| 62980105 | Failed to get the data| 212| 62980178 | Failed to create the PixelMap| 213 214**Example** 215 216```ts 217import { BusinessError } from '@kit.BasicServicesKit'; 218 219async function Demo(surfaceId: string) { 220 let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 221 image.createPixelMapFromSurface(surfaceId, region).then(() => { 222 console.info('Succeeded in creating pixelmap from Surface'); 223 }).catch((error: BusinessError) => { 224 console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`); 225 }); 226} 227``` 228 229## image.createPixelMapFromSurfaceSync<sup>12+</sup> 230 231createPixelMapFromSurfaceSync(surfaceId: string, region: Region): PixelMap 232 233Creates a **PixelMap** object from a surface ID. This API returns the result synchronously. 234 235**System capability**: SystemCapability.Multimedia.Image.Core 236 237**Parameters** 238 239| Name | Type | Mandatory| Description | 240| ---------------------- | ------------- | ---- | ---------------------------------------- | 241| surfaceId | string | Yes | Surface ID, which is obtained from [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md).| 242| region | [Region](#region7) | Yes | Size of the image. | 243 244**Return value** 245| Type | Description | 246| -------------------------------- | --------------------- | 247| [PixelMap](#pixelmap7) | Returns a **PixelMap** object if the operation is successful; throws an error otherwise.| 248 249**Error codes** 250 251For details about the error codes, see [Image Error Codes](errorcode-image.md). 252 253| ID| Error Message| 254| ------- | --------------------------------------------| 255| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 256| 62980105 | Failed to get the data| 257| 62980178 | Failed to create the PixelMap| 258 259**Example** 260 261```ts 262import { BusinessError } from '@kit.BasicServicesKit'; 263 264async function Demo(surfaceId: string) { 265 let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 266 let pixelMap : image.PixelMap = image.createPixelMapFromSurfaceSync(surfaceId, region); 267 return pixelMap; 268} 269``` 270 271## image.createPixelMapSync<sup>12+</sup> 272 273createPixelMapSync(colors: ArrayBuffer, options: InitializationOptions): PixelMap 274 275Creates a **PixelMap** object with the specified pixel properties. This API returns the result synchronously. 276 277**System capability**: SystemCapability.Multimedia.Image.Core 278 279**Parameters** 280 281| Name | Type | Mandatory| Description | 282| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 283| colors | ArrayBuffer | Yes | Color array in BGRA_8888 format. | 284| options | [InitializationOptions](#initializationoptions8) | Yes | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.| 285 286**Return value** 287| Type | Description | 288| -------------------------------- | --------------------- | 289| [PixelMap](#pixelmap7) | Returns a **PixelMap** object if the operation is successful; throws an error otherwise.| 290 291**Error codes** 292 293For details about the error codes, see [Image Error Codes](errorcode-image.md). 294 295| ID| Error Message| 296| ------- | --------------------------------------------| 297| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 298 299**Example** 300 301```ts 302import { BusinessError } from '@kit.BasicServicesKit'; 303 304async function Demo() { 305 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. 306 let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } 307 let pixelMap : image.PixelMap = image.createPixelMapSync(color, opts); 308 return pixelMap; 309} 310``` 311 312## image.createPixelMapSync<sup>12+</sup> 313 314createPixelMapSync(options: InitializationOptions): PixelMap 315 316Creates a **PixelMap** object with the specified pixel properties. This API returns the result synchronously. 317 318**System capability**: SystemCapability.Multimedia.Image.Core 319 320**Parameters** 321 322| Name | Type | Mandatory| Description | 323| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 324| options | [InitializationOptions](#initializationoptions8) | Yes | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.| 325 326**Return value** 327| Type | Description | 328| -------------------------------- | --------------------- | 329| [PixelMap](#pixelmap7) | Returns a **PixelMap** object if the operation is successful; throws an error otherwise.| 330 331**Error codes** 332 333For details about the error codes, see [Image Error Codes](errorcode-image.md). 334 335| ID| Error Message| 336| ------- | --------------------------------------------| 337| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 338 339**Example** 340 341```ts 342import { BusinessError } from '@kit.BasicServicesKit'; 343 344async function Demo() { 345 let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } 346 let pixelMap : image.PixelMap = image.createPixelMapSync(opts); 347 return pixelMap; 348} 349``` 350 351## image.createPremultipliedPixelMap<sup>12+</sup> 352 353createPremultipliedPixelMap(src: PixelMap, dst: PixelMap, callback: AsyncCallback\<void>): void 354 355Converts a non-premultiplied alpha of a pixel map to a premultiplied one and stores the converted data to a target pixel map. This API uses an asynchronous callback to return the result. 356 357**System capability**: SystemCapability.Multimedia.Image.Core 358 359**Parameters** 360 361| Name | Type | Mandatory| Description | 362| -------- | ------------------------------------------------ | ---- | -------------------------- | 363| src | [PixelMap](#pixelmap7) | Yes | Source **PixelMap** object.| 364| dst | [PixelMap](#pixelmap7) | Yes | Target **PixelMap** object.| 365|callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 366 367**Error codes** 368 369For details about the error codes, see [Image Error Codes](errorcode-image.md). 370 371| ID| Error Message| 372| ------- | --------------------------------------------| 373| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 374| 62980103 | The image data is not supported | 375| 62980246 | Failed to read the pixelMap | 376| 62980248 | Pixelmap not allow modify | 377 378**Example** 379 380```ts 381import { BusinessError } from '@kit.BasicServicesKit'; 382 383async function Demo() { 384 const color: ArrayBuffer = new ArrayBuffer(16); // 16 is the size of the pixel map buffer to create. The value is calculated as follows: height x width x 4. 385 let bufferArr = new Uint8Array(color); 386 for (let i = 0; i < bufferArr.length; i += 4) { 387 bufferArr[i] = 255; 388 bufferArr[i+1] = 255; 389 bufferArr[i+2] = 122; 390 bufferArr[i+3] = 122; 391 } 392 let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 2, width: 2 } , alphaType: 3} 393 let srcPixelmap = image.createPixelMapSync(color, opts); 394 let dstPixelMap = image.createPixelMapSync(opts); 395 image.createPremultipliedPixelMap(srcPixelmap, dstPixelMap, (error: BusinessError) => { 396 if(error) { 397 console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`); 398 return; 399 } else { 400 console.info('Succeeded in converting pixelmap.'); 401 } 402 }) 403} 404``` 405 406## image.createPremultipliedPixelMap<sup>12+</sup> 407 408createPremultipliedPixelMap(src: PixelMap, dst: PixelMap): Promise\<void> 409 410Converts a non-premultiplied alpha of a pixel map to a premultiplied one and stores the converted data to a target pixel map. This API uses a promise to return the result. 411 412**System capability**: SystemCapability.Multimedia.Image.Core 413 414**Parameters** 415 416| Name | Type | Mandatory| Description | 417| -------- | ------------------------------------------------ | ---- | -------------------------- | 418| src | [PixelMap](#pixelmap7) | Yes | Source **PixelMap** object.| 419| dst | [PixelMap](#pixelmap7) | Yes | Target **PixelMap** object.| 420 421**Return value** 422 423| Type | Description | 424| -------------------------------- | ----------------------------------------------------------------------- | 425| Promise\<void> | Promise that returns no value.| 426 427**Error codes** 428 429For details about the error codes, see [Image Error Codes](errorcode-image.md). 430 431| ID| Error Message| 432| ------- | --------------------------------------------| 433| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 434| 62980103 | The image data is not supported | 435| 62980246 | Failed to read the pixelMap | 436| 62980248 | Pixelmap not allow modify | 437 438**Example** 439 440```ts 441import { BusinessError } from '@kit.BasicServicesKit'; 442 443async function Demo() { 444 const color: ArrayBuffer = new ArrayBuffer(16); // 16 is the size of the pixel map buffer to create. The value is calculated as follows: height x width x 4. 445 let bufferArr = new Uint8Array(color); 446 for (let i = 0; i < bufferArr.length; i += 4) { 447 bufferArr[i] = 255; 448 bufferArr[i+1] = 255; 449 bufferArr[i+2] = 122; 450 bufferArr[i+3] = 122; 451 } 452 let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 2, width: 2 } , alphaType: 2} 453 let srcPixelmap = image.createPixelMapSync(color, opts); 454 let dstPixelMap = image.createPixelMapSync(opts); 455 image.createPremultipliedPixelMap(srcPixelmap, dstPixelMap).then(() => { 456 console.info('Succeeded in converting pixelmap.'); 457 }).catch((error: BusinessError) => { 458 console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`); 459 }) 460} 461``` 462 463## image.createUnpremultipliedPixelMap<sup>12+</sup> 464 465createUnpremultipliedPixelMap(src: PixelMap, dst: PixelMap, callback: AsyncCallback\<void>): void 466 467Converts a premultiplied alpha of a pixel map to a non-premultiplied one and stores the converted data to a target pixel map. This API uses an asynchronous callback to return the result. 468 469**System capability**: SystemCapability.Multimedia.Image.Core 470 471**Parameters** 472 473| Name | Type | Mandatory| Description | 474| -------- | ------------------------------------------------ | ---- | -------------------------- | 475| src | [PixelMap](#pixelmap7) | Yes | Source **PixelMap** object.| 476| dst | [PixelMap](#pixelmap7) | Yes | Target **PixelMap** object.| 477|callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 478 479**Error codes** 480 481For details about the error codes, see [Image Error Codes](errorcode-image.md). 482 483| ID| Error Message| 484| ------- | --------------------------------------------| 485| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 486| 62980103 | The image data is not supported | 487| 62980246 | Failed to read the pixelMap | 488| 62980248 | Pixelmap not allow modify | 489 490**Example** 491 492```ts 493import { BusinessError } from '@kit.BasicServicesKit'; 494 495async function Demo() { 496 const color: ArrayBuffer = new ArrayBuffer(16); // 16 is the size of the pixel map buffer to create. The value is calculated as follows: height x width x 4. 497 let bufferArr = new Uint8Array(color); 498 for (let i = 0; i < bufferArr.length; i += 4) { 499 bufferArr[i] = 255; 500 bufferArr[i+1] = 255; 501 bufferArr[i+2] = 122; 502 bufferArr[i+3] = 122; 503 } 504 let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 2, width: 2 } , alphaType: 2} 505 let srcPixelmap = image.createPixelMapSync(color, opts); 506 let dstPixelMap = image.createPixelMapSync(opts); 507 image.createUnpremultipliedPixelMap(srcPixelmap, dstPixelMap, (error: BusinessError) => { 508 if(error) { 509 console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`); 510 return; 511 } else { 512 console.info('Succeeded in converting pixelmap.'); 513 } 514 }) 515} 516``` 517 518## image.createUnpremultipliedPixelMap<sup>12+</sup> 519 520createUnpremultipliedPixelMap(src: PixelMap, dst: PixelMap): Promise\<void> 521 522Converts a premultiplied alpha of a pixel map to a non-premultiplied one and stores the converted data to a target pixel map. This API uses a promise to return the result. 523 524**System capability**: SystemCapability.Multimedia.Image.Core 525 526**Parameters** 527 528| Name | Type | Mandatory| Description | 529| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 530| src | [PixelMap](#pixelmap7) | Yes | Source **PixelMap** object.| 531| dst | [PixelMap](#pixelmap7) | Yes | Target **PixelMap** object.| 532 533**Return value** 534 535| Type | Description | 536| -------------------------------- | ----------------------------------------------------------------------- | 537| Promise\<void> | Promise that returns no value.| 538 539**Error codes** 540 541For details about the error codes, see [Image Error Codes](errorcode-image.md). 542 543| ID| Error Message| 544| ------- | --------------------------------------------| 545| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 546| 62980103 | The image data is not supported | 547| 62980246 | Failed to read the pixelMap. | 548| 62980248 | PixelMap not allow modify. | 549 550**Example** 551 552```ts 553import { BusinessError } from '@kit.BasicServicesKit'; 554 555async function Demo() { 556 const color: ArrayBuffer = new ArrayBuffer(16); // 16 is the size of the pixel map buffer to create. The value is calculated as follows: height x width x 4. 557 let bufferArr = new Uint8Array(color); 558 for (let i = 0; i < bufferArr.length; i += 4) { 559 bufferArr[i] = 255; 560 bufferArr[i+1] = 255; 561 bufferArr[i+2] = 122; 562 bufferArr[i+3] = 122; 563 } 564 let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 2, width: 2 } , alphaType: 3} 565 let srcPixelmap = image.createPixelMapSync(color, opts); 566 let dstPixelMap = image.createPixelMapSync(opts); 567 image.createUnpremultipliedPixelMap(srcPixelmap, dstPixelMap).then(() => { 568 console.info('Succeeded in converting pixelmap.'); 569 }).catch((error: BusinessError) => { 570 console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`); 571 }) 572} 573``` 574 575 576## PixelMap<sup>7+</sup> 577 578Provides APIs to read or write image data and obtain image 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. 579 580Since API version 11, **PixelMap** supports cross-thread calls through workers. If a **PixelMap** object is invoked by another thread through [Worker](../apis-arkts/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. 581 582Before calling any API in **PixelMap**, you must use [image.createPixelMap](#imagecreatepixelmap8) to create a **PixelMap** object. 583 584### Attributes 585 586**System capability**: SystemCapability.Multimedia.Image.Core 587 588| Name | Type | Readable| Writable| Description | 589| -----------------| ------- | ---- | ---- | -------------------------- | 590| isEditable | boolean | Yes | No | Whether the pixels of an image are editable.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12.| 591| isStrideAlignment<sup>11+</sup> | boolean | Yes | No | Whether the image memory is the DMA memory.| 592 593### readPixelsToBuffer<sup>7+</sup> 594 595readPixelsToBuffer(dst: ArrayBuffer): Promise\<void> 596 597Reads the pixels of this image and writes the data to the buffer based on the pixel format of the pixel map. This API uses a promise to return the result. 598 599**Widget capability**: This API can be used in ArkTS widgets since API version 12. 600 601**Atomic service API**: This API can be used in atomic services since API version 11. 602 603**System capability**: SystemCapability.Multimedia.Image.Core 604 605**Parameters** 606 607| Name| Type | Mandatory| Description | 608| ------ | ----------- | ---- | ----------------------------------------------------------------------------------------------------- | 609| dst | ArrayBuffer | Yes | Buffer to which the pixels will be written. The buffer size is obtained by calling [getPixelBytesNumber](#getpixelbytesnumber7).| 610 611**Return value** 612 613| Type | Description | 614| -------------- | ----------------------------------------------- | 615| Promise\<void> | Promise that returns no value. | 616 617**Example** 618 619```ts 620import { BusinessError } from '@kit.BasicServicesKit'; 621 622async function Demo() { 623 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. 624 if (pixelMap != undefined) { 625 pixelMap.readPixelsToBuffer(readBuffer).then(() => { 626 console.info('Succeeded in reading image pixel data.'); // Called if the condition is met. 627 }).catch((error: BusinessError) => { 628 console.error(`Failed to read image pixel data. code is ${error.code}, message is ${error.message}`); // Called if no condition is met. 629 }) 630 } 631} 632``` 633 634### readPixelsToBuffer<sup>7+</sup> 635 636readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\<void>): void 637 638Reads the pixels of this image and writes the data to the buffer based on the pixel format of the pixel map. This API uses an asynchronous callback to return the result. 639 640**Widget capability**: This API can be used in ArkTS widgets since API version 12. 641 642**Atomic service API**: This API can be used in atomic services since API version 11. 643 644**System capability**: SystemCapability.Multimedia.Image.Core 645 646**Parameters** 647 648| Name | Type | Mandatory| Description | 649| -------- | -------------------- | ---- | ----------------------------------------------------------------------------------------------------- | 650| dst | ArrayBuffer | Yes | Buffer to which the pixels will be written. The buffer size is obtained by calling [getPixelBytesNumber](#getpixelbytesnumber7).| 651| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 652 653**Example** 654 655```ts 656import { BusinessError } from '@kit.BasicServicesKit'; 657 658async function Demo() { 659 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. 660 if (pixelMap != undefined) { 661 pixelMap.readPixelsToBuffer(readBuffer, (error: BusinessError, res: void) => { 662 if(error) { 663 console.error(`Failed to read image pixel data. code is ${error.code}, message is ${error.message}`); // Called if no condition is met. 664 return; 665 } else { 666 console.info('Succeeded in reading image pixel data.'); // Called if the condition is met. 667 } 668 }) 669 } 670} 671``` 672 673### readPixelsToBufferSync<sup>12+</sup> 674 675readPixelsToBufferSync(dst: ArrayBuffer): void 676 677Reads the pixels of this image and writes the data to the buffer based on the pixel format of the pixel map. This API returns the result synchronously. 678 679**Widget capability**: This API can be used in ArkTS widgets since API version 12. 680 681**Atomic service API**: This API can be used in atomic services since API version 12. 682 683**System capability**: SystemCapability.Multimedia.Image.Core 684 685**Parameters** 686 687| Name | Type | Mandatory| Description | 688| -------- | -------------------- | ---- | ----------------------------------------------------------------------------------------------------- | 689| dst | ArrayBuffer | Yes | Buffer to which the pixels will be written. The buffer size is obtained by calling [getPixelBytesNumber](#getpixelbytesnumber7).| 690 691**Error codes** 692 693For details about the error codes, see [Image Error Codes](errorcode-image.md). 694 695| ID| Error Message| 696| ------- | --------------------------------------------| 697| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 698| 501 | Resource Unavailable | 699 700**Example** 701 702```ts 703import { BusinessError } from '@kit.BasicServicesKit'; 704 705async function Demo() { 706 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. 707 if (pixelMap != undefined) { 708 pixelMap.readPixelsToBufferSync(readBuffer); 709 } 710} 711``` 712 713### readPixels<sup>7+</sup> 714 715readPixels(area: PositionArea): Promise\<void> 716 717Reads the pixels from an area of this image and writes the data to the buffer based on the BGRA_8888 format. This API uses a promise to return the result. 718 719**Widget capability**: This API can be used in ArkTS widgets since API version 12. 720 721**Atomic service API**: This API can be used in atomic services since API version 11. 722 723**System capability**: SystemCapability.Multimedia.Image.Core 724 725**Parameters** 726 727| Name| Type | Mandatory| Description | 728| ------ | ------------------------------ | ---- | ------------------------ | 729| area | [PositionArea](#positionarea7) | Yes | Area from which the pixels will be read.| 730 731**Return value** 732 733| Type | Description | 734| :------------- | :-------------------------------------------------- | 735| Promise\<void> | Promise that returns no value. | 736 737**Example** 738 739```ts 740import { BusinessError } from '@kit.BasicServicesKit'; 741 742async function Demo() { 743 const area: image.PositionArea = { 744 pixels: new ArrayBuffer(8), 745 offset: 0, 746 stride: 8, 747 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 748 }; 749 if (pixelMap != undefined) { 750 pixelMap.readPixels(area).then(() => { 751 console.info('Succeeded in reading the image data in the area.'); // Called if the condition is met. 752 }).catch((error: BusinessError) => { 753 console.error(`Failed to read the image data in the area. code is ${error.code}, message is ${error.message}`);// Called if no condition is met. 754 }) 755 } 756} 757``` 758 759### readPixels<sup>7+</sup> 760 761readPixels(area: PositionArea, callback: AsyncCallback\<void>): void 762 763Reads the pixels from an area of this image and writes the data to the buffer based on the BGRA_8888 format. This API uses an asynchronous callback to return the result. 764 765**Widget capability**: This API can be used in ArkTS widgets since API version 12. 766 767**Atomic service API**: This API can be used in atomic services since API version 11. 768 769**System capability**: SystemCapability.Multimedia.Image.Core 770 771**Parameters** 772 773| Name | Type | Mandatory| Description | 774| -------- | ------------------------------ | ---- | ------------------------------ | 775| area | [PositionArea](#positionarea7) | Yes | Area from which the pixels will be read. | 776| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 777 778**Example** 779 780```ts 781import { BusinessError } from '@kit.BasicServicesKit'; 782 783async function Demo() { 784 const area: image.PositionArea = { 785 pixels: new ArrayBuffer(8), 786 offset: 0, 787 stride: 8, 788 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 789 }; 790 if (pixelMap != undefined) { 791 pixelMap.readPixels(area, (error: BusinessError) => { 792 if (error) { 793 console.error(`Failed to read pixelmap from the specified area. code is ${error.code}, message is ${error.message}`); 794 return; 795 } else { 796 console.info('Succeeded in reading pixelmap from the specified area.'); 797 } 798 }) 799 } 800} 801``` 802 803### readPixelsSync<sup>12+</sup> 804 805readPixelsSync(area: PositionArea): void 806 807Reads the pixels from an area of this image and writes the data to the buffer based on the BGRA_8888 format. This API returns the result synchronously. 808 809**Atomic service API**: This API can be used in atomic services since API version 12. 810 811**System capability**: SystemCapability.Multimedia.Image.Core 812 813**Parameters** 814 815| Name| Type | Mandatory| Description | 816| ------ | ------------------------------ | ---- | ------------------------ | 817| area | [PositionArea](#positionarea7) | Yes | Area from which the pixels will be read.| 818 819**Error codes** 820 821For details about the error codes, see [Image Error Codes](errorcode-image.md). 822 823| ID| Error Message| 824| ------- | --------------------------------------------| 825| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 826| 501 | Resource Unavailable | 827 828**Example** 829 830```ts 831import { BusinessError } from '@kit.BasicServicesKit'; 832 833async function Demo() { 834 const area : image.PositionArea = { 835 pixels: new ArrayBuffer(8), 836 offset: 0, 837 stride: 8, 838 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 839 }; 840 if (pixelMap != undefined) { 841 pixelMap.readPixelsSync(area); 842 } 843} 844``` 845 846### writePixels<sup>7+</sup> 847 848writePixels(area: PositionArea): Promise\<void> 849 850Writes the pixels of this image to the specified area based on the BGRA_8888 format. This API uses a promise to return the result. 851 852**Widget capability**: This API can be used in ArkTS widgets since API version 12. 853 854**Atomic service API**: This API can be used in atomic services since API version 11. 855 856**System capability**: SystemCapability.Multimedia.Image.Core 857 858**Parameters** 859 860| Name| Type | Mandatory| Description | 861| ------ | ------------------------------ | ---- | -------------------- | 862| area | [PositionArea](#positionarea7) | Yes | Area to which the pixels will be written.| 863 864**Return value** 865 866| Type | Description | 867| :------------- | :-------------------------------------------------- | 868| Promise\<void> | Promise that returns no value. | 869 870**Example** 871 872```ts 873import { BusinessError } from '@kit.BasicServicesKit'; 874 875async function Demo() { 876 const area: image.PositionArea = { 877 pixels: new ArrayBuffer(8), 878 offset: 0, 879 stride: 8, 880 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 881 }; 882 let bufferArr: Uint8Array = new Uint8Array(area.pixels); 883 for (let i = 0; i < bufferArr.length; i++) { 884 bufferArr[i] = i + 1; 885 } 886 if (pixelMap != undefined) { 887 pixelMap.writePixels(area).then(() => { 888 console.info('Succeeded in writing pixelmap into the specified area.'); 889 }).catch((error: BusinessError) => { 890 console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`); 891 }) 892 } 893} 894``` 895 896### writePixels<sup>7+</sup> 897 898writePixels(area: PositionArea, callback: AsyncCallback\<void>): void 899 900Writes the pixels of this image to the specified area based on the BGRA_8888 format. This API uses an asynchronous callback to return the result. 901 902**Widget capability**: This API can be used in ArkTS widgets since API version 12. 903 904**Atomic service API**: This API can be used in atomic services since API version 11. 905 906**System capability**: SystemCapability.Multimedia.Image.Core 907 908**Parameters** 909 910| Name | Type | Mandatory| Description | 911| --------- | ------------------------------ | ---- | ------------------------------ | 912| area | [PositionArea](#positionarea7) | Yes | Area to which the pixels will be written. | 913| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 914 915**Example** 916 917```ts 918import { BusinessError } from '@kit.BasicServicesKit'; 919 920async function Demo() { 921 const area: image.PositionArea = { pixels: new ArrayBuffer(8), 922 offset: 0, 923 stride: 8, 924 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 925 }; 926 let bufferArr: Uint8Array = new Uint8Array(area.pixels); 927 for (let i = 0; i < bufferArr.length; i++) { 928 bufferArr[i] = i + 1; 929 } 930 if (pixelMap != undefined) { 931 pixelMap.writePixels(area, (error : BusinessError) => { 932 if (error) { 933 console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`); 934 return; 935 } else { 936 console.info('Succeeded in writing pixelmap into the specified area.'); 937 } 938 }) 939 } 940} 941``` 942 943### writePixelsSync<sup>12+</sup> 944 945writePixelsSync(area: PositionArea): void 946 947Writes the pixels of this image to the specified area based on the BGRA_8888 format. This API returns the result synchronously. 948 949**Widget capability**: This API can be used in ArkTS widgets since API version 12. 950 951**Atomic service API**: This API can be used in atomic services since API version 12. 952 953**System capability**: SystemCapability.Multimedia.Image.Core 954 955**Parameters** 956 957| Name| Type | Mandatory| Description | 958| ------ | ------------------------------ | ---- | -------------------- | 959| area | [PositionArea](#positionarea7) | Yes | Area to which the pixels will be written.| 960 961**Error codes** 962 963For details about the error codes, see [Image Error Codes](errorcode-image.md). 964 965| ID| Error Message| 966| ------- | --------------------------------------------| 967| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 968| 501 | Resource Unavailable | 969 970**Example** 971 972```ts 973import { BusinessError } from '@kit.BasicServicesKit'; 974 975async function Demo() { 976 const area: image.PositionArea = { 977 pixels: new ArrayBuffer(8), 978 offset: 0, 979 stride: 8, 980 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 981 }; 982 let bufferArr: Uint8Array = new Uint8Array(area.pixels); 983 for (let i = 0; i < bufferArr.length; i++) { 984 bufferArr[i] = i + 1; 985 } 986 if (pixelMap != undefined) { 987 pixelMap.writePixelsSync(area); 988 } 989} 990``` 991 992### writeBufferToPixels<sup>7+</sup> 993 994writeBufferToPixels(src: ArrayBuffer): Promise\<void> 995 996Reads the pixels in the buffer and writes the data to the pixel map based on the pixel format of the pixel map. This API uses a promise to return the result. 997 998**Widget capability**: This API can be used in ArkTS widgets since API version 12. 999 1000**Atomic service API**: This API can be used in atomic services since API version 11. 1001 1002**System capability**: SystemCapability.Multimedia.Image.Core 1003 1004**Parameters** 1005 1006| Name| Type | Mandatory| Description | 1007| ------ | ----------- | ---- | -------------- | 1008| src | ArrayBuffer | Yes | Buffer from which the image data will be read.| 1009 1010**Return value** 1011 1012| Type | Description | 1013| -------------- | ----------------------------------------------- | 1014| Promise\<void> | Promise that returns no value. | 1015 1016**Example** 1017 1018```ts 1019import { BusinessError } from '@kit.BasicServicesKit'; 1020 1021async function Demo() { 1022 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. 1023 let bufferArr: Uint8Array = new Uint8Array(color); 1024 for (let i = 0; i < bufferArr.length; i++) { 1025 bufferArr[i] = i + 1; 1026 } 1027 if (pixelMap != undefined) { 1028 pixelMap.writeBufferToPixels(color).then(() => { 1029 console.info("Succeeded in writing data from a buffer to a PixelMap."); 1030 }).catch((error: BusinessError) => { 1031 console.error(`Failed to write data from a buffer to a PixelMap. code is ${error.code}, message is ${error.message}`); 1032 }) 1033 } 1034} 1035``` 1036 1037### writeBufferToPixels<sup>7+</sup> 1038 1039writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\<void>): void 1040 1041Reads the pixels in the buffer and writes the data to the pixel map based on the pixel format of the pixel map. This API uses an asynchronous callback to return the result. 1042 1043**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1044 1045**Atomic service API**: This API can be used in atomic services since API version 11. 1046 1047**System capability**: SystemCapability.Multimedia.Image.Core 1048 1049**Parameters** 1050 1051| Name | Type | Mandatory| Description | 1052| -------- | -------------------- | ---- | ------------------------------ | 1053| src | ArrayBuffer | Yes | Buffer from which the image data will be read. | 1054| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 1055 1056**Example** 1057 1058```ts 1059import { BusinessError } from '@kit.BasicServicesKit'; 1060 1061async function Demo() { 1062 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. 1063 let bufferArr: Uint8Array = new Uint8Array(color); 1064 for (let i = 0; i < bufferArr.length; i++) { 1065 bufferArr[i] = i + 1; 1066 } 1067 if (pixelMap != undefined) { 1068 pixelMap.writeBufferToPixels(color, (error: BusinessError) => { 1069 if (error) { 1070 console.error(`Failed to write data from a buffer to a PixelMap. code is ${error.code}, message is ${error.message}`); 1071 return; 1072 } else { 1073 console.info("Succeeded in writing data from a buffer to a PixelMap."); 1074 } 1075 }) 1076 } 1077} 1078``` 1079 1080### writeBufferToPixelsSync<sup>12+</sup> 1081 1082writeBufferToPixelsSync(src: ArrayBuffer): void 1083 1084Reads the pixels in the buffer and writes the data to the pixel map based on the pixel format of the pixel map. This API returns the result synchronously. 1085 1086**Atomic service API**: This API can be used in atomic services since API version 12. 1087 1088**System capability**: SystemCapability.Multimedia.Image.Core 1089 1090**Parameters** 1091 1092| Name| Type | Mandatory| Description | 1093| ------ | ----------- | ---- | -------------- | 1094| src | ArrayBuffer | Yes | Buffer from which the image data will be read.| 1095 1096**Error codes** 1097 1098For details about the error codes, see [Image Error Codes](errorcode-image.md). 1099 1100| ID| Error Message| 1101| ------- | --------------------------------------------| 1102| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 1103| 501 | Resource Unavailable | 1104 1105**Example** 1106 1107```ts 1108import { BusinessError } from '@kit.BasicServicesKit'; 1109 1110async function Demo() { 1111 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. 1112 let bufferArr : Uint8Array = new Uint8Array(color); 1113 for (let i = 0; i < bufferArr.length; i++) { 1114 bufferArr[i] = i + 1; 1115 } 1116 if (pixelMap != undefined) { 1117 pixelMap.writeBufferToPixelsSync(color); 1118 } 1119} 1120``` 1121 1122 1123### getImageInfo<sup>7+</sup> 1124 1125getImageInfo(): Promise\<ImageInfo> 1126 1127Obtains the image information. This API uses a promise to return the result. 1128 1129**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1130 1131**Atomic service API**: This API can be used in atomic services since API version 11. 1132 1133**System capability**: SystemCapability.Multimedia.Image.Core 1134 1135**Return value** 1136 1137| Type | Description | 1138| --------------------------------- | ----------------------------------------------------------- | 1139| Promise\<[ImageInfo](#imageinfo)> | Promise used to return the image information.| 1140 1141**Example** 1142 1143```ts 1144import { BusinessError } from '@kit.BasicServicesKit'; 1145 1146async function Demo() { 1147 if (pixelMap != undefined) { 1148 pixelMap.getImageInfo().then((imageInfo: image.ImageInfo) => { 1149 if (imageInfo != undefined) { 1150 console.info("Succeeded in obtaining the image pixel map information."+ imageInfo.size.height); 1151 } 1152 }).catch((error: BusinessError) => { 1153 console.error(`Failed to obtain the image pixel map information. code is ${error.code}, message is ${error.message}`); 1154 }) 1155 } 1156} 1157``` 1158 1159### getImageInfo<sup>7+</sup> 1160 1161getImageInfo(callback: AsyncCallback\<ImageInfo>): void 1162 1163Obtains the image information. This API uses an asynchronous callback to return the result. 1164 1165**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1166 1167**Atomic service API**: This API can be used in atomic services since API version 11. 1168 1169**System capability**: SystemCapability.Multimedia.Image.Core 1170 1171**Parameters** 1172 1173| Name | Type | Mandatory| Description | 1174| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | 1175| callback | AsyncCallback\<[ImageInfo](#imageinfo)> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the image information obtained; otherwise, **err** is an error object.| 1176 1177**Example** 1178 1179```ts 1180import { BusinessError } from '@kit.BasicServicesKit'; 1181 1182async function Demo() { 1183 if (pixelMap != undefined) { 1184 pixelMap.getImageInfo((error: BusinessError, imageInfo: image.ImageInfo) => { 1185 if (error) { 1186 console.error(`Failed to obtain the image pixel map information. code is ${error.code}, message is ${error.message}`); 1187 return; 1188 } else { 1189 console.info("Succeeded in obtaining the image pixel map information."+ imageInfo.size.height); 1190 } 1191 }) 1192 } 1193} 1194``` 1195 1196### getImageInfoSync<sup>12+</sup> 1197 1198getImageInfoSync(): ImageInfo 1199 1200Obtains the image information. This API returns the result synchronously. 1201 1202**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1203 1204**Atomic service API**: This API can be used in atomic services since API version 12. 1205 1206**System capability**: SystemCapability.Multimedia.Image.ImageSource 1207 1208**Return value** 1209 1210| Type | Description | 1211| --------------------------------- | ----------------------------------------------------------- | 1212| [ImageInfo](#imageinfo) | Image information. | 1213 1214**Error codes** 1215 1216For details about the error codes, see [Image Error Codes](errorcode-image.md). 1217 1218| ID| Error Message| 1219| ------- | --------------------------------------------| 1220| 501 | Resource Unavailable | 1221 1222**Example** 1223 1224```ts 1225import { BusinessError } from '@kit.BasicServicesKit'; 1226 1227async function Demo() { 1228 if (pixelMap != undefined) { 1229 let imageInfo : image.ImageInfo = pixelMap.getImageInfoSync(); 1230 return imageInfo; 1231 } 1232 return undefined; 1233} 1234``` 1235 1236### getBytesNumberPerRow<sup>7+</sup> 1237 1238getBytesNumberPerRow(): number 1239 1240Obtains the number of bytes per row of this image. 1241 1242**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1243 1244**Atomic service API**: This API can be used in atomic services since API version 11. 1245 1246**System capability**: SystemCapability.Multimedia.Image.Core 1247 1248**Return value** 1249 1250| Type | Description | 1251| ------ | -------------------- | 1252| number | Number of bytes per row.| 1253 1254**Example** 1255 1256```ts 1257let rowCount: number = pixelMap.getBytesNumberPerRow(); 1258``` 1259 1260### getPixelBytesNumber<sup>7+</sup> 1261 1262getPixelBytesNumber(): number 1263 1264Obtains the total number of bytes of this image. 1265 1266**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1267 1268**Atomic service API**: This API can be used in atomic services since API version 11. 1269 1270**System capability**: SystemCapability.Multimedia.Image.Core 1271 1272**Return value** 1273 1274| Type | Description | 1275| ------ | -------------------- | 1276| number | Total number of bytes.| 1277 1278**Example** 1279 1280```ts 1281let pixelBytesNumber: number = pixelMap.getPixelBytesNumber(); 1282``` 1283 1284### getDensity<sup>9+</sup> 1285 1286getDensity():number 1287 1288Obtains the density of this image. 1289 1290**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1291 1292**Atomic service API**: This API can be used in atomic services since API version 11. 1293 1294**System capability**: SystemCapability.Multimedia.Image.Core 1295 1296**Return value** 1297 1298| Type | Description | 1299| ------ | --------------- | 1300| number | Density of the image.| 1301 1302**Example** 1303 1304```ts 1305let getDensity: number = pixelMap.getDensity(); 1306``` 1307 1308### opacity<sup>9+</sup> 1309 1310opacity(rate: number, callback: AsyncCallback\<void>): void 1311 1312Sets an opacity rate for this image. This API uses an asynchronous callback to return the result. It is invalid for YUV images. 1313 1314**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1315 1316**Atomic service API**: This API can be used in atomic services since API version 11. 1317 1318**System capability**: SystemCapability.Multimedia.Image.Core 1319 1320**Parameters** 1321 1322| Name | Type | Mandatory| Description | 1323| -------- | -------------------- | ---- | ------------------------------ | 1324| rate | number | Yes | Opacity rate. | 1325| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 1326 1327**Example** 1328 1329```ts 1330import { BusinessError } from '@kit.BasicServicesKit'; 1331 1332async function Demo() { 1333 let rate: number = 0.5; 1334 if (pixelMap != undefined) { 1335 pixelMap.opacity(rate, (err: BusinessError) => { 1336 if (err) { 1337 console.error(`Failed to set opacity. code is ${err.code}, message is ${err.message}`); 1338 return; 1339 } else { 1340 console.info("Succeeded in setting opacity."); 1341 } 1342 }) 1343 } 1344} 1345``` 1346 1347### opacity<sup>9+</sup> 1348 1349opacity(rate: number): Promise\<void> 1350 1351Sets an opacity rate for this image. This API uses a promise to return the result. It is invalid for YUV images. 1352 1353**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1354 1355**Atomic service API**: This API can be used in atomic services since API version 11. 1356 1357**System capability**: SystemCapability.Multimedia.Image.Core 1358 1359**Parameters** 1360 1361| Name| Type | Mandatory| Description | 1362| ------ | ------ | ---- | --------------------------- | 1363| rate | number | Yes | Opacity rate.| 1364 1365**Return value** 1366 1367| Type | Description | 1368| -------------- | ----------------------------------------------- | 1369| Promise\<void> | Promise that returns no value. | 1370 1371**Example** 1372 1373```ts 1374import { BusinessError } from '@kit.BasicServicesKit'; 1375 1376async function Demo() { 1377 let rate: number = 0.5; 1378 if (pixelMap != undefined) { 1379 pixelMap.opacity(rate).then(() => { 1380 console.info('Succeeded in setting opacity.'); 1381 }).catch((err: BusinessError) => { 1382 console.error(`Failed to set opacity. code is ${err.code}, message is ${err.message}`); 1383 }) 1384 } 1385} 1386``` 1387 1388### opacitySync<sup>12+</sup> 1389 1390opacitySync(rate: number): void 1391 1392Sets an opacity rate for this image. This API returns the result synchronously. It is invalid for YUV images. 1393 1394**Atomic service API**: This API can be used in atomic services since API version 12. 1395 1396**System capability**: SystemCapability.Multimedia.Image.Core 1397 1398**Parameters** 1399 1400| Name | Type | Mandatory| Description | 1401| -------- | -------------------- | ---- | ------------------------------ | 1402| rate | number | Yes | Opacity rate. | 1403 1404**Error codes** 1405 1406For details about the error codes, see [Image Error Codes](errorcode-image.md). 1407 1408| ID| Error Message| 1409| ------- | --------------------------------------------| 1410| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 1411| 501 | Resource Unavailable | 1412 1413**Example** 1414 1415```ts 1416import { BusinessError } from '@kit.BasicServicesKit'; 1417 1418async function Demo() { 1419 let rate : number = 0.5; 1420 if (pixelMap != undefined) { 1421 pixelMap.opacitySync(rate); 1422 } 1423} 1424``` 1425 1426### createAlphaPixelmap<sup>9+</sup> 1427 1428createAlphaPixelmap(): Promise\<PixelMap> 1429 1430Creates 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. It is invalid for YUV images. 1431 1432**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1433 1434**Atomic service API**: This API can be used in atomic services since API version 11. 1435 1436**System capability**: SystemCapability.Multimedia.Image.Core 1437 1438**Return value** 1439 1440| Type | Description | 1441| -------------------------------- | --------------------------- | 1442| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.| 1443 1444**Example** 1445 1446```ts 1447import { BusinessError } from '@kit.BasicServicesKit'; 1448 1449async function Demo() { 1450 if (pixelMap != undefined) { 1451 pixelMap.createAlphaPixelmap().then((alphaPixelMap: image.PixelMap) => { 1452 console.info('Succeeded in creating alpha pixelmap.'); 1453 }).catch((error: BusinessError) => { 1454 console.error(`Failed to create alpha pixelmap. code is ${error.code}, message is ${error.message}`); 1455 }) 1456 } 1457} 1458``` 1459 1460### createAlphaPixelmap<sup>9+</sup> 1461 1462createAlphaPixelmap(callback: AsyncCallback\<PixelMap>): void 1463 1464Creates 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. It is invalid for YUV images. 1465 1466**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1467 1468**Atomic service API**: This API can be used in atomic services since API version 11. 1469 1470**System capability**: SystemCapability.Multimedia.Image.Core 1471 1472**Parameters** 1473 1474| Name | Type | Mandatory| Description | 1475| -------- | ------------------------ | ---- | ------------------------ | 1476| callback | AsyncCallback\<[PixelMap](#pixelmap7)> | Yes | Callback used to return the result. If the operation is successful, **err** is undefined and **data** is the **PixelMap** object obtained; otherwise, **err** is an error object.| 1477 1478**Example** 1479 1480```ts 1481import { BusinessError } from '@kit.BasicServicesKit'; 1482 1483async function Demo() { 1484 if (pixelMap != undefined) { 1485 pixelMap.createAlphaPixelmap((err: BusinessError, alphaPixelMap: image.PixelMap) => { 1486 if (alphaPixelMap == undefined) { 1487 console.error(`Failed to obtain new pixel map. code is ${err.code}, message is ${err.message}`); 1488 return; 1489 } else { 1490 console.info('Succeeded in obtaining new pixel map.'); 1491 } 1492 }) 1493 } 1494} 1495``` 1496 1497### createAlphaPixelmapSync<sup>12+</sup> 1498 1499createAlphaPixelmapSync(): PixelMap 1500 1501Creates a **PixelMap** object that contains only the alpha channel information. This object can be used for the shadow effect. This API returns the result synchronously. It is invalid for YUV images. 1502 1503**Atomic service API**: This API can be used in atomic services since API version 12. 1504 1505**System capability**: SystemCapability.Multimedia.Image.Core 1506 1507**Return value** 1508 1509| Type | Description | 1510| -------------------------------- | --------------------- | 1511| [PixelMap](#pixelmap7) | Returns a **PixelMap** object if the operation is successful; throws an error otherwise.| 1512 1513**Error codes** 1514 1515For details about the error codes, see [Image Error Codes](errorcode-image.md). 1516 1517| ID| Error Message| 1518| ------- | --------------------------------------------| 1519| 401 | Parameter error. Possible causes: 1.Parameter verification failed | 1520| 501 | Resource Unavailable | 1521 1522**Example** 1523 1524```ts 1525import { BusinessError } from '@kit.BasicServicesKit'; 1526 1527async function Demo() { 1528 if (pixelMap != undefined) { 1529 let pixelmap : image.PixelMap = pixelMap.createAlphaPixelmapSync(); 1530 return pixelmap; 1531 } 1532 return undefined; 1533} 1534``` 1535 1536### scale<sup>9+</sup> 1537 1538scale(x: number, y: number, callback: AsyncCallback\<void>): void 1539 1540Scales this image based on a given scaling multiple of the width and height. This API uses an asynchronous callback to return the result. 1541 1542**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1543 1544**Atomic service API**: This API can be used in atomic services since API version 11. 1545 1546**System capability**: SystemCapability.Multimedia.Image.Core 1547 1548**Parameters** 1549 1550| Name | Type | Mandatory| Description | 1551| -------- | -------------------- | ---- | ------------------------------- | 1552| x | number | Yes | Scaling multiple of the width.| 1553| y | number | Yes | Scaling multiple of the height.| 1554| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 1555 1556**Example** 1557 1558```ts 1559import { BusinessError } from '@kit.BasicServicesKit'; 1560 1561async function Demo() { 1562 let scaleX: number = 2.0; 1563 let scaleY: number = 1.0; 1564 if (pixelMap != undefined) { 1565 pixelMap.scale(scaleX, scaleY, (err: BusinessError) => { 1566 if (err) { 1567 console.error(`Failed to scale pixelmap. code is ${err.code}, message is ${err.message}`); 1568 return; 1569 } else { 1570 console.info("Succeeded in scaling pixelmap."); 1571 } 1572 }) 1573 } 1574} 1575``` 1576 1577### scale<sup>9+</sup> 1578 1579scale(x: number, y: number): Promise\<void> 1580 1581Scales this image based on a given scaling multiple of the width and height. This API uses a promise to return the result. 1582 1583**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1584 1585**Atomic service API**: This API can be used in atomic services since API version 11. 1586 1587**System capability**: SystemCapability.Multimedia.Image.Core 1588 1589**Parameters** 1590 1591| Name| Type | Mandatory| Description | 1592| ------ | ------ | ---- | ------------------------------- | 1593| x | number | Yes | Scaling multiple of the width.| 1594| y | number | Yes | Scaling multiple of the height.| 1595 1596**Return value** 1597 1598| Type | Description | 1599| -------------- | --------------------------- | 1600| Promise\<void> | Promise that returns no value.| 1601 1602**Example** 1603 1604```ts 1605import { BusinessError } from '@kit.BasicServicesKit'; 1606 1607async function Demo() { 1608 let scaleX: number = 2.0; 1609 let scaleY: number = 1.0; 1610 if (pixelMap != undefined) { 1611 pixelMap.scale(scaleX, scaleY).then(() => { 1612 console.info('Succeeded in scaling pixelmap.'); 1613 }).catch((err: BusinessError) => { 1614 console.error(`Failed to scale pixelmap. code is ${err.code}, message is ${err.message}`); 1615 1616 }) 1617 } 1618} 1619``` 1620 1621### scaleSync<sup>12+</sup> 1622 1623scaleSync(x: number, y: number): void 1624 1625Scales this image based on a given width and height. This API returns the result synchronously. 1626 1627**Atomic service API**: This API can be used in atomic services since API version 12. 1628 1629**System capability**: SystemCapability.Multimedia.Image.Core 1630 1631**Parameters** 1632 1633| Name| Type | Mandatory| Description | 1634| ------ | ------ | ---- | ------------------------------- | 1635| x | number | Yes | Scaling multiple of the width.| 1636| y | number | Yes | Scaling multiple of the height.| 1637 1638**Error codes** 1639 1640For details about the error codes, see [Image Error Codes](errorcode-image.md). 1641 1642| ID| Error Message| 1643| ------- | --------------------------------------------| 1644| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 1645| 501 | Resource Unavailable | 1646 1647**Example** 1648 1649```ts 1650import { BusinessError } from '@kit.BasicServicesKit'; 1651 1652async function Demo() { 1653 let scaleX: number = 2.0; 1654 let scaleY: number = 1.0; 1655 if (pixelMap != undefined) { 1656 pixelMap.scaleSync(scaleX, scaleY); 1657 } 1658} 1659``` 1660 1661### scale<sup>12+</sup> 1662 1663scale(x: number, y: number, level: AntiAliasingLevel): Promise\<void> 1664 1665Scales this image based on a given scaling multiple of the width and height. This API uses a promise to return the result. 1666 1667**Atomic service API**: This API can be used in atomic services since API version 12. 1668 1669**System capability**: SystemCapability.Multimedia.Image.Core 1670 1671**Parameters** 1672 1673| Name| Type | Mandatory| Description | 1674| ------ | ------ | ---- | ------------------------------- | 1675| x | number | Yes | Scaling multiple of the width.| 1676| y | number | Yes | Scaling multiple of the height.| 1677| level | [AntiAliasingLevel](#antialiasinglevel12) | Yes | Anti-aliasing level.| 1678 1679**Return value** 1680 1681| Type | Description | 1682| -------------- | --------------------------- | 1683| Promise\<void> | Promise that returns no value.| 1684 1685**Error codes** 1686 1687For details about the error codes, see [Image Error Codes](errorcode-image.md). 1688 1689| ID| Error Message| 1690| ------- | --------------------------------------------| 1691| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 1692| 501 | Resource Unavailable | 1693 1694**Example** 1695 1696```ts 1697import { BusinessError } from '@kit.BasicServicesKit'; 1698 1699async function Demo() { 1700 let scaleX: number = 2.0; 1701 let scaleY: number = 1.0; 1702 if (pixelMap != undefined) { 1703 pixelMap.scale(scaleX, scaleY, image.AntiAliasingLevel.LOW).then(() => { 1704 console.info('Succeeded in scaling pixelmap.'); 1705 }).catch((err: BusinessError) => { 1706 console.error(`Failed to scale pixelmap. code is ${err.code}, message is ${err.message}`); 1707 1708 }) 1709 } 1710} 1711``` 1712 1713### scaleSync<sup>12+</sup> 1714 1715scaleSync(x: number, y: number, level: AntiAliasingLevel): void 1716 1717Scales this image based on a given width and height. This API returns the result synchronously. 1718 1719**Atomic service API**: This API can be used in atomic services since API version 12. 1720 1721**System capability**: SystemCapability.Multimedia.Image.Core 1722 1723**Parameters** 1724 1725| Name| Type | Mandatory| Description | 1726| ------ | ------ | ---- | ------------------------------- | 1727| x | number | Yes | Scaling multiple of the width.| 1728| y | number | Yes | Scaling multiple of the height.| 1729| level | [AntiAliasingLevel](#antialiasinglevel12) | Yes | Anti-aliasing level.| 1730 1731**Error codes** 1732 1733For details about the error codes, see [Image Error Codes](errorcode-image.md). 1734 1735| ID| Error Message| 1736| ------- | --------------------------------------------| 1737| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 1738| 501 | Resource Unavailable | 1739 1740**Example** 1741 1742```ts 1743import { BusinessError } from '@kit.BasicServicesKit'; 1744 1745async function Demo() { 1746 let scaleX: number = 2.0; 1747 let scaleY: number = 1.0; 1748 if (pixelMap != undefined) { 1749 pixelMap.scaleSync(scaleX, scaleY, image.AntiAliasingLevel.LOW); 1750 } 1751} 1752``` 1753 1754### translate<sup>9+</sup> 1755 1756translate(x: number, y: number, callback: AsyncCallback\<void>): void 1757 1758Translates this image based on given coordinates. This API uses an asynchronous callback to return the result. 1759 1760**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1761 1762**Atomic service API**: This API can be used in atomic services since API version 11. 1763 1764**System capability**: SystemCapability.Multimedia.Image.Core 1765 1766**Parameters** 1767 1768| Name | Type | Mandatory| Description | 1769| -------- | -------------------- | ---- | ----------------------------- | 1770| x | number | Yes | X coordinate to translate. | 1771| y | number | Yes | Y coordinate to translate. | 1772| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 1773 1774**Example** 1775 1776```ts 1777import { BusinessError } from '@kit.BasicServicesKit'; 1778 1779async function Demo() { 1780 let translateX: number = 50.0; 1781 let translateY: number = 10.0; 1782 if (pixelMap != undefined) { 1783 pixelMap.translate(translateX, translateY, (err: BusinessError) => { 1784 if (err) { 1785 console.error(`Failed to translate pixelmap. code is ${err.code}, message is ${err.message}`); 1786 return; 1787 } else { 1788 console.info("Succeeded in translating pixelmap."); 1789 } 1790 }) 1791 } 1792} 1793``` 1794 1795### translate<sup>9+</sup> 1796 1797translate(x: number, y: number): Promise\<void> 1798 1799Translates this image based on given coordinates. This API uses a promise to return the result. 1800 1801**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1802 1803**Atomic service API**: This API can be used in atomic services since API version 11. 1804 1805**System capability**: SystemCapability.Multimedia.Image.Core 1806 1807**Parameters** 1808 1809| Name| Type | Mandatory| Description | 1810| ------ | ------ | ---- | ----------- | 1811| x | number | Yes | X coordinate to translate.| 1812| y | number | Yes | Y coordinate to translate.| 1813 1814**Return value** 1815 1816| Type | Description | 1817| -------------- | --------------------------- | 1818| Promise\<void> | Promise that returns no value.| 1819 1820**Example** 1821 1822```ts 1823import { BusinessError } from '@kit.BasicServicesKit'; 1824 1825async function Demo() { 1826 let translateX: number = 50.0; 1827 let translateY: number = 10.0; 1828 if (pixelMap != undefined) { 1829 pixelMap.translate(translateX, translateY).then(() => { 1830 console.info('Succeeded in translating pixelmap.'); 1831 }).catch((err: BusinessError) => { 1832 console.error(`Failed to translate pixelmap. code is ${err.code}, message is ${err.message}`); 1833 }) 1834 } 1835} 1836``` 1837 1838### translateSync<sup>12+</sup> 1839 1840translateSync(x: number, y: number): void 1841 1842Translates this image based on given coordinates. This API returns the result synchronously. 1843 1844**Atomic service API**: This API can be used in atomic services since API version 12. 1845 1846**System capability**: SystemCapability.Multimedia.Image.Core 1847 1848**Parameters** 1849 1850| Name | Type | Mandatory| Description | 1851| -------- | -------------------- | ---- | ------------------------------- | 1852| x | number | Yes | Scaling multiple of the width.| 1853| y | number | Yes | Scaling multiple of the height.| 1854 1855**Error codes** 1856 1857For details about the error codes, see [Image Error Codes](errorcode-image.md). 1858 1859| ID| Error Message| 1860| ------- | --------------------------------------------| 1861| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 1862| 501 | Resource Unavailable | 1863 1864**Example** 1865 1866```ts 1867import { BusinessError } from '@kit.BasicServicesKit'; 1868 1869async function Demo() { 1870 let translateX : number = 50.0; 1871 let translateY : number = 10.0; 1872 if (pixelMap != undefined) { 1873 pixelMap.translateSync(translateX, translateY); 1874 } 1875} 1876``` 1877 1878### rotate<sup>9+</sup> 1879 1880rotate(angle: number, callback: AsyncCallback\<void>): void 1881 1882Rotates this image based on a given angle. This API uses an asynchronous callback to return the result. 1883 1884**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1885 1886**Atomic service API**: This API can be used in atomic services since API version 11. 1887 1888**System capability**: SystemCapability.Multimedia.Image.Core 1889 1890**Parameters** 1891 1892| Name | Type | Mandatory| Description | 1893| -------- | -------------------- | ---- | ----------------------------- | 1894| angle | number | Yes | Angle to rotate. | 1895| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 1896 1897**Example** 1898 1899```ts 1900import { BusinessError } from '@kit.BasicServicesKit'; 1901 1902async function Demo() { 1903 let angle: number = 90.0; 1904 if (pixelMap != undefined) { 1905 pixelMap.rotate(angle, (err: BusinessError) => { 1906 if (err) { 1907 console.error(`Failed to rotate pixelmap. code is ${err.code}, message is ${err.message}`); 1908 return; 1909 } else { 1910 console.info("Succeeded in rotating pixelmap."); 1911 } 1912 }) 1913 } 1914} 1915``` 1916 1917### rotate<sup>9+</sup> 1918 1919rotate(angle: number): Promise\<void> 1920 1921Rotates this image based on a given angle. This API uses a promise to return the result. 1922 1923**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1924 1925**Atomic service API**: This API can be used in atomic services since API version 11. 1926 1927**System capability**: SystemCapability.Multimedia.Image.Core 1928 1929**Parameters** 1930 1931| Name| Type | Mandatory| Description | 1932| ------ | ------ | ---- | ----------------------------- | 1933| angle | number | Yes | Angle to rotate. | 1934 1935**Return value** 1936 1937| Type | Description | 1938| -------------- | --------------------------- | 1939| Promise\<void> | Promise that returns no value.| 1940 1941**Example** 1942 1943```ts 1944import { BusinessError } from '@kit.BasicServicesKit'; 1945 1946async function Demo() { 1947 let angle: number = 90.0; 1948 if (pixelMap != undefined) { 1949 pixelMap.rotate(angle).then(() => { 1950 console.info('Succeeded in rotating pixelmap.'); 1951 }).catch((err: BusinessError) => { 1952 console.error(`Failed to rotate pixelmap. code is ${err.code}, message is ${err.message}`); 1953 }) 1954 } 1955} 1956``` 1957 1958### rotateSync<sup>12+</sup> 1959 1960rotateSync(angle: number): void 1961 1962Rotates this image based on a given angle. This API returns the result synchronously. 1963 1964**Atomic service API**: This API can be used in atomic services since API version 12. 1965 1966**System capability**: SystemCapability.Multimedia.Image.Core 1967 1968**Parameters** 1969 1970| Name | Type | Mandatory| Description | 1971| -------- | -------------------- | ---- | ----------------------------- | 1972| angle | number | Yes | Angle to rotate. | 1973 1974**Error codes** 1975 1976For details about the error codes, see [Image Error Codes](errorcode-image.md). 1977 1978| ID| Error Message| 1979| ------- | --------------------------------------------| 1980| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 1981| 501 | Resource Unavailable | 1982 1983**Example** 1984 1985```ts 1986import { BusinessError } from '@kit.BasicServicesKit'; 1987 1988async function Demo() { 1989 let angle : number = 90.0; 1990 if (pixelMap != undefined) { 1991 pixelMap.rotateSync(angle); 1992 } 1993} 1994``` 1995 1996### flip<sup>9+</sup> 1997 1998flip(horizontal: boolean, vertical: boolean, callback: AsyncCallback\<void>): void 1999 2000Flips this image horizontally or vertically, or both. This API uses an asynchronous callback to return the result. 2001 2002**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2003 2004**Atomic service API**: This API can be used in atomic services since API version 11. 2005 2006**System capability**: SystemCapability.Multimedia.Image.Core 2007 2008**Parameters** 2009 2010| Name | Type | Mandatory| Description | 2011| ---------- | -------------------- | ---- | ----------------------------- | 2012| horizontal | boolean | Yes | Whether to flip the image horizontally. | 2013| vertical | boolean | Yes | Whether to flip the image vertically. | 2014| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 2015 2016**Example** 2017 2018```ts 2019import { BusinessError } from '@kit.BasicServicesKit'; 2020 2021async function Demo() { 2022 let horizontal: boolean = true; 2023 let vertical: boolean = false; 2024 if (pixelMap != undefined) { 2025 pixelMap.flip(horizontal, vertical, (err: BusinessError) => { 2026 if (err) { 2027 console.error(`Failed to flip pixelmap. code is ${err.code}, message is ${err.message}`); 2028 return; 2029 } else { 2030 console.info("Succeeded in flipping pixelmap."); 2031 } 2032 }) 2033 } 2034} 2035``` 2036 2037### flip<sup>9+</sup> 2038 2039flip(horizontal: boolean, vertical: boolean): Promise\<void> 2040 2041Flips this image horizontally or vertically, or both. This API uses a promise to return the result. 2042 2043**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2044 2045**Atomic service API**: This API can be used in atomic services since API version 11. 2046 2047**System capability**: SystemCapability.Multimedia.Image.Core 2048 2049**Parameters** 2050 2051| Name | Type | Mandatory| Description | 2052| ---------- | ------- | ---- | --------- | 2053| horizontal | boolean | Yes | Whether to flip the image horizontally.| 2054| vertical | boolean | Yes | Whether to flip the image vertically.| 2055 2056**Return value** 2057 2058| Type | Description | 2059| -------------- | --------------------------- | 2060| Promise\<void> | Promise that returns no value.| 2061 2062**Example** 2063 2064```ts 2065import { BusinessError } from '@kit.BasicServicesKit'; 2066 2067async function Demo() { 2068 let horizontal: boolean = true; 2069 let vertical: boolean = false; 2070 if (pixelMap != undefined) { 2071 pixelMap.flip(horizontal, vertical).then(() => { 2072 console.info('Succeeded in flipping pixelmap.'); 2073 }).catch((err: BusinessError) => { 2074 console.error(`Failed to flip pixelmap. code is ${err.code}, message is ${err.message}`); 2075 }) 2076 } 2077} 2078``` 2079 2080### flipSync<sup>12+</sup> 2081 2082flipSync(horizontal: boolean, vertical: boolean): void 2083 2084Flips this image horizontally or vertically, or both. This API returns the result synchronously. 2085 2086**Atomic service API**: This API can be used in atomic services since API version 12. 2087 2088**System capability**: SystemCapability.Multimedia.Image.Core 2089 2090**Parameters** 2091 2092| Name | Type | Mandatory| Description | 2093| ---------- | -------------------- | ---- | ----------------------------- | 2094| horizontal | boolean | Yes | Whether to flip the image horizontally. | 2095| vertical | boolean | Yes | Whether to flip the image vertically. | 2096 2097**Error codes** 2098 2099For details about the error codes, see [Image Error Codes](errorcode-image.md). 2100 2101| ID| Error Message| 2102| ------- | --------------------------------------------| 2103| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2104| 501 | Resource Unavailable | 2105 2106**Example** 2107 2108```ts 2109import { BusinessError } from '@kit.BasicServicesKit'; 2110 2111async function Demo() { 2112 let horizontal : boolean = true; 2113 let vertical : boolean = false; 2114 if (pixelMap != undefined) { 2115 pixelMap.flipSync(horizontal, vertical); 2116 } 2117} 2118``` 2119 2120### crop<sup>9+</sup> 2121 2122crop(region: Region, callback: AsyncCallback\<void>): void 2123 2124Crops this image based on a given size. This API uses an asynchronous callback to return the result. 2125 2126**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2127 2128**Atomic service API**: This API can be used in atomic services since API version 11. 2129 2130**System capability**: SystemCapability.Multimedia.Image.Core 2131 2132**Parameters** 2133 2134| Name | Type | Mandatory| Description | 2135| -------- | -------------------- | ---- | ----------------------------- | 2136| region | [Region](#region7) | Yes | Size of the image after cropping. | 2137| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 2138 2139**Example** 2140 2141```ts 2142import { BusinessError } from '@kit.BasicServicesKit'; 2143 2144async function Demo() { 2145 let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 2146 if (pixelMap != undefined) { 2147 pixelMap.crop(region, (err: BusinessError) => { 2148 if (err) { 2149 console.error(`Failed to crop pixelmap. code is ${err.code}, message is ${err.message}`); 2150 return; 2151 } else { 2152 console.info("Succeeded in cropping pixelmap."); 2153 } 2154 }) 2155 } 2156} 2157``` 2158 2159### crop<sup>9+</sup> 2160 2161crop(region: Region): Promise\<void> 2162 2163Crops this image based on a given size. This API uses a promise to return the result. 2164 2165**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2166 2167**Atomic service API**: This API can be used in atomic services since API version 11. 2168 2169**System capability**: SystemCapability.Multimedia.Image.Core 2170 2171**Parameters** 2172 2173| Name| Type | Mandatory| Description | 2174| ------ | ------------------ | ---- | ----------- | 2175| region | [Region](#region7) | Yes | Size of the image after cropping.| 2176 2177**Return value** 2178 2179| Type | Description | 2180| -------------- | --------------------------- | 2181| Promise\<void> | Promise that returns no value.| 2182 2183**Example** 2184 2185```ts 2186import { BusinessError } from '@kit.BasicServicesKit'; 2187 2188async function Demo() { 2189 let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 2190 if (pixelMap != undefined) { 2191 pixelMap.crop(region).then(() => { 2192 console.info('Succeeded in cropping pixelmap.'); 2193 }).catch((err: BusinessError) => { 2194 console.error(`Failed to crop pixelmap. code is ${err.code}, message is ${err.message}`); 2195 2196 }); 2197 } 2198} 2199``` 2200 2201### cropSync<sup>12+</sup> 2202 2203cropSync(region: Region): void 2204 2205Crops this image based on a given size. This API returns the result synchronously. 2206 2207**Atomic service API**: This API can be used in atomic services since API version 12. 2208 2209**System capability**: SystemCapability.Multimedia.Image.Core 2210 2211**Parameters** 2212 2213| Name | Type | Mandatory| Description | 2214| -------- | -------------------- | ---- | ----------------------------- | 2215| region | [Region](#region7) | Yes | Size of the image after cropping. | 2216 2217**Error codes** 2218 2219For details about the error codes, see [Image Error Codes](errorcode-image.md). 2220 2221| ID| Error Message| 2222| ------- | --------------------------------------------| 2223| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2224| 501 | Resource Unavailable | 2225 2226**Example** 2227 2228```ts 2229import { BusinessError } from '@kit.BasicServicesKit'; 2230 2231async function Demo() { 2232 let region : image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 2233 if (pixelMap != undefined) { 2234 pixelMap.cropSync(region); 2235 } 2236} 2237``` 2238 2239### getColorSpace<sup>10+</sup> 2240 2241getColorSpace(): colorSpaceManager.ColorSpaceManager 2242 2243Obtains the color space of this image. 2244 2245**System capability**: SystemCapability.Multimedia.Image.Core 2246 2247**Return value** 2248 2249| Type | Description | 2250| ----------------------------------- | ---------------- | 2251| [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | Color space obtained.| 2252 2253**Error codes** 2254 2255For details about the error codes, see [Image Error Codes](errorcode-image.md). 2256 2257| ID| Error Message| 2258| ------- | --------------------------------------------| 2259| 62980101| If the image data abnormal. | 2260| 62980103| If the image data unsupport. | 2261| 62980115| If the image parameter invalid. | 2262 2263**Example** 2264 2265```ts 2266async function Demo() { 2267 if (pixelMap != undefined) { 2268 let csm = pixelMap.getColorSpace(); 2269 } 2270} 2271``` 2272 2273### setColorSpace<sup>10+</sup> 2274 2275setColorSpace(colorSpace: colorSpaceManager.ColorSpaceManager): void 2276 2277Sets the color space for this image. 2278 2279**System capability**: SystemCapability.Multimedia.Image.Core 2280 2281**Parameters** 2282 2283| Name | Type | Mandatory| Description | 2284| ---------- | ----------------------------------- | ---- | --------------- | 2285| colorSpace | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | Yes | Color space to set.| 2286 2287**Error codes** 2288 2289For details about the error codes, see [Image Error Codes](errorcode-image.md). 2290 2291| ID| Error Message| 2292| ------- | --------------------------------------------| 2293| 62980111| If the operation invalid. | 2294| 62980115| If the image parameter invalid. | 2295 2296**Example** 2297 2298```ts 2299import { colorSpaceManager } from '@kit.ArkGraphics2D'; 2300async function Demo() { 2301 let colorSpaceName = colorSpaceManager.ColorSpace.SRGB; 2302 let csm: colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName); 2303 if (pixelMap != undefined) { 2304 pixelMap.setColorSpace(csm); 2305 } 2306} 2307``` 2308 2309### applyColorSpace<sup>11+</sup> 2310 2311applyColorSpace(targetColorSpace: colorSpaceManager.ColorSpaceManager, callback: AsyncCallback\<void>): void 2312 2313Performs 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. 2314 2315**System capability**: SystemCapability.Multimedia.Image.Core 2316 2317**Parameters** 2318 2319| Name | Type | Mandatory| Description | 2320| -------- | -------------------- | ---- | ----------------------------- | 2321| targetColorSpace | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | Yes | Target color space. SRGB, DCI_P3, DISPLAY_P3, and ADOBE_RGB_1998 are supported.| 2322| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 2323 2324**Error codes** 2325 2326For details about the error codes, see [Image Error Codes](errorcode-image.md). 2327 2328| ID| Error Message| 2329| ------- | ------------------------------------------| 2330| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2331| 62980104| Failed to initialize the internal object. | 2332| 62980108| Failed to convert the color space. | 2333| 62980115| Invalid image parameter. | 2334 2335**Example** 2336 2337```ts 2338import { colorSpaceManager } from '@kit.ArkGraphics2D'; 2339import { BusinessError } from '@kit.BasicServicesKit'; 2340 2341async function Demo() { 2342 let colorSpaceName = colorSpaceManager.ColorSpace.SRGB; 2343 let targetColorSpace: colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName); 2344 if (pixelMap != undefined) { 2345 pixelMap.applyColorSpace(targetColorSpace, (err: BusinessError) => { 2346 if (err) { 2347 console.error(`Failed to apply color space for pixelmap object. code is ${err.code}, message is ${err.message}`); 2348 return; 2349 } else { 2350 console.info('Succeeded in applying color space for pixelmap object.'); 2351 } 2352 }) 2353 } 2354} 2355``` 2356 2357### applyColorSpace<sup>11+</sup> 2358 2359applyColorSpace(targetColorSpace: colorSpaceManager.ColorSpaceManager): Promise\<void> 2360 2361Performs CSC on the image pixel color based on a given color space. This API uses a promise to return the result. 2362 2363**System capability**: SystemCapability.Multimedia.Image.Core 2364 2365**Parameters** 2366 2367| Name| Type | Mandatory| Description | 2368| ------ | ------------------ | ---- | ----------- | 2369| targetColorSpace | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | Yes | Target color space. SRGB, DCI_P3, DISPLAY_P3, and ADOBE_RGB_1998 are supported.| 2370 2371**Return value** 2372 2373| Type | Description | 2374| -------------- | --------------------------- | 2375| Promise\<void> | Promise that returns no value.| 2376 2377**Error codes** 2378 2379For details about the error codes, see [Image Error Codes](errorcode-image.md). 2380 2381| ID| Error Message| 2382| ------- | ------------------------------------------| 2383| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2384| 62980104| Failed to initialize the internal object. | 2385| 62980108| Failed to convert the color space. | 2386| 62980115| Invalid image parameter. | 2387 2388**Example** 2389 2390```ts 2391import { colorSpaceManager } from '@kit.ArkGraphics2D'; 2392import { BusinessError } from '@kit.BasicServicesKit'; 2393 2394async function Demo() { 2395 let colorSpaceName = colorSpaceManager.ColorSpace.SRGB; 2396 let targetColorSpace: colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName); 2397 if (pixelMap != undefined) { 2398 pixelMap.applyColorSpace(targetColorSpace).then(() => { 2399 console.info('Succeeded in applying color space for pixelmap object.'); 2400 }).catch((error: BusinessError) => { 2401 console.error(`Failed to apply color space for pixelmap object. code is ${error.code}, message is ${error.message}`); 2402 }) 2403 } 2404} 2405``` 2406 2407### toSdr<sup>12+<sup> 2408 2409toSdr(): Promise\<void> 2410 2411Converts an HDR image into an SDR image. This API uses a promise to return the result. 2412 2413**System capability**: SystemCapability.Multimedia.Image.Core 2414 2415**Return value** 2416 2417| Type | Description | 2418| -------------- | --------------------------- | 2419| Promise\<void> | Promise that returns no value.| 2420 2421**Error codes** 2422 2423For details about the error codes, see [Image Error Codes](errorcode-image.md). 2424 2425| ID| Error Message| 2426| ------- | --------------------------------------------| 2427| 62980137 | Invalid image operation. | 2428 2429**Example** 2430 2431```ts 2432import image from '@ohos.multimedia.image' 2433import resourceManager from '@ohos.resourceManager' 2434import { BusinessError } from '@kit.BasicServicesKit'; 2435 2436// 'hdr.jpg' is only an example. Replace it with the actual one in use. Otherwise, the imageSource instance fails to be created, and subsequent operations cannot be performed. 2437let img = await getContext(this).resourceManager.getMediaContent($r('app.media.hdr')); 2438let imageSource = image.createImageSource(img.buffer.slice(0)); 2439let decodingOptions: image.DecodingOptions = { 2440 desiredDynamicRange: image.DecodingDynamicRange.AUTO 2441}; 2442let pixelmap = imageSource.createPixelMapSync(decodingOptions); 2443if (pixelmap != undefined) { 2444 console.info('Succeeded in creating pixelMap object.'); 2445 try { 2446 await pixelmap.toSdr(); 2447 let imageInfo = pixelmap.getImageInfoSync(); 2448 console.info("after toSdr ,imageInfo isHdr:" + imageInfo.isHdr); 2449 } catch (e) { 2450 console.info('toSdr failed' + e); 2451 } 2452} else { 2453 console.info('Failed to create pixelMap.'); 2454} 2455``` 2456 2457### getMetadata<sup>12+</sup> 2458 2459getMetadata(key: HdrMetadataKey): HdrMetadataValue 2460 2461Obtains the value of the metadata with a given key in this pixel map. 2462 2463**System capability**: SystemCapability.Multimedia.Image.Core 2464 2465**Parameters** 2466 2467| Name | Type | Mandatory| Description | 2468| ------------- | -------------------------------- | ---- | ---------------- | 2469| key | [HdrMetadataKey](#hdrmetadatakey12) | Yes | Key of the HDR metadata.| 2470 2471**Return value** 2472 2473| Type | Description | 2474| --------------------------------- | --------------------------------- | 2475| [HdrMetadataValue](#hdrmetadatavalue12) | Value of the metadata with the given key.| 2476 2477**Error codes** 2478 2479For details about the error codes, see [Image Error Codes](errorcode-image.md). 2480 2481| ID| Error Message| 2482| ------- | --------------------------------------------| 2483| 401| Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 2484| 501 | Resource unavailable. | 2485| 62980173 | The DMA memory does not exist. | 2486| 62980173 | Memory copy failed. | 2487 2488**Example** 2489 2490```ts 2491import { BusinessError } from '@kit.BasicServicesKit'; 2492import image from '@ohos.multimedia.image' 2493 2494// Replace 'app.media.test' with a local HDR image. 2495let img = await getContext(this).resourceManager.getMediaContent($r('app.media.test')); 2496let imageSource = image.createImageSource(img.buffer.slice(0)); 2497let decodingOptions: image.DecodingOptions = { 2498 desiredDynamicRange: image.DecodingDynamicRange.AUTO 2499}; 2500let pixelmap = imageSource.createPixelMapSync(decodingOptions); 2501if (pixelmap != undefined) { 2502 console.info('Succeeded in creating pixelMap object.'); 2503 try { 2504 let staticMetadata = pixelmap.getMetadata(image.HdrMetadataKey.HDR_STATIC_METADATA); 2505 console.info("getmetadata:" + JSON.stringify(staticMetadata)); 2506 } catch (e) { 2507 console.info('pixelmap create failed' + e); 2508 } 2509} else { 2510 console.info('Failed to create pixelMap.'); 2511} 2512``` 2513 2514### setMetadata<sup>12+</sup> 2515 2516setMetadata(key: HdrMetadataKey, value: HdrMetadataValue): Promise\<void> 2517 2518Sets the value for the metadata with a given key in this pixel map. 2519 2520**System capability**: SystemCapability.Multimedia.Image.Core 2521 2522**Parameters** 2523 2524| Name | Type | Mandatory| Description | 2525| ------------- | -------------------------------- | ---- | ---------------- | 2526| key | [HdrMetadataKey](#hdrmetadatakey12) | Yes | Key of the HDR metadata.| 2527| value | [HdrMetadataValue](#hdrmetadatavalue12) | Yes | Value of the metadata.| 2528 2529**Return value** 2530 2531| Type | Description | 2532| -------------- | --------------------- | 2533| Promise\<void> | Promise that returns no value.| 2534 2535**Error codes** 2536 2537For details about the error codes, see [Image Error Codes](errorcode-image.md). 2538 2539| ID| Error Message| 2540| ------- | --------------------------------------------| 2541| 401| Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 2542| 501 | Resource unavailable. | 2543| 62980173 | The DMA memory does not exist. | 2544| 62980173 | Memory copy failed. | 2545 2546**Example** 2547 2548```ts 2549import image from '@ohos.multimedia.image' 2550import { BusinessError } from '@kit.BasicServicesKit'; 2551@State pixelmap: image.PixelMap | undefined = undefined; 2552 2553async Demo() { 2554 let staticMetadata: image.HdrStaticMetadata = { 2555 displayPrimariesX: [1.1, 1.1, 1.1], 2556 displayPrimariesY: [1.2, 1.2, 1.2], 2557 whitePointX: 1.1, 2558 whitePointY: 1.2, 2559 maxLuminance: 2.1, 2560 minLuminance: 1.0, 2561 maxContentLightLevel: 2.1, 2562 maxFrameAverageLightLevel: 2.1, 2563 } 2564 this.pixelmap?.setMetadata(image.HdrMetadataKey.HDR_STATIC_METADATA, staticMetadata); 2565} 2566``` 2567 2568### setTransferDetached<sup>12+<sup> 2569 2570setTransferDetached(detached: boolean): void 2571 2572Sets whether to detach from the original thread when this pixel map is transmitted across threads. This API applies to the scenario where the pixel map needs to be released immediately. 2573 2574**System capability**: SystemCapability.Multimedia.Image.Core 2575 2576**Parameters** 2577 2578| Name | Type | Mandatory| Description | 2579| ------- | ------------------ | ---- | ----------------------------- | 2580| detached | boolean | Yes | Whether to detach from the original thread. | 2581 2582**Error codes** 2583 2584For details about the error codes, see [Image Error Codes](errorcode-image.md). 2585 2586| ID| Error Message| 2587| ------- | --------------------------------------------| 2588| 501 | Resource Unavailable | 2589 2590**Example** 2591 2592```ts 2593import { BusinessError } from '@kit.BasicServicesKit'; 2594 2595async function Demo() { 2596 if (pixelMap != undefined) { 2597 pixelMap.setTransferDetached(true); 2598 } 2599} 2600``` 2601 2602### marshalling<sup>10+</sup> 2603 2604marshalling(sequence: rpc.MessageSequence): void 2605 2606Marshals this **PixelMap** object and writes it to a **MessageSequence** object. 2607 2608**System capability**: SystemCapability.Multimedia.Image.Core 2609 2610**Parameters** 2611 2612| Name | Type | Mandatory| Description | 2613| ---------------------- | ------------------------------------------------------ | ---- | ---------------------------------------- | 2614| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | Yes | **MessageSequence** object. | 2615 2616**Error codes** 2617 2618For details about the error codes, see [Image Error Codes](errorcode-image.md). 2619 2620| ID| Error Message| 2621| ------- | --------------------------------------------| 2622| 62980115 | Invalid image parameter. | 2623| 62980097 | IPC error. | 2624 2625**Example** 2626 2627```ts 2628import { image } from '@kit.ImageKit'; 2629import { rpc } from '@kit.IPCKit'; 2630 2631class MySequence implements rpc.Parcelable { 2632 pixel_map: image.PixelMap; 2633 constructor(conPixelMap : image.PixelMap) { 2634 this.pixel_map = conPixelMap; 2635 } 2636 marshalling(messageSequence : rpc.MessageSequence) { 2637 this.pixel_map.marshalling(messageSequence); 2638 console.info('marshalling'); 2639 return true; 2640 } 2641 unmarshalling(messageSequence : rpc.MessageSequence) { 2642 image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}}).then((pixelParcel: image.PixelMap) => { 2643 pixelParcel.unmarshalling(messageSequence).then(async (pixelMap: image.PixelMap) => { 2644 this.pixel_map = pixelMap; 2645 pixelMap.getImageInfo().then((imageInfo: image.ImageInfo) => { 2646 console.info("unmarshalling information h:" + imageInfo.size.height + "w:" + imageInfo.size.width); 2647 }) 2648 }) 2649 }); 2650 return true; 2651 } 2652} 2653async function Demo() { 2654 const color: ArrayBuffer = new ArrayBuffer(96); 2655 let bufferArr: Uint8Array = new Uint8Array(color); 2656 for (let i = 0; i < bufferArr.length; i++) { 2657 bufferArr[i] = 0x80; 2658 } 2659 let opts: image.InitializationOptions = { 2660 editable: true, 2661 pixelFormat: 4, 2662 size: { height: 4, width: 6 }, 2663 alphaType: 3 2664 } 2665 let pixelMap: image.PixelMap | undefined = undefined; 2666 image.createPixelMap(color, opts).then((srcPixelMap: image.PixelMap) => { 2667 pixelMap = srcPixelMap; 2668 }) 2669 if (pixelMap != undefined) { 2670 // Implement serialization. 2671 let parcelable: MySequence = new MySequence(pixelMap); 2672 let data: rpc.MessageSequence = rpc.MessageSequence.create(); 2673 data.writeParcelable(parcelable); 2674 2675 // Implement deserialization to obtain data through the RPC. 2676 let ret: MySequence = new MySequence(pixelMap); 2677 data.readParcelable(ret); 2678 } 2679} 2680``` 2681 2682### unmarshalling<sup>10+</sup> 2683 2684unmarshalling(sequence: rpc.MessageSequence): Promise\<PixelMap> 2685 2686Unmarshals a **MessageSequence** object to obtain a **PixelMap** object. 2687To create a **PixelMap** object in synchronous mode, use [createPixelMapFromParcel](#imagecreatepixelmapfromparcel11). 2688 2689**System capability**: SystemCapability.Multimedia.Image.Core 2690 2691**Parameters** 2692 2693| Name | Type | Mandatory| Description | 2694| ---------------------- | ----------------------------------------------------- | ---- | ---------------------------------------- | 2695| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | Yes | **MessageSequence** object that stores the **PixelMap** information. | 2696 2697**Return value** 2698 2699| Type | Description | 2700| -------------------------------- | --------------------- | 2701| Promise\<[PixelMap](#pixelmap7)> |Promise used to return the **PixelMap** object.| 2702 2703**Error codes** 2704 2705For details about the error codes, see [Image Error Codes](errorcode-image.md). 2706 2707| ID| Error Message| 2708| ------- | --------------------------------------------| 2709| 62980115 | Invalid image parameter. | 2710| 62980097 | IPC error. | 2711| 62980096 | The operation failed. | 2712 2713**Example** 2714 2715```ts 2716import { image } from '@kit.ImageKit'; 2717import { rpc } from '@kit.IPCKit'; 2718 2719class MySequence implements rpc.Parcelable { 2720 pixel_map: image.PixelMap; 2721 constructor(conPixelMap: image.PixelMap) { 2722 this.pixel_map = conPixelMap; 2723 } 2724 marshalling(messageSequence: rpc.MessageSequence) { 2725 this.pixel_map.marshalling(messageSequence); 2726 console.info('marshalling'); 2727 return true; 2728 } 2729 unmarshalling(messageSequence: rpc.MessageSequence) { 2730 image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}}).then((pixelParcel : image.PixelMap) => { 2731 pixelParcel.unmarshalling(messageSequence).then(async (pixelMap : image.PixelMap) => { 2732 this.pixel_map = pixelMap; 2733 pixelMap.getImageInfo().then((imageInfo : image.ImageInfo) => { 2734 console.info("unmarshalling information h:" + imageInfo.size.height + "w:" + imageInfo.size.width); 2735 }) 2736 }) 2737 }); 2738 return true; 2739 } 2740} 2741async function Demo() { 2742 const color: ArrayBuffer = new ArrayBuffer(96); 2743 let bufferArr: Uint8Array = new Uint8Array(color); 2744 for (let i = 0; i < bufferArr.length; i++) { 2745 bufferArr[i] = 0x80; 2746 } 2747 let opts: image.InitializationOptions = { 2748 editable: true, 2749 pixelFormat: 4, 2750 size: { height: 4, width: 6 }, 2751 alphaType: 3 2752 } 2753 let pixelMap: image.PixelMap | undefined = undefined; 2754 image.createPixelMap(color, opts).then((srcPixelMap : image.PixelMap) => { 2755 pixelMap = srcPixelMap; 2756 }) 2757 if (pixelMap != undefined) { 2758 // Implement serialization. 2759 let parcelable: MySequence = new MySequence(pixelMap); 2760 let data : rpc.MessageSequence = rpc.MessageSequence.create(); 2761 data.writeParcelable(parcelable); 2762 2763 // Implement deserialization to obtain data through the RPC. 2764 let ret : MySequence = new MySequence(pixelMap); 2765 data.readParcelable(ret); 2766 } 2767} 2768``` 2769 2770### release<sup>7+</sup> 2771 2772release():Promise\<void> 2773 2774Releases this **PixelMap** object. This API uses a promise to return the result. 2775 2776ArkTS supports memory reclamation. Even if the application does not call **release()**, the memory of the **PixelMap** object will be released by the system. However, images usually occupy a large amount of memory. Therefore, it is recommended that the application proactively call the API to release the memory when the **PixelMap** object is no longer required. 2777 2778**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2779 2780**Atomic service API**: This API can be used in atomic services since API version 11. 2781 2782**System capability**: SystemCapability.Multimedia.Image.Core 2783 2784**Return value** 2785 2786| Type | Description | 2787| -------------- | ------------------------------- | 2788| Promise\<void> | Promise that returns no value.| 2789 2790**Example** 2791 2792```ts 2793import { BusinessError } from '@kit.BasicServicesKit'; 2794 2795async function Demo() { 2796 if (pixelMap != undefined) { 2797 pixelMap.release().then(() => { 2798 console.info('Succeeded in releasing pixelmap object.'); 2799 }).catch((error: BusinessError) => { 2800 console.error(`Failed to release pixelmap object. code is ${error.code}, message is ${error.message}`); 2801 }) 2802 } 2803} 2804``` 2805 2806### release<sup>7+</sup> 2807 2808release(callback: AsyncCallback\<void>): void 2809 2810Releases this **PixelMap** object. This API uses an asynchronous callback to return the result. 2811 2812ArkTS supports memory reclamation. Even if the application does not call **release()**, the memory of the **PixelMap** object will be released by the system. However, images usually occupy a large amount of memory. Therefore, it is recommended that the application proactively call the API to release the memory when the **PixelMap** object is no longer required. 2813 2814**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2815 2816**Atomic service API**: This API can be used in atomic services since API version 11. 2817 2818**System capability**: SystemCapability.Multimedia.Image.Core 2819 2820**Parameters** 2821 2822| Name | Type | Mandatory| Description | 2823| -------- | -------------------- | ---- | ------------------ | 2824| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 2825 2826**Example** 2827 2828```ts 2829import { BusinessError } from '@kit.BasicServicesKit'; 2830 2831async function Demo() { 2832 if (pixelMap != undefined) { 2833 pixelMap.release((err: BusinessError) => { 2834 if (err) { 2835 console.error(`Failed to release pixelmap object. code is ${err.code}, message is ${err.message}`); 2836 return; 2837 } else { 2838 console.info('Succeeded in releasing pixelmap object.'); 2839 } 2840 }) 2841 } 2842} 2843``` 2844 2845## image.createImageSource 2846 2847createImageSource(uri: string): ImageSource 2848 2849Creates an **ImageSource** instance based on a given URI. 2850 2851 2852**Atomic service API**: This API can be used in atomic services since API version 11. 2853 2854**System capability**: SystemCapability.Multimedia.Image.ImageSource 2855 2856**Parameters** 2857 2858| Name| Type | Mandatory| Description | 2859| ------ | ------ | ---- | ---------------------------------- | 2860| uri | string | Yes | Image path. Currently, only the application sandbox path is supported.<br>The following formats are supported: .jpg, .png, .gif, .bmp, .webp, .dng, [.svg<sup>10+</sup>](#svg-tags), and .ico<sup>11+</sup>.| 2861 2862**Return value** 2863 2864| Type | Description | 2865| --------------------------- | -------------------------------------------- | 2866| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 2867 2868**Example** 2869 2870```ts 2871const context: Context = getContext(this); 2872// 'test.jpg' is only an example. Replace it with the actual one in use. Otherwise, the imageSource instance fails to be created, and subsequent operations cannot be performed. 2873const path: string = context.filesDir + "/test.jpg"; 2874const imageSourceApi: image.ImageSource = image.createImageSource(path); 2875``` 2876 2877## image.createImageSource<sup>9+</sup> 2878 2879createImageSource(uri: string, options: SourceOptions): ImageSource 2880 2881Creates an **ImageSource** instance based on a given URI. 2882 2883**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2884 2885**Atomic service API**: This API can be used in atomic services since API version 11. 2886 2887**System capability**: SystemCapability.Multimedia.Image.ImageSource 2888 2889**Parameters** 2890 2891| Name | Type | Mandatory| Description | 2892| ------- | ------------------------------- | ---- | ----------------------------------- | 2893| 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, .dng, [.svg<sup>10+</sup>](#svg-tags), and .ico<sup>11+</sup>.| 2894| options | [SourceOptions](#sourceoptions9) | Yes | Image properties, including the image pixel density, pixel format, and image size.| 2895 2896**Return value** 2897 2898| Type | Description | 2899| --------------------------- | -------------------------------------------- | 2900| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 2901 2902**Example** 2903 2904```ts 2905let sourceOptions: image.SourceOptions = { sourceDensity: 120 }; 2906const context: Context = getContext(this); 2907// 'test.png' is only an example. Replace it with the actual one in use. Otherwise, the imageSource instance fails to be created, and subsequent operations cannot be performed. 2908const path: string = context.filesDir + "/test.png"; 2909let imageSourceApi: image.ImageSource = image.createImageSource(path, sourceOptions); 2910``` 2911 2912## image.createImageSource<sup>7+</sup> 2913 2914createImageSource(fd: number): ImageSource 2915 2916Creates an **ImageSource** instance based on a given file descriptor. 2917 2918**Atomic service API**: This API can be used in atomic services since API version 11. 2919 2920**System capability**: SystemCapability.Multimedia.Image.ImageSource 2921 2922**Parameters** 2923 2924| Name| Type | Mandatory| Description | 2925| ------ | ------ | ---- | ------------- | 2926| fd | number | Yes | File descriptor.| 2927 2928**Return value** 2929 2930| Type | Description | 2931| --------------------------- | -------------------------------------------- | 2932| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 2933 2934**Example** 2935 2936```ts 2937import { fileIo } from '@kit.CoreFileKit'; 2938 2939const context: Context = getContext(this); 2940// 'test.jpg' is only an example. Replace it with the actual one in use. Otherwise, the imageSource instance fails to be created, and subsequent operations cannot be performed. 2941let filePath: string = context.filesDir + "/test.jpg"; 2942let file = fileIo.openSync(filePath, fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE); 2943const imageSourceApi: image.ImageSource = image.createImageSource(file.fd); 2944``` 2945 2946## image.createImageSource<sup>9+</sup> 2947 2948createImageSource(fd: number, options: SourceOptions): ImageSource 2949 2950Creates an **ImageSource** instance based on a given file descriptor. 2951 2952**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2953 2954**Atomic service API**: This API can be used in atomic services since API version 11. 2955 2956**System capability**: SystemCapability.Multimedia.Image.ImageSource 2957 2958**Parameters** 2959 2960| Name | Type | Mandatory| Description | 2961| ------- | ------------------------------- | ---- | ----------------------------------- | 2962| fd | number | Yes | File descriptor. | 2963| options | [SourceOptions](#sourceoptions9) | Yes | Image properties, including the image pixel density, pixel format, and image size.| 2964 2965**Return value** 2966 2967| Type | Description | 2968| --------------------------- | -------------------------------------------- | 2969| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 2970 2971**Example** 2972 2973```ts 2974import { fileIo } from '@kit.CoreFileKit'; 2975 2976let sourceOptions: image.SourceOptions = { sourceDensity: 120 }; 2977const context: Context = getContext(); 2978// 'test.jpg' is only an example. Replace it with the actual one in use. Otherwise, the imageSource instance fails to be created, and subsequent operations cannot be performed. 2979const filePath: string = context.filesDir + "/test.jpg"; 2980let file = fileIo.openSync(filePath, fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE); 2981const imageSourceApi: image.ImageSource = image.createImageSource(file.fd, sourceOptions); 2982``` 2983 2984## image.createImageSource<sup>9+</sup> 2985 2986createImageSource(buf: ArrayBuffer): ImageSource 2987 2988Creates an **ImageSource** instance based on buffers. 2989 2990**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2991 2992**Atomic service API**: This API can be used in atomic services since API version 11. 2993 2994**System capability**: SystemCapability.Multimedia.Image.ImageSource 2995 2996**Parameters** 2997 2998| Name| Type | Mandatory| Description | 2999| ------ | ----------- | ---- | ---------------- | 3000| buf | ArrayBuffer | Yes | Array of image buffers.| 3001 3002**Return value** 3003 3004| Type | Description | 3005| --------------------------- | -------------------------------------------- | 3006| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 3007 3008 3009**Example** 3010 3011```ts 3012const 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. 3013const imageSourceApi: image.ImageSource = image.createImageSource(buf); 3014``` 3015 3016## image.createImageSource<sup>9+</sup> 3017 3018createImageSource(buf: ArrayBuffer, options: SourceOptions): ImageSource 3019 3020Creates an **ImageSource** instance based on buffers. 3021 3022**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3023 3024**Atomic service API**: This API can be used in atomic services since API version 11. 3025 3026**System capability**: SystemCapability.Multimedia.Image.ImageSource 3027 3028**Parameters** 3029 3030| Name| Type | Mandatory| Description | 3031| ------ | -------------------------------- | ---- | ------------------------------------ | 3032| buf | ArrayBuffer | Yes | Array of image buffers. | 3033| options | [SourceOptions](#sourceoptions9) | Yes | Image properties, including the image pixel density, pixel format, and image size.| 3034 3035**Return value** 3036 3037| Type | Description | 3038| --------------------------- | -------------------------------------------- | 3039| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 3040 3041**Example** 3042 3043```ts 3044const data: ArrayBuffer = new ArrayBuffer(112); 3045let sourceOptions: image.SourceOptions = { sourceDensity: 120 }; 3046const imageSourceApi: image.ImageSource = image.createImageSource(data, sourceOptions); 3047``` 3048 3049## image.createImageSource<sup>11+</sup> 3050 3051createImageSource(rawfile: resourceManager.RawFileDescriptor, options?: SourceOptions): ImageSource 3052 3053Creates an **ImageSource** instance based on the raw file descriptor of an image resource file. 3054 3055**Atomic service API**: This API can be used in atomic services since API version 11. 3056 3057**System capability**: SystemCapability.Multimedia.Image.ImageSource 3058 3059**Parameters** 3060 3061| Name| Type | Mandatory| Description | 3062| ------ | -------------------------------- | ---- | ------------------------------------ | 3063| rawfile | [resourceManager.RawFileDescriptor](../apis-localization-kit/js-apis-resource-manager.md#rawfiledescriptor8) | Yes| Raw file descriptor of the image resource file.| 3064| options | [SourceOptions](#sourceoptions9) | No| Image properties, including the image pixel density, pixel format, and image size.| 3065 3066**Return value** 3067 3068| Type | Description | 3069| --------------------------- | -------------------------------------------- | 3070| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 3071 3072**Example** 3073 3074```ts 3075import { resourceManager } from '@kit.LocalizationKit'; 3076 3077const context: Context = getContext(this); 3078// Obtain a resource manager. 3079const resourceMgr: resourceManager.ResourceManager = context.resourceManager; 3080// 'test.jpg' is only an example. Replace it with the actual one in use. Otherwise, the imageSource instance fails to be created, and subsequent operations cannot be performed. 3081resourceMgr.getRawFd('test.jpg').then((rawFileDescriptor: resourceManager.RawFileDescriptor) => { 3082 const imageSourceApi: image.ImageSource = image.createImageSource(rawFileDescriptor); 3083}).catch((error: BusinessError) => { 3084 console.error(`Failed to get RawFileDescriptor.code is ${error.code}, message is ${error.message}`); 3085}) 3086``` 3087 3088## image.CreateIncrementalSource<sup>9+</sup> 3089 3090CreateIncrementalSource(buf: ArrayBuffer): ImageSource 3091 3092Creates an **ImageSource** instance in incremental mode based on buffers. Such an instance does not support reading or writing of EXIF information. 3093 3094The **ImageSource** instance created in incremental mode supports the following capabilities (applicable to synchronous, callback, and promise modes): 3095- Obtaining image information: Call [getImageInfo](#getimageinfo) to obtain image information by index, or call [getImageInfo](#getimageinfo-1) to directly obtain image information. 3096- Obtaining an image property: Call [getImageProperty](#getimageproperty11) to obtain the value of a property with the specified index in an image. 3097- Obtaining image properties: Call [getImageProperties](#getimageproperties12) to obtain the values of properties with the given names in an image. 3098- Updating incremental data: Call [updateData](#updatedata9) to update data. 3099- Creating a **PixelMap** object: Call [createPixelMap](#createpixelmap7) or [createPixelMap](#createpixelmap7-2) to create a pixel map based on image decoding parameters, or call [createPixelMap](#createpixelmap7-1) to create a pixel map based on default parameters. 3100- Releasing an **ImageSource** instance: Call [release](#release) to release an image source. 3101 3102**System capability**: SystemCapability.Multimedia.Image.ImageSource 3103 3104**Parameters** 3105 3106| Name | Type | Mandatory| Description | 3107| ------- | ------------| ---- | ----------| 3108| buf | ArrayBuffer | Yes | Incremental data.| 3109 3110**Return value** 3111 3112| Type | Description | 3113| --------------------------- | --------------------------------- | 3114| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns undefined otherwise.| 3115 3116**Example** 3117 3118```ts 3119const context: Context = getContext(this) 3120let imageArray = context.resourceManager.getMediaContentSync($r('app.media.startIcon')) // Obtain the image resource. 3121// 'app.media.startIcon' is only an example. Replace it with the actual one in use. Otherwise, the imageArray instance fails to be created, and subsequent operations cannot be performed. 3122let splitBuff1 = imageArray.slice(0, imageArray.byteLength / 2) // Image slice. 3123let splitBuff2 = imageArray.slice(imageArray.byteLength / 2) 3124const imageSourceIncrementalSApi: image.ImageSource = image.CreateIncrementalSource(new ArrayBuffer(imageArray.byteLength)); 3125imageSourceIncrementalSApi.updateData(splitBuff1, false, 0, splitBuff1.byteLength).then(() => { 3126 imageSourceIncrementalSApi.updateData(splitBuff2, true, 0, splitBuff2.byteLength).then(() => { 3127 let pixelMap = imageSourceIncrementalSApi.createPixelMapSync() 3128 let imageInfo = pixelMap.getImageInfoSync() 3129 console.info('Succeeded in creating pixelMap') 3130 }).catch((error : BusinessError) => { 3131 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`) 3132 }) 3133}).catch((error : BusinessError) => { 3134 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`) 3135}) 3136``` 3137 3138## image.CreateIncrementalSource<sup>9+</sup> 3139 3140CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource 3141 3142Creates an **ImageSource** instance in incremental mode based on buffers. Such an instance does not support reading or writing of EXIF information. 3143 3144The capabilities supported by the **ImageSource** instance created by this API are the same as those supported by the instance created by [CreateIncrementalSource(buf: ArrayBuffer): ImageSource](#imagecreateincrementalsource9). 3145 3146**System capability**: SystemCapability.Multimedia.Image.ImageSource 3147 3148**Parameters** 3149 3150| Name | Type | Mandatory| Description | 3151| ------- | ------------------------------- | ---- | ------------------------------------ | 3152| buf | ArrayBuffer | Yes | Incremental data. | 3153| options | [SourceOptions](#sourceoptions9) | No | Image properties, including the image pixel density, pixel format, and image size.| 3154 3155**Return value** 3156 3157| Type | Description | 3158| --------------------------- | --------------------------------- | 3159| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns undefined otherwise.| 3160 3161**Example** 3162 3163```ts 3164const context: Context = getContext(this) 3165let imageArray = context.resourceManager.getMediaContentSync($r('app.media.startIcon')) // Obtain the image resource. 3166// 'app.media.startIcon' is only an example. Replace it with the actual one in use. Otherwise, the imageArray instance fails to be created, and subsequent operations cannot be performed. 3167let splitBuff1 = imageArray.slice(0, imageArray.byteLength / 2) // Image slice. 3168let splitBuff2 = imageArray.slice(imageArray.byteLength / 2) 3169let sourceOptions: image.SourceOptions = { sourceDensity: 120}; 3170 3171const imageSourceIncrementalSApi: image.ImageSource = image.CreateIncrementalSource(new ArrayBuffer(imageArray.byteLength), sourceOptions); 3172imageSourceIncrementalSApi.updateData(splitBuff1, false, 0, splitBuff1.byteLength).then(() => { 3173 imageSourceIncrementalSApi.updateData(splitBuff2, true, 0, splitBuff2.byteLength).then(() => { 3174 let pixelMap = imageSourceIncrementalSApi.createPixelMapSync() 3175 let imageInfo = pixelMap.getImageInfoSync() 3176 console.info('Succeeded in creating pixelMap') 3177 }).catch((error : BusinessError) => { 3178 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`) 3179 }) 3180}).catch((error : BusinessError) => { 3181 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`) 3182}) 3183``` 3184 3185## ImageSource 3186 3187Provides APIs to obtain image information. Before calling any API in **ImageSource**, you must use [createImageSource](#imagecreateimagesource) to create an **ImageSource** instance. 3188 3189### Attributes 3190 3191**System capability**: SystemCapability.Multimedia.Image.ImageSource 3192 3193| Name | Type | Readable| Writable| Description | 3194| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | 3195| supportedFormats | Array\<string> | Yes | No | Supported image formats, including PNG, JPEG, BMP, GIF, WebP, and DNG.| 3196 3197### getImageInfo 3198 3199getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void 3200 3201Obtains information about an image with the specified index. This API uses an asynchronous callback to return the result. 3202 3203**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3204 3205**Atomic service API**: This API can be used in atomic services since API version 11. 3206 3207**System capability**: SystemCapability.Multimedia.Image.ImageSource 3208 3209**Parameters** 3210 3211| Name | Type | Mandatory| Description | 3212| -------- | -------------------------------------- | ---- | ---------------------------------------- | 3213| index | number | Yes | Index of the image. | 3214| callback | AsyncCallback<[ImageInfo](#imageinfo)> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the image information obtained; otherwise, **err** is an error object.| 3215 3216**Example** 3217 3218```ts 3219import { BusinessError } from '@kit.BasicServicesKit'; 3220 3221imageSourceApi.getImageInfo(0, (error: BusinessError, imageInfo: image.ImageInfo) => { 3222 if (error) { 3223 console.error(`Failed to obtain the image information.code is ${error.code}, message is ${error.message}`); 3224 } else { 3225 console.info('Succeeded in obtaining the image information.'); 3226 } 3227}) 3228``` 3229 3230### getImageInfo 3231 3232getImageInfo(callback: AsyncCallback\<ImageInfo>): void 3233 3234Obtains information about this image. This API uses an asynchronous callback to return the result. 3235 3236**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3237 3238**Atomic service API**: This API can be used in atomic services since API version 11. 3239 3240**System capability**: SystemCapability.Multimedia.Image.ImageSource 3241 3242**Parameters** 3243 3244| Name | Type | Mandatory| Description | 3245| -------- | -------------------------------------- | ---- | ---------------------------------------- | 3246| callback | AsyncCallback<[ImageInfo](#imageinfo)> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the image information obtained; otherwise, **err** is an error object.| 3247 3248**Example** 3249 3250```ts 3251import { BusinessError } from '@kit.BasicServicesKit'; 3252 3253imageSourceApi.getImageInfo((err: BusinessError, imageInfo: image.ImageInfo) => { 3254 if (err) { 3255 console.error(`Failed to obtain the image information.code is ${err.code}, message is ${err.message}`); 3256 } else { 3257 console.info('Succeeded in obtaining the image information.'); 3258 } 3259}) 3260``` 3261 3262### getImageInfo 3263 3264getImageInfo(index?: number): Promise\<ImageInfo> 3265 3266Obtains information about an image with the specified index. This API uses a promise to return the result. 3267 3268**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3269 3270**Atomic service API**: This API can be used in atomic services since API version 11. 3271 3272**System capability**: SystemCapability.Multimedia.Image.ImageSource 3273 3274**Parameters** 3275 3276| Name| Type | Mandatory| Description | 3277| ----- | ------ | ---- | ------------------------------------- | 3278| index | number | No | Index of the image. If this parameter is not set, the default value **0** is used.| 3279 3280**Return value** 3281 3282| Type | Description | 3283| -------------------------------- | ---------------------- | 3284| Promise<[ImageInfo](#imageinfo)> | Promise used to return the image information obtained.| 3285 3286**Example** 3287 3288```ts 3289import { BusinessError } from '@kit.BasicServicesKit'; 3290 3291imageSourceApi.getImageInfo(0) 3292 .then((imageInfo: image.ImageInfo) => { 3293 console.info('Succeeded in obtaining the image information.'); 3294 }).catch((error: BusinessError) => { 3295 console.error(`Failed to obtain the image information.code is ${error.code}, message is ${error.message}`); 3296 }) 3297``` 3298 3299### getImageInfoSync<sup>12+</sup> 3300 3301getImageInfoSync(index?: number): ImageInfo 3302 3303Obtains information about an image with the specified index. This API returns the result synchronously. 3304 3305**System capability**: SystemCapability.Multimedia.Image.ImageSource 3306 3307**Parameters** 3308 3309| Name| Type | Mandatory| Description | 3310| ----- | ------ | ---- | ------------------------------------- | 3311| index | number | No | Index of the image. If this parameter is not set, the default value **0** is used.| 3312 3313**Return value** 3314 3315| Type | Description | 3316| -------------------------------- | ---------------------- | 3317| [ImageInfo](#imageinfo) | Image information.| 3318 3319**Example** 3320 3321```ts 3322import { image } from '@kit.ImageKit'; 3323 3324const context: Context = getContext(this); 3325// 'test.jpg' is only an example. Replace it with the actual one in use. Otherwise, the imageSource instance fails to be created, and subsequent operations cannot be performed. 3326let filePath: string = context.filesDir + "/test.jpg"; 3327let imageSource = image.createImageSource(filePath); 3328let imageInfo = imageSource.getImageInfoSync(0); 3329if (imageInfo == undefined) { 3330 console.error('Failed to obtain the image information.'); 3331} else { 3332 console.info('Succeeded in obtaining the image information.'); 3333 console.info('imageInfo.size.height:' + imageInfo.size.height); 3334 console.info('imageInfo.size.width:' + imageInfo.size.width); 3335} 3336``` 3337 3338### getImageProperty<sup>11+</sup> 3339 3340getImageProperty(key:PropertyKey, options?: ImagePropertyOptions): Promise\<string> 3341 3342Obtains 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 or PNG format and contain EXIF information. 3343 3344**System capability**: SystemCapability.Multimedia.Image.ImageSource 3345 3346**Parameters** 3347 3348| Name | Type | Mandatory| Description | 3349| ------- | ---------------------------------------------------- | ---- | ------------------------------------ | 3350| key | [PropertyKey](#propertykey7) | Yes | Name of the property. | 3351| options | [ImagePropertyOptions](#imagepropertyoptions11) | No | Image properties, including the image index and default property value.| 3352 3353**Return value** 3354 3355| Type | Description | 3356| ---------------- | ----------------------------------------------------------------- | 3357| Promise\<string> | Promise used to return the property value. If the operation fails, the default value is returned.| 3358 3359**Error codes** 3360 3361For details about the error codes, see [Image Error Codes](errorcode-image.md). 3362 3363| ID| Error Message| 3364| ------- | --------------------------------------------| 3365| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 3366| 62980096 | The operation failed. | 3367| 62980103 | The image data is not supported. | 3368| 62980110 | The image source data is incorrect. | 3369| 62980111 | The image source data is incomplete. | 3370| 62980112 | The image format does not match. | 3371| 62980113 | Unknown image format. | 3372| 62980115 | Invalid image parameter. | 3373| 62980116| Failed to decode the image. | 3374| 62980118 | Failed to create the image plugin. | 3375| 62980122 | Failed to decode the image header. | 3376| 62980123| Images in EXIF format are not supported. | 3377| 62980135| The EXIF value is invalid. | 3378 3379**Example** 3380 3381```ts 3382import { BusinessError } from '@kit.BasicServicesKit'; 3383 3384let options: image.ImagePropertyOptions = { index: 0, defaultValue: '9999' } 3385imageSourceApi.getImageProperty(image.PropertyKey.BITS_PER_SAMPLE, options) 3386.then((data: string) => { 3387 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 3388}).catch((error: BusinessError) => { 3389 console.error('Failed to get the value of the specified attribute key of the image.'); 3390}) 3391``` 3392 3393### getImageProperty<sup>(deprecated)</sup> 3394 3395getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\<string> 3396 3397Obtains 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 or PNG format and contain EXIF information. 3398 3399> **NOTE** 3400> 3401> This API is deprecated since API version 11. You are advised to use [getImageProperty](#getimageproperty11). 3402 3403**System capability**: SystemCapability.Multimedia.Image.ImageSource 3404 3405**Parameters** 3406 3407| Name | Type | Mandatory| Description | 3408| ------- | ---------------------------------------------------- | ---- | ------------------------------------ | 3409| key | string | Yes | Name of the property. | 3410| options | [GetImagePropertyOptions](#getimagepropertyoptionsdeprecated) | No | Image properties, including the image index and default property value.| 3411 3412**Return value** 3413 3414| Type | Description | 3415| ---------------- | ----------------------------------------------------------------- | 3416| Promise\<string> | Promise used to return the property value. If the operation fails, the default value is returned.| 3417 3418**Example** 3419 3420```ts 3421import { BusinessError } from '@kit.BasicServicesKit'; 3422 3423imageSourceApi.getImageProperty("BitsPerSample") 3424 .then((data: string) => { 3425 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 3426 }).catch((error: BusinessError) => { 3427 console.error('Failed to get the value of the specified attribute key of the image.'); 3428 }) 3429``` 3430 3431### getImageProperty<sup>(deprecated)</sup> 3432 3433getImageProperty(key:string, callback: AsyncCallback\<string>): void 3434 3435Obtains 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 or PNG format and contain EXIF information. 3436 3437> **NOTE** 3438> 3439> This API is deprecated since API version 11. You are advised to use [getImageProperty](#getimageproperty11). 3440 3441**System capability**: SystemCapability.Multimedia.Image.ImageSource 3442 3443**Parameters** 3444 3445| Name | Type | Mandatory| Description | 3446| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3447| key | string | Yes | Name of the property. | 3448| callback | AsyncCallback\<string> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the property value obtained; otherwise, **err** is an error object.| 3449 3450**Example** 3451 3452```ts 3453import { BusinessError } from '@kit.BasicServicesKit'; 3454 3455imageSourceApi.getImageProperty("BitsPerSample", (error: BusinessError, data: string) => { 3456 if (error) { 3457 console.error('Failed to get the value of the specified attribute key of the image.'); 3458 } else { 3459 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 3460 } 3461}) 3462``` 3463 3464### getImageProperty<sup>(deprecated)</sup> 3465 3466getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCallback\<string>): void 3467 3468Obtains the value of a property in this image. This API uses an asynchronous callback to return the result. The image must be in JPEG or PNG format and contain EXIF information. 3469 3470> **NOTE** 3471> 3472> This API is deprecated since API version 11. You are advised to use [getImageProperty](#getimageproperty11). 3473 3474**System capability**: SystemCapability.Multimedia.Image.ImageSource 3475 3476**Parameters** 3477 3478| Name | Type | Mandatory| Description | 3479| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------- | 3480| key | string | Yes | Name of the property. | 3481| options | [GetImagePropertyOptions](#getimagepropertyoptionsdeprecated) | Yes | Image properties, including the image index and default property value. | 3482| callback | AsyncCallback\<string> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the property value obtained; otherwise, **err** is an error object.| 3483 3484**Example** 3485 3486```ts 3487import { BusinessError } from '@kit.BasicServicesKit'; 3488 3489let property: image.GetImagePropertyOptions = { index: 0, defaultValue: '9999' } 3490imageSourceApi.getImageProperty("BitsPerSample", property, (error: BusinessError, data: string) => { 3491 if (error) { 3492 console.error('Failed to get the value of the specified attribute key of the image.'); 3493 } else { 3494 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 3495 } 3496}) 3497``` 3498 3499### getImageProperties<sup>12+</sup> 3500 3501getImageProperties(key: Array<PropertyKey>): Promise<Record<PropertyKey, string|null>> 3502 3503Obtains the values of properties with the given names in this image. This API uses a promise to return the result. The image must be in JPEG or PNG format and contain EXIF information. 3504 3505**System capability**: SystemCapability.Multimedia.Image.ImageSource 3506 3507**Parameters** 3508 3509| Name | Type | Mandatory| Description | 3510| ------- | ---------------------------------------------------- | ---- | ------------------------------------ | 3511| key | Array\<[PropertyKey](#propertykey7)> | Yes | Array of properties names. | 3512 3513**Return value** 3514 3515| Type | Description | 3516| ---------------- | ----------------------------------------------------------------- | 3517| Promise\<Record<[PropertyKey](#propertykey7), string \| null>> | Promise used to return the property values. If the operation fails, **null** is returned.| 3518 3519**Error codes** 3520 3521For details about the error codes, see [Image Error Codes](errorcode-image.md). 3522 3523| ID| Error Message| 3524| ------- | --------------------------------------------| 3525| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 3526| 62980096| The operation failed. | 3527| 62980110| The image source data is incorrect. | 3528| 62980113| Unknown image format. | 3529| 62980116| Failed to decode the image. | 3530 3531**Example** 3532 3533```ts 3534import { image } from '@kit.ImageKit'; 3535import { BusinessError } from '@kit.BasicServicesKit'; 3536 3537let key = [image.PropertyKey.IMAGE_WIDTH, image.PropertyKey.IMAGE_LENGTH]; 3538imageSourceApi.getImageProperties(key).then((data) => { 3539 console.info(JSON.stringify(data)); 3540}).catch((err: BusinessError) => { 3541 console.error(JSON.stringify(err)); 3542}); 3543``` 3544 3545### modifyImageProperty<sup>11+</sup> 3546 3547modifyImageProperty(key: PropertyKey, value: string): Promise\<void> 3548 3549Modifies the value of a property in this image. This API uses a promise to return the result. The image must be in JPEG or PNG format and contain EXIF information. 3550 3551> **NOTE** 3552> 3553> The property byte length is changed when the **modifyImageProperty** API is called to modify the value of a property. Currently, you can call the API in an **ImageSource** instance created based on a file descriptor or path, but not an **ImageSource** instance created based on buffers. 3554 3555**System capability**: SystemCapability.Multimedia.Image.ImageSource 3556 3557**Parameters** 3558 3559| Name | Type | Mandatory| Description | 3560| ------- | ------ | ---- | ------------ | 3561| key | [PropertyKey](#propertykey7) | Yes | Name of the property.| 3562| value | string | Yes | New value of the property. | 3563 3564**Return value** 3565 3566| Type | Description | 3567| -------------- | --------------------------- | 3568| Promise\<void> | Promise that returns no value.| 3569 3570**Error codes** 3571 3572For details about the error codes, see [Image Error Codes](errorcode-image.md). 3573 3574| ID| Error Message| 3575| ------- | --------------------------------------------| 3576| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; | 3577| 62980123| Images in EXIF format are not supported. | 3578| 62980133| The EXIF data is out of range. | 3579| 62980135| The EXIF value is invalid. | 3580| 62980146| The EXIF data failed to be written to the file. | 3581 3582**Example** 3583 3584```ts 3585import { BusinessError } from '@kit.BasicServicesKit'; 3586 3587imageSourceApi.modifyImageProperty(image.PropertyKey.IMAGE_WIDTH, "120").then(() => { 3588 imageSourceApi.getImageProperty(image.PropertyKey.IMAGE_WIDTH).then((width: string) => { 3589 console.info(`ImageWidth is :${width}`); 3590 }).catch((error: BusinessError) => { 3591 console.error('Failed to get the Image Width.'); 3592 }) 3593}).catch((error: BusinessError) => { 3594 console.error('Failed to modify the Image Width'); 3595}) 3596``` 3597 3598### modifyImageProperty<sup>(deprecated)</sup> 3599 3600modifyImageProperty(key: string, value: string): Promise\<void> 3601 3602Modifies the value of a property in this image. This API uses a promise to return the result. The image must be in JPEG or PNG format and contain EXIF information. 3603 3604> **NOTE** 3605> 3606> The property byte length is changed when the **modifyImageProperty** API is called to modify the value of a property. Currently, you can call the API in an **ImageSource** instance created based on a file descriptor or path, but not an **ImageSource** instance created based on buffers. 3607> 3608> This API is deprecated since API version 11. You are advised to use [modifyImageProperty](#modifyimageproperty11). 3609 3610**System capability**: SystemCapability.Multimedia.Image.ImageSource 3611 3612**Parameters** 3613 3614| Name | Type | Mandatory| Description | 3615| ------- | ------ | ---- | ------------ | 3616| key | string | Yes | Name of the property.| 3617| value | string | Yes | New value of the property. | 3618 3619**Return value** 3620 3621| Type | Description | 3622| -------------- | --------------------------- | 3623| Promise\<void> | Promise that returns no value.| 3624 3625**Example** 3626 3627```ts 3628import { BusinessError } from '@kit.BasicServicesKit'; 3629 3630imageSourceApi.modifyImageProperty("ImageWidth", "120").then(() => { 3631 imageSourceApi.getImageProperty("ImageWidth").then((width: string) => { 3632 console.info(`ImageWidth is :${width}`); 3633 }).catch((error: BusinessError) => { 3634 console.error('Failed to get the Image Width.'); 3635 }) 3636}).catch((error: BusinessError) => { 3637 console.error('Failed to modify the Image Width'); 3638}) 3639``` 3640 3641### modifyImageProperty<sup>(deprecated)</sup> 3642 3643modifyImageProperty(key: string, value: string, callback: AsyncCallback\<void>): void 3644 3645Modifies the value of a property in this image. This API uses an asynchronous callback to return the result. The image must be in JPEG or PNG format and contain EXIF information. 3646 3647> **NOTE** 3648> 3649> The property byte length is changed when the **modifyImageProperty** API is called to modify the value of a property. Currently, you can call the API in an **ImageSource** instance created based on a file descriptor or path, but not an **ImageSource** instance created based on buffers. 3650> 3651>This API is deprecated since API version 11. You are advised to use [modifyImageProperty](#modifyimageproperty11). 3652 3653**System capability**: SystemCapability.Multimedia.Image.ImageSource 3654 3655**Parameters** 3656 3657| Name | Type | Mandatory| Description | 3658| -------- | ------------------- | ---- | ------------------------------ | 3659| key | string | Yes | Name of the property. | 3660| value | string | Yes | New value of the property. | 3661| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 3662 3663**Example** 3664 3665```ts 3666import { BusinessError } from '@kit.BasicServicesKit'; 3667 3668imageSourceApi.modifyImageProperty("ImageWidth", "120", (err: BusinessError) => { 3669 if (err) { 3670 console.error(`Failed to modify the Image Width.code is ${err.code}, message is ${err.message}`); 3671 } else { 3672 console.info('Succeeded in modifying the Image Width.'); 3673 } 3674}) 3675``` 3676 3677### modifyImageProperties<sup>12+</sup> 3678 3679modifyImageProperties(records: Record<PropertyKey, string|null>): Promise\<void> 3680 3681Modifies the values of properties in this image. This API uses a promise to return the result. The image must be in JPEG or PNG format and contain EXIF information. 3682 3683> **NOTE** 3684> 3685> The property byte length is changed when the **modifyImageProperties** API is called to modify the values of properties. Currently, you can call the API in an **ImageSource** instance created based on a file descriptor or path, but not an **ImageSource** instance created based on buffers. 3686> 3687 3688**System capability**: SystemCapability.Multimedia.Image.ImageSource 3689 3690**Parameters** 3691 3692| Name | Type | Mandatory| Description | 3693| ------- | ------ | ---- | ------------ | 3694| records | Record<[PropertyKey](#propertykey7), string \| null> | Yes | Array of property names and property values.| 3695 3696**Return value** 3697 3698| Type | Description | 3699| -------------- | --------------------------- | 3700| Promise\<void> | Promise that returns no value.| 3701 3702**Error codes** 3703 3704For details about the error codes, see [Image Error Codes](errorcode-image.md). 3705 3706| ID| Error Message| 3707| ------- | --------------------------------------------| 3708| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 3709| 62980123| Images in EXIF format are not supported. | 3710| 62980133| The EXIF data is out of range. | 3711| 62980135| The EXIF value is invalid. | 3712| 62980146| The EXIF data failed to be written to the file. | 3713 3714**Example** 3715 3716```ts 3717import { image } from '@kit.ImageKit'; 3718import { BusinessError } from '@kit.BasicServicesKit'; 3719 3720let keyValues: Record<PropertyKey, string|null> = { 3721 [image.PropertyKey.IMAGE_WIDTH] : "1024", 3722 [image.PropertyKey.IMAGE_LENGTH] : "1024" 3723}; 3724let checkKey = [image.PropertyKey.IMAGE_WIDTH, image.PropertyKey.IMAGE_LENGTH]; 3725imageSourceApi.modifyImageProperties(keyValues).then(() => { 3726 imageSourceApi.getImageProperties(checkKey).then((data) => { 3727 console.info(JSON.stringify(data)); 3728 }).catch((err: BusinessError) => { 3729 console.error(JSON.stringify(err)); 3730 }); 3731}).catch((err: BusinessError) => { 3732 console.error(JSON.stringify(err)); 3733}); 3734``` 3735 3736### updateData<sup>9+</sup> 3737 3738updateData(buf: ArrayBuffer, isFinished: boolean, offset: number, length: number): Promise\<void> 3739 3740Updates incremental data. This API uses a promise to return the result. 3741 3742**System capability**: SystemCapability.Multimedia.Image.ImageSource 3743 3744**Parameters** 3745 3746| Name | Type | Mandatory| Description | 3747| ---------- | ----------- | ---- | ------------ | 3748| buf | ArrayBuffer | Yes | Incremental data. | 3749| isFinished | boolean | Yes | Whether the update is complete.| 3750| offset | number | Yes | Offset for data reading. | 3751| length | number | Yes | Array length. | 3752 3753**Return value** 3754 3755| Type | Description | 3756| -------------- | -------------------------- | 3757| Promise\<void> | Promise that returns no value.| 3758 3759**Example** 3760 3761```ts 3762import { BusinessError } from '@kit.BasicServicesKit'; 3763 3764const array: ArrayBuffer = new ArrayBuffer(100); 3765imageSourceApi.updateData(array, false, 0, 10).then(() => { 3766 console.info('Succeeded in updating data.'); 3767}).catch((err: BusinessError) => { 3768 console.error(`Failed to update data.code is ${err.code},message is ${err.message}`); 3769}) 3770``` 3771 3772 3773### updateData<sup>9+</sup> 3774 3775updateData(buf: ArrayBuffer, isFinished: boolean, offset: number, length: number, callback: AsyncCallback\<void>): void 3776 3777Updates incremental data. This API uses an asynchronous callback to return the result. 3778 3779**System capability**: SystemCapability.Multimedia.Image.ImageSource 3780 3781**Parameters** 3782 3783| Name | Type | Mandatory| Description | 3784| ---------- | ------------------- | ---- | -------------------- | 3785| buf | ArrayBuffer | Yes | Incremental data. | 3786| isFinished | boolean | Yes | Whether the update is complete. | 3787| offset | number | Yes | Offset for data reading. | 3788| length | number | Yes | Array length. | 3789| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 3790 3791**Example** 3792 3793```ts 3794import { BusinessError } from '@kit.BasicServicesKit'; 3795 3796const array: ArrayBuffer = new ArrayBuffer(100); 3797imageSourceApi.updateData(array, false, 0, 10, (err: BusinessError) => { 3798 if (err) { 3799 console.error(`Failed to update data.code is ${err.code},message is ${err.message}`); 3800 } else { 3801 console.info('Succeeded in updating data.'); 3802 } 3803}) 3804``` 3805 3806### createPixelMap<sup>7+</sup> 3807 3808createPixelMap(options?: DecodingOptions): Promise\<PixelMap> 3809 3810Creates a **PixelMap** object based on image decoding parameters. This API uses a promise to return the result. 3811 3812**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3813 3814**Atomic service API**: This API can be used in atomic services since API version 11. 3815 3816**System capability**: SystemCapability.Multimedia.Image.ImageSource 3817 3818**Parameters** 3819 3820| Name | Type | Mandatory| Description | 3821| ------- | ------------------------------------ | ---- | ---------- | 3822| options | [DecodingOptions](#decodingoptions7) | No | Image decoding parameters.| 3823 3824**Return value** 3825 3826| Type | Description | 3827| -------------------------------- | --------------------- | 3828| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.| 3829 3830**Example** 3831 3832```ts 3833import { BusinessError } from '@kit.BasicServicesKit'; 3834 3835imageSourceApi.createPixelMap().then((pixelMap: image.PixelMap) => { 3836 console.info('Succeeded in creating pixelMap object through image decoding parameters.'); 3837}).catch((error: BusinessError) => { 3838 console.error('Failed to create pixelMap object through image decoding parameters.'); 3839}) 3840``` 3841 3842### createPixelMap<sup>7+</sup> 3843 3844createPixelMap(callback: AsyncCallback\<PixelMap>): void 3845 3846Creates a **PixelMap** object based on the default parameters. This API uses an asynchronous callback to return the result. 3847 3848**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3849 3850**Atomic service API**: This API can be used in atomic services since API version 11. 3851 3852**System capability**: SystemCapability.Multimedia.Image.ImageSource 3853 3854**Parameters** 3855 3856| Name | Type | Mandatory| Description | 3857| -------- | ------------------------------------- | ---- | -------------------------- | 3858| callback | AsyncCallback<[PixelMap](#pixelmap7)> | Yes | Callback used to return the result. If the operation is successful, **err** is undefined and **data** is the **PixelMap** object obtained; otherwise, **err** is an error object.| 3859 3860**Example** 3861 3862```ts 3863import { BusinessError } from '@kit.BasicServicesKit'; 3864 3865imageSourceApi.createPixelMap((err: BusinessError, pixelMap: image.PixelMap) => { 3866 if (err) { 3867 console.error(`Failed to create pixelMap.code is ${err.code},message is ${err.message}`); 3868 } else { 3869 console.info('Succeeded in creating pixelMap object.'); 3870 } 3871}) 3872``` 3873 3874### createPixelMap<sup>7+</sup> 3875 3876createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): void 3877 3878Creates a **PixelMap** object based on image decoding parameters. This API uses an asynchronous callback to return the result. 3879 3880**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3881 3882**Atomic service API**: This API can be used in atomic services since API version 11. 3883 3884**System capability**: SystemCapability.Multimedia.Image.ImageSource 3885 3886**Parameters** 3887 3888| Name | Type | Mandatory| Description | 3889| -------- | ------------------------------------- | ---- | -------------------------- | 3890| options | [DecodingOptions](#decodingoptions7) | Yes | Image decoding parameters. | 3891| callback | AsyncCallback<[PixelMap](#pixelmap7)> | Yes | Callback used to return the result. If the operation is successful, **err** is undefined and **data** is the **PixelMap** object obtained; otherwise, **err** is an error object.| 3892 3893**Example** 3894 3895```ts 3896import { BusinessError } from '@kit.BasicServicesKit'; 3897 3898let decodingOptions: image.DecodingOptions = { 3899 sampleSize: 1, 3900 editable: true, 3901 desiredSize: { width: 1, height: 2 }, 3902 rotate: 10, 3903 desiredPixelFormat: 3, 3904 desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 }, 3905 index: 0 3906}; 3907imageSourceApi.createPixelMap(decodingOptions, (err: BusinessError, pixelMap: image.PixelMap) => { 3908 if (err) { 3909 console.error(`Failed to create pixelMap.code is ${err.code},message is ${err.message}`); 3910 } else { 3911 console.info('Succeeded in creating pixelMap object.'); 3912 } 3913}) 3914``` 3915 3916### createPixelMapSync<sup>12+</sup> 3917 3918createPixelMapSync(options?: DecodingOptions): PixelMap 3919 3920Creates a **PixelMap** object based on image decoding parameters. This API returns the result synchronously. 3921 3922**System capability**: SystemCapability.Multimedia.Image.ImageSource 3923 3924**Parameters** 3925 3926| Name | Type | Mandatory| Description | 3927| -------- | ------------------------------------- | ---- | -------------------------- | 3928| options | [DecodingOptions](#decodingoptions7) | No | Image decoding parameters. | 3929 3930**Return value** 3931 3932| Type | Description | 3933| -------------------------------- | --------------------- | 3934| [PixelMap](#pixelmap7) | **PixelMap** object.| 3935 3936**Example** 3937 3938```ts 3939import { image } from '@kit.ImageKit'; 3940 3941const context: Context = getContext(this); 3942// 'test.jpg' is only an example. Replace it with the actual one in use. Otherwise, the imageSource instance fails to be created, and subsequent operations cannot be performed. 3943let filePath: string = context.filesDir + "/test.jpg"; 3944let imageSource = image.createImageSource(filePath); 3945let decodingOptions: image.DecodingOptions = { 3946 sampleSize: 1, 3947 editable: true, 3948 desiredSize: { width: 1, height: 2 }, 3949 rotate: 10, 3950 desiredPixelFormat: 3, 3951 desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 }, 3952 index: 0 3953}; 3954let pixelmap = imageSource.createPixelMapSync(decodingOptions); 3955if (pixelmap != undefined) { 3956 console.info('Succeeded in creating pixelMap object.'); 3957} else { 3958 console.info('Failed to create pixelMap.'); 3959} 3960``` 3961 3962### createPixelMapList<sup>10+</sup> 3963 3964createPixelMapList(options?: DecodingOptions): Promise<Array\<PixelMap>> 3965 3966Creates an array of **PixelMap** objects based on image decoding parameters. This API uses a promise to return the result. For dynamic images such as GIF and WebP images, this API returns the data of each frame of the image. For static images, this API returns the data of the unique frame of the image. 3967 3968**System capability**: SystemCapability.Multimedia.Image.ImageSource 3969 3970**Parameters** 3971 3972| Name | Type | Mandatory| Description | 3973| -------- | ------------------------------------- | ---- | -------------------------- | 3974| options | [DecodingOptions](#decodingoptions7) | No | Image decoding parameters. | 3975 3976**Return value** 3977 3978| Type | Description | 3979| -------------------------------- | --------------------- | 3980| Promise<Array<[PixelMap](#pixelmap7)>> | Promise used to return an array of **PixelMap** objects.| 3981 3982**Error codes** 3983 3984For details about the error codes, see [Image Error Codes](errorcode-image.md). 3985 3986| ID| Error Message| 3987| ------- | --------------------------------------------| 3988| 62980096| The operation failed. | 3989| 62980099 | The shared memory data is abnormal. | 3990| 62980101 | The image data is abnormal. | 3991| 62980103| The image data is not supported. | 3992| 62980106 | The image is too large. | 3993| 62980109 | Failed to crop the image. | 3994| 62980110| The image source data is incorrect. | 3995| 62980111| The image source data is incomplete. | 3996| 62980112 | The image format does not match. | 3997| 62980113 | Unknown image format. | 3998| 62980115 | Invalid image parameter. | 3999| 62980116 | Failed to decode the image. | 4000| 62980118| Failed to create the image plugin. | 4001| 62980122 | The image decoding header is abnormal. | 4002| 62980137 | Invalid media operation. | 4003| 62980173 | The DMA memory does not exist. | 4004| 62980174 | The DMA memory data is abnormal. | 4005 4006**Example** 4007 4008```ts 4009import { BusinessError } from '@kit.BasicServicesKit'; 4010 4011let decodeOpts: image.DecodingOptions = { 4012 sampleSize: 1, 4013 editable: true, 4014 desiredSize: { width: 198, height: 202 }, 4015 rotate: 0, 4016 desiredPixelFormat: 3, 4017 index: 0, 4018}; 4019imageSourceApi.createPixelMapList(decodeOpts).then((pixelMapList: Array<image.PixelMap>) => { 4020 console.info('Succeeded in creating pixelMapList object.'); 4021}).catch((err: BusinessError) => { 4022 console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`); 4023}) 4024``` 4025 4026### createPixelMapList<sup>10+</sup> 4027 4028createPixelMapList(callback: AsyncCallback<Array\<PixelMap>>): void 4029 4030Creates an array of **PixelMap** objects based on the default parameters. This API uses an asynchronous callback to return the result. For dynamic images such as GIF and WebP images, this API returns the data of each frame of the image. For static images, this API returns the data of the unique frame of the image. 4031 4032**System capability**: SystemCapability.Multimedia.Image.ImageSource 4033 4034**Parameters** 4035 4036| Name | Type | Mandatory| Description | 4037| -------- | ------------------------------------- | ---- | -------------------------- | 4038| callback | AsyncCallback<Array<[PixelMap](#pixelmap7)>> | Yes | Callback used to return the result. If the operation is successful, **err** is undefined and **data** is the array of **PixelMap** objects obtained; otherwise, **err** is an error object. | 4039 4040**Error codes** 4041 4042For details about the error codes, see [Image Error Codes](errorcode-image.md). 4043 4044| ID| Error Message| 4045| ------- | --------------------------------------------| 4046| 62980096 | The operation failed. | 4047| 62980099 | The shared memory data is abnormal. | 4048| 62980101 | The image data is abnormal. | 4049| 62980103 | The image data is not supported. | 4050| 62980106 | The image is too large. | 4051| 62980109 | Failed to crop the image. | 4052| 62980110 | The image source data is incorrect. | 4053| 62980111 | The image source data is incomplete. | 4054| 62980112 | The image format does not match. | 4055| 62980113 | Unknown image format. | 4056| 62980115 | Invalid image parameter. | 4057| 62980116 | Failed to decode the image. | 4058| 62980118 | Failed to create the image plugin. | 4059| 62980122 | The image decoding header is abnormal. | 4060| 62980137 | Invalid media operation. | 4061| 62980173 | The DMA memory does not exist. | 4062| 62980174 | The DMA memory data is abnormal. | 4063 4064**Example** 4065 4066```ts 4067import { BusinessError } from '@kit.BasicServicesKit'; 4068 4069imageSourceApi.createPixelMapList((err: BusinessError, pixelMapList: Array<image.PixelMap>) => { 4070 if (err) { 4071 console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`); 4072 } else { 4073 console.info('Succeeded in creating pixelMapList object.'); 4074 } 4075}) 4076``` 4077 4078### createPixelMapList<sup>10+</sup> 4079 4080createPixelMapList(options: DecodingOptions, callback: AsyncCallback<Array\<PixelMap>>): void 4081 4082Creates an array of **PixelMap** objects based on image decoding parameters. This API uses an asynchronous callback to return the result. For dynamic images such as GIF and WebP images, this API returns the data of each frame of the image. For static images, this API returns the data of the unique frame of the image. 4083 4084**System capability**: SystemCapability.Multimedia.Image.ImageSource 4085 4086**Parameters** 4087 4088| Name | Type | Mandatory| Description | 4089| -------- | -------------------- | ---- | ---------------------------------- | 4090| options | [DecodingOptions](#decodingoptions7) | Yes| Image decoding parameters.| 4091| callback | AsyncCallback<Array<[PixelMap](#pixelmap7)>> | Yes | Callback used to return the result. If the operation is successful, **err** is undefined and **data** is the array of **PixelMap** objects obtained; otherwise, **err** is an error object. | 4092 4093**Error codes** 4094 4095For details about the error codes, see [Image Error Codes](errorcode-image.md). 4096 4097| ID| Error Message| 4098| ------- | --------------------------------------------| 4099| 62980096 | The operation failed. | 4100| 62980099 | The shared memory data is abnormal. | 4101| 62980101 | The image data is abnormal. | 4102| 62980103 | The image data is not supported. | 4103| 62980106 | The image is too large. | 4104| 62980109 | Failed to crop the image. | 4105| 62980110 | The image source data is incorrect. | 4106| 62980111 | The image source data is incomplete. | 4107| 62980112 | The image format does not match. | 4108| 62980113 | Unknown image format. | 4109| 62980115 | Invalid image parameter. | 4110| 62980116 | Failed to decode the image. | 4111| 62980118 | Failed to create the image plugin. | 4112| 62980122 | The image decoding header is abnormal. | 4113| 62980137 | Invalid media operation. | 4114| 62980173 | The DMA memory does not exist. | 4115| 62980174 | The DMA memory data is abnormal. | 4116 4117**Example** 4118 4119```ts 4120import { BusinessError } from '@kit.BasicServicesKit'; 4121 4122let decodeOpts: image.DecodingOptions = { 4123 sampleSize: 1, 4124 editable: true, 4125 desiredSize: { width: 198, height: 202 }, 4126 rotate: 0, 4127 desiredPixelFormat: 3, 4128 index: 0, 4129}; 4130imageSourceApi.createPixelMapList(decodeOpts, (err: BusinessError, pixelMapList: Array<image.PixelMap>) => { 4131 if (err) { 4132 console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`); 4133 } else { 4134 console.info('Succeeded in creating pixelMapList object.'); 4135 } 4136}) 4137``` 4138 4139### getDelayTimeList<sup>10+</sup> 4140 4141getDelayTimeList(callback: AsyncCallback<Array\<number>>): void 4142 4143Obtains an array of delay times. This API uses an asynchronous callback to return the result. This API applies only to images in GIF or WebP format. 4144 4145**System capability**: SystemCapability.Multimedia.Image.ImageSource 4146 4147**Parameters** 4148 4149| Name | Type | Mandatory| Description | 4150| -------- | -------------------- | ---- | ---------------------------------- | 4151| callback | AsyncCallback<Array\<number>> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the array of delay times obtained; otherwise, **err** is an error object.| 4152 4153**Error codes** 4154 4155For details about the error codes, see [Image Error Codes](errorcode-image.md). 4156 4157| ID| Error Message| 4158| ------- | --------------------------------------------| 4159| 62980096| The operation failed. | 4160| 62980110| The image source data is incorrect. | 4161| 62980111| The image source data is incomplete. | 4162| 62980112 | The image format does not match. | 4163| 62980113| Unknown image format. | 4164| 62980115 | Invalid image parameter. | 4165| 62980116| Failed to decode the image. | 4166| 62980118| Failed to create the image plugin. | 4167| 62980122| The image decoding header is abnormal. | 4168| 62980137 | Invalid media operation. | 4169| 62980149 | Invalid media parameter. | 4170 4171**Example** 4172 4173```ts 4174import { BusinessError } from '@kit.BasicServicesKit'; 4175 4176imageSourceApi.getDelayTimeList((err: BusinessError, delayTimes: Array<number>) => { 4177 if (err) { 4178 console.error(`Failed to get delayTimes object.code is ${err.code},message is ${err.message}`); 4179 } else { 4180 console.info('Succeeded in getting delayTimes object.'); 4181 } 4182}) 4183``` 4184 4185### getDelayTimeList<sup>10+</sup> 4186 4187getDelayTimeList(): Promise<Array\<number>> 4188 4189Obtains an array of delay times. This API uses a promise to return the result. This API applies only to images in GIF or WebP format. 4190 4191**System capability**: SystemCapability.Multimedia.Image.ImageSource 4192 4193**Return value** 4194 4195| Type | Description | 4196| -------------- | --------------------------- | 4197| Promise<Array\<number>> | Promise used to return an array of delay times.| 4198 4199**Error codes** 4200 4201For details about the error codes, see [Image Error Codes](errorcode-image.md). 4202 4203| ID| Error Message| 4204| ------- | --------------------------------------------| 4205| 62980096 | The operation failed. | 4206| 62980110 | The image source data is incorrect. | 4207| 62980111 | The image source data is incomplete. | 4208| 62980112 | The image format does not match. | 4209| 62980113 | Unknown image format. | 4210| 62980115 | Invalid image parameter. | 4211| 62980116 | Failed to decode the image. | 4212| 62980118 | Failed to create the image plugin. | 4213| 62980122 | The image decoding header is abnormal. | 4214| 62980137 | Invalid media operation. | 4215| 62980149 | Invalid media parameter. | 4216 4217**Example** 4218 4219```ts 4220import { BusinessError } from '@kit.BasicServicesKit'; 4221 4222imageSourceApi.getDelayTimeList().then((delayTimes: Array<number>) => { 4223 console.info('Succeeded in getting delayTimes object.'); 4224}).catch((err: BusinessError) => { 4225 console.error(`Failed to get delayTimes object.code is ${err.code},message is ${err.message}`); 4226}) 4227``` 4228 4229### getFrameCount<sup>10+</sup> 4230 4231getFrameCount(callback: AsyncCallback\<number>): void 4232 4233Obtains the number of frames. This API uses an asynchronous callback to return the result. 4234 4235**System capability**: SystemCapability.Multimedia.Image.ImageSource 4236 4237**Parameters** 4238 4239| Name | Type | Mandatory| Description | 4240| -------- | -------------------- | ---- | ---------------------------------- | 4241| callback | AsyncCallback\<number> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the number of frames obtained; otherwise, **err** is an error object.| 4242 4243**Error codes** 4244 4245For details about the error codes, see [Image Error Codes](errorcode-image.md). 4246 4247| ID| Error Message| 4248| ------- | --------------------------------------------| 4249| 62980096| The operation failed. | 4250| 62980110| The image source data is incorrect. | 4251| 62980111| The image source data is incomplete. | 4252| 62980112| The image format does not match. | 4253| 62980113| Unknown image format. | 4254| 62980115| Invalid image parameter. | 4255| 62980116| Failed to decode the image. | 4256| 62980118| Failed to create the image plugin. | 4257| 62980122| The image decoding header is abnormal. | 4258| 62980137| Invalid media operation. | 4259 4260**Example** 4261 4262```ts 4263import { BusinessError } from '@kit.BasicServicesKit'; 4264 4265imageSourceApi.getFrameCount((err: BusinessError, frameCount: number) => { 4266 if (err) { 4267 console.error(`Failed to get frame count.code is ${err.code},message is ${err.message}`); 4268 } else { 4269 console.info('Succeeded in getting frame count.'); 4270 } 4271}) 4272``` 4273 4274### getFrameCount<sup>10+</sup> 4275 4276getFrameCount(): Promise\<number> 4277 4278Obtains the number of frames. This API uses a promise to return the result. 4279 4280**System capability**: SystemCapability.Multimedia.Image.ImageSource 4281 4282**Return value** 4283 4284| Type | Description | 4285| -------------- | --------------------------- | 4286| Promise\<number> | Promise used to return the number of frames.| 4287 4288**Error codes** 4289 4290For details about the error codes, see [Image Error Codes](errorcode-image.md). 4291 4292| ID| Error Message| 4293| ------- | --------------------------------------------| 4294| 62980096 | The operation failed. | 4295| 62980110 | The image source data is incorrect. | 4296| 62980111 | The image source data is incomplete. | 4297| 62980112 | The image format does not match. | 4298| 62980113 | Unknown image format. | 4299| 62980115 | Invalid image parameter. | 4300| 62980116 | Failed to decode the image. | 4301| 62980118 | Failed to create the image plugin. | 4302| 62980122 | The image decoding header is abnormal. | 4303| 62980137 | Invalid media operation. | 4304 4305**Example** 4306 4307```ts 4308import { BusinessError } from '@kit.BasicServicesKit'; 4309 4310imageSourceApi.getFrameCount().then((frameCount: number) => { 4311 console.info('Succeeded in getting frame count.'); 4312}).catch((err: BusinessError) => { 4313 console.error(`Failed to get frame count.code is ${err.code},message is ${err.message}`); 4314}) 4315``` 4316 4317### getDisposalTypeList<sup>12+</sup> 4318 4319getDisposalTypeList(): Promise\<Array\<number>> 4320 4321Obtains the list of disposal types. This API uses a promise to return the result. It is used only for GIF images. 4322 4323**System capability**: SystemCapability.Multimedia.Image.ImageSource 4324 4325**Return value** 4326 4327| Type | Description | 4328| -------------- | --------------------------- | 4329| Promise\<Array\<number>> | Promise used to return an array of disposal types.| 4330 4331**Error codes** 4332 4333For details about the error codes, see [Image Error Codes](errorcode-image.md). 4334 4335| ID| Error Message| 4336| ------- | --------------------------------------------| 4337| 62980096 | The operation failed. | 4338| 62980101 | The image data is abnormal. | 4339| 62980137 | Invalid media operation. | 4340| 62980149 | Invalid image source mime type. | 4341 4342**Example** 4343 4344```ts 4345import { BusinessError } from '@kit.BasicServicesKit'; 4346imageSourceApi.getDisposalTypeList().then((disposalTypes: Array<number>) => { 4347 console.info('Succeeded in getting disposalTypes object.'); 4348}).catch((err: BusinessError) => { 4349 console.error(`Failed to get disposalTypes object.code ${err.code},message is ${err.message}`); 4350}) 4351``` 4352 4353### release 4354 4355release(callback: AsyncCallback\<void>): void 4356 4357Releases this **ImageSource** instance. This API uses an asynchronous callback to return the result. 4358 4359ArkTS supports memory reclamation. Even if the application does not call **release()**, the memory of the **ImageSource** object will be released by the system. However, images usually occupy a large amount of memory. Therefore, it is recommended that the application proactively call the API to release the memory when the object is no longer required. 4360 4361**System capability**: SystemCapability.Multimedia.Image.ImageSource 4362 4363**Parameters** 4364 4365| Name | Type | Mandatory| Description | 4366| -------- | -------------------- | ---- | ---------------------------------- | 4367| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 4368 4369**Example** 4370 4371```ts 4372import { BusinessError } from '@kit.BasicServicesKit'; 4373 4374imageSourceApi.release((err: BusinessError) => { 4375 if (err) { 4376 console.error(`Failed to release the image source instance.code ${err.code},message is ${err.message}`); 4377 } else { 4378 console.info('Succeeded in releasing the image source instance.'); 4379 } 4380}) 4381``` 4382 4383### release 4384 4385release(): Promise\<void> 4386 4387Releases this **ImageSource** instance. This API uses a promise to return the result. 4388 4389ArkTS supports memory reclamation. Even if the application does not call **release()**, the memory of the **ImageSource** object will be released by the system. However, images usually occupy a large amount of memory. Therefore, it is recommended that the application proactively call the API to release the memory when the object is no longer required. 4390 4391**System capability**: SystemCapability.Multimedia.Image.ImageSource 4392 4393**Return value** 4394 4395| Type | Description | 4396| -------------- | --------------------------- | 4397| Promise\<void> | Promise that returns no value.| 4398 4399**Example** 4400 4401```ts 4402import { BusinessError } from '@kit.BasicServicesKit'; 4403 4404imageSourceApi.release().then(() => { 4405 console.info('Succeeded in releasing the image source instance.'); 4406}).catch((error: BusinessError) => { 4407 console.error(`Failed to release the image source instance.code ${error.code},message is ${error.message}`); 4408}) 4409``` 4410 4411## image.createImagePacker 4412 4413createImagePacker(): ImagePacker 4414 4415Creates an **ImagePacker** instance. 4416 4417**Atomic service API**: This API can be used in atomic services since API version 11. 4418 4419**System capability**: SystemCapability.Multimedia.Image.ImagePacker 4420 4421**Return value** 4422 4423| Type | Description | 4424| --------------------------- | --------------------- | 4425| [ImagePacker](#imagepacker) | **ImagePacker** instance created.| 4426 4427**Example** 4428 4429```ts 4430const imagePackerApi: image.ImagePacker = image.createImagePacker(); 4431``` 4432 4433## ImagePacker 4434 4435Provides 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. 4436 4437### Attributes 4438 4439**System capability**: SystemCapability.Multimedia.Image.ImagePacker 4440 4441| Name | Type | Readable| Writable| Description | 4442| ---------------- | -------------- | ---- | ---- | -------------------------- | 4443| supportedFormats | Array\<string> | Yes | No | Supported image formats, which can be JPEG, WebP, and PNG.| 4444 4445### packing 4446 4447packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void 4448 4449Packs an image. This API uses an asynchronous callback to return the result. 4450 4451**Atomic service API**: This API can be used in atomic services since API version 11. 4452 4453**System capability**: SystemCapability.Multimedia.Image.ImagePacker 4454 4455**Parameters** 4456 4457| Name | Type | Mandatory| Description | 4458| -------- | ---------------------------------- | ---- | ---------------------------------- | 4459| source | [ImageSource](#imagesource) | Yes | Image to pack. | 4460| option | [PackingOption](#packingoption) | Yes | Option for image packing. | 4461| callback | AsyncCallback\<ArrayBuffer> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the packed image data; otherwise, **err** is an error object. | 4462 4463**Example** 4464 4465```ts 4466import { BusinessError } from '@kit.BasicServicesKit'; 4467 4468const context: Context = getContext(); 4469// 'test.jpg' is only an example. Replace it with the actual one in use. Otherwise, the imageSource instance fails to be created, and subsequent operations cannot be performed. 4470let filePath: string = context.filesDir + "/test.jpg"; 4471const imageSourceApi: image.ImageSource = image.createImageSource(filePath); 4472let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }; 4473imagePackerApi.packing(imageSourceApi, packOpts, (err: BusinessError, data: ArrayBuffer) => { 4474 if (err) { 4475 console.error(`Failed to pack the image.code ${err.code},message is ${err.message}`); 4476 } else { 4477 console.info('Succeeded in packing the image.'); 4478 } 4479}) 4480``` 4481 4482### packing 4483 4484packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer> 4485 4486Packs an image. This API uses a promise to return the result. 4487 4488**Atomic service API**: This API can be used in atomic services since API version 11. 4489 4490**System capability**: SystemCapability.Multimedia.Image.ImagePacker 4491 4492**Parameters** 4493 4494| Name| Type | Mandatory| Description | 4495| ------ | ------------------------------- | ---- | -------------- | 4496| source | [ImageSource](#imagesource) | Yes | Image to pack.| 4497| option | [PackingOption](#packingoption) | Yes | Option for image packing.| 4498 4499**Return value** 4500 4501| Type | Description | 4502| ---------------------------- | --------------------------------------------- | 4503| Promise\<ArrayBuffer> | Promise used to return the packed image data.| 4504 4505**Example** 4506 4507```ts 4508import { BusinessError } from '@kit.BasicServicesKit'; 4509 4510const context: Context = getContext(); 4511// 'test.jpg' is only an example. Replace it with the actual one in use. Otherwise, the imageSource instance fails to be created, and subsequent operations cannot be performed. 4512let filePath: string = context.filesDir + "/test.jpg"; 4513const imageSourceApi: image.ImageSource = image.createImageSource(filePath); 4514let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 4515imagePackerApi.packing(imageSourceApi, packOpts) 4516 .then((data: ArrayBuffer) => { 4517 console.info('Succeeded in packing the image.'); 4518 }).catch((error: BusinessError) => { 4519 console.error(`Failed to pack the image.code ${error.code},message is ${error.message}`); 4520 }) 4521``` 4522 4523### packing<sup>8+</sup> 4524 4525packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void 4526 4527Packs an image. This API uses an asynchronous callback to return the result. 4528 4529**Atomic service API**: This API can be used in atomic services since API version 11. 4530 4531**System capability**: SystemCapability.Multimedia.Image.ImagePacker 4532 4533**Parameters** 4534 4535| Name | Type | Mandatory| Description | 4536| -------- | ------------------------------- | ---- | ---------------------------------- | 4537| source | [PixelMap](#pixelmap7) | Yes | **PixelMap** object to pack. | 4538| option | [PackingOption](#packingoption) | Yes | Option for image packing. | 4539| callback | AsyncCallback\<ArrayBuffer> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the packed image data; otherwise, **err** is an error object. | 4540 4541**Example** 4542 4543```ts 4544import { BusinessError } from '@kit.BasicServicesKit'; 4545 4546const 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. 4547let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } 4548image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => { 4549 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 4550 imagePackerApi.packing(pixelMap, packOpts, (err: BusinessError, data: ArrayBuffer) => { 4551 if (err) { 4552 console.error(`Failed to pack the image.code ${err.code},message is ${err.message}`); 4553 } else { 4554 console.info('Succeeded in packing the image.'); 4555 } 4556 }) 4557}).catch((error: BusinessError) => { 4558 console.error(`Failed to create the PixelMap.code ${error.code},message is ${error.message}`); 4559}) 4560``` 4561 4562### packing<sup>8+</sup> 4563 4564packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer> 4565 4566Packs an image. This API uses a promise to return the result. 4567 4568**Atomic service API**: This API can be used in atomic services since API version 11. 4569 4570**System capability**: SystemCapability.Multimedia.Image.ImagePacker 4571 4572**Parameters** 4573 4574| Name| Type | Mandatory| Description | 4575| ------ | ------------------------------- | ---- | ------------------ | 4576| source | [PixelMap](#pixelmap7) | Yes | **PixelMap** object to pack.| 4577| option | [PackingOption](#packingoption) | Yes | Option for image packing. | 4578 4579**Return value** 4580 4581| Type | Description | 4582| --------------------- | -------------------------------------------- | 4583| Promise\<ArrayBuffer> | Promise used to return the packed image data.| 4584 4585**Example** 4586 4587```ts 4588import { BusinessError } from '@kit.BasicServicesKit'; 4589 4590const 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. 4591let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } 4592image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => { 4593 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 4594 imagePackerApi.packing(pixelMap, packOpts) 4595 .then((data: ArrayBuffer) => { 4596 console.info('Succeeded in packing the image.'); 4597 }).catch((error: BusinessError) => { 4598 console.error(`Failed to pack the image.code ${error.code},message is ${error.message}`); 4599 }) 4600}).catch((error: BusinessError) => { 4601 console.error(`Failed to create PixelMap.code ${error.code},message is ${error.message}`); 4602}) 4603``` 4604 4605### release 4606 4607release(callback: AsyncCallback\<void>): void 4608 4609Releases this **ImagePacker** instance. This API uses an asynchronous callback to return the result. 4610 4611ArkTS supports memory reclamation. Even if the application does not call **release()**, the memory of the **ImagePacker** object will be released by the system. However, images usually occupy a large amount of memory. Therefore, it is recommended that the application proactively call the API to release the memory when the object is no longer required. 4612 4613**System capability**: SystemCapability.Multimedia.Image.ImagePacker 4614 4615**Parameters** 4616 4617| Name | Type | Mandatory| Description | 4618| -------- | -------------------- | ---- | ------------------------------ | 4619| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 4620 4621**Example** 4622 4623```ts 4624import { BusinessError } from '@kit.BasicServicesKit'; 4625 4626imagePackerApi.release((err: BusinessError)=>{ 4627 if (err) { 4628 console.error(`Failed to release image packaging.code ${err.code},message is ${err.message}`); 4629 } else { 4630 console.info('Succeeded in releasing image packaging.'); 4631 } 4632}) 4633``` 4634 4635### release 4636 4637release(): Promise\<void> 4638 4639Releases this **ImagePacker** instance. This API uses a promise to return the result. 4640 4641ArkTS supports memory reclamation. Even if the application does not call **release()**, the memory of the **ImagePacker** object will be released by the system. However, images usually occupy a large amount of memory. Therefore, it is recommended that the application proactively call the API to release the memory when the object is no longer required. 4642 4643**System capability**: SystemCapability.Multimedia.Image.ImagePacker 4644 4645**Return value** 4646 4647| Type | Description | 4648| -------------- | ------------------------------------------------------ | 4649| Promise\<void> | Promise that returns no value.| 4650 4651**Example** 4652 4653```ts 4654import { BusinessError } from '@kit.BasicServicesKit'; 4655 4656imagePackerApi.release().then(() => { 4657 console.info('Succeeded in releasing image packaging.'); 4658}).catch((error: BusinessError) => { 4659 console.error(`Failed to release image packaging.code ${error.code},message is ${error.message}`); 4660}) 4661``` 4662 4663### packToFile<sup>11+</sup> 4664 4665packToFile(source: ImageSource, fd: number, options: PackingOption, callback: AsyncCallback\<void>): void 4666 4667Encodes an **ImageSource** instance and packs it into a file. This API uses an asynchronous callback to return the result. 4668 4669**System capability**: SystemCapability.Multimedia.Image.ImagePacker 4670 4671**Parameters** 4672 4673| Name | Type | Mandatory| Description | 4674| -------- | ------------------------------- | ---- | ------------------------------ | 4675| source | [ImageSource](#imagesource) | Yes | Image to pack. | 4676| fd | number | Yes | File descriptor. | 4677| options | [PackingOption](#packingoption) | Yes | Option for image packing. | 4678| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 4679 4680**Example** 4681 4682```ts 4683import { BusinessError } from '@kit.BasicServicesKit'; 4684import { fileIo } from '@kit.CoreFileKit'; 4685 4686const context: Context = getContext(this); 4687// 'test.png' is only an example. Replace it with the actual one in use. Otherwise, the imageSource instance fails to be created, and subsequent operations cannot be performed. 4688const path: string = context.filesDir + "/test.png"; 4689const imageSourceApi: image.ImageSource = image.createImageSource(path); 4690let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }; 4691const filePath: string = context.filesDir + "/image_source.jpg"; 4692let file = fileIo.openSync(filePath, fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE); 4693const imagePackerApi: image.ImagePacker = image.createImagePacker(); 4694imagePackerApi.packToFile(imageSourceApi, file.fd, packOpts, (err: BusinessError) => { 4695 if (err) { 4696 console.error(`Failed to pack the image to file.code ${err.code},message is ${err.message}`); 4697 } else { 4698 console.info('Succeeded in packing the image to file.'); 4699 } 4700}) 4701``` 4702 4703### packToFile<sup>11+</sup> 4704 4705packToFile (source: ImageSource, fd: number, options: PackingOption): Promise\<void> 4706 4707Encodes an **ImageSource** instance and packs it into a file. This API uses a promise to return the result. 4708 4709**System capability**: SystemCapability.Multimedia.Image.ImagePacker 4710 4711**Parameters** 4712 4713| Name| Type | Mandatory| Description | 4714| ------ | ------------------------------- | ---- | -------------- | 4715| source | [ImageSource](#imagesource) | Yes | Image to pack.| 4716| fd | number | Yes | File descriptor. | 4717| options | [PackingOption](#packingoption) | Yes | Option for image packing.| 4718 4719**Return value** 4720 4721| Type | Description | 4722| -------------- | --------------------------------- | 4723| Promise\<void> | Promise that returns no value.| 4724 4725**Example** 4726 4727```ts 4728import { BusinessError } from '@kit.BasicServicesKit'; 4729import { fileIo } from '@kit.CoreFileKit'; 4730 4731const context: Context = getContext(this); 4732// 'test.png' is only an example. Replace it with the actual one in use. Otherwise, the imageSource instance fails to be created, and subsequent operations cannot be performed. 4733const path: string = context.filesDir + "/test.png"; 4734const imageSourceApi: image.ImageSource = image.createImageSource(path); 4735let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }; 4736const filePath: string = context.filesDir + "/image_source.jpg"; 4737let file = fileIo.openSync(filePath, fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE); 4738const imagePackerApi: image.ImagePacker = image.createImagePacker(); 4739imagePackerApi.packToFile(imageSourceApi, file.fd, packOpts).then(() => { 4740 console.info('Succeeded in packing the image to file.'); 4741}).catch((error: BusinessError) => { 4742 console.error(`Failed to pack the image to file.code ${error.code},message is ${error.message}`); 4743}) 4744``` 4745 4746### packToFile<sup>11+</sup> 4747 4748packToFile (source: PixelMap, fd: number, options: PackingOption, callback: AsyncCallback\<void>): void; 4749 4750Encodes a **PixelMap** instance and packs it into a file. This API uses an asynchronous callback to return the result. 4751 4752**System capability**: SystemCapability.Multimedia.Image.ImagePacker 4753 4754**Parameters** 4755 4756| Name | Type | Mandatory| Description | 4757| -------- | ------------------------------- | ---- | ------------------------------ | 4758| source | [PixelMap](#pixelmap7) | Yes | **PixelMap** object to pack. | 4759| fd | number | Yes | File descriptor. | 4760| options | [PackingOption](#packingoption) | Yes | Option for image packing. | 4761| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 4762 4763**Example** 4764 4765```ts 4766import { BusinessError } from '@kit.BasicServicesKit'; 4767import { fileIo } from '@kit.CoreFileKit'; 4768 4769const 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. 4770let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } 4771const context: Context = getContext(this); 4772const path: string = context.filesDir + "/pixel_map.jpg"; 4773image.createPixelMap(color, opts).then((pixelmap: image.PixelMap) => { 4774 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 4775 let file = fileIo.openSync(path, fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE); 4776 const imagePackerApi: image.ImagePacker = image.createImagePacker(); 4777 imagePackerApi.packToFile(pixelmap, file.fd, packOpts, (err: BusinessError) => { 4778 if (err) { 4779 console.error(`Failed to pack the image to file.code ${err.code},message is ${err.message}`); 4780 } else { 4781 console.info('Succeeded in packing the image to file.'); 4782 } 4783 }) 4784}) 4785``` 4786 4787### packToFile<sup>11+</sup> 4788 4789packToFile (source: PixelMap, fd: number, options: PackingOption): Promise\<void> 4790 4791Encodes a **PixelMap** instance and packs it into a file. This API uses a promise to return the result. 4792 4793**System capability**: SystemCapability.Multimedia.Image.ImagePacker 4794 4795**Parameters** 4796 4797| Name| Type | Mandatory| Description | 4798| ------ | ------------------------------- | ---- | -------------------- | 4799| source | [PixelMap](#pixelmap7) | Yes | **PixelMap** object to pack.| 4800| fd | number | Yes | File descriptor. | 4801| options | [PackingOption](#packingoption) | Yes | Option for image packing. | 4802 4803**Return value** 4804 4805| Type | Description | 4806| -------------- | --------------------------------- | 4807| Promise\<void> | Promise that returns no value.| 4808 4809**Example** 4810 4811```ts 4812import { BusinessError } from '@kit.BasicServicesKit'; 4813import { fileIo } from '@kit.CoreFileKit'; 4814 4815const 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. 4816let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } 4817const context: Context = getContext(this); 4818const path: string = context.filesDir + "/pixel_map.jpg"; 4819image.createPixelMap(color, opts).then((pixelmap: image.PixelMap) => { 4820 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 4821 let file = fileIo.openSync(path, fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE); 4822 const imagePackerApi: image.ImagePacker = image.createImagePacker(); 4823 imagePackerApi.packToFile(pixelmap, file.fd, packOpts) 4824 .then(() => { 4825 console.info('Succeeded in packing the image to file.'); 4826 }).catch((error: BusinessError) => { 4827 console.error(`Failed to pack the image to file.code ${error.code},message is ${error.message}`); 4828 }) 4829}) 4830``` 4831 4832## image.createImageReceiver<sup>11+</sup> 4833 4834createImageReceiver(size: Size, format: ImageFormat, capacity: number): ImageReceiver 4835 4836Creates an **ImageReceiver** instance by specifying the image size, format, and capacity. 4837 4838**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 4839 4840**Parameters** 4841 4842| Name | Type | Mandatory| Description | 4843| -------- | ------ | ---- | ---------------------- | 4844| size | [Size](#size) | Yes | Default size of the image. | 4845| format | [ImageFormat](#imageformat9) | Yes | Image format, which is a constant of [ImageFormat](#imageformat9). (Currently, only **ImageFormat:JPEG** is supported. The format actually returned is determined by the producer, for example, camera.) | 4846| capacity | number | Yes | Maximum number of images that can be accessed at the same time.| 4847 4848**Return value** 4849 4850| Type | Description | 4851| -------------------------------- | --------------------------------------- | 4852| [ImageReceiver](#imagereceiver9) | Returns an **ImageReceiver** instance if the operation is successful.| 4853 4854**Error codes** 4855 4856For details about the error codes, see [Image Error Codes](errorcode-image.md). 4857 4858| ID| Error Message| 4859| ------- | --------------------------------------------| 4860| 401| Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; | 4861 4862**Example** 4863 4864```ts 4865let size: image.Size = { 4866 height: 8192, 4867 width: 8 4868} 4869let receiver: image.ImageReceiver = image.createImageReceiver(size, image.ImageFormat.JPEG, 8); 4870``` 4871 4872## image.createImageReceiver<sup>(deprecated)</sup> 4873 4874createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver 4875 4876Creates an **ImageReceiver** instance by specifying the image width, height, format, and capacity. 4877 4878> **NOTE** 4879> 4880> This API is deprecated since API version 11. You are advised to use [createImageReceiver](#imagecreateimagereceiver11). 4881 4882**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 4883 4884**Parameters** 4885 4886| Name | Type | Mandatory| Description | 4887| -------- | ------ | ---- | ---------------------- | 4888| width | number | Yes | Default image width. | 4889| height | number | Yes | Default image height. | 4890| format | number | Yes | Image format, which is a constant of [ImageFormat](#imageformat9). (Currently, only **ImageFormat:JPEG** is supported. The format actually returned is determined by the producer, for example, camera.) | 4891| capacity | number | Yes | Maximum number of images that can be accessed at the same time.| 4892 4893**Return value** 4894 4895| Type | Description | 4896| -------------------------------- | --------------------------------------- | 4897| [ImageReceiver](#imagereceiver9) | Returns an **ImageReceiver** instance if the operation is successful.| 4898 4899**Example** 4900 4901```ts 4902let receiver: image.ImageReceiver = image.createImageReceiver(8192, 8, image.ImageFormat.JPEG, 8); 4903``` 4904 4905## ImageReceiver<sup>9+</sup> 4906 4907Provides APIs to obtain the surface ID of a component, read the latest image, read the next image, and release the **ImageReceiver** instance. 4908 4909Before calling any APIs in **ImageReceiver**, you must create an **ImageReceiver** instance. 4910 4911### Attributes 4912 4913**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 4914 4915| Name | Type | Readable| Writable| Description | 4916| -------- | ---------------------------- | ---- | ---- | ------------------ | 4917| size | [Size](#size) | Yes | No | Image size. | 4918| capacity | number | Yes | No | Maximum number of images that can be accessed at the same time.| 4919| format | [ImageFormat](#imageformat9) | Yes | No | Image format. | 4920 4921### getReceivingSurfaceId<sup>9+</sup> 4922 4923getReceivingSurfaceId(callback: AsyncCallback\<string>): void 4924 4925Obtains a surface ID for the camera or other components. This API uses an asynchronous callback to return the result. 4926 4927**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 4928 4929**Parameters** 4930 4931| Name | Type | Mandatory| Description | 4932| -------- | ---------------------- | ---- | -------------------------- | 4933| callback | AsyncCallback\<string> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the surface ID obtained. Otherwise, **err** is an error object.| 4934 4935**Example** 4936 4937```ts 4938import { BusinessError } from '@kit.BasicServicesKit'; 4939 4940receiver.getReceivingSurfaceId((err: BusinessError, id: string) => { 4941 if (err) { 4942 console.error(`Failed to get the ReceivingSurfaceId.code ${err.code},message is ${err.message}`); 4943 } else { 4944 console.info('Succeeded in getting the ReceivingSurfaceId.'); 4945 } 4946}); 4947``` 4948 4949### getReceivingSurfaceId<sup>9+</sup> 4950 4951getReceivingSurfaceId(): Promise\<string> 4952 4953Obtains a surface ID for the camera or other components. This API uses a promise to return the result. 4954 4955**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 4956 4957**Return value** 4958 4959| Type | Description | 4960| ---------------- | -------------------- | 4961| Promise\<string> | Promise used to return the surface ID.| 4962 4963**Example** 4964 4965```ts 4966import { BusinessError } from '@kit.BasicServicesKit'; 4967 4968receiver.getReceivingSurfaceId().then((id: string) => { 4969 console.info('Succeeded in getting the ReceivingSurfaceId.'); 4970}).catch((error: BusinessError) => { 4971 console.error(`Failed to get the ReceivingSurfaceId.code ${error.code},message is ${error.message}`); 4972}) 4973``` 4974 4975### readLatestImage<sup>9+</sup> 4976 4977readLatestImage(callback: AsyncCallback\<Image>): void 4978 4979Reads the latest image from the **ImageReceiver** instance. This API uses an asynchronous callback to return the result. 4980 4981**NOTE**: When the [Image](#image9) object returned by this API is no longer needed, call [release](#release9-4) to release the object. New data can be received only after the release. 4982 4983**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 4984 4985**Parameters** 4986 4987| Name | Type | Mandatory| Description | 4988| -------- | ------------------------------- | ---- | ------------------------ | 4989| callback | AsyncCallback<[Image](#image9)> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the latest image obtained; otherwise, **err** is an error object. | 4990 4991**Example** 4992 4993```ts 4994import { BusinessError } from '@kit.BasicServicesKit'; 4995 4996receiver.readLatestImage((err: BusinessError, img: image.Image) => { 4997 if (err) { 4998 console.error(`Failed to read the latest Image.code ${err.code},message is ${err.message}`); 4999 } else { 5000 console.info('Succeeded in reading the latest Image.'); 5001 } 5002}); 5003``` 5004 5005### readLatestImage<sup>9+</sup> 5006 5007readLatestImage(): Promise\<Image> 5008 5009Reads the latest image from the **ImageReceiver** instance. This API uses a promise to return the result. 5010 5011**NOTE**: When the [Image](#image9) object returned by this API is no longer needed, call [release](#release9-4) to release the object. New data can be received only after the release. 5012 5013**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 5014 5015**Return value** 5016 5017| Type | Description | 5018| ------------------------- | ------------------ | 5019| Promise<[Image](#image9)> | Promise used to return the latest image.| 5020 5021**Example** 5022 5023```ts 5024import { BusinessError } from '@kit.BasicServicesKit'; 5025 5026receiver.readLatestImage().then((img: image.Image) => { 5027 console.info('Succeeded in reading the latest Image.'); 5028}).catch((error: BusinessError) => { 5029 console.error(`Failed to read the latest Image.code ${error.code},message is ${error.message}`); 5030}) 5031``` 5032 5033### readNextImage<sup>9+</sup> 5034 5035readNextImage(callback: AsyncCallback\<Image>): void 5036 5037Reads the next image from the **ImageReceiver** instance. This API uses an asynchronous callback to return the result. 5038 5039**NOTE**: When the [Image](#image9) object returned by this API is no longer needed, call [release](#release9-4) to release the object. New data can be received only after the release. 5040 5041**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 5042 5043**Parameters** 5044 5045| Name | Type | Mandatory| Description | 5046| -------- | ------------------------------- | ---- | -------------------------- | 5047| callback | AsyncCallback<[Image](#image9)> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the next image obtained. Otherwise, **err** is an error object. | 5048 5049**Example** 5050 5051```ts 5052import { BusinessError } from '@kit.BasicServicesKit'; 5053 5054receiver.readNextImage((err: BusinessError, img: image.Image) => { 5055 if (err) { 5056 console.error(`Failed to read the next Image.code ${err.code},message is ${err.message}`); 5057 } else { 5058 console.info('Succeeded in reading the next Image.'); 5059 } 5060}); 5061``` 5062 5063### readNextImage<sup>9+</sup> 5064 5065readNextImage(): Promise\<Image> 5066 5067Reads the next image from the **ImageReceiver** instance. This API uses a promise to return the result. 5068 5069**NOTE**: When the [Image](#image9) object returned by this API is no longer needed, call [release](#release9-4) to release the object. New data can be received only after the release. 5070 5071**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 5072 5073**Return value** 5074 5075| Type | Description | 5076| ------------------------- | -------------------- | 5077| Promise<[Image](#image9)> | Promise used to return the next image.| 5078 5079**Example** 5080 5081```ts 5082import { BusinessError } from '@kit.BasicServicesKit'; 5083 5084receiver.readNextImage().then((img: image.Image) => { 5085 console.info('Succeeded in reading the next Image.'); 5086}).catch((error: BusinessError) => { 5087 console.error(`Failed to read the next Image.code ${error.code},message is ${error.message}`); 5088}) 5089``` 5090 5091### on<sup>9+</sup> 5092 5093on(type: 'imageArrival', callback: AsyncCallback\<void>): void 5094 5095Listens for image arrival events. 5096 5097**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 5098 5099**Parameters** 5100 5101| Name | Type | Mandatory| Description | 5102| -------- | -------------------- | ---- | ------------------------------------------------------ | 5103| type | string | Yes | Type of event to listen for. The value is fixed at **'imageArrival'**, which is triggered when an image is received.| 5104| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 5105 5106**Example** 5107 5108```ts 5109receiver.on('imageArrival', () => { 5110 // image arrival, do something. 5111}) 5112``` 5113 5114### release<sup>9+</sup> 5115 5116release(callback: AsyncCallback\<void>): void 5117 5118Releases this **ImageReceiver** instance. This API uses an asynchronous callback to return the result. 5119 5120ArkTS supports memory reclamation. Even if the application does not call **release()**, the memory of the **ImageReceiver** object will be released by the system. However, images usually occupy a large amount of memory. Therefore, it is recommended that the application proactively call the API to release the memory when the object is no longer required. 5121 5122**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 5123 5124**Parameters** 5125 5126| Name | Type | Mandatory| Description | 5127| -------- | -------------------- | ---- | ------------------------ | 5128| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 5129 5130**Example** 5131 5132```ts 5133import { BusinessError } from '@kit.BasicServicesKit'; 5134 5135receiver.release((err: BusinessError) => { 5136 if (err) { 5137 console.error(`Failed to release the receiver.code ${err.code},message is ${err.message}`); 5138 } else { 5139 console.info('Succeeded in releasing the receiver.'); 5140 } 5141}) 5142``` 5143 5144### release<sup>9+</sup> 5145 5146release(): Promise\<void> 5147 5148Releases this **ImageReceiver** instance. This API uses a promise to return the result. 5149 5150ArkTS supports memory reclamation. Even if the application does not call **release()**, the memory of the **ImageReceiver** object will be released by the system. However, images usually occupy a large amount of memory. Therefore, it is recommended that the application proactively call the API to release the memory when the object is no longer required. 5151 5152**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 5153 5154**Return value** 5155 5156| Type | Description | 5157| -------------- | ------------------ | 5158| Promise\<void> | Promise that returns no value.| 5159 5160**Example** 5161 5162```ts 5163import { BusinessError } from '@kit.BasicServicesKit'; 5164 5165receiver.release().then(() => { 5166 console.info('Succeeded in releasing the receiver.'); 5167}).catch((error: BusinessError) => { 5168 console.error(`Failed to release the receiver.code ${error.code},message is ${error.message}`); 5169}) 5170``` 5171 5172## image.createImageCreator<sup>11+</sup> 5173 5174createImageCreator(size: Size, format: ImageFormat, capacity: number): ImageCreator 5175 5176Creates an **ImageCreator** instance by specifying the image size, format, and capacity. 5177 5178**System capability**: SystemCapability.Multimedia.Image.ImageCreator 5179 5180**Parameters** 5181 5182| Name | Type | Mandatory| Description | 5183| -------- | ------ | ---- | ---------------------- | 5184| size | [Size](#size) | Yes | Default size of the image. | 5185| format | [ImageFormat](#imageformat9) | Yes | Image format, for example, YCBCR_422_SP or JPEG. | 5186| capacity | number | Yes | Maximum number of images that can be accessed at the same time.| 5187 5188**Return value** 5189 5190| Type | Description | 5191| ------------------------------ | --------------------------------------- | 5192| [ImageCreator](#imagecreator9) | Returns an **ImageCreator** instance if the operation is successful.| 5193 5194 5195**Error codes** 5196 5197For details about the error codes, see [Image Error Codes](errorcode-image.md). 5198 5199| ID| Error Message| 5200| ------- | --------------------------------------------| 5201| 401| Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; | 5202 5203**Example** 5204 5205```ts 5206let size: image.Size = { 5207 height: 8192, 5208 width: 8 5209} 5210let creator: image.ImageCreator = image.createImageCreator(size, image.ImageFormat.JPEG, 8); 5211``` 5212 5213## image.createImageCreator<sup>(deprecated)</sup> 5214 5215createImageCreator(width: number, height: number, format: number, capacity: number): ImageCreator 5216 5217Creates an **ImageCreator** instance by specifying the image width, height, format, and capacity. 5218 5219> **NOTE** 5220> 5221> This API is deprecated since API version 11. You are advised to use [createImageCreator](#imagecreateimagecreator11). 5222 5223**System capability**: SystemCapability.Multimedia.Image.ImageCreator 5224 5225**Parameters** 5226 5227| Name | Type | Mandatory| Description | 5228| -------- | ------ | ---- | ---------------------- | 5229| width | number | Yes | Default image width. | 5230| height | number | Yes | Default image height. | 5231| format | number | Yes | Image format, for example, YCBCR_422_SP or JPEG. | 5232| capacity | number | Yes | Maximum number of images that can be accessed at the same time.| 5233 5234**Return value** 5235 5236| Type | Description | 5237| ------------------------------ | --------------------------------------- | 5238| [ImageCreator](#imagecreator9) | Returns an **ImageCreator** instance if the operation is successful.| 5239 5240**Example** 5241 5242```ts 5243let creator: image.ImageCreator = image.createImageCreator(8192, 8, image.ImageFormat.JPEG, 8); 5244``` 5245 5246## ImageCreator<sup>9+</sup> 5247 5248Provides APIs for applications to request an image native data area and compile native image data. 5249Before calling any APIs in **ImageCreator**, you must create an [ImageCreator](#imagecreator9) instance. **ImageCreator** does not support multiple threads. 5250 5251### Attributes 5252 5253**System capability**: SystemCapability.Multimedia.Image.ImageCreator 5254 5255| Name | Type | Readable| Writable| Description | 5256| -------- | ---------------------------- | ---- | ---- | ------------------ | 5257| capacity | number | Yes | No | Maximum number of images that can be accessed at the same time.| 5258| format | [ImageFormat](#imageformat9) | Yes | No | Image format. | 5259 5260### dequeueImage<sup>9+</sup> 5261 5262dequeueImage(callback: AsyncCallback\<Image>): void 5263 5264Obtains an image buffer from the idle queue and writes image data into it. This API uses an asynchronous callback to return the result. 5265 5266**System capability**: SystemCapability.Multimedia.Image.ImageCreator 5267 5268**Parameters** 5269 5270| Name | Type | Mandatory| Description | 5271| ------------- | ---------------------------------------| ---- | -------------------- | 5272| callback | AsyncCallback\<[Image](#image9)> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the latest image obtained; otherwise, **err** is an error object. | 5273 5274**Example** 5275 5276```ts 5277import { BusinessError } from '@kit.BasicServicesKit'; 5278 5279creator.dequeueImage((err: BusinessError, img: image.Image) => { 5280 if (err) { 5281 console.error(`Failed to dequeue the Image.code ${err.code},message is ${err.message}`); 5282 } else { 5283 console.info('Succeeded in dequeuing the Image.'); 5284 } 5285}); 5286``` 5287 5288### dequeueImage<sup>9+</sup> 5289 5290dequeueImage(): Promise\<Image> 5291 5292Obtains an image buffer from the idle queue and writes image data into it. This API uses a promise to return the result. 5293 5294**System capability**: SystemCapability.Multimedia.Image.ImageCreator 5295 5296**Return value** 5297 5298| Type | Description | 5299| --------------- | ------------- | 5300| Promise\<[Image](#image9)> | Promise used to return the latest image.| 5301 5302**Example** 5303 5304```ts 5305import { BusinessError } from '@kit.BasicServicesKit'; 5306 5307creator.dequeueImage().then((img: image.Image) => { 5308 console.info('Succeeded in dequeuing the Image.'); 5309}).catch((error: BusinessError) => { 5310 console.error(`Failed to dequeue the Image.code ${error.code},message is ${error.message}`); 5311}) 5312``` 5313 5314### queueImage<sup>9+</sup> 5315 5316queueImage(interface: Image, callback: AsyncCallback\<void>): void 5317 5318Places the drawn image in the dirty queue. This API uses an asynchronous callback to return the result. 5319 5320**System capability**: SystemCapability.Multimedia.Image.ImageCreator 5321 5322**Parameters** 5323 5324| Name | Type | Mandatory| Description | 5325| ------------- | -------------------------| ---- | -------------------- | 5326| interface | [Image](#image9) | Yes | Drawn image.| 5327| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 5328 5329**Example** 5330 5331```ts 5332import { BusinessError } from '@kit.BasicServicesKit'; 5333 5334creator.dequeueImage().then((img: image.Image) => { 5335 // Draw the image. 5336 img.getComponent(4).then((component : image.Component) => { 5337 let bufferArr: Uint8Array = new Uint8Array(component.byteBuffer); 5338 for (let i = 0; i < bufferArr.length; i += 4) { 5339 bufferArr[i] = 0; //B 5340 bufferArr[i + 1] = 0; //G 5341 bufferArr[i + 2] = 255; //R 5342 bufferArr[i + 3] = 255; //A 5343 } 5344 }) 5345 creator.queueImage(img, (err: BusinessError) => { 5346 if (err) { 5347 console.error(`Failed to queue the Image.code ${err.code},message is ${err.message}`); 5348 } else { 5349 console.info('Succeeded in queuing the Image.'); 5350 } 5351 }) 5352}) 5353 5354``` 5355 5356### queueImage<sup>9+</sup> 5357 5358queueImage(interface: Image): Promise\<void> 5359 5360Places the drawn image in the dirty queue. This API uses a promise to return the result. 5361 5362**System capability**: SystemCapability.Multimedia.Image.ImageCreator 5363 5364**Parameters** 5365 5366| Name | Type | Mandatory| Description | 5367| ------------- | --------| ---- | ------------------- | 5368| interface | [Image](#image9) | Yes | Drawn image.| 5369 5370**Return value** 5371 5372| Type | Description | 5373| -------------- | ------------- | 5374| Promise\<void> | Promise that returns no value.| 5375 5376**Example** 5377 5378```ts 5379import { BusinessError } from '@kit.BasicServicesKit'; 5380 5381creator.dequeueImage().then((img: image.Image) => { 5382 // Draw the image. 5383 img.getComponent(4).then((component: image.Component) => { 5384 let bufferArr: Uint8Array = new Uint8Array(component.byteBuffer); 5385 for (let i = 0; i < bufferArr.length; i += 4) { 5386 bufferArr[i] = 0; //B 5387 bufferArr[i + 1] = 0; //G 5388 bufferArr[i + 2] = 255; //R 5389 bufferArr[i + 3] = 255; //A 5390 } 5391 }) 5392 creator.queueImage(img).then(() => { 5393 console.info('Succeeded in queuing the Image.'); 5394 }).catch((error: BusinessError) => { 5395 console.error(`Failed to queue the Image.code ${error.code},message is ${error.message}`); 5396 }) 5397}) 5398 5399``` 5400 5401### on<sup>9+</sup> 5402 5403on(type: 'imageRelease', callback: AsyncCallback\<void>): void 5404 5405Listens for image release events. This API uses an asynchronous callback to return the result. 5406 5407**System capability**: SystemCapability.Multimedia.Image.ImageCreator 5408 5409**Parameters** 5410 5411| Name | Type | Mandatory| Description | 5412| ------------- | -------------------------| ---- | -------------------- | 5413| type | string | Yes | Type of event, which is **'imageRelease'**.| 5414| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 5415 5416**Example** 5417 5418```ts 5419import { BusinessError } from '@kit.BasicServicesKit'; 5420 5421creator.on('imageRelease', (err: BusinessError) => { 5422 if (err) { 5423 console.error(`Failed to get the imageRelease callback.code ${err.code},message is ${err.message}`); 5424 } else { 5425 console.info('Succeeded in getting imageRelease callback.'); 5426 } 5427}) 5428``` 5429 5430### release<sup>9+</sup> 5431 5432release(callback: AsyncCallback\<void>): void 5433 5434Releases this **ImageCreator** instance. This API uses an asynchronous callback to return the result. 5435 5436ArkTS supports memory reclamation. Even if the application does not call **release()**, the memory of the **ImageCreator** object will be released by the system. However, images usually occupy a large amount of memory. Therefore, it is recommended that the application proactively call the API to release the memory when the object is no longer required. 5437 5438**System capability**: SystemCapability.Multimedia.Image.ImageCreator 5439 5440**Parameters** 5441 5442| Name | Type | Mandatory| Description | 5443| ------------- | -------------------------| ---- | -------------------- | 5444| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 5445 5446**Example** 5447 5448```ts 5449import { BusinessError } from '@kit.BasicServicesKit'; 5450 5451creator.release((err: BusinessError) => { 5452 if (err) { 5453 console.error(`Failed to release the creator.code ${err.code},message is ${err.message}`); 5454 } else { 5455 console.info('Succeeded in releasing creator.'); 5456 } 5457}); 5458``` 5459### release<sup>9+</sup> 5460 5461release(): Promise\<void> 5462 5463Releases this **ImageCreator** instance. This API uses a promise to return the result. 5464 5465ArkTS supports memory reclamation. Even if the application does not call **release()**, the memory of the **ImageCreator** object will be released by the system. However, images usually occupy a large amount of memory. Therefore, it is recommended that the application proactively call the API to release the memory when the object is no longer required. 5466 5467**System capability**: SystemCapability.Multimedia.Image.ImageCreator 5468 5469**Return value** 5470 5471| Type | Description | 5472| -------------- | ------------- | 5473| Promise\<void> | Promise that returns no value.| 5474 5475**Example** 5476 5477```ts 5478import { BusinessError } from '@kit.BasicServicesKit'; 5479 5480creator.release().then(() => { 5481 console.info('Succeeded in releasing creator.'); 5482}).catch((error: BusinessError) => { 5483 console.error(`Failed to release the creator.code ${error.code},message is ${error.message}`); 5484}) 5485``` 5486 5487## Image<sup>9+</sup> 5488 5489Provides 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. 5490 5491### Attributes 5492 5493**System capability**: SystemCapability.Multimedia.Image.Core 5494 5495| Name | Type | Readable| Writable| Description | 5496| -------- | ------------------ | ---- | ---- | -------------------------------------------------- | 5497| clipRect | [Region](#region7) | Yes | Yes | Image area to be cropped. | 5498| size | [Size](#size) | Yes | No | Image size. | 5499| format | number | Yes | No | Image format. For details, see [OH_NativeBuffer_Format](../apis-arkgraphics2d/_o_h___native_buffer.md#oh_nativebuffer_format).| 5500| timestamp<sup>12+</sup> | number | Yes | No | Image timestamp.| 5501 5502### getComponent<sup>9+</sup> 5503 5504getComponent(componentType: ComponentType, callback: AsyncCallback\<Component>): void 5505 5506Obtains the component buffer from the **Image** instance based on the color component type. This API uses an asynchronous callback to return the result. 5507 5508**System capability**: SystemCapability.Multimedia.Image.Core 5509 5510**Parameters** 5511 5512| Name | Type | Mandatory| Description | 5513| ------------- | --------------------------------------- | ---- | -------------------- | 5514| componentType | [ComponentType](#componenttype9) | Yes | Color component type of the image. (Currently, only **ComponentType:JPEG** is supported. The format actually returned is determined by the producer, for example, camera.) | 5515| callback | AsyncCallback<[Component](#component9)> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the component buffer obtained; otherwise, **err** is an error object. | 5516 5517**Example** 5518 5519```ts 5520import { BusinessError } from '@kit.BasicServicesKit'; 5521 5522img.getComponent(4, (err: BusinessError, component: image.Component) => { 5523 if (err) { 5524 console.error(`Failed to get the component.code ${err.code},message is ${err.message}`); 5525 } else { 5526 console.info('Succeeded in getting component.'); 5527 } 5528}) 5529``` 5530 5531### getComponent<sup>9+</sup> 5532 5533getComponent(componentType: ComponentType): Promise\<Component> 5534 5535Obtains the component buffer from the **Image** instance based on the color component type. This API uses a promise to return the result. 5536 5537**System capability**: SystemCapability.Multimedia.Image.Core 5538 5539**Parameters** 5540 5541| Name | Type | Mandatory| Description | 5542| ------------- | -------------------------------- | ---- | ---------------- | 5543| componentType | [ComponentType](#componenttype9) | Yes | Color component type of the image. (Currently, only **ComponentType:JPEG** is supported. The format actually returned is determined by the producer, for example, camera.)| 5544 5545**Return value** 5546 5547| Type | Description | 5548| --------------------------------- | --------------------------------- | 5549| Promise<[Component](#component9)> | Promise used to return the component buffer.| 5550 5551**Example** 5552 5553```ts 5554import { BusinessError } from '@kit.BasicServicesKit'; 5555 5556img.getComponent(4).then((component: image.Component) => { 5557 console.info('Succeeded in getting component.'); 5558}).catch((error: BusinessError) => { 5559 console.error(`Failed to get the component.code ${error.code},message is ${error.message}`); 5560}) 5561``` 5562 5563### release<sup>9+</sup> 5564 5565release(callback: AsyncCallback\<void>): void 5566 5567Releases this **Image** instance. This API uses an asynchronous callback to return the result. 5568 5569The corresponding resources must be released before another image arrives. 5570 5571ArkTS supports memory reclamation. Even if the application does not call **release()**, the memory of the **Image** object will be released by the system. However, images usually occupy a large amount of memory. Therefore, it is recommended that the application proactively call the API to release the memory when the object is no longer required. 5572 5573**System capability**: SystemCapability.Multimedia.Image.Core 5574 5575**Parameters** 5576 5577| Name | Type | Mandatory| Description | 5578| -------- | -------------------- | ---- | -------------- | 5579| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 5580 5581**Example** 5582 5583```ts 5584import { BusinessError } from '@kit.BasicServicesKit'; 5585 5586img.release((err: BusinessError) => { 5587 if (err) { 5588 console.error(`Failed to release the image instance.code ${err.code},message is ${err.message}`); 5589 } else { 5590 console.info('Succeeded in releasing the image instance.'); 5591 } 5592}) 5593``` 5594 5595### release<sup>9+</sup> 5596 5597release(): Promise\<void> 5598 5599Releases this **Image** instance. This API uses a promise to return the result. 5600 5601The corresponding resources must be released before another image arrives. 5602 5603ArkTS supports memory reclamation. Even if the application does not call **release()**, the memory of the **Image** object will be released by the system. However, images usually occupy a large amount of memory. Therefore, it is recommended that the application proactively call the API to release the memory when the object is no longer required. 5604 5605**System capability**: SystemCapability.Multimedia.Image.Core 5606 5607**Return value** 5608 5609| Type | Description | 5610| -------------- | --------------------- | 5611| Promise\<void> | Promise that returns no value.| 5612 5613**Example** 5614 5615```ts 5616import { BusinessError } from '@kit.BasicServicesKit'; 5617 5618img.release().then(() => { 5619 console.info('Succeeded in releasing the image instance.'); 5620}).catch((error: BusinessError) => { 5621 console.error(`Failed to release the image instance.code ${error.code},message is ${error.message}`); 5622}) 5623``` 5624 5625## PositionArea<sup>7+</sup> 5626 5627Describes area information in an image. 5628 5629**Widget capability**: This API can be used in ArkTS widgets since API version 12. 5630 5631**Atomic service API**: This API can be used in atomic services since API version 11. 5632 5633**System capability**: SystemCapability.Multimedia.Image.Core 5634 5635| Name | Type | Read Only| Optional| Description | 5636| ------ | ------------------ | ---| -----|------------------------------------------------------- | 5637| pixels | ArrayBuffer | No| No | Pixels of the image. | 5638| offset | number | No| No | Offset for data reading. | 5639| stride | number | No| No | Number of bytes from one row of pixels in memory to the next row of pixels in memory. The value of **stride** must be greater than or equal to the value of **region.size.width** multiplied by 4. | 5640| region | [Region](#region7) | No| No |Region to read or write. The width of the region to write plus the X coordinate cannot be greater than the width of the original image. The height of the region to write plus the Y coordinate cannot be greater than the height of the original image.| 5641 5642## ImageInfo 5643 5644Describes image information. 5645 5646**System capability**: SystemCapability.Multimedia.Image.Core 5647 5648| Name| Type | Read Only| Optional| Description | 5649| ---- | ------------- | --- |-----|---------- | 5650| size<sup>6+</sup> | [Size](#size) | No| No |Image size.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12.| 5651| density<sup>9+</sup> | number | No | No|Pixel density, in ppi.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12.| 5652| stride<sup>11+</sup> | number | No | No | Number of bytes from one row of pixels in memory to the next row of pixels in memory.stride >= region.size.width*4 <br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12.| 5653| pixelFormat<sup>12+</sup> | [PixelMapFormat](#pixelmapformat7) | No | No| Pixel format.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12.| 5654| alphaType<sup>12+</sup> | [AlphaType](#alphatype9) | No | No |Alpha type.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12.| 5655| mimeType<sup>12+</sup> | string | No | No |Actual image format (MIME type). | 5656| isHdr<sup>12+</sup> | boolean | No | No | Whether the image is in High Dynamic Range (HDR) format. For [ImageSource](#imagesource), this parameter specifies whether the source image is in HDR format. For [PixelMap](#pixelmap7), this parameter specifies whether the decoded pixel map is in HDR format.| 5657 5658## Size 5659 5660Describes the size of an image. 5661 5662**Widget capability**: This API can be used in ArkTS widgets since API version 12. 5663 5664**Atomic service API**: This API can be used in atomic services since API version 11. 5665 5666**System capability**: SystemCapability.Multimedia.Image.Core 5667 5668| Name | Type | Read Only| Optional |Description | 5669| ------ | ------ | -- |-----| -------------- | 5670| height | number | No | No |Image height, in px.| 5671| width | number | No | No| Image width, in px.| 5672 5673## PixelMapFormat<sup>7+</sup> 5674 5675Enumerates the pixel formats of images. 5676 5677**Widget capability**: This API can be used in ArkTS widgets since API version 12. 5678 5679**Atomic service API**: This API can be used in atomic services since API version 11. 5680 5681**System capability**: SystemCapability.Multimedia.Image.Core 5682 5683| Name | Value | Description | 5684| ---------------------- | ------ | ----------------- | 5685| UNKNOWN | 0 | Unknown format. | 5686| RGB_565 | 2 | RGB_565. | 5687| RGBA_8888 | 3 | RGBA_8888.| 5688| BGRA_8888<sup>9+</sup> | 4 | BGRA_8888.| 5689| RGB_888<sup>9+</sup> | 5 | RGB_888. | 5690| ALPHA_8<sup>9+</sup> | 6 | ALPHA_8. | 5691| RGBA_F16<sup>9+</sup> | 7 | RGBA_F16. | 5692| NV21<sup>9+</sup> | 8 | NV21. | 5693| NV12<sup>9+</sup> | 9 | NV12. | 5694 5695## AlphaType<sup>9+</sup> 5696 5697Enumerates the alpha types of images. 5698 5699**Widget capability**: This API can be used in ArkTS widgets since API version 12. 5700 5701**Atomic service API**: This API can be used in atomic services since API version 11. 5702 5703**System capability**: SystemCapability.Multimedia.Image.Core 5704 5705| Name | Value | Description | 5706| -------- | ------ | ----------------------- | 5707| UNKNOWN | 0 | Unknown alpha type. | 5708| OPAQUE | 1 | There is no alpha or the image is opaque.| 5709| PREMUL | 2 | Premultiplied alpha. | 5710| UNPREMUL | 3 | Unpremultiplied alpha, that is, straight alpha. | 5711 5712## ScaleMode<sup>9+</sup> 5713 5714Enumerates the scale modes of images. 5715 5716**Widget capability**: This API can be used in ArkTS widgets since API version 12. 5717 5718**Atomic service API**: This API can be used in atomic services since API version 11. 5719 5720**System capability**: SystemCapability.Multimedia.Image.Core 5721 5722| Name | Value | Description | 5723| --------------- | ------ | -------------------------------------------------- | 5724| CENTER_CROP | 1 | Scales the image so that it fills the requested bounds of the target and crops the extra.| 5725| FIT_TARGET_SIZE | 0 | Reduces the image size to the dimensions of the target. | 5726 5727## SourceOptions<sup>9+</sup> 5728 5729Defines image source initialization options. 5730 5731**Widget capability**: This API can be used in ArkTS widgets since API version 12. 5732 5733**Atomic service API**: This API can be used in atomic services since API version 11. 5734 5735**System capability**: SystemCapability.Multimedia.Image.Core 5736 5737| Name | Type | Read Only| Optional| Description | 5738| ----------------- | ---------------------------------- | ---- | ---- | ------------------ | 5739| sourceDensity | number | No | No | Pixel density of the image resource, in DPI.<br>If **desiredSize** is not set in [DecodingOptions](# decodingoptions7) and **SourceOptions.sourceDensity** and **DecodingOptions.fitDensity** are not 0, the pixel map output after decoding will be scaled.<br>The formula for calculating the width after scaling is as follows (the same applies to the height): (width * fitDensity + (sourceDensity >> 1)) / sourceDensity.| 5740| sourcePixelFormat | [PixelMapFormat](#pixelmapformat7) | No | Yes | Image pixel format. The default value is **UNKNOWN**. | 5741| sourceSize | [Size](#size) | No | Yes | Image pixel size. The default value is null. | 5742 5743 5744## InitializationOptions<sup>8+</sup> 5745 5746Defines pixel map initialization options. 5747 5748**System capability**: SystemCapability.Multimedia.Image.Core 5749 5750| Name | Type | Read Only|Optional| Description | 5751| ------------------------ | ---------------------------------- | ----| -----| -------------- | 5752| alphaType<sup>9+</sup> | [AlphaType](#alphatype9) | No | Yes| Alpha type. The default value is **IMAGE_ALPHA_TYPE_PREMUL**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12. | 5753| editable | boolean | No | Yes| Whether the image is editable. The default value is **false**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12.| 5754| srcPixelFormat<sup>12+</sup> | [PixelMapFormat](#pixelmapformat7) | No| Yes| Pixel format of the passed-in buffer data. The default value is **BGRA_8888**.| 5755| pixelFormat | [PixelMapFormat](#pixelmapformat7) | No| Yes| Pixel format of the generated pixel map. The default value is **RGBA_8888**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12. | 5756| scaleMode<sup>9+</sup> | [ScaleMode](#scalemode9) | No | Yes| Scale mode. The default value is **0**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12. | 5757| size | [Size](#size) | No | No|Image size.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12.| 5758 5759## DecodingOptions<sup>7+</sup> 5760 5761Describes the image decoding options. 5762 5763**System capability**: SystemCapability.Multimedia.Image.ImageSource 5764 5765| Name | Type | Read Only| Optional| Description | 5766| ------------------ | ---------------------------------- | ---- | ---- | ---------------- | 5767| sampleSize | number | No | Yes | Sampling size of the thumbnail. The default value is **1**. Currently, the value can only be **1**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12.| 5768| rotate | number | No | Yes | Rotation angle. The default value is **0**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12. | 5769| editable | boolean | No | Yes | Whether the image is editable. The default value is **false**. If this option is set to **false**, the image cannot be edited again, and operations such as writing pixels will fail.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12. | 5770| desiredSize | [Size](#size) | No | Yes | Expected output size. The default value is null.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12. | 5771| desiredRegion | [Region](#region7) | No | Yes | Region to decode. The default value is null.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12. | 5772| desiredPixelFormat | [PixelMapFormat](#pixelmapformat7) | No | Yes | Pixel format for decoding. The default value is **RGBA_8888**. Only RGBA_8888, BGRA_8888, and RGB_565 are supported. RGB_565 is not supported for images with alpha channels, such as PNG, GIF, ICO, and WEBP.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12.| 5773| index | number | No | Yes | Index of the image to decode. The default value is **0**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12. | 5774| fitDensity<sup>9+</sup> | number | No | Yes | Pixel density, in ppi. The default value is **0**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12. | 5775| desiredColorSpace<sup>11+</sup> | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | No | Yes | Target color space. The default value is **UNKNOWN**.| 5776| desiredDynamicRange<sup>12+</sup> | [DecodingDynamicRange](#decodingdynamicrange12) | No | Yes | Desired dynamic range. The default value is **SDR**.<br>This property cannot be set for an image source created using [CreateIncrementalSource](#imagecreateincrementalsource9). By default, the image source is decoded as SDR content.<br>If the platform does not support HDR, the setting is invalid and the content is decoded as SDR content by default.| 5777 5778## Region<sup>7+</sup> 5779 5780Describes the region information. 5781 5782**Widget capability**: This API can be used in ArkTS widgets since API version 12. 5783 5784**Atomic service API**: This API can be used in atomic services since API version 11. 5785 5786**System capability**: SystemCapability.Multimedia.Image.Core 5787 5788| Name| Type | Read Only| Optional| Description | 5789| ---- | ------------- | ---- | ---- | ------------ | 5790| size | [Size](#size) | No | No | Region size. | 5791| x | number | No | No | X coordinate to translate.| 5792| y | number | No | No | Y coordinate of the region.| 5793 5794## PackingOption 5795 5796Describes the options for image packing. 5797 5798**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5799 5800| Name | Type | Read Only| Optional| Description | 5801| ------- | ------ | ---- | ---- | --------------------------------------------------- | 5802| format | string | No | No | Format of the packed image.<br>Currently, only **"image/jpeg"**, **"image/webp"**, and **"image/png"** are supported.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 5803| quality | number | No | No | Quality of the output image in JPEG encoding. The value ranges from 0 to 100. The value **0** means the lowest quality, and **100** means the highest quality. The higher the quality, the larger the space occupied by the generated image.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 5804| bufferSize<sup>9+</sup> | number | No | Yes | Size of the buffer for receiving the encoded data, in bytes. If the size is not set, the default value 25 MB is used. If the size of an image exceeds 25 MB, you must specify the size. The value of **bufferSize** must be greater than the size of the encoded image. The use of [packToFile](#packtofile11) is not restricted by this parameter.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 5805| desiredDynamicRange<sup>12+</sup> | [PackingDynamicRange](#packingdynamicrange12) | No | Yes | Desired dynamic range. The default value is **SDR**.| 5806| needsPackProperties<sup>12+</sup> | boolean | No | Yes | Whether to encode image property information, for example, EXIF. The default value is **false**.| 5807 5808## ImagePropertyOptions<sup>11+</sup> 5809 5810Describes the image properties. 5811 5812**System capability**: SystemCapability.Multimedia.Image.ImageSource 5813 5814| Name | Type | Read Only| Optional| Description | 5815| ------------ | ------ | ---- | ---- | ------------ | 5816| index | number | Yes | Yes | Index of the image. The default value is **0**. | 5817| defaultValue | string | Yes | Yes | Default property value. The default value is null.| 5818 5819## GetImagePropertyOptions<sup>(deprecated)</sup> 5820 5821Describes the image properties. 5822 5823> **NOTE** 5824> 5825> This API is deprecated since API version 11. You are advised to use [ImagePropertyOptions](#imagepropertyoptions11). 5826 5827**System capability**: SystemCapability.Multimedia.Image.ImageSource 5828 5829| Name | Type | Read Only| Optional| Description | 5830| ------------ | ------ | ---- | ---- | ------------ | 5831| index | number | No | Yes | Index of the image. The default value is **0**. | 5832| defaultValue | string | No | Yes | Default property value. The default value is null.| 5833 5834## PropertyKey<sup>7+</sup> 5835 5836Describes the exchangeable image file format (EXIF) data of an image. 5837 5838**System capability**: SystemCapability.Multimedia.Image.Core 5839 5840| Name | Value | Description | 5841| ----------------- | ----------------------- |---------------------------| 5842| NEW_SUBFILE_TYPE <sup>12+</sup> | "NewSubfileType" | **Read/Write capability**: readable and writable<br> Data type of a subfile, such as a full-resolution image, a thumbnail, or a part of a multi-frame image. The value is a bit mask. The value 0 indicates a full-resolution image, **1** indicates a thumbnail, and **2** indicates a part of a multi-frame image.| 5843| SUBFILE_TYPE <sup>12+</sup> | "SubfileType" | **Read/Write capability**: readable and writable<br> Type of data contained in this subfile. This tag has been deprecated. Use **NewSubfileType** instead.| 5844| IMAGE_WIDTH | "ImageWidth" | **Read/Write capability**: readable and writable<br> Image width.| 5845| IMAGE_LENGTH | "ImageLength" | **Read/Write capability**: readable and writable<br> Image length.| 5846| BITS_PER_SAMPLE | "BitsPerSample" | **Read/Write capability**: readable and writable<br> Number of bits per component.| 5847| COMPRESSION <sup>12+</sup> | "Compression" | **Read/Write capability**: readable and writable<br> Compression scheme used on the image data.| 5848| PHOTOMETRIC_INTERPRETATION <sup>12+</sup> | "PhotometricInterpretation" | **Read/Write capability**: readable and writable<br> Color space of the image data, for example, RGB or YCbCr.| 5849| IMAGE_DESCRIPTION<sup>10+</sup> | "ImageDescription" | **Read/Write capability**: readable and writable<br> Image description.| 5850| MAKE<sup>10+</sup> | "Make" | **Read/Write capability**: readable and writable<br> Manufacturer.| 5851| MODEL<sup>10+</sup> | "Model" | **Read/Write capability**: readable and writable<br> Device model.| 5852| STRIP_OFFSETS <sup>12+</sup> | "StripOffsets" | **Read/Write capability**: readable and writable<br> Byte offset of each strip.| 5853| ORIENTATION | "Orientation" | **Read/Write capability**: readable and writable<br> Image orientation.<br>- 1: **Top-left**: The image is not rotated.<br>- 2: **Top-right**: The image is flipped horizontally.<br>- 3: **Bottom-right**: The image is rotated by 180°.<br>- 4: **Bottom-left**: The image is flipped vertically.<br>- 5: **Left-top**: The image is flipped horizontally and then rotated clockwise by 270°.<br>- 6: **Right-top**: The image is rotated clockwise by 90°.<br>- 7: **Right-bottom**: The image is vertically flipped and then rotated clockwise by 90°.<br>- 8: **Left-bottom**: The image is rotated clockwise by 270°.<br>- **Unknown Value**: No value is defined.| 5854| SAMPLES_PER_PIXEL <sup>12+</sup> | "SamplesPerPixel" | **Read/Write capability**: readable and writable<br> Number of components per pixel. The value is 3 for RGB and YCbCr images. The **JPEG** key is used in JPEG compressed data.| 5855| ROWS_PER_STRIP <sup>12+</sup> | "RowsPerStrip" | **Read/Write capability**: readable and writable<br> Number of rows per strip.| 5856| STRIP_BYTE_COUNTS <sup>12+</sup> | "StripByteCounts" | **Read/Write capability**: readable and writable<br> Number of bytes in each strip after compression.| 5857| X_RESOLUTION <sup>12+</sup> | "XResolution" | **Read/Write capability**: readable and writable<br> Number of pixels per ResolutionUnit in the image width (X) direction.| 5858| Y_RESOLUTION <sup>12+</sup> | "YResolution" | **Read/Write capability**: readable and writable<br> Number of pixels per ResolutionUnit in the image height (Y) direction.| 5859| PLANAR_CONFIGURATION <sup>12+</sup> | "PlanarConfiguration" | **Read/Write capability**: readable and writable<br> Storage format of components of each pixel, which can be chunky or planar.| 5860| RESOLUTION_UNIT <sup>12+</sup> | "ResolutionUnit" | **Read/Write capability**: readable and writable<br> Unit of measurement for XResolution and YResolution.| 5861| TRANSFER_FUNCTION <sup>12+</sup> | "TransferFunction" | **Read/Write capability**: readable and writable<br> Transfer function for the image, which is usually used for color correction.| 5862| SOFTWARE <sup>12+</sup> | "Software" | **Read/Write capability**: readable and writable<br> Name and version number of the software used to create the image.| 5863| DATE_TIME<sup>10+</sup> | "DateTime" | **Read/Write capability**: readable and writable<br> Date and time of image creation.| 5864| ARTIST <sup>12+</sup> | "Artist" | **Read/Write capability**: readable and writable<br> Person who created the image.| 5865| WHITE_POINT <sup>12+</sup> | "WhitePoint" | **Read/Write capability**: readable and writable<br> Chromaticity of the white point of the image.| 5866| PRIMARY_CHROMATICITIES <sup>12+</sup> | "PrimaryChromaticities" | **Read/Write capability**: readable and writable<br> Chromaticities of the primaries of the image.| 5867| PHOTO_MODE<sup>10+</sup> | "PhotoMode" | **Read/Write capability**: readable and writable<br> Photographing mode.| 5868| JPEG_INTERCHANGE_FORMAT <sup>12+</sup> | "JPEGInterchangeFormat" | **Read/Write capability**: readable and writable<br> Offset of the SOI marker of a JPEG interchange format bitstream.| 5869| JPEG_INTERCHANGE_FORMAT_LENGTH <sup>12+</sup> | "JPEGInterchangeFormatLength" | **Read/Write capability**: readable and writable<br> Number of bytes of the JPEG stream.| 5870| YCBCR_COEFFICIENTS <sup>12+</sup> | "YCbCrCoefficients" | **Read/Write capability**: readable and writable<br> Transformation from RGB to YCbCr image data.| 5871| YCBCR_SUB_SAMPLING <sup>12+</sup> | "YCbCrSubSampling" | **Read/Write capability**: readable and writable<br> Subsampling factors used for the chrominance components of a YCbCr image.| 5872| YCBCR_POSITIONING <sup>12+</sup> | "YCbCrPositioning" | **Read/Write capability**: readable and writable<br> Positioning of subsampled chrominance components relative to luminance samples.| 5873| REFERENCE_BLACK_WHITE <sup>12+</sup> | "ReferenceBlackWhite" | **Read/Write capability**: readable and writable<br> A pair of headroom and footroom image data values (codes) for each pixel component.| 5874| COPYRIGHT <sup>12+</sup> | "Copyright" | **Read/Write capability**: readable and writable<br> Copyright notice of the image.| 5875| EXPOSURE_TIME<sup>9+</sup> | "ExposureTime" | **Read/Write capability**: readable and writable<br> Exposure time, for example, 1/33 seconds.| 5876| F_NUMBER<sup>9+</sup> | "FNumber" | **Read/Write capability**: readable and writable<br> F number, for example, f/1.8.| 5877| EXPOSURE_PROGRAM <sup>12+</sup> | "ExposureProgram" | **Read/Write capability**: readable and writable<br> Class of the program used by the camera to set exposure when the image was captured.| 5878| SPECTRAL_SENSITIVITY <sup>12+</sup> | "SpectralSensitivity" | **Read/Write capability**: readable and writable<br> Spectral sensitivity of each channel of the camera.| 5879| GPS_VERSION_ID <sup>12+</sup> | "GPSVersionID" | **Read/Write capability**: readable and writable<br> Version of GPSInfoIFD.| 5880| GPS_LATITUDE_REF | "GPSLatitudeRef" | **Read/Write capability**: readable and writable<br> Whether the latitude is north or south latitude.| 5881| GPS_LATITUDE | "GPSLatitude" | **Read/Write capability**: readable and writable<br> Image latitude.| 5882| GPS_LONGITUDE_REF | "GPSLongitudeRef" | **Read/Write capability**: readable and writable<br> Whether the longitude is east or west longitude.| 5883| GPS_LONGITUDE | "GPSLongitude" | **Read/Write capability**: readable and writable<br> Image longitude.| 5884| GPS_ALTITUDE_REF <sup>12+</sup> | "GPSAltitudeRef" | **Read/Write capability**: readable and writable<br> Whether the latitude is north or south latitude.| 5885| GPS_ALTITUDE <sup>12+</sup> | "GPSAltitude" | **Read/Write capability**: readable and writable<br> Altitude based on the reference in GPSAltitudeRef.| 5886| GPS_TIME_STAMP<sup>10+</sup> | "GPSTimeStamp" | **Read/Write capability**: readable and writable<br> GPS timestamp.| 5887| GPS_SATELLITES <sup>12+</sup> | "GPSSatellites" | **Read/Write capability**: readable and writable<br> GPS satellites used for measurement.| 5888| GPS_STATUS <sup>12+</sup> | "GPSStatus" | **Read/Write capability**: readable and writable<br> Status of the GPS receiver when the image was recorded.| 5889| GPS_MEASURE_MODE <sup>12+</sup> | "GPSMeasureMode" | **Read/Write capability**: readable and writable<br> GPS measurement pmode.| 5890| GPS_DOP <sup>12+</sup> | "GPSDOP" | **Read/Write capability**: readable and writable<br> GPS DOP (data degree of precision)| 5891| GPS_SPEED_REF <sup>12+</sup> | "GPSSpeedRef" | **Read/Write capability**: readable and writable<br> Unit used to express the movement speed of the GPS receiver.| 5892| GPS_SPEED <sup>12+</sup> | "GPSSpeed" | **Read/Write capability**: readable and writable<br> Movement speed of the GPS receiver.| 5893| GPS_TRACK_REF <sup>12+</sup> | "GPSTrackRef" | **Read/Write capability**: readable and writable<br> Reference of the movement direction of the GPS receiver.| 5894| GPS_TRACK <sup>12+</sup> | "GPSTrack" | **Read/Write capability**: readable and writable<br> Movement direction of the GPS receiver.| 5895| GPS_IMG_DIRECTION_REF <sup>12+</sup> | "GPSImgDirectionRef" | **Read/Write capability**: readable and writable<br> Reference of the direction of the image when it was captured.| 5896| GPS_IMG_DIRECTION <sup>12+</sup> | "GPSImgDirection" | **Read/Write capability**: readable and writable<br> Direction of the image when it was captured.| 5897| GPS_MAP_DATUM <sup>12+</sup> | "GPSMapDatum" | **Read/Write capability**: readable and writable<br> Geodetic survey data used by the GPS receiver.| 5898| GPS_DEST_LATITUDE_REF <sup>12+</sup> | "GPSDestLatitudeRef" | **Read/Write capability**: readable and writable<br> Whether the latitude of the destination point is north or south latitude.| 5899| GPS_DEST_LATITUDE <sup>12+</sup> | "GPSDestLatitude" | **Read/Write capability**: readable and writable<br> Latitude of the destination point.| 5900| GPS_DEST_LONGITUDE_REF <sup>12+</sup> | "GPSDestLongitudeRef" | **Read/Write capability**: readable and writable<br> Whether the longitude of the destination point is east or west longitude.| 5901| GPS_DEST_LONGITUDE <sup>12+</sup> | "GPSDestLongitude" | **Read/Write capability**: readable and writable<br> Longitude of the destination point.| 5902| GPS_DEST_BEARING_REF <sup>12+</sup> | "GPSDestBearingRef" | **Read/Write capability**: readable and writable<br> Reference of the bearing to the destination point.| 5903| GPS_DEST_BEARING <sup>12+</sup> | "GPSDestBearing" | **Read/Write capability**: readable and writable<br> Bearing to the destination point.| 5904| GPS_DEST_DISTANCE_REF <sup>12+</sup> | "GPSDestDistanceRef" | **Read/Write capability**: readable and writable<br> Unit used to express the distance to the destination point.| 5905| GPS_DEST_DISTANCE <sup>12+</sup> | "GPSDestDistance" | **Read/Write capability**: readable and writable<br> Distance to the destination point.| 5906| GPS_PROCESSING_METHOD <sup>12+</sup> | "GPSProcessingMethod" | **Read/Write capability**: readable and writable<br> String that records the name of the method used for positioning.| 5907| GPS_AREA_INFORMATION <sup>12+</sup> | "GPSAreaInformation" | **Read/Write capability**: readable and writable<br> String that records the name of the GPS area.| 5908| GPS_DATE_STAMP<sup>10+</sup> | "GPSDateStamp" | **Read/Write capability**: readable and writable<br> GPS date stamp.| 5909| GPS_DIFFERENTIAL <sup>12+</sup> | "GPSDifferential" | **Read/Write capability**: readable and writable<br> Whether differential correction is applied to the GPS receiver. It is critical to accurate location accuracy.| 5910| GPS_H_POSITIONING_ERROR <sup>12+</sup> | "GPSHPositioningError" | **Read/Write capability**: readable and writable<br> Horizontal positioning error, in meters.| 5911| ISO_SPEED_RATINGS<sup>9+</sup> | "ISOSpeedRatings" | **Read/Write capability**: readable and writable<br> ISO sensitivity or ISO speed, for example, 400.| 5912| PHOTOGRAPHIC_SENSITIVITY <sup>12+</sup> | "PhotographicSensitivity" | **Read/Write capability**: readable and writable<br> Sensitivity of the camera or input device when the image was captured.| 5913| OECF <sup>12+</sup> | "OECF" | **Read/Write capability**: readable and writable<br> Opto-Electric Conversion Function (OECF) specified in ISO 14524.| 5914| SENSITIVITY_TYPE<sup>10+</sup> | "SensitivityType" | **Read/Write capability**: readable and writable<br> Sensitivity type.| 5915| STANDARD_OUTPUT_SENSITIVITY<sup>10+</sup> | "StandardOutputSensitivity" | **Read/Write capability**: readable and writable<br> Standard output sensitivity.| 5916| RECOMMENDED_EXPOSURE_INDEX<sup>10+</sup> | "RecommendedExposureIndex" | **Read/Write capability**: readable and writable<br> Recommended exposure index.| 5917| ISO_SPEED<sup>10+</sup> | "ISOSpeedRatings" | **Read/Write capability**: readable and writable<br> ISO speed.| 5918| ISO_SPEED_LATITUDE_YYY <sup>12+</sup> | "ISOSpeedLatitudeyyy" | **Read/Write capability**: readable and writable<br> ISO speed latitude yyy value of the camera or input device, which is defined in ISO 12232.| 5919| ISO_SPEED_LATITUDE_ZZZ <sup>12+</sup> | "ISOSpeedLatitudezzz" | **Read/Write capability**: readable and writable<br> ISO speed latitude zzz value of the camera or input device, which is defined in ISO 12232.| 5920| EXIF_VERSION <sup>12+</sup> | "ExifVersion" | **Read/Write capability**: readable and writable<br> Version of the supported EXIF standard.| 5921| DATE_TIME_ORIGINAL<sup>9+</sup> | "DateTimeOriginal" | **Read/Write capability**: readable and writable<br> Time when the original image data was generated, for example, 2022:09:06 15:48:00.| 5922| DATE_TIME_DIGITIZED <sup>12+</sup> | "DateTimeDigitized" | **Read/Write capability**: readable and writable<br> Date and time when the image was stored as digital data, in the format of YYYY:MM:DD HH:MM:SS.| 5923| OFFSET_TIME <sup>12+</sup> | "OffsetTime" | **Read/Write capability**: readable and writable<br> Time with an offset from UTC when the image was captured, in the format of ±HH:MM.| 5924| OFFSET_TIME_ORIGINAL <sup>12+</sup> | "OffsetTimeOriginal" | **Read/Write capability**: readable and writable<br> Time with an offset from UTC when the original image was created. It is critical for time-sensitive applications.| 5925| OFFSET_TIME_DIGITIZED <sup>12+</sup> | "OffsetTimeDigitized" | **Read/Write capability**: readable and writable<br> Time with an offset from UTC when the image was digitized. It helps to accurately adjust the timestamp.| 5926| COMPONENTS_CONFIGURATION <sup>12+</sup> | "ComponentsConfiguration" | **Read/Write capability**: readable and writable<br> Specific information about compressed data.| 5927| COMPRESSED_BITS_PER_PIXEL <sup>12+</sup> | "CompressedBitsPerPixel" | **Read/Write capability**: readable and writable<br> Number of bits per pixel. It is specific to compressed data.| 5928| SHUTTER_SPEED <sup>12+</sup> | "ShutterSpeedValue" | **Read/Write capability**: readable and writable<br> Shutter speed, expressed in Additive System of Photographic Exposure (APEX) values.| 5929| APERTURE_VALUE<sup>10+</sup> | "ApertureValue" | **Read/Write capability**: readable and writable<br> Lens aperture.| 5930| BRIGHTNESS_VALUE <sup>12+</sup> | "BrightnessValue" | **Read/Write capability**: readable and writable<br> Value of brightness, expressed in APEX values.| 5931| EXPOSURE_BIAS_VALUE<sup>10+</sup> | "ExposureBiasValue" | **Read/Write capability**: readable and writable<br> Exposure bias.| 5932| MAX_APERTURE_VALUE <sup>12+</sup> | "MaxApertureValue" | **Read/Write capability**: readable and writable<br> Smallest F number of the lens.| 5933| SUBJECT_DISTANCE <sup>12+</sup> | "SubjectDistance" | **Read/Write capability**: readable and writable<br> Distance to the subject, in meters.| 5934| METERING_MODE<sup>10+</sup> | "MeteringMode" | **Read/Write capability**: readable and writable<br> Metering mode.| 5935| LIGHT_SOURCE<sup>10+</sup> | "LightSource" | **Read/Write capability**: readable and writable<br> Light source.| 5936| FLASH <sup>10+</sup> | "Flash" | **Read/Write capability**: readable and writable<br> Flash status.| 5937| FOCAL_LENGTH <sup>10+</sup> | "FocalLength" | **Read/Write capability**: readable and writable<br> Focal length of the lens.| 5938| SUBJECT_AREA <sup>12+</sup> | "SubjectArea" | **Read/Write capability**: readable and writable<br> Location and area of the main subject in the entire scene.| 5939| MAKER_NOTE <sup>12+</sup> | "MakerNote" | **Read/Write capability**: read-only<br> Marker used by EXIF/DCF manufacturers to record any required information.| 5940| SCENE_POINTER <sup>12+</sup> | "HwMnoteScenePointer" | **Read/Write capability**: read-only<br> Pointer to the scene.| 5941| SCENE_VERSION <sup>12+</sup> | "HwMnoteSceneVersion" | **Read/Write capability**: read-only<br> Scene algorithm version.| 5942| SCENE_FOOD_CONF<sup>11+</sup> | "HwMnoteSceneFoodConf" | **Read/Write capability**: read-only<br> Photographing scene: food.| 5943| SCENE_STAGE_CONF<sup>11+</sup> | "HwMnoteSceneStageConf" | **Read/Write capability**: read-only<br> Photographing scene: stage.| 5944| SCENE_BLUE_SKY_CONF<sup>11+</sup> | "HwMnoteSceneBlueSkyConf" | **Read/Write capability**: read-only<br> Photographing scene: blue sky.| 5945| SCENE_GREEN_PLANT_CONF<sup>11+</sup> | "HwMnoteSceneGreenPlantConf" | **Read/Write capability**: read-only<br> Photographing scene: green plant.| 5946| SCENE_BEACH_CONF<sup>11+</sup> | "HwMnoteSceneBeachConf" | **Read/Write capability**: read-only<br> Photographing scene: beach.| 5947| SCENE_SNOW_CONF<sup>11+</sup> | "HwMnoteSceneSnowConf" | **Read/Write capability**: read-only<br> Photographing scene: snow.| 5948| SCENE_SUNSET_CONF<sup>11+</sup> | "HwMnoteSceneSunsetConf" | **Read/Write capability**: read-only<br> Photographing scene: sunset.| 5949| SCENE_FLOWERS_CONF<sup>11+</sup> | "HwMnoteSceneFlowersConf" | **Read/Write capability**: read-only<br> Photographing scene: flowers.| 5950| SCENE_NIGHT_CONF<sup>11+</sup> | "HwMnoteSceneNightConf" | **Read/Write capability**: read-only<br> Photographing scene: night.| 5951| SCENE_TEXT_CONF<sup>11+</sup> | "HwMnoteSceneTextConf" | **Read/Write capability**: read-only<br> Photographing scene: text.| 5952| FACE_POINTER <sup>12+</sup> | "HwMnoteFacePointer" | **Read/Write capability**: read-only<br> Face pointer.| 5953| FACE_VERSION <sup>12+</sup> | "HwMnoteFaceVersion" | **Read/Write capability**: read-only<br> Facial recognition algorithm version.| 5954| FACE_COUNT<sup>11+</sup> | "HwMnoteFaceCount" | **Read/Write capability**: read-only<br> Number of faces.| 5955| FACE_CONF <sup>12+</sup> | "HwMnoteFaceConf" | **Read/Write capability**: read-only<br> Face confidence.| 5956| FACE_SMILE_SCORE <sup>12+</sup> | "HwMnoteFaceSmileScore" | **Read/Write capability**: read-only<br> Smile score of for faces.| 5957| FACE_RECT <sup>12+</sup> | "HwMnoteFaceRect" | **Read/Write capability**: read-only<br> Face rectangle.| 5958| FACE_LEYE_CENTER <sup>12+</sup> | "HwMnoteFaceLeyeCenter" | **Read/Write capability**: read-only<br> Left eye centered.| 5959| FACE_REYE_CENTER <sup>12+</sup> | "HwMnoteFaceReyeCenter" | **Read/Write capability**: read-only<br> Right eye centered.| 5960| FACE_MOUTH_CENTER <sup>12+</sup> | "HwMnoteFaceMouthCenter" | **Read/Write capability**: read-only<br> Mouth centered.| 5961| CAPTURE_MODE <sup>10+</sup> | "HwMnoteCaptureMode" | **Read/Write capability**: readable and writable<br> Capture mode.| 5962| BURST_NUMBER <sup>12+</sup> | "HwMnoteBurstNumber" | **Read/Write capability**: read-only<br> Number of burst shooting times.| 5963| FRONT_CAMERA <sup>12+</sup> | "HwMnoteFrontCamera" | **Read/Write capability**: read-only<br> Whether the front camera is used to take a selfie.| 5964| ROLL_ANGLE <sup>11+</sup> | "HwMnoteRollAngle" | **Read/Write capability**: read-only<br> Roll angle.| 5965| PITCH_ANGLE<sup>11+</sup> | "HwMnotePitchAngle" | **Read/Write capability**: read-only<br> Pitch angle.| 5966| PHYSICAL_APERTURE <sup>10+</sup> | "HwMnotePhysicalAperture" | **Read/Write capability**: read-only<br> Physical aperture.| 5967| FOCUS_MODE<sup>11+</sup> | "HwMnoteFocusMode" | **Read/Write capability**: read-only<br> Focus mode.| 5968| USER_COMMENT <sup>10+</sup> | "UserComment" | **Read/Write capability**: readable and writable<br> User comments.| 5969| SUBSEC_TIME <sup>12+</sup> | "SubsecTime" | **Read/Write capability**: readable and writable<br> Tag used to record fractions of seconds for the **DateTime** tag.| 5970| SUBSEC_TIME_ORIGINAL <sup>12+</sup> | "SubsecTimeOriginal" | **Read/Write capability**: readable and writable<br> Tag used to record fractions of seconds for the **DateTimeOriginal** tag.| 5971| SUBSEC_TIME_DIGITIZED <sup>12+</sup> | "SubsecTimeDigitized" | **Read/Write capability**: readable and writable<br> Tag used to record fractions of seconds for the **DateTimeDigitized** tag.| 5972| FLASHPIX_VERSION <sup>12+</sup> | "FlashpixVersion" | **Read/Write capability**: readable and writable<br> FlashPix format version supported by an FPXR file. It is used to enhance device compatibility.| 5973| COLOR_SPACE <sup>12+</sup> | "ColorSpace" | **Read/Write capability**: readable and writable<br> Color space information, which is usually recorded as a color space specifier.| 5974| PIXEL_X_DIMENSION <sup>10+</sup> | "PixelXDimension" | **Read/Write capability**: readable and writable<br> Pixel X dimension.| 5975| PIXEL_Y_DIMENSION<sup>10+</sup> | "PixelYDimension" | **Read/Write capability**: readable and writable<br> Pixel Y dimension.| 5976| RELATED_SOUND_FILE <sup>12+</sup> | "RelatedSoundFile" | **Read/Write capability**: readable and writable<br> Name of an audio file related to the image data.| 5977| FLASH_ENERGY <sup>12+</sup> | "FlashEnergy" | **Read/Write capability**: readable and writable<br> Strobe energy at the time the image was captured, in Beam Candle Power Seconds (BCPS).| 5978| SPATIAL_FREQUENCY_RESPONSE <sup>12+</sup> | "SpatialFrequencyResponse" | **Read/Write capability**: readable and writable<br> Spatial frequency table of the camera or input device.| 5979| FOCAL_PLANE_X_RESOLUTION <sup>12+</sup> | "FocalPlaneXResolution" | **Read/Write capability**: readable and writable<br> Number of pixels in the image width (X) direction per FocalPlaneResolutionUnit.| 5980| FOCAL_PLANE_Y_RESOLUTION <sup>12+</sup> | "FocalPlaneYResolution" | **Read/Write capability**: readable and writable<br> Number of pixels in the image height (Y) direction per FocalPlaneResolutionUnit.| 5981| FOCAL_PLANE_RESOLUTION_UNIT <sup>12+</sup> | "FocalPlaneResolutionUnit" | **Read/Write capability**: readable and writable<br> Unit for measuring FocalPlaneXResolution and FocalPlaneYResolution.| 5982| SUBJECT_LOCATION <sup>12+</sup> | "SubjectLocation" | **Read/Write capability**: readable and writable<br> Location of the main subject relative to the left edge.| 5983| EXPOSURE_INDEX <sup>12+</sup> | "ExposureIndex" | **Read/Write capability**: readable and writable<br> Exposure index selected at the time the image is captured.| 5984| SENSING_METHOD <sup>12+</sup> | "SensingMethod" | **Read/Write capability**: readable and writable<br> Type of the image sensor on the camera.| 5985| FILE_SOURCE <sup>12+</sup> | "FileSource" | **Read/Write capability**: readable and writable<br> Image source.| 5986| SCENE_TYPE<sup>9+</sup> | "SceneType" | **Read/Write capability**: readable and writable<br> Type of the scene, for example, portrait, scenery, motion, and night.| 5987| CFA_PATTERN <sup>12+</sup> | "CFAPattern" | **Read/Write capability**: readable and writable<br> Color Filter Array (CFA) geometric pattern of the image sensor.| 5988| CUSTOM_RENDERED <sup>12+</sup> | "CustomRendered" | **Read/Write capability**: readable and writable<br> Special processing on image data.| 5989| EXPOSURE_MODE <sup>12+</sup> | "ExposureMode" | **Read/Write capability**: readable and writable<br> Exposure mode set when the image was captured.| 5990| WHITE_BALANCE <sup>10+</sup> | "WhiteBalance" | **Read/Write capability**: readable and writable<br> White balance.| 5991| DIGITAL_ZOOM_RATIO <sup>12+</sup> | "DigitalZoomRatio" | **Read/Write capability**: readable and writable<br> Digital zoom ratio when the image was captured.| 5992| FOCAL_LENGTH_IN_35_MM_FILM <sup>10+</sup> | "FocalLengthIn35mmFilm" | **Read/Write capability**: readable and writable<br> Focal length in 35mm film.| 5993| SCENE_CAPTURE_TYPE <sup>12+</sup> | "SceneCaptureType" | **Read/Write capability**: readable and writable<br> Type of the scene that was captured.| 5994| GAIN_CONTROL <sup>12+</sup> | "GainControl" | **Read/Write capability**: readable and writable<br> Degree of overall image gain adjustment.| 5995| CONTRAST <sup>12+</sup> | "Contrast" | **Read/Write capability**: readable and writable<br> Direction of contrast processing used by the camera.| 5996| SATURATION <sup>12+</sup> | "Saturation" | **Read/Write capability**: readable and writable<br> Direction of saturation processing used by the camera.| 5997| SHARPNESS <sup>12+</sup> | "Sharpness" | **Read/Write capability**: readable and writable<br> Direction of sharpness processing used by the camera.| 5998| DEVICE_SETTING_DESCRIPTION <sup>12+</sup> | "DeviceSettingDescription" | **Read/Write capability**: readable and writable<br> Information about the photographing conditions of a specific camera model.| 5999| SUBJECT_DISTANCE_RANGE <sup>12+</sup> | "SubjectDistanceRange" | **Read/Write capability**: readable and writable<br> Distance to the subject.| 6000| IMAGE_UNIQUE_ID <sup>12+</sup> | "ImageUniqueID" | **Read/Write capability**: readable and writable<br> Unique identifier assigned to each image.| 6001| CAMERA_OWNER_NAME <sup>12+</sup> | "CameraOwnerName" | **Read/Write capability**: readable and writable<br> Name of the camera owner.| 6002| BODY_SERIAL_NUMBER <sup>12+</sup> | "BodySerialNumber" | **Read/Write capability**: readable and writable<br> Serial number of the camera body.| 6003| LENS_SPECIFICATION <sup>12+</sup> | "LensSpecification" | **Read/Write capability**: readable and writable<br> Specifications of the lens.| 6004| LENS_MAKE <sup>12+</sup> | "LensMake" | **Read/Write capability**: readable and writable<br> Manufacturer of the lens.| 6005| LENS_MODEL <sup>12+</sup> | "LensModel" | **Read/Write capability**: readable and writable<br> Model of the lens.| 6006| LENS_SERIAL_NUMBER <sup>12+</sup> | "LensSerialNumber" | **Read/Write capability**: readable and writable<br> Serial number of the lens.| 6007| COMPOSITE_IMAGE <sup>12+</sup> | "CompositeImage" | **Read/Write capability**: readable and writable<br> Whether the image is a composite image.| 6008| SOURCE_IMAGE_NUMBER_OF_COMPOSITE_IMAGE <sup>12+</sup> | "SourceImageNumberOfCompositeImage" | **Read/Write capability**: readable and writable<br> Number of source images of the composite image.| 6009| SOURCE_EXPOSURE_TIMES_OF_COMPOSITE_IMAGE <sup>12+</sup> | "SourceExposureTimesOfCompositeImage" | **Read/Write capability**: readable and writable<br> Exposure time of source images of the composite image.| 6010| GAMMA <sup>12+</sup> | "Gamma" | **Read/Write capability**: readable and writable<br> Gamma value.| 6011| DNG_VERSION <sup>12+</sup> | "DNGVersion" | **Read/Write capability**: readable and writable<br> DNG version. It encodes the DNG 4-tier version number.| 6012| DEFAULT_CROP_SIZE <sup>12+</sup> | "DefaultCropSize" | **Read/Write capability**: readable and writable<br> Size of the final image area, in raw image coordinates, taking into account extra pixels around the edges of the final image.| 6013| GIF_LOOP_COUNT <sup>12+</sup> | "GIFLoopCount" | **Read/Write capability**: read-only<br> Number of GIF loops. The value **0** means an infinite loop, and other values means the number of loops.| 6014 6015## ImageFormat<sup>9+</sup> 6016 6017Enumerates the image formats. 6018 6019**System capability**: SystemCapability.Multimedia.Image.Core 6020 6021| Name | Value | Description | 6022| ------------ | ------ | -------------------- | 6023| YCBCR_422_SP | 1000 | YCBCR422 semi-planar format.| 6024| JPEG | 2000 | JPEG encoding format. | 6025 6026## ComponentType<sup>9+</sup> 6027 6028Enumerates the color component types of images. 6029 6030**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 6031 6032| Name | Value | Description | 6033| ----- | ------ | ----------- | 6034| YUV_Y | 1 | Luminance component. | 6035| YUV_U | 2 | Chrominance component. | 6036| YUV_V | 3 | Chrominance component. | 6037| JPEG | 4 | JPEG type.| 6038 6039## Component<sup>9+</sup> 6040 6041Describes the color components of an image. 6042 6043**System capability**: SystemCapability.Multimedia.Image.Core 6044 6045| Name | Type | Read Only| Optional| Description | 6046| ------------- | -------------------------------- | ---- | ---- | ------------ | 6047| componentType | [ComponentType](#componenttype9) | Yes | No | Color component type. | 6048| rowStride | number | Yes | No | Row stride. | 6049| pixelStride | number | Yes | No | Pixel stride. | 6050| byteBuffer | ArrayBuffer | Yes | No | Component buffer.| 6051 6052## DecodingDynamicRange<sup>12+</sup> 6053 6054Describes the desired dynamic range of an image during decoding. 6055 6056**System capability**: SystemCapability.Multimedia.Image.Core 6057 6058| Name | Value | Description | 6059| ------------- | ----------| ------------ | 6060| AUTO | 0 | The image is decoded based on the format. If the image is in HDR format, it is decoded based on the HDR content; otherwise, it is decoded based on the SDR content. The image source created by calling [CreateIncrementalSource](#imagecreateincrementalsource9) is decoded into SDR content. | 6061| SDR | 1 | The image is decoded according to the standard dynamic range. | 6062| HDR | 2 | The image is decoded according to the high dynamic range. The image source created by calling [CreateIncrementalSource](#imagecreateincrementalsource9) is decoded into SDR content. | 6063 6064## PackingDynamicRange<sup>12+</sup> 6065 6066Describes the desired dynamic range of a pixel map during encoding. 6067 6068**System capability**: SystemCapability.Multimedia.Image.Core 6069 6070| Name | Value | Description | 6071| ------------- | ----------| ------------ | 6072| AUTO | 0 | Adaptive. The [pixelmap](#pixelmap7) is encoded based on the format. If the pixel map is in HDR format, it is encoded based on the HDR content; otherwise, it is encoded based on the SDR content. | 6073| SDR | 1 | The image is decoded according to the standard dynamic range. | 6074 6075## HdrMetadataKey<sup>12+</sup> 6076 6077Enumerates the keys of HDR metadata used by [pixelmap](#pixelmap7). 6078 6079**System capability**: SystemCapability.Multimedia.Image.Core 6080 6081| Name | Value | Description | 6082| ------------- | ----------| ------------ | 6083| HDR_METADATA_TYPE | 0 | Metadata type used by [pixelmap](#pixelmap7). | 6084| HDR_STATIC_METADATA | 1 | Static metadata. | 6085| HDR_DYNAMIC_METADATA | 2 | Dynamic metadata. | 6086| HDR_GAINMAP_METADATA | 3 | Metadata used by gain maps. | 6087 6088## HdrMetadataType<sup>12+</sup> 6089 6090Enumerates the values available for **HDR_METADATA_TYPE** in [HdrMetadataKey](#hdrmetadatakey12). 6091 6092**System capability**: SystemCapability.Multimedia.Image.Core 6093 6094| Name | Value | Description | 6095| ------------- | ----------| ------------ | 6096| NONE | 0 | No metadata. | 6097| BASE | 1 | Metadata used for base graphics. | 6098| GAINMAP | 2 | Metadata used for gain maps. | 6099| ALTERNATE| 3 | Metadata used for synthesized HDR graphics. | 6100 6101## HdrStaticMetadata<sup>12+</sup> 6102 6103Describes the static metadata keys, that is, the values available for **HDR_STATIC_METADATA** in [HdrMetadataKey](#hdrmetadatakey12). 6104 6105**System capability**: SystemCapability.Multimedia.Image.Core 6106 6107| Name | Type | Description | 6108| ------------- | ----------| ------------ | 6109| displayPrimariesX | Array\<number> | X coordinate of the three primary colors of the display device after normalization. The array length is 3. The unit is 0.00002. The value range is [0.0, 1.0]. | 6110| displayPrimariesY | Array\<number> | Y coordinate of the three primary colors of the display device after normalization. The array length is 3. The unit is 0.00002. The value range is [0.0, 1.0]. | 6111| whitePointX | number | X coordinate of the white point after normalization. The unit is 0.00002. The value range is [0.0, 1.0]. | 6112| whitePointY | number | X coordinate of the white point after normalization. The unit is 0.00002. The value range is [0.0, 1.0]. | 6113| maxLuminance | number | Maximum luminance of the main monitor. The unit is 1, and the maximum value is 65535. | 6114| minLuminance | number | Minimum luminance of the main monitor. The unit is 0.0001, and the maximum value is 6.55535. | 6115| maxContentLightLevel | number | Maximum luminance of the displayed content. The unit is 1, and the maximum value is 65535. | 6116| maxFrameAverageLightLevel | number | Maximum average luminance of the displayed content. The unit is 1, and the maximum value is 65535.| 6117 6118## GainmapChannel<sup>12+</sup> 6119 6120Describes the data content of a single channel of the gain map. For details, see ISO 21496-1. 6121 6122**System capability**: SystemCapability.Multimedia.Image.Core 6123 6124| Name | Type | Description | 6125| ------------- | ----------| ------------ | 6126| gainmapMax | number | Maximum value of the gain map. For details, see ISO 21496-1. | 6127| gainmapMin | number | Minimum value of the gain map. For details, see ISO 21496-1. | 6128| gamma | number | Gamma. For details, see ISO 21496-1. | 6129| baseOffset | number | Offset of the base graphic. For details, see ISO 21496-1. | 6130| alternateOffset | number | Offset of the alternative graphic that can be extracted. For details, see ISO 21496-1. | 6131 6132## HdrGainmapMetadata<sup>12+</sup> 6133 6134Describes the metadata keys used by a gain map, that is, the values available for **HDR_GAINMAP_METADATA** in [HdrMetadataKey](#hdrmetadatakey12). For details, see ISO 21496-1. 6135 6136**System capability**: SystemCapability.Multimedia.Image.Core 6137 6138| Name | Type | Description | 6139| ------------- | ----------| ------------ | 6140| writerVersion | number | Version used by the metadata editor. | 6141| miniVersion | number | Minimum version that needs to be understood for metadata parsing. | 6142| gainmapChannelCount | number | Number of color channels of the gain map. When the value is 3, the metadata values of the RGB channels are different. When the value is 1, the metadata values of the RGB channels are the same. For details, see ISO 21496-1. | 6143| useBaseColorFlag | boolean | Whether to use the color space of the base graphic. For details, see ISO 21496-1. | 6144| baseHeadroom | number | Headroom of the base graphic, which means the additional brightness that can be added to the base graphic. For details, see ISO 21496-1. | 6145| alternateHeadroom | number | Headroom of the alternate graphic. For details, see ISO 21496-1. | 6146| channels | Array<[GainmapChannel](#gainmapchannel12)> | Number of channels. The length is 3. For details, see ISO 21496-1.| 6147 6148## HdrMetadataValue<sup>12+</sup> 6149 6150type HdrMetadataValue = HdrMetadataType | HdrStaticMetadata | ArrayBuffer | HdrGainmapMetadata 6151 6152Describes the HDR metadata values used by a pixel map, which corresponds to the values available for [HdrMetadataKey](#hdrmetadatakey12). 6153 6154**System capability**: SystemCapability.Multimedia.Image.Core 6155 6156| Type | Description | 6157| ------------------- | ----------------------------------------------- | 6158| [HdrMetadataType](#hdrmetadatatype12) | Metadata value corresponding to the **HDR_GAINMAP_METADATA** key in [HdrMetadataKey](#hdrmetadatakey12).| 6159| [HdrStaticMetadata](#hdrstaticmetadata12) | Metadata value corresponding to the **HDR_STATIC_METADATA** key in [HdrMetadataKey](#hdrmetadatakey12).| 6160| ArrayBuffer | Metadata value corresponding to the **HDR_DYNAMIC_METADATA** key in [HdrMetadataKey](#hdrmetadatakey12).| 6161| [HdrGainmapMetadata](#hdrgainmapmetadata12) | Metadata value corresponding to the **HDR_GAINMAP_METADATA** key in [HdrMetadataKey](#hdrmetadatakey12).| 6162 6163## AntiAliasingLevel<sup>12+</sup> 6164 6165Enumerates the anti-aliasing levels. 6166 6167**System capability**: SystemCapability.Multimedia.Image.Core 6168 6169| Name | Value | Description | 6170| ---------------------- | ------ | ----------------- | 6171| NONE | 0 | The nearest neighbor interpolation algorithm is used by default. | 6172| LOW | 1 | Bilinear interpolation. | 6173| MEDIUM | 2 | Bilinear interpolation with mipmap enabled.| 6174| HIGH | 3 | Cubic convolution.| 6175 6176## Supplementary Information 6177### SVG Tags 6178 6179The SVG tags are supported since API version 10. The used version is (SVG) 1.1. An XML declaration that starts with **<?xml** needs to be added to an SVG file, and the width and height of the SVG tag need to be set. Currently, the following tags are supported: 6180- a 6181- circla 6182- clipPath 6183- defs 6184- ellipse 6185- feBlend 6186- feColorMatrix 6187- feComposite 6188- feDiffuseLighting 6189- feDisplacementMap 6190- feDistantLight 6191- feFlood 6192- feGaussianBlur 6193- feImage 6194- feMorphology 6195- feOffset 6196- fePointLight 6197- feSpecularLighting 6198- feSpotLight 6199- feTurbulence 6200- filter 6201- g 6202- image 6203- line 6204- linearGradient 6205- mask 6206- path 6207- pattern 6208- polygon 6209- polyline 6210- radialGradient 6211- rect 6212- stop 6213- svg 6214- text 6215- textPath 6216- tspan 6217- use 6218