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.createPicture<sup>13+</sup> 18 19createPicture(mainPixelmap : PixelMap): Picture 20 21Creates a **Picture** object based on a main PixelMap. 22 23**System capability**: SystemCapability.Multimedia.Image.Core 24 25**Parameters** 26 27| Name | Type | Mandatory| Description | 28| ------------ | ------------------- | ---- | ---------------- | 29| mainPixelmap | [PixelMap](#pixelmap7) | Yes | Main PixelMap.| 30 31**Return value** 32 33| Type | Description | 34| ------------------ | ----------------- | 35| [Picture](#picture13) | **Picture** object.| 36 37**Error codes** 38 39For details about the error codes, see [Image Error Codes](errorcode-image.md). 40 41| ID| Error Message | 42| -------- | ------------------------------------------------------------ | 43| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. | 44 45**Example** 46 47```ts 48import { image } from '@kit.ImageKit'; 49 50async function CreatePicture() { 51 const context = getContext(); 52 const resourceMgr = context.resourceManager; 53 const rawFile = await resourceMgr.getRawFileContent("test.jpg"); 54 let ops: image.SourceOptions = { 55 sourceDensity: 98, 56 } 57 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 58 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 59 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 60 if (pictureObj != null) { 61 console.info('Create picture succeeded'); 62 } else { 63 console.info('Create picture failed'); 64 } 65} 66``` 67 68## image.createPictureFromParcel<sup>13+</sup> 69 70createPictureFromParcel(sequence: rpc.MessageSequence): Picture 71 72Creates a **Picture** object from a **MessageSequence** object. 73 74**System capability**: SystemCapability.Multimedia.Image.Core 75 76**Parameters** 77 78| Name | Type | Mandatory| Description | 79| -------- | ------------------------------------------------------------------- | ---- | ------------------------------------ | 80| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | Yes | **MessageSequence** object that stores the **Picture** information.| 81 82**Return value** 83 84| Type | Description | 85| ------------------ | ----------------- | 86| [Picture](#picture13) | **Picture** object.| 87 88**Error codes** 89 90For details about the error codes, see [Image Error Codes](errorcode-image.md). 91 92| ID| Error Message | 93| -------- | ------------------------------------------------------------ | 94| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. | 95| 62980097 | IPC error. | 96 97**Example** 98 99```ts 100import { rpc } from '@kit.IPCKit'; 101import { BusinessError } from '@kit.BasicServicesKit'; 102import { image } from '@kit.ImageKit'; 103 104class MySequence implements rpc.Parcelable { 105 picture: image.Picture | null = null; 106 constructor(conPicture: image.Picture) { 107 this.picture = conPicture; 108 } 109 marshalling(messageSequence: rpc.MessageSequence) { 110 if(this.picture != null) { 111 this.picture.marshalling(messageSequence); 112 console.info('Marshalling success !'); 113 return true; 114 } else { 115 console.info('Marshalling failed !'); 116 return false; 117 } 118 } 119 unmarshalling(messageSequence : rpc.MessageSequence) { 120 this.picture = image.createPictureFromParcel(messageSequence); 121 this.picture.getMainPixelmap().getImageInfo().then((imageInfo : image.ImageInfo) => { 122 console.info('Unmarshalling to get mainPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width); 123 }).catch((error: BusinessError) => { 124 console.error('Unmarshalling failed error.code: ${error.code} ,error.message: ${error.message}'); 125 }); 126 return true; 127 } 128} 129 130async function Marshalling_UnMarshalling() { 131 const context = getContext(); 132 const resourceMgr = context.resourceManager; 133 const rawFile = await resourceMgr.getRawFileContent("test.jpg"); 134 let ops: image.SourceOptions = { 135 sourceDensity: 98, 136 } 137 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 138 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 139 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 140 if (pictureObj != null) { 141 let parcelable: MySequence = new MySequence(pictureObj); 142 let data: rpc.MessageSequence = rpc.MessageSequence.create(); 143 // marshalling. 144 data.writeParcelable(parcelable); 145 let ret: MySequence = new MySequence(pictureObj); 146 // unmarshalling. 147 data.readParcelable(ret); 148 } else { 149 console.info('PictureObj is null'); 150 } 151} 152``` 153 154## image.createPixelMap<sup>8+</sup> 155 156createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<PixelMap> 157 158Creates a **PixelMap** object with the default BGRA_8888 format and specified pixel properties. This API uses a promise to return the result. 159 160**System capability**: SystemCapability.Multimedia.Image.Core 161 162**Parameters** 163 164| Name | Type | Mandatory| Description | 165| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 166| colors | ArrayBuffer | Yes | Buffer for storing the pixel data. It is used to initialize the pixels of the PixelMap. Before initialization, the pixel format in the buffer must be specified by [InitializationOptions](#initializationoptions8).srcPixelFormat.<br>**NOTE**: The length of the buffer required for storing the pixel data is determined by multiplying the width, height, and the number of bytes per pixel.| 167| options | [InitializationOptions](#initializationoptions8) | Yes | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.| 168 169**Return value** 170 171| Type | Description | 172| -------------------------------- | ----------------------------------------------------------------------- | 173| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.<br>If the size of the created PixelMap exceeds that of the original image, the PixelMap size of the original image is returned.| 174 175**Example** 176 177```ts 178import { BusinessError } from '@kit.BasicServicesKit'; 179 180async function CreatePixelMap() { 181 const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 182 let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 183 image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => { 184 console.info('Succeeded in creating pixelmap.'); 185 }).catch((error: BusinessError) => { 186 console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`); 187 }) 188} 189``` 190 191## image.createPixelMap<sup>8+</sup> 192 193createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: AsyncCallback\<PixelMap>): void 194 195Creates a **PixelMap** object with the default BGRA_8888 format and specified pixel properties. This API uses an asynchronous callback to return the result. 196 197**System capability**: SystemCapability.Multimedia.Image.Core 198 199**Parameters** 200 201| Name | Type | Mandatory| Description | 202| -------- | ------------------------------------------------ | ---- | -------------------------- | 203| colors | ArrayBuffer | Yes | Buffer for storing the pixel data. It is used to initialize the pixels of the PixelMap. Before initialization, the pixel format in the buffer must be specified by [InitializationOptions](#initializationoptions8).srcPixelFormat.<br>**NOTE**: The length of the buffer required for storing the pixel data is determined by multiplying the width, height, and the number of bytes per pixel.| 204| options | [InitializationOptions](#initializationoptions8) | Yes | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.| 205| 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.| 206 207**Example** 208 209```ts 210import { BusinessError } from '@kit.BasicServicesKit'; 211 212async function CreatePixelMap() { 213 const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 214 let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 215 image.createPixelMap(color, opts, (error: BusinessError, pixelMap: image.PixelMap) => { 216 if(error) { 217 console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`); 218 return; 219 } else { 220 console.info('Succeeded in creating pixelmap.'); 221 } 222 }) 223} 224``` 225 226## image.createPixelMapFromParcel<sup>11+</sup> 227 228createPixelMapFromParcel(sequence: rpc.MessageSequence): PixelMap 229 230Creates a **PixelMap** object from a **MessageSequence** object. 231 232**System capability**: SystemCapability.Multimedia.Image.Core 233 234**Parameters** 235 236| Name | Type | Mandatory| Description | 237| ---------------------- | ----------------------------------------------------- | ---- | ---------------------------------------- | 238| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | Yes | **MessageSequence** object that stores the **PixelMap** information. | 239 240**Return value** 241 242| Type | Description | 243| -------------------------------- | --------------------- | 244| [PixelMap](#pixelmap7) | Returns a **PixelMap** object if the operation is successful; throws an error otherwise.| 245 246**Error codes** 247 248For details about the error codes, see [Image Error Codes](errorcode-image.md). 249 250| ID| Error Message| 251| ------- | --------------------------------------------| 252| 62980096 | Operation failed.| 253| 62980097 | IPC error.| 254| 62980115 | Invalid input parameter.| 255| 62980105 | Failed to get the data.| 256| 62980177 | Abnormal API environment.| 257| 62980178 | Failed to create the PixelMap.| 258| 62980179 | Abnormal buffer size.| 259| 62980180 | FD mapping failed.| 260| 62980246 | Failed to read the PixelMap.| 261 262**Example** 263 264```ts 265import { image } from '@kit.ImageKit'; 266import { rpc } from '@kit.IPCKit'; 267import { BusinessError } from '@kit.BasicServicesKit'; 268 269class MySequence implements rpc.Parcelable { 270 pixel_map: image.PixelMap; 271 constructor(conPixelmap: image.PixelMap) { 272 this.pixel_map = conPixelmap; 273 } 274 marshalling(messageSequence: rpc.MessageSequence) { 275 this.pixel_map.marshalling(messageSequence); 276 return true; 277 } 278 unmarshalling(messageSequence: rpc.MessageSequence) { 279 try { 280 this.pixel_map = image.createPixelMapFromParcel(messageSequence); 281 } catch(e) { 282 let error = e as BusinessError; 283 console.error(`createPixelMapFromParcel error. code is ${error.code}, message is ${error.message}`); 284 return false; 285 } 286 return true; 287 } 288} 289async function CreatePixelMapFromParcel() { 290 const color: ArrayBuffer = new ArrayBuffer(96); 291 let bufferArr: Uint8Array = new Uint8Array(color); 292 for (let i = 0; i < bufferArr.length; i++) { 293 bufferArr[i] = 0x80; 294 } 295 let opts: image.InitializationOptions = { 296 editable: true, 297 pixelFormat: image.PixelMapFormat.BGRA_8888, 298 size: { height: 4, width: 6 }, 299 alphaType: image.AlphaType.UNPREMUL 300 } 301 let pixelMap: image.PixelMap | undefined = undefined; 302 image.createPixelMap(color, opts).then((srcPixelMap: image.PixelMap) => { 303 pixelMap = srcPixelMap; 304 }) 305 if (pixelMap != undefined) { 306 // Implement serialization. 307 let parcelable: MySequence = new MySequence(pixelMap); 308 let data: rpc.MessageSequence = rpc.MessageSequence.create(); 309 data.writeParcelable(parcelable); 310 311 // Implement deserialization to obtain data through the RPC. 312 let ret: MySequence = new MySequence(pixelMap); 313 data.readParcelable(ret); 314 315 // Obtain the PixelMap object. 316 let unmarshPixelmap = ret.pixel_map; 317 } 318} 319``` 320 321## image.createPixelMapFromSurface<sup>11+</sup> 322 323createPixelMapFromSurface(surfaceId: string, region: Region): Promise\<PixelMap> 324 325Creates a **PixelMap** object based on the surface ID and region information. The size of the region is specified by [Region](#region8).size. This API uses a promise to return the result. 326 327> **NOTE** 328> 329> When working with foldable devices, switching between folded and unfolded states may cause the API call to fail due to the rotation angle of surface. To address this, you need to adjust the width and height according to the rotation angle. In such cases, [image.createPixelMapFromSurface](#imagecreatepixelmapfromsurface15) is recommended. 330 331**System capability**: SystemCapability.Multimedia.Image.Core 332 333**Parameters** 334 335| Name | Type | Mandatory| Description | 336| ---------------------- | ------------- | ---- | ---------------------------------------- | 337| surfaceId | string | Yes | Surface ID, which can be obtained through the preview component, for example, [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md).| 338| region | [Region](#region8) | Yes | Region information. The width and height in [Region](#region8).size must be the same as those of the preview stream.| 339 340**Return value** 341| Type | Description | 342| -------------------------------- | --------------------- | 343| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.| 344 345**Error codes** 346 347For details about the error codes, see [Image Error Codes](errorcode-image.md). 348 349| ID| Error Message| 350| ------- | --------------------------------------------| 351| 62980115 | If the image parameter invalid.| 352| 62980105 | Failed to get the data.| 353| 62980178 | Failed to create the PixelMap.| 354 355**Example** 356 357```ts 358import { BusinessError } from '@kit.BasicServicesKit'; 359 360async function CreatePixelMapFromSurface(surfaceId: string) { 361 let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 362 image.createPixelMapFromSurface(surfaceId, region).then(() => { 363 console.info('Succeeded in creating pixelmap from Surface'); 364 }).catch((error: BusinessError) => { 365 console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`); 366 }); 367} 368``` 369 370## image.createPixelMapFromSurfaceSync<sup>12+</sup> 371 372createPixelMapFromSurfaceSync(surfaceId: string, region: Region): PixelMap 373 374Creates a **PixelMap** object based on the surface ID and region information. This API returns the result synchronously. The size of the region is specified by [Region](#region8).size. 375 376> **NOTE** 377> 378> When working with foldable devices, switching between folded and unfolded states may cause the API call to fail due to the rotation angle of surface. To address this, you need to adjust the width and height according to the rotation angle. In such cases, [image.createPixelMapFromSurfaceSync](#imagecreatepixelmapfromsurfacesync15) is recommended. 379 380**System capability**: SystemCapability.Multimedia.Image.Core 381 382**Parameters** 383 384| Name | Type | Mandatory| Description | 385| ---------------------- | ------------- | ---- | ---------------------------------------- | 386| surfaceId | string | Yes | Surface ID, which can be obtained through the preview component, for example, [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md).| 387| region | [Region](#region8) | Yes | Region information. The width and height in [Region](#region8).size must be the same as those of the preview stream.| 388 389**Return value** 390| Type | Description | 391| -------------------------------- | --------------------- | 392| [PixelMap](#pixelmap7) | Returns a **PixelMap** object if the operation is successful; throws an error otherwise.| 393 394**Error codes** 395 396For details about the error codes, see [Image Error Codes](errorcode-image.md). 397 398| ID| Error Message| 399| ------- | --------------------------------------------| 400| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.| 401| 62980105 | Failed to get the data.| 402| 62980178 | Failed to create the PixelMap.| 403 404**Example** 405 406```ts 407import { BusinessError } from '@kit.BasicServicesKit'; 408 409async function Demo(surfaceId: string) { 410 let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 411 let pixelMap : image.PixelMap = image.createPixelMapFromSurfaceSync(surfaceId, region); 412 return pixelMap; 413} 414``` 415 416## image.createPixelMapFromSurface<sup>15+</sup> 417 418createPixelMapFromSurface(surfaceId: string): Promise\<PixelMap> 419 420Creates a **PixelMap** object from a surface ID. This API uses a promise to return the result. 421 422**System capability**: SystemCapability.Multimedia.Image.Core 423 424**Parameters** 425 426| Name | Type | Mandatory| Description | 427| ---------------------- | ------------- | ---- | ---------------------------------------- | 428| surfaceId | string | Yes | Surface ID, which can be obtained through the preview component, for example, [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md).| 429 430**Return value** 431| Type | Description | 432| -------------------------------- | --------------------- | 433| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.| 434 435**Error codes** 436 437For details about the error codes, see [Image Error Codes](errorcode-image.md). 438 439| ID| Error Message| 440| ------- | --------------------------------------------| 441| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 442| 62980105 | Failed to get the data| 443| 62980178 | Failed to create the PixelMap| 444 445**Example** 446 447```ts 448import { BusinessError } from '@kit.BasicServicesKit'; 449 450async function Demo(surfaceId: string) { 451 image.createPixelMapFromSurface(surfaceId).then(() => { 452 console.info('Succeeded in creating pixelmap from Surface'); 453 }).catch((error: BusinessError) => { 454 console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`); 455 }); 456} 457``` 458 459## image.createPixelMapFromSurfaceSync<sup>15+</sup> 460 461createPixelMapFromSurfaceSync(surfaceId: string): PixelMap 462 463Creates a **PixelMap** object from a surface ID. This API returns the result synchronously. 464 465**System capability**: SystemCapability.Multimedia.Image.Core 466 467**Parameters** 468 469| Name | Type | Mandatory| Description | 470| ---------------------- | ------------- | ---- | ---------------------------------------- | 471| surfaceId | string | Yes | Surface ID, which can be obtained through the preview component, for example, [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md).| 472 473**Return value** 474| Type | Description | 475| -------------------------------- | --------------------- | 476| [PixelMap](#pixelmap7) | Returns a **PixelMap** object if the operation is successful; throws an error otherwise.| 477 478**Error codes** 479 480For details about the error codes, see [Image Error Codes](errorcode-image.md). 481 482| ID| Error Message| 483| ------- | --------------------------------------------| 484| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 485| 62980105 | Failed to get the data| 486| 62980178 | Failed to create the PixelMap| 487 488**Example** 489 490```ts 491import { BusinessError } from '@kit.BasicServicesKit'; 492 493async function Demo(surfaceId: string) { 494 let pixelMap : image.PixelMap = image.createPixelMapFromSurfaceSync(surfaceId); 495 return pixelMap; 496} 497``` 498## image.createPixelMapSync<sup>12+</sup> 499 500createPixelMapSync(colors: ArrayBuffer, options: InitializationOptions): PixelMap 501 502Creates a **PixelMap** object with the default BGRA_8888 format and specified pixel properties. This API returns the result synchronously. 503 504**System capability**: SystemCapability.Multimedia.Image.Core 505 506**Parameters** 507 508| Name | Type | Mandatory| Description | 509| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 510| colors | ArrayBuffer | Yes | Buffer for storing the pixel data. It is used to initialize the pixels of the PixelMap. Before initialization, the pixel format in the buffer must be specified by [InitializationOptions](#initializationoptions8).srcPixelFormat.<br>**NOTE**: The length of the buffer required for storing the pixel data is determined by multiplying the width, height, and the number of bytes per pixel.| 511| options | [InitializationOptions](#initializationoptions8) | Yes | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.| 512 513**Return value** 514| Type | Description | 515| -------------------------------- | --------------------- | 516| [PixelMap](#pixelmap7) | Returns a **PixelMap** object if the operation is successful; throws an error otherwise.| 517 518**Error codes** 519 520For details about the error codes, see [Image Error Codes](errorcode-image.md). 521 522| ID| Error Message| 523| ------- | --------------------------------------------| 524| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 525 526**Example** 527 528```ts 529import { BusinessError } from '@kit.BasicServicesKit'; 530 531async function CreatePixelMapSync() { 532 const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 533 let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 534 let pixelMap : image.PixelMap = image.createPixelMapSync(color, opts); 535 return pixelMap; 536} 537``` 538 539## image.createPixelMapSync<sup>12+</sup> 540 541createPixelMapSync(options: InitializationOptions): PixelMap 542 543Creates a **PixelMap** object with the specified pixel properties. This API returns the result synchronously. 544 545**System capability**: SystemCapability.Multimedia.Image.Core 546 547**Parameters** 548 549| Name | Type | Mandatory| Description | 550| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 551| options | [InitializationOptions](#initializationoptions8) | Yes | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.| 552 553**Return value** 554| Type | Description | 555| -------------------------------- | --------------------- | 556| [PixelMap](#pixelmap7) | Returns a **PixelMap** object if the operation is successful; throws an error otherwise.| 557 558**Error codes** 559 560For details about the error codes, see [Image Error Codes](errorcode-image.md). 561 562| ID| Error Message| 563| ------- | --------------------------------------------| 564| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 565 566**Example** 567 568```ts 569import { BusinessError } from '@kit.BasicServicesKit'; 570 571async function CreatePixelMapSync() { 572 let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 573 let pixelMap : image.PixelMap = image.createPixelMapSync(opts); 574 return pixelMap; 575} 576``` 577 578## image.createPremultipliedPixelMap<sup>12+</sup> 579 580createPremultipliedPixelMap(src: PixelMap, dst: PixelMap, callback: AsyncCallback\<void>): void 581 582Converts a non-premultiplied alpha of a PixelMap to a premultiplied one and stores the converted data to a target PixelMap. This API uses an asynchronous callback to return the result. 583 584**System capability**: SystemCapability.Multimedia.Image.Core 585 586**Parameters** 587 588| Name | Type | Mandatory| Description | 589| -------- | ------------------------------------------------ | ---- | -------------------------- | 590| src | [PixelMap](#pixelmap7) | Yes | Source **PixelMap** object.| 591| dst | [PixelMap](#pixelmap7) | Yes | Target **PixelMap** object.| 592|callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 593 594**Error codes** 595 596For details about the error codes, see [Image Error Codes](errorcode-image.md). 597 598| ID| Error Message| 599| ------- | --------------------------------------------| 600| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 601| 62980103 | The image data is not supported | 602| 62980246 | Failed to read the pixelMap | 603| 62980248 | Pixelmap not allow modify | 604 605**Example** 606 607```ts 608import { BusinessError } from '@kit.BasicServicesKit'; 609 610async function CreatePremultipliedPixelMap() { 611 const color: ArrayBuffer = new ArrayBuffer(16); // 16 is the size of the pixel buffer to create. The value is calculated as follows: height * width * 4. 612 let bufferArr = new Uint8Array(color); 613 for (let i = 0; i < bufferArr.length; i += 4) { 614 bufferArr[i] = 255; 615 bufferArr[i+1] = 255; 616 bufferArr[i+2] = 122; 617 bufferArr[i+3] = 122; 618 } 619 let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.UNPREMUL} 620 let srcPixelmap = image.createPixelMapSync(color, optsForUnpre); 621 let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.PREMUL} 622 let dstPixelMap = image.createPixelMapSync(optsForPre); 623 image.createPremultipliedPixelMap(srcPixelmap, dstPixelMap, (error: BusinessError) => { 624 if(error) { 625 console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`); 626 return; 627 } else { 628 console.info('Succeeded in converting pixelmap.'); 629 } 630 }) 631} 632``` 633 634## image.createPremultipliedPixelMap<sup>12+</sup> 635 636createPremultipliedPixelMap(src: PixelMap, dst: PixelMap): Promise\<void> 637 638Converts a non-premultiplied alpha of a PixelMap to a premultiplied one and stores the converted data to a target PixelMap. This API uses a promise to return the result. 639 640**System capability**: SystemCapability.Multimedia.Image.Core 641 642**Parameters** 643 644| Name | Type | Mandatory| Description | 645| -------- | ------------------------------------------------ | ---- | -------------------------- | 646| src | [PixelMap](#pixelmap7) | Yes | Source **PixelMap** object.| 647| dst | [PixelMap](#pixelmap7) | Yes | Target **PixelMap** object.| 648 649**Return value** 650 651| Type | Description | 652| -------------------------------- | ----------------------------------------------------------------------- | 653| Promise\<void> | Promise that returns no value.| 654 655**Error codes** 656 657For details about the error codes, see [Image Error Codes](errorcode-image.md). 658 659| ID| Error Message| 660| ------- | --------------------------------------------| 661| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 662| 62980103 | The image data is not supported | 663| 62980246 | Failed to read the pixelMap | 664| 62980248 | Pixelmap not allow modify | 665 666**Example** 667 668```ts 669import { BusinessError } from '@kit.BasicServicesKit'; 670 671async function CreatePremultipliedPixelMap() { 672 const color: ArrayBuffer = new ArrayBuffer(16); // 16 is the size of the pixel buffer to create. The value is calculated as follows: height * width * 4. 673 let bufferArr = new Uint8Array(color); 674 for (let i = 0; i < bufferArr.length; i += 4) { 675 bufferArr[i] = 255; 676 bufferArr[i+1] = 255; 677 bufferArr[i+2] = 122; 678 bufferArr[i+3] = 122; 679 } 680 let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.UNPREMUL} 681 let srcPixelmap = image.createPixelMapSync(color, optsForUnpre); 682 let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.PREMUL} 683 let dstPixelMap = image.createPixelMapSync(optsForPre); 684 image.createPremultipliedPixelMap(srcPixelmap, dstPixelMap).then(() => { 685 console.info('Succeeded in converting pixelmap.'); 686 }).catch((error: BusinessError) => { 687 console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`); 688 }) 689} 690``` 691 692## image.createUnpremultipliedPixelMap<sup>12+</sup> 693 694createUnpremultipliedPixelMap(src: PixelMap, dst: PixelMap, callback: AsyncCallback\<void>): void 695 696Converts a premultiplied alpha of a PixelMap to a non-premultiplied one and stores the converted data to a target PixelMap. This API uses an asynchronous callback to return the result. 697 698**System capability**: SystemCapability.Multimedia.Image.Core 699 700**Parameters** 701 702| Name | Type | Mandatory| Description | 703| -------- | ------------------------------------------------ | ---- | -------------------------- | 704| src | [PixelMap](#pixelmap7) | Yes | Source **PixelMap** object.| 705| dst | [PixelMap](#pixelmap7) | Yes | Target **PixelMap** object.| 706|callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 707 708**Error codes** 709 710For details about the error codes, see [Image Error Codes](errorcode-image.md). 711 712| ID| Error Message| 713| ------- | --------------------------------------------| 714| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 715| 62980103 | The image data is not supported | 716| 62980246 | Failed to read the pixelMap | 717| 62980248 | Pixelmap not allow modify | 718 719**Example** 720 721```ts 722import { BusinessError } from '@kit.BasicServicesKit'; 723 724async function CreateUnpremultipliedPixelMap() { 725 const color: ArrayBuffer = new ArrayBuffer(16); // 16 is the size of the pixel buffer to create. The value is calculated as follows: height * width * 4. 726 let bufferArr = new Uint8Array(color); 727 for (let i = 0; i < bufferArr.length; i += 4) { 728 bufferArr[i] = 255; 729 bufferArr[i+1] = 255; 730 bufferArr[i+2] = 122; 731 bufferArr[i+3] = 122; 732 } 733 let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.PREMUL} 734 let srcPixelmap = image.createPixelMapSync(color, optsForPre); 735 let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.UNPREMUL} 736 let dstPixelMap = image.createPixelMapSync(optsForUnpre); 737 image.createUnpremultipliedPixelMap(srcPixelmap, dstPixelMap, (error: BusinessError) => { 738 if(error) { 739 console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`); 740 return; 741 } else { 742 console.info('Succeeded in converting pixelmap.'); 743 } 744 }) 745} 746``` 747 748## image.createUnpremultipliedPixelMap<sup>12+</sup> 749 750createUnpremultipliedPixelMap(src: PixelMap, dst: PixelMap): Promise\<void> 751 752Converts a premultiplied alpha of a PixelMap to a non-premultiplied one and stores the converted data to a target PixelMap. This API uses a promise to return the result. 753 754**System capability**: SystemCapability.Multimedia.Image.Core 755 756**Parameters** 757 758| Name | Type | Mandatory| Description | 759| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 760| src | [PixelMap](#pixelmap7) | Yes | Source **PixelMap** object.| 761| dst | [PixelMap](#pixelmap7) | Yes | Target **PixelMap** object.| 762 763**Return value** 764 765| Type | Description | 766| -------------------------------- | ----------------------------------------------------------------------- | 767| Promise\<void> | Promise that returns no value.| 768 769**Error codes** 770 771For details about the error codes, see [Image Error Codes](errorcode-image.md). 772 773| ID| Error Message| 774| ------- | --------------------------------------------| 775| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.| 776| 62980103 | The image data is not supported. | 777| 62980246 | Failed to read the pixelMap. | 778| 62980248 | Pixelmap not allow modify. | 779 780**Example** 781 782```ts 783import { BusinessError } from '@kit.BasicServicesKit'; 784 785async function CreateUnpremultipliedPixelMap() { 786 const color: ArrayBuffer = new ArrayBuffer(16); // 16 is the size of the pixel buffer to create. The value is calculated as follows: height * width * 4. 787 let bufferArr = new Uint8Array(color); 788 for (let i = 0; i < bufferArr.length; i += 4) { 789 bufferArr[i] = 255; 790 bufferArr[i+1] = 255; 791 bufferArr[i+2] = 122; 792 bufferArr[i+3] = 122; 793 } 794 let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.PREMUL} 795 let srcPixelmap = image.createPixelMapSync(color, optsForPre); 796 let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.UNPREMUL} 797 let dstPixelMap = image.createPixelMapSync(optsForUnpre); 798 image.createUnpremultipliedPixelMap(srcPixelmap, dstPixelMap).then(() => { 799 console.info('Succeeded in converting pixelmap.'); 800 }).catch((error: BusinessError) => { 801 console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`); 802 }) 803} 804``` 805 806 807## Picture<sup>13+</sup> 808 809An image that contains special information can be decoded into a picture object, which generally contains the main picture, auxiliary picture, and metadata. The main picture contains most information about the image and is mainly used to render the image. The auxiliary picture is used to store data related to but different from the main picture, revealing more comprehensive details. The metadata is generally used to store information about the image file. The picture object class is used to read or write picture objects. Before calling any API in **Picture**, you must use [createPicture](#imagecreatepicture13) to create a **Picture** object. 810 811### Properties 812 813**System capability**: SystemCapability.Multimedia.Image.Core 814 815### getMainPixelmap<sup>13+</sup> 816 817getMainPixelmap(): PixelMap 818 819Obtains the **PixelMap** object of the main picture. This API returns the result synchronously. 820 821**System capability**: SystemCapability.Multimedia.Image.Core 822 823**Return value** 824 825| Type | Description | 826| ------------------- | ---------------------- | 827| [PixelMap](#pixelmap7) | **PixelMap** object.| 828 829**Example** 830 831```ts 832import { BusinessError } from '@kit.BasicServicesKit'; 833import { image } from '@kit.ImageKit'; 834 835async function GetMainPixelmap() { 836 let funcName = "getMainPixelmap"; 837 if (pictureObj != null) { 838 let mainPixelmap: image.PixelMap = pictureObj.getMainPixelmap(); 839 if (mainPixelmap != null) { 840 mainPixelmap.getImageInfo().then((imageInfo: image.ImageInfo) => { 841 if (imageInfo != null) { 842 console.info('GetMainPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width); 843 } 844 }).catch((error: BusinessError) => { 845 console.error(funcName, 'Failed error.code: ${error.code} ,error.message: ${error.message}'); 846 }); 847 } 848 } else { 849 console.info('PictureObj is null'); 850 } 851} 852``` 853 854### getHdrComposedPixelmap<sup>13+</sup> 855 856getHdrComposedPixelmap(): Promise\<PixelMap> 857 858Generates an HDR image and obtains its **PixelMap** object. This API uses a promise to return the result. 859 860**System capability**: SystemCapability.Multimedia.Image.Core 861 862**Return value** 863 864| Type | Description | 865| ----------------------------- | --------------------------- | 866| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.| 867 868**Error codes** 869 870For details about the error codes, see [Image Error Codes](errorcode-image.md). 871 872| ID| Error Message | 873| -------- | ---------------------- | 874| 7600901 | Unknown error. | 875| 7600201 | Unsupported operation. | 876 877**Example** 878 879```ts 880import { BusinessError } from '@kit.BasicServicesKit'; 881import { image } from '@kit.ImageKit'; 882 883async function GetHdrComposedPixelmap() { 884 let funcName = "getHdrComposedPixelmap"; 885 if (pictureObj != null) { // An HDR image is contained. 886 let hdrComposedPixelmap: image.PixelMap = await pictureObj.getHdrComposedPixelmap(); 887 if (hdrComposedPixelmap != null) { 888 hdrComposedPixelmap.getImageInfo().then((imageInfo: image.ImageInfo) => { 889 if (imageInfo != null) { 890 console.info('GetHdrComposedPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width); 891 } 892 }).catch((error: BusinessError) => { 893 console.error(funcName, 'Failed error.code: ${error.code} ,error.message: ${error.message}'); 894 }); 895 } 896 } else { 897 console.info('PictureObj is null'); 898 } 899} 900``` 901 902### getGainmapPixelmap<sup>13+</sup> 903 904getGainmapPixelmap(): PixelMap | null 905 906Obtains the **PixelMap** object of the gain map. 907 908**System capability**: SystemCapability.Multimedia.Image.Core 909 910**Return value** 911 912| Type | Description | 913| ------------------------- | -------------------------------------- | 914| [PixelMap](#pixelmap7) \| null | **PixelMap** object obtained. If there is no **PixelMap** object, null is returned.| 915 916**Example** 917 918```ts 919import { BusinessError } from '@kit.BasicServicesKit'; 920import { image } from '@kit.ImageKit'; 921 922async function GetGainmapPixelmap() { 923 let funcName = "getGainmapPixelmap"; 924 if (pictureObj != null) { // A gain map is contained. 925 let gainPixelmap: image.PixelMap | null = pictureObj.getGainmapPixelmap(); 926 if (gainPixelmap != null) { 927 gainPixelmap.getImageInfo().then((imageInfo: image.ImageInfo) => { 928 if (imageInfo != null) { 929 console.info('GetGainmapPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width); 930 } else { 931 console.info('GainPixelmap is null'); 932 } 933 }).catch((error: BusinessError) => { 934 console.error(funcName, 'Failed error.code: ${error.code} ,error.message: ${error.message}'); 935 }); 936 } else { 937 console.info('GainPixelmap is null'); 938 } 939 } else { 940 console.info('PictureObj is null'); 941 } 942} 943``` 944 945### setAuxiliaryPicture<sup>13+</sup> 946 947setAuxiliaryPicture(type: AuxiliaryPictureType, auxiliaryPicture: AuxiliaryPicture): void 948 949Sets an auxiliary picture. 950 951**System capability**: SystemCapability.Multimedia.Image.Core 952 953**Parameters** 954 955| Name | Type | Mandatory| Description | 956| ---------------- | -------------------- | ---- | ------------ | 957| type | [AuxiliaryPictureType](#auxiliarypicturetype13) | Yes | Type of the auxiliary picture.| 958| auxiliaryPicture | [AuxiliaryPicture](#auxiliarypicture13) | Yes | **AuxiliaryPicture** object.| 959 960**Error codes** 961 962For details about the error codes, see [Image Error Codes](errorcode-image.md). 963 964| ID| Error Message | 965| -------- | ------------------------------------------------------------ | 966| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 967 968**Example** 969 970```ts 971import { image } from '@kit.ImageKit'; 972 973async function SetAuxiliaryPicture() { 974 const context = getContext(); 975 const resourceMgr = context.resourceManager; 976 const rawFile = await resourceMgr.getRawFileContent("hdr.jpg"); // Support for HDR images is required. 977 let ops: image.SourceOptions = { 978 sourceDensity: 98, 979 } 980 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 981 let pixelMap: image.PixelMap = await imageSource.createPixelMap(); 982 let auxPicture: image.Picture = image.createPicture(pixelMap); 983 if (auxPicture != null) { 984 console.info('Create picture succeeded'); 985 } else { 986 console.info('Create picture failed'); 987 } 988 989 if (pictureObj != null) { 990 let type: image.AuxiliaryPictureType = image.AuxiliaryPictureType.GAINMAP; 991 let auxPictureObj: image.AuxiliaryPicture | null = await auxPicture.getAuxiliaryPicture(type); 992 if (auxPictureObj != null) { 993 pictureObj.setAuxiliaryPicture(type, auxPictureObj); 994 } 995 } 996} 997``` 998 999### getAuxiliaryPicture<sup>13+</sup> 1000 1001getAuxiliaryPicture(type: AuxiliaryPictureType): AuxiliaryPicture | null 1002 1003Obtains an auxiliary picture by type. 1004 1005**System capability**: SystemCapability.Multimedia.Image.Core 1006 1007**Parameters** 1008 1009| Name| Type | Mandatory| Description | 1010| ------ | -------------------- | ---- | ------------ | 1011| type | [AuxiliaryPictureType](#auxiliarypicturetype13) | Yes | Type of the auxiliary picture.| 1012 1013**Return value** 1014 1015| Type | Description | 1016| ---------------------- | ---------------------------------------------- | 1017| [AuxiliaryPicture](#auxiliarypicture13) \| null | **AuxiliaryPicture** object. If there is no **AuxiliaryPicture** object, null is returned.| 1018 1019**Error codes** 1020 1021For details about the error codes, see [Image Error Codes](errorcode-image.md). 1022 1023| ID| Error Message | 1024| -------- | ------------------------------------------------------------ | 1025| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 1026 1027**Example** 1028 1029```ts 1030import { image } from '@kit.ImageKit'; 1031 1032async function GetAuxiliaryPicture() { 1033 if (pictureObj != null) { 1034 let type: image.AuxiliaryPictureType = image.AuxiliaryPictureType.GAINMAP; 1035 let auxPictureObj: image.AuxiliaryPicture | null = pictureObj.getAuxiliaryPicture(type); 1036 } 1037} 1038``` 1039 1040### setMetadata<sup>13+</sup> 1041 1042setMetadata(metadataType: MetadataType, metadata: Metadata): Promise\<void> 1043 1044Sets the metadata for this **Picture** object. 1045 1046**System capability**: SystemCapability.Multimedia.Image.Core 1047 1048**Parameters** 1049 1050| Name | Type | Mandatory| Description | 1051| ------------ | ------------ | ---- | ------------ | 1052| metadataType | [MetadataType](#metadatatype13) | Yes | Metadata type.| 1053| metadata | [Metadata](#metadata13) | Yes | **Metadata** object.| 1054 1055**Return value** 1056 1057| Type | Description | 1058| -------------- | -------------------------------------- | 1059| Promise\<void> | Promise that returns no value.| 1060 1061**Error codes** 1062 1063For details about the error codes, see [Image Error Codes](errorcode-image.md). 1064 1065| ID| Error Message | 1066| -------- | ------------------------------------------------------------ | 1067| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 1068| 7600202 | Unsupported metadata. Possible causes: Unsupported metadata type. | 1069 1070**Example** 1071 1072```ts 1073import { BusinessError } from '@kit.BasicServicesKit'; 1074import { image } from '@kit.ImageKit'; 1075 1076async function SetPictureObjMetadata() { 1077 const exifContext = getContext(); 1078 const exifResourceMgr = exifContext.resourceManager; 1079 const exifRawFile = await exifResourceMgr.getRawFileContent("exif.jpg"); // The image contains EXIF metadata. 1080 let exifOps: image.SourceOptions = { 1081 sourceDensity: 98, 1082 } 1083 let exifImageSource: image.ImageSource = image.createImageSource(exifRawFile.buffer as ArrayBuffer, exifOps); 1084 let exifCommodityPixelMap: image.PixelMap = await exifImageSource.createPixelMap(); 1085 let exifPictureObj: image.Picture = image.createPicture(exifCommodityPixelMap); 1086 if (exifPictureObj != null) { 1087 console.info('Create picture succeeded'); 1088 } else { 1089 console.info('Create picture failed'); 1090 } 1091 1092 if (pictureObj != null) { 1093 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 1094 let exifMetaData: image.Metadata = await exifPictureObj.getMetadata(metadataType); 1095 pictureObj.setMetadata(metadataType, exifMetaData).then(() => { 1096 console.info('Set metadata success'); 1097 }).catch((error: BusinessError) => { 1098 console.error('Failed to set metadata. error.code: ' +JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message)); 1099 }); 1100 } else { 1101 console.info('PictureObj is null'); 1102 } 1103} 1104``` 1105 1106### getMetadata<sup>13+</sup> 1107 1108getMetadata(metadataType: MetadataType): Promise\<Metadata> 1109 1110Obtains the metadata of this **Picture** object. 1111 1112**System capability**: SystemCapability.Multimedia.Image.Core 1113 1114**Parameters** 1115 1116| Name | Type | Mandatory| Description | 1117| ------------ | ------------ | ---- | ------------ | 1118| metadataType | [MetadataType](#metadatatype13) | Yes | Metadata type.| 1119 1120**Return value** 1121 1122| Type | Description | 1123| ------------------ | ------------------------- | 1124| Promise\<[Metadata](#metadata13)> | Promise used to return the metadata.| 1125 1126**Error codes** 1127 1128For details about the error codes, see [Image Error Codes](errorcode-image.md). 1129 1130| ID| Error Message | 1131| -------- | ------------------------------------------------------------ | 1132| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 1133| 7600202 | Unsupported metadata. Possible causes: Unsupported metadata type. | 1134 1135**Example** 1136 1137```ts 1138import { image } from '@kit.ImageKit'; 1139 1140async function GetPictureObjMetadataProperties() { 1141 if (pictureObj != null) { 1142 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 1143 let pictureObjMetaData: image.Metadata = await pictureObj.getMetadata(metadataType); 1144 if (pictureObjMetaData != null) { 1145 console.info('get picture metadata success'); 1146 } else { 1147 console.info('get picture metadata is failed'); 1148 } 1149 } else { 1150 console.info(" pictureObj is null"); 1151 } 1152} 1153``` 1154 1155### marshalling<sup>13+</sup> 1156 1157marshalling(sequence: rpc.MessageSequence): void 1158 1159Marshals this **Picture** object and writes it to a **MessageSequence** object. 1160 1161**System capability**: SystemCapability.Multimedia.Image.Core 1162 1163**Parameters** 1164 1165| Name | Type | Mandatory| Description | 1166| -------- | ------------------------------------------------------------------- | ---- | ------------------------- | 1167| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | Yes | **MessageSequence** object.| 1168 1169**Error codes** 1170 1171For details about the error codes, see [Image Error Codes](errorcode-image.md). 1172 1173| ID| Error Message | 1174| -------- | ------------------------------------------------------------ | 1175| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 1176| 62980097 | IPC error. | 1177 1178**Example** 1179 1180```ts 1181import { BusinessError } from '@kit.BasicServicesKit'; 1182import { image } from '@kit.ImageKit'; 1183import { rpc } from '@kit.IPCKit'; 1184 1185class MySequence implements rpc.Parcelable { 1186 picture: image.Picture | null = null; 1187 constructor(conPicture: image.Picture) { 1188 this.picture = conPicture; 1189 } 1190 marshalling(messageSequence: rpc.MessageSequence) { 1191 if(this.picture != null) { 1192 this.picture.marshalling(messageSequence); 1193 console.info('Marshalling success !'); 1194 return true; 1195 } else { 1196 console.info('Marshalling failed !'); 1197 return false; 1198 } 1199 } 1200 unmarshalling(messageSequence : rpc.MessageSequence) { 1201 this.picture = image.createPictureFromParcel(messageSequence); 1202 this.picture.getMainPixelmap().getImageInfo().then((imageInfo : image.ImageInfo) => { 1203 console.info('Unmarshalling to get mainPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width); 1204 }).catch((error: BusinessError) => { 1205 console.error('Unmarshalling failed error.code: ${error.code} ,error.message: ${error.message}'); 1206 }); 1207 return true; 1208 } 1209} 1210 1211async function Marshalling_UnMarshalling() { 1212 if (pictureObj != null) { 1213 let parcelable: MySequence = new MySequence(pictureObj); 1214 let data: rpc.MessageSequence = rpc.MessageSequence.create(); 1215 // marshalling. 1216 data.writeParcelable(parcelable); 1217 let ret: MySequence = new MySequence(pictureObj); 1218 // unmarshalling. 1219 data.readParcelable(ret); 1220 } else { 1221 console.info('PictureObj is null'); 1222 } 1223} 1224``` 1225 1226### release<sup>13+</sup> 1227 1228release(): void 1229 1230Releases this **Picture** object. 1231 1232**System capability**: SystemCapability.Multimedia.Image.Core 1233 1234**Example** 1235 1236```ts 1237import { image } from '@kit.ImageKit'; 1238 1239async function Release() { 1240 let funcName = "Release"; 1241 if (pictureObj != null) { 1242 pictureObj.release(); 1243 if (pictureObj.getMainPixelmap() == null) { 1244 console.info(funcName, 'Success !'); 1245 } else { 1246 console.info(funcName, 'Failed !'); 1247 } 1248 } else { 1249 console.info('PictureObj is null'); 1250 } 1251} 1252``` 1253 1254## PixelMap<sup>7+</sup> 1255 1256Provides 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 PixelMap 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. 1257 1258Since 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. 1259 1260Before calling any API in **PixelMap**, you must use [image.createPixelMap](#imagecreatepixelmap8) to create a **PixelMap** object. 1261 1262To develop an atomic service, use [ImageSoure](#imagesource) to create a **PixelMap** object. 1263 1264### Properties 1265 1266**System capability**: SystemCapability.Multimedia.Image.Core 1267 1268| Name | Type | Readable| Writable| Description | 1269| -----------------| ------- | ---- | ---- | -------------------------- | 1270| isEditable | boolean | Yes | No | Whether the PixelMap is editable. The value **true** means that the PixelMap is editable, and **false** means the opposite.<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.| 1271| isStrideAlignment<sup>11+</sup> | boolean | Yes | No | Whether the PixelMap uses DMA memory. The value** true** means that the PixelMap uses DMA memory, and **false** means the opposite.| 1272 1273### readPixelsToBuffer<sup>7+</sup> 1274 1275readPixelsToBuffer(dst: ArrayBuffer): Promise\<void> 1276 1277Reads the pixels of this **PixelMap** object based on the PixelMap's pixel format and writes the data to the buffer. This API uses a promise to return the result. 1278 1279**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1280 1281**Atomic service API**: This API can be used in atomic services since API version 11. 1282 1283**System capability**: SystemCapability.Multimedia.Image.Core 1284 1285**Parameters** 1286 1287| Name| Type | Mandatory| Description | 1288| ------ | ----------- | ---- | ----------------------------------------------------------------------------------------------------- | 1289| dst | ArrayBuffer | Yes | Buffer to which the pixels will be written. The buffer size is obtained by calling [getPixelBytesNumber](#getpixelbytesnumber7).| 1290 1291**Return value** 1292 1293| Type | Description | 1294| -------------- | ----------------------------------------------- | 1295| Promise\<void> | Promise that returns no value. | 1296 1297**Example** 1298 1299```ts 1300import { BusinessError } from '@kit.BasicServicesKit'; 1301 1302async function ReadPixelsToBuffer() { 1303 const readBuffer: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 1304 if (pixelMap != undefined) { 1305 pixelMap.readPixelsToBuffer(readBuffer).then(() => { 1306 console.info('Succeeded in reading image pixel data.'); // Called if the condition is met. 1307 }).catch((error: BusinessError) => { 1308 console.error(`Failed to read image pixel data. code is ${error.code}, message is ${error.message}`); // Called if no condition is met. 1309 }) 1310 } 1311} 1312``` 1313 1314### readPixelsToBuffer<sup>7+</sup> 1315 1316readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\<void>): void 1317 1318Reads the pixels of this **PixelMap** object based on the PixelMap's pixel format and writes the data to the buffer. This API uses an asynchronous callback to return the result. 1319 1320**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1321 1322**Atomic service API**: This API can be used in atomic services since API version 11. 1323 1324**System capability**: SystemCapability.Multimedia.Image.Core 1325 1326**Parameters** 1327 1328| Name | Type | Mandatory| Description | 1329| -------- | -------------------- | ---- | ----------------------------------------------------------------------------------------------------- | 1330| dst | ArrayBuffer | Yes | Buffer to which the pixels will be written. The buffer size is obtained by calling [getPixelBytesNumber](#getpixelbytesnumber7).| 1331| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 1332 1333**Example** 1334 1335```ts 1336import { BusinessError } from '@kit.BasicServicesKit'; 1337 1338async function ReadPixelsToBuffer() { 1339 const readBuffer: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 1340 if (pixelMap != undefined) { 1341 pixelMap.readPixelsToBuffer(readBuffer, (error: BusinessError, res: void) => { 1342 if(error) { 1343 console.error(`Failed to read image pixel data. code is ${error.code}, message is ${error.message}`); // Called if no condition is met. 1344 return; 1345 } else { 1346 console.info('Succeeded in reading image pixel data.'); // Called if the condition is met. 1347 } 1348 }) 1349 } 1350} 1351``` 1352 1353### readPixelsToBufferSync<sup>12+</sup> 1354 1355readPixelsToBufferSync(dst: ArrayBuffer): void 1356 1357Reads the pixels of this **PixelMap** object based on the PixelMap's pixel format and writes the data to the buffer. This API returns the result synchronously. 1358 1359**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1360 1361**Atomic service API**: This API can be used in atomic services since API version 12. 1362 1363**System capability**: SystemCapability.Multimedia.Image.Core 1364 1365**Parameters** 1366 1367| Name | Type | Mandatory| Description | 1368| -------- | -------------------- | ---- | ----------------------------------------------------------------------------------------------------- | 1369| dst | ArrayBuffer | Yes | Buffer to which the pixels will be written. The buffer size is obtained by calling [getPixelBytesNumber](#getpixelbytesnumber7).| 1370 1371**Error codes** 1372 1373For details about the error codes, see [Image Error Codes](errorcode-image.md). 1374 1375| ID| Error Message| 1376| ------- | --------------------------------------------| 1377| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 1378| 501 | Resource Unavailable | 1379 1380**Example** 1381 1382```ts 1383import { BusinessError } from '@kit.BasicServicesKit'; 1384 1385async function ReadPixelsToBufferSync() { 1386 const readBuffer: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 1387 if (pixelMap != undefined) { 1388 pixelMap.readPixelsToBufferSync(readBuffer); 1389 } 1390} 1391``` 1392 1393### readPixels<sup>7+</sup> 1394 1395readPixels(area: PositionArea): Promise\<void> 1396 1397Reads the pixels in the area specified by [PositionArea](#positionarea7).region of this **PixelMap** object in the BGRA_8888 format and writes the data to the [PositionArea](#positionarea7).pixels buffer. This API uses a promise to return the result. 1398 1399You can use a formula to calculate the size of the memory to be applied for based on **PositionArea**. 1400 1401YUV region calculation formula: region to read (region.size{width * height}) * 1.5 (1 * Y component + 0.25 * U component + 0.25 * V component) 1402 1403RGBA region calculation formula: region to read (region.size{width * height}) * 4 (1 * R component + 1 * G component + 1 * B component + 1 * A component) 1404 1405**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1406 1407**Atomic service API**: This API can be used in atomic services since API version 11. 1408 1409**System capability**: SystemCapability.Multimedia.Image.Core 1410 1411**Parameters** 1412 1413| Name| Type | Mandatory| Description | 1414| ------ | ------------------------------ | ---- | ------------------------ | 1415| area | [PositionArea](#positionarea7) | Yes | Area from which the pixels will be read.| 1416 1417**Return value** 1418 1419| Type | Description | 1420| :------------- | :-------------------------------------------------- | 1421| Promise\<void> | Promise that returns no value. | 1422 1423**Example** 1424 1425```ts 1426import { BusinessError } from '@kit.BasicServicesKit'; 1427 1428async function ReadPixelsRGBA() { 1429 const area: image.PositionArea = { 1430 pixels: new ArrayBuffer(8), // 8 is the size of the PixelMap buffer to create. The value is calculated as follows: height * width * 4. 1431 offset: 0, 1432 stride: 8, 1433 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 1434 }; 1435 if (pixelMap != undefined) { 1436 pixelMap.readPixels(area).then(() => { 1437 console.info('Succeeded in reading the image data in the area.'); // Called if the condition is met. 1438 }).catch((error: BusinessError) => { 1439 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. 1440 }) 1441 } 1442} 1443 1444async function ReadPixelsYUV() { 1445 const area: image.PositionArea = { 1446 pixels: new ArrayBuffer(6), // 6 is the size of the PixelMap buffer to create. The value is calculated as follows: height * width * 1.5. 1447 offset: 0, 1448 stride: 8, 1449 region: { size: { height: 2, width: 2 }, x: 0, y: 0 } 1450 }; 1451 if (pixelMap != undefined) { 1452 pixelMap.readPixels(area).then(() => { 1453 console.info('Succeeded in reading the image data in the area.'); // Called if the condition is met. 1454 }).catch((error: BusinessError) => { 1455 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. 1456 }) 1457 } 1458} 1459``` 1460 1461### readPixels<sup>7+</sup> 1462 1463readPixels(area: PositionArea, callback: AsyncCallback\<void>): void 1464 1465Reads the pixels in the area specified by [PositionArea](#positionarea7).region of this **PixelMap** object in the BGRA_8888 format and writes the data to the [PositionArea](#positionarea7).pixels buffer. This API uses an asynchronous callback to return the result. 1466 1467You can use a formula to calculate the size of the memory to be applied for based on **PositionArea**. 1468 1469YUV region calculation formula: region to read (region.size{width * height}) * 1.5 (1 * Y component + 0.25 * U component + 0.25 * V component) 1470 1471RGBA region calculation formula: region to read (region.size{width * height}) * 4 (1 * R component + 1 * G component + 1 * B component + 1 * A component) 1472 1473**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1474 1475**Atomic service API**: This API can be used in atomic services since API version 11. 1476 1477**System capability**: SystemCapability.Multimedia.Image.Core 1478 1479**Parameters** 1480 1481| Name | Type | Mandatory| Description | 1482| -------- | ------------------------------ | ---- | ------------------------------ | 1483| area | [PositionArea](#positionarea7) | Yes | Area from which the pixels will be read. | 1484| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 1485 1486**Example** 1487 1488```ts 1489import { BusinessError } from '@kit.BasicServicesKit'; 1490 1491async function ReadPixelsRGBA() { 1492 const area: image.PositionArea = { 1493 pixels: new ArrayBuffer(8), // 8 is the size of the PixelMap buffer to create. The value is calculated as follows: height * width * 4. 1494 offset: 0, 1495 stride: 8, 1496 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 1497 }; 1498 if (pixelMap != undefined) { 1499 pixelMap.readPixels(area, (error: BusinessError) => { 1500 if (error) { 1501 console.error(`Failed to read pixelmap from the specified area. code is ${error.code}, message is ${error.message}`); 1502 return; 1503 } else { 1504 console.info('Succeeded in reading pixelmap from the specified area.'); 1505 } 1506 }) 1507 } 1508} 1509 1510async function ReadPixelsYUV() { 1511 const area: image.PositionArea = { 1512 pixels: new ArrayBuffer(6), // 6 is the size of the PixelMap buffer to create. The value is calculated as follows: height * width * 1.5. 1513 offset: 0, 1514 stride: 8, 1515 region: { size: { height: 2, width: 2 }, x: 0, y: 0 } 1516 }; 1517 if (pixelMap != undefined) { 1518 pixelMap.readPixels(area, (error: BusinessError) => { 1519 if (error) { 1520 console.error(`Failed to read pixelmap from the specified area. code is ${error.code}, message is ${error.message}`); 1521 return; 1522 } else { 1523 console.info('Succeeded in reading pixelmap from the specified area.'); 1524 } 1525 }) 1526 } 1527} 1528``` 1529 1530### readPixelsSync<sup>12+</sup> 1531 1532readPixelsSync(area: PositionArea): void 1533 1534Reads the pixels in the area specified by [PositionArea](#positionarea7).region of this **PixelMap** object in the BGRA_8888 format and writes the data to the [PositionArea](#positionarea7).pixels buffer. This API returns the result synchronously. 1535 1536**Atomic service API**: This API can be used in atomic services since API version 12. 1537 1538**System capability**: SystemCapability.Multimedia.Image.Core 1539 1540**Parameters** 1541 1542| Name| Type | Mandatory| Description | 1543| ------ | ------------------------------ | ---- | ------------------------ | 1544| area | [PositionArea](#positionarea7) | Yes | Area from which the pixels will be read.| 1545 1546**Error codes** 1547 1548For details about the error codes, see [Image Error Codes](errorcode-image.md). 1549 1550| ID| Error Message| 1551| ------- | --------------------------------------------| 1552| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 1553| 501 | Resource Unavailable | 1554 1555**Example** 1556 1557```ts 1558import { BusinessError } from '@kit.BasicServicesKit'; 1559 1560async function ReadPixelsSync() { 1561 const area : image.PositionArea = { 1562 pixels: new ArrayBuffer(8), 1563 offset: 0, 1564 stride: 8, 1565 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 1566 }; 1567 if (pixelMap != undefined) { 1568 pixelMap.readPixelsSync(area); 1569 } 1570} 1571``` 1572 1573### writePixels<sup>7+</sup> 1574 1575writePixels(area: PositionArea): Promise\<void> 1576 1577Reads the pixels in the [PositionArea](#positionarea7).pixels buffer in the BGRA_8888 format and writes the data to the area specified by [PositionArea](#positionarea7).region in this **PixelMap** object. This API uses a promise to return the result. 1578 1579You can use a formula to calculate the size of the memory to be applied for based on **PositionArea**. 1580 1581YUV region calculation formula: region to read (region.size{width * height}) * 1.5 (1 * Y component + 0.25 * U component + 0.25 * V component) 1582 1583RGBA region calculation formula: region to read (region.size{width * height}) * 4 (1 * R component + 1 * G component + 1 * B component + 1 * A component) 1584 1585**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1586 1587**Atomic service API**: This API can be used in atomic services since API version 11. 1588 1589**System capability**: SystemCapability.Multimedia.Image.Core 1590 1591**Parameters** 1592 1593| Name| Type | Mandatory| Description | 1594| ------ | ------------------------------ | ---- | -------------------- | 1595| area | [PositionArea](#positionarea7) | Yes | Area to which the pixels will be written.| 1596 1597**Return value** 1598 1599| Type | Description | 1600| :------------- | :-------------------------------------------------- | 1601| Promise\<void> | Promise that returns no value. | 1602 1603**Example** 1604 1605```ts 1606import { BusinessError } from '@kit.BasicServicesKit'; 1607 1608async function WritePixelsRGBA() { 1609 const area: image.PositionArea = { 1610 pixels: new ArrayBuffer(8), // 8 is the size of the PixelMap buffer to create. The value is calculated as follows: height * width * 4. 1611 offset: 0, 1612 stride: 8, 1613 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 1614 }; 1615 let bufferArr: Uint8Array = new Uint8Array(area.pixels); 1616 for (let i = 0; i < bufferArr.length; i++) { 1617 bufferArr[i] = i + 1; 1618 } 1619 if (pixelMap != undefined) { 1620 pixelMap.writePixels(area).then(() => { 1621 console.info('Succeeded in writing pixelmap into the specified area.'); 1622 }).catch((error: BusinessError) => { 1623 console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`); 1624 }) 1625 } 1626} 1627 1628async function WritePixelsYUV() { 1629 const area: image.PositionArea = { 1630 pixels: new ArrayBuffer(6), // 6 is the size of the PixelMap buffer to create. The value is calculated as follows: height * width * 1.5. 1631 offset: 0, 1632 stride: 8, 1633 region: { size: { height: 2, width: 2 }, x: 0, y: 0 } 1634 }; 1635 let bufferArr: Uint8Array = new Uint8Array(area.pixels); 1636 for (let i = 0; i < bufferArr.length; i++) { 1637 bufferArr[i] = i + 1; 1638 } 1639 if (pixelMap != undefined) { 1640 pixelMap.writePixels(area).then(() => { 1641 console.info('Succeeded in writing pixelmap into the specified area.'); 1642 }).catch((error: BusinessError) => { 1643 console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`); 1644 }) 1645 } 1646} 1647``` 1648 1649### writePixels<sup>7+</sup> 1650 1651writePixels(area: PositionArea, callback: AsyncCallback\<void>): void 1652 1653Reads the pixels in the [PositionArea](#positionarea7).pixels buffer in the BGRA_8888 format and writes the data to the area specified by [PositionArea](#positionarea7).region in this **PixelMap** object. This API uses an asynchronous callback to return the result. 1654 1655You can use a formula to calculate the size of the memory to be applied for based on **PositionArea**. 1656 1657YUV region calculation formula: region to read (region.size{width * height}) * 1.5 (1 * Y component + 0.25 * U component + 0.25 * V component) 1658 1659RGBA region calculation formula: region to read (region.size{width * height}) * 4 (1 * R component + 1 * G component + 1 * B component + 1 * A component) 1660 1661**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1662 1663**Atomic service API**: This API can be used in atomic services since API version 11. 1664 1665**System capability**: SystemCapability.Multimedia.Image.Core 1666 1667**Parameters** 1668 1669| Name | Type | Mandatory| Description | 1670| --------- | ------------------------------ | ---- | ------------------------------ | 1671| area | [PositionArea](#positionarea7) | Yes | Area to which the pixels will be written. | 1672| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 1673 1674**Example** 1675 1676```ts 1677import { BusinessError } from '@kit.BasicServicesKit'; 1678 1679async function WritePixelsRGBA() { 1680 const area: image.PositionArea = { pixels: new ArrayBuffer(8), // 8 is the size of the PixelMap buffer to create. The value is calculated as follows: height * width * 4. 1681 offset: 0, 1682 stride: 8, 1683 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 1684 }; 1685 let bufferArr: Uint8Array = new Uint8Array(area.pixels); 1686 for (let i = 0; i < bufferArr.length; i++) { 1687 bufferArr[i] = i + 1; 1688 } 1689 if (pixelMap != undefined) { 1690 pixelMap.writePixels(area, (error : BusinessError) => { 1691 if (error) { 1692 console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`); 1693 return; 1694 } else { 1695 console.info('Succeeded in writing pixelmap into the specified area.'); 1696 } 1697 }) 1698 } 1699} 1700 1701async function WritePixelsYUV() { 1702 const area: image.PositionArea = { pixels: new ArrayBuffer(6), // 6 is the size of the PixelMap buffer to create. The value is calculated as follows: height * width * 1.5. 1703 offset: 0, 1704 stride: 8, 1705 region: { size: { height: 2, width: 2 }, x: 0, y: 0 } 1706 }; 1707 let bufferArr: Uint8Array = new Uint8Array(area.pixels); 1708 for (let i = 0; i < bufferArr.length; i++) { 1709 bufferArr[i] = i + 1; 1710 } 1711 if (pixelMap != undefined) { 1712 pixelMap.writePixels(area, (error : BusinessError) => { 1713 if (error) { 1714 console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`); 1715 return; 1716 } else { 1717 console.info('Succeeded in writing pixelmap into the specified area.'); 1718 } 1719 }) 1720 } 1721} 1722``` 1723 1724### writePixelsSync<sup>12+</sup> 1725 1726writePixelsSync(area: PositionArea): void 1727 1728Reads the pixels in the [PositionArea](#positionarea7).pixels buffer in the BGRA_8888 format and writes the data to the area specified by [PositionArea](#positionarea7).region in this **PixelMap** object. This API returns the result synchronously. 1729 1730**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1731 1732**Atomic service API**: This API can be used in atomic services since API version 12. 1733 1734**System capability**: SystemCapability.Multimedia.Image.Core 1735 1736**Parameters** 1737 1738| Name| Type | Mandatory| Description | 1739| ------ | ------------------------------ | ---- | -------------------- | 1740| area | [PositionArea](#positionarea7) | Yes | Area to which the pixels will be written.| 1741 1742**Error codes** 1743 1744For details about the error codes, see [Image Error Codes](errorcode-image.md). 1745 1746| ID| Error Message| 1747| ------- | --------------------------------------------| 1748| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 1749| 501 | Resource Unavailable | 1750 1751**Example** 1752 1753```ts 1754import { BusinessError } from '@kit.BasicServicesKit'; 1755 1756async function WritePixelsSync() { 1757 const area: image.PositionArea = { 1758 pixels: new ArrayBuffer(8), 1759 offset: 0, 1760 stride: 8, 1761 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 1762 }; 1763 let bufferArr: Uint8Array = new Uint8Array(area.pixels); 1764 for (let i = 0; i < bufferArr.length; i++) { 1765 bufferArr[i] = i + 1; 1766 } 1767 if (pixelMap != undefined) { 1768 pixelMap.writePixelsSync(area); 1769 } 1770} 1771``` 1772 1773### writeBufferToPixels<sup>7+</sup> 1774 1775writeBufferToPixels(src: ArrayBuffer): Promise\<void> 1776 1777Reads the pixels in the buffer based on the PixelMap's pixel format and writes the data to this **PixelMap** object. This API uses a promise to return the result. 1778 1779**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1780 1781**Atomic service API**: This API can be used in atomic services since API version 11. 1782 1783**System capability**: SystemCapability.Multimedia.Image.Core 1784 1785**Parameters** 1786 1787| Name| Type | Mandatory| Description | 1788| ------ | ----------- | ---- | -------------- | 1789| src | ArrayBuffer | Yes | Buffer from which the pixels are read. The buffer size is obtained by calling [getPixelBytesNumber](#getpixelbytesnumber7).| 1790 1791**Return value** 1792 1793| Type | Description | 1794| -------------- | ----------------------------------------------- | 1795| Promise\<void> | Promise that returns no value. | 1796 1797**Example** 1798 1799```ts 1800import { BusinessError } from '@kit.BasicServicesKit'; 1801 1802async function WriteBufferToPixels() { 1803 const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 1804 let bufferArr: Uint8Array = new Uint8Array(color); 1805 for (let i = 0; i < bufferArr.length; i++) { 1806 bufferArr[i] = i + 1; 1807 } 1808 if (pixelMap != undefined) { 1809 pixelMap.writeBufferToPixels(color).then(() => { 1810 console.info("Succeeded in writing data from a buffer to a PixelMap."); 1811 }).catch((error: BusinessError) => { 1812 console.error(`Failed to write data from a buffer to a PixelMap. code is ${error.code}, message is ${error.message}`); 1813 }) 1814 } 1815} 1816``` 1817 1818### writeBufferToPixels<sup>7+</sup> 1819 1820writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\<void>): void 1821 1822Reads the pixels in the buffer based on the PixelMap's pixel format and writes the data to this **PixelMap** object. This API uses an asynchronous callback to return the result. 1823 1824**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1825 1826**Atomic service API**: This API can be used in atomic services since API version 11. 1827 1828**System capability**: SystemCapability.Multimedia.Image.Core 1829 1830**Parameters** 1831 1832| Name | Type | Mandatory| Description | 1833| -------- | -------------------- | ---- | ------------------------------ | 1834| src | ArrayBuffer | Yes | Buffer from which the pixels are read. The buffer size is obtained by calling [getPixelBytesNumber](#getpixelbytesnumber7).| 1835| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the pixels in the buffer are successfully written to the PixelMap, **err** is **undefined**; otherwise, **err** is an error object.| 1836 1837**Example** 1838 1839```ts 1840import { BusinessError } from '@kit.BasicServicesKit'; 1841 1842async function WriteBufferToPixels() { 1843 const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 1844 let bufferArr: Uint8Array = new Uint8Array(color); 1845 for (let i = 0; i < bufferArr.length; i++) { 1846 bufferArr[i] = i + 1; 1847 } 1848 if (pixelMap != undefined) { 1849 pixelMap.writeBufferToPixels(color, (error: BusinessError) => { 1850 if (error) { 1851 console.error(`Failed to write data from a buffer to a PixelMap. code is ${error.code}, message is ${error.message}`); 1852 return; 1853 } else { 1854 console.info("Succeeded in writing data from a buffer to a PixelMap."); 1855 } 1856 }) 1857 } 1858} 1859``` 1860 1861### writeBufferToPixelsSync<sup>12+</sup> 1862 1863writeBufferToPixelsSync(src: ArrayBuffer): void 1864 1865Reads the pixels in the buffer based on the PixelMap's pixel format and writes the data to this **PixelMap** object. This API returns the result synchronously. 1866 1867**Atomic service API**: This API can be used in atomic services since API version 12. 1868 1869**System capability**: SystemCapability.Multimedia.Image.Core 1870 1871**Parameters** 1872 1873| Name| Type | Mandatory| Description | 1874| ------ | ----------- | ---- | -------------- | 1875| src | ArrayBuffer | Yes | Buffer from which the pixels are read. The buffer size is obtained by calling [getPixelBytesNumber](#getpixelbytesnumber7).| 1876 1877**Error codes** 1878 1879For details about the error codes, see [Image Error Codes](errorcode-image.md). 1880 1881| ID| Error Message| 1882| ------- | --------------------------------------------| 1883| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 1884| 501 | Resource Unavailable | 1885 1886**Example** 1887 1888```ts 1889import { BusinessError } from '@kit.BasicServicesKit'; 1890 1891async function WriteBufferToPixelsSync() { 1892 const color : ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 1893 let bufferArr : Uint8Array = new Uint8Array(color); 1894 for (let i = 0; i < bufferArr.length; i++) { 1895 bufferArr[i] = i + 1; 1896 } 1897 if (pixelMap != undefined) { 1898 pixelMap.writeBufferToPixelsSync(color); 1899 } 1900} 1901``` 1902 1903 1904### getImageInfo<sup>7+</sup> 1905 1906getImageInfo(): Promise\<ImageInfo> 1907 1908Obtains the image information. This API uses a promise to return the result. 1909 1910**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1911 1912**Atomic service API**: This API can be used in atomic services since API version 11. 1913 1914**System capability**: SystemCapability.Multimedia.Image.Core 1915 1916**Return value** 1917 1918| Type | Description | 1919| --------------------------------- | ----------------------------------------------------------- | 1920| Promise\<[ImageInfo](#imageinfo)> | Promise used to return the image information.| 1921 1922**Example** 1923 1924```ts 1925import { BusinessError } from '@kit.BasicServicesKit'; 1926 1927async function GetImageInfo() { 1928 if (pixelMap != undefined) { 1929 pixelMap.getImageInfo().then((imageInfo: image.ImageInfo) => { 1930 if (imageInfo != undefined) { 1931 console.info("Succeeded in obtaining the image pixel map information."+ imageInfo.size.height); 1932 } 1933 }).catch((error: BusinessError) => { 1934 console.error(`Failed to obtain the image pixel map information. code is ${error.code}, message is ${error.message}`); 1935 }) 1936 } 1937} 1938``` 1939 1940### getImageInfo<sup>7+</sup> 1941 1942getImageInfo(callback: AsyncCallback\<ImageInfo>): void 1943 1944Obtains the image information. This API uses an asynchronous callback to return the result. 1945 1946**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1947 1948**Atomic service API**: This API can be used in atomic services since API version 11. 1949 1950**System capability**: SystemCapability.Multimedia.Image.Core 1951 1952**Parameters** 1953 1954| Name | Type | Mandatory| Description | 1955| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | 1956| 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.| 1957 1958**Example** 1959 1960```ts 1961import { BusinessError } from '@kit.BasicServicesKit'; 1962 1963async function GetImageInfo() { 1964 if (pixelMap != undefined) { 1965 pixelMap.getImageInfo((error: BusinessError, imageInfo: image.ImageInfo) => { 1966 if (error) { 1967 console.error(`Failed to obtain the image pixel map information. code is ${error.code}, message is ${error.message}`); 1968 return; 1969 } else { 1970 console.info("Succeeded in obtaining the image pixel map information."+ imageInfo.size.height); 1971 } 1972 }) 1973 } 1974} 1975``` 1976 1977### getImageInfoSync<sup>12+</sup> 1978 1979getImageInfoSync(): ImageInfo 1980 1981Obtains the image information. This API returns the result synchronously. 1982 1983**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1984 1985**Atomic service API**: This API can be used in atomic services since API version 12. 1986 1987**System capability**: SystemCapability.Multimedia.Image.ImageSource 1988 1989**Return value** 1990 1991| Type | Description | 1992| --------------------------------- | ----------------------------------------------------------- | 1993| [ImageInfo](#imageinfo) | Image information. | 1994 1995**Error codes** 1996 1997For details about the error codes, see [Image Error Codes](errorcode-image.md). 1998 1999| ID| Error Message| 2000| ------- | --------------------------------------------| 2001| 501 | Resource Unavailable | 2002 2003**Example** 2004 2005```ts 2006import { BusinessError } from '@kit.BasicServicesKit'; 2007 2008async function GetImageInfoSync() { 2009 if (pixelMap != undefined) { 2010 let imageInfo : image.ImageInfo = pixelMap.getImageInfoSync(); 2011 return imageInfo; 2012 } 2013 return undefined; 2014} 2015``` 2016 2017### getBytesNumberPerRow<sup>7+</sup> 2018 2019getBytesNumberPerRow(): number 2020 2021Obtains the number of bytes per row of this image. 2022 2023**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2024 2025**Atomic service API**: This API can be used in atomic services since API version 11. 2026 2027**System capability**: SystemCapability.Multimedia.Image.Core 2028 2029**Return value** 2030 2031| Type | Description | 2032| ------ | -------------------- | 2033| number | Number of bytes per row.| 2034 2035**Example** 2036 2037```ts 2038let rowCount: number = pixelMap.getBytesNumberPerRow(); 2039``` 2040 2041### getPixelBytesNumber<sup>7+</sup> 2042 2043getPixelBytesNumber(): number 2044 2045Obtains the total number of bytes of this image. 2046 2047**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2048 2049**Atomic service API**: This API can be used in atomic services since API version 11. 2050 2051**System capability**: SystemCapability.Multimedia.Image.Core 2052 2053**Return value** 2054 2055| Type | Description | 2056| ------ | -------------------- | 2057| number | Total number of bytes.| 2058 2059**Example** 2060 2061```ts 2062let pixelBytesNumber: number = pixelMap.getPixelBytesNumber(); 2063``` 2064 2065### getDensity<sup>9+</sup> 2066 2067getDensity():number 2068 2069Obtains the density of this image. 2070 2071**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2072 2073**Atomic service API**: This API can be used in atomic services since API version 11. 2074 2075**System capability**: SystemCapability.Multimedia.Image.Core 2076 2077**Return value** 2078 2079| Type | Description | 2080| ------ | --------------- | 2081| number | Density of the image.| 2082 2083**Example** 2084 2085```ts 2086let getDensity: number = pixelMap.getDensity(); 2087``` 2088 2089### opacity<sup>9+</sup> 2090 2091opacity(rate: number, callback: AsyncCallback\<void>): void 2092 2093Sets an opacity rate for this image. This API uses an asynchronous callback to return the result. It is invalid for YUV images. 2094 2095**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2096 2097**Atomic service API**: This API can be used in atomic services since API version 11. 2098 2099**System capability**: SystemCapability.Multimedia.Image.Core 2100 2101**Parameters** 2102 2103| Name | Type | Mandatory| Description | 2104| -------- | -------------------- | ---- | ------------------------------ | 2105| rate | number | Yes | Opacity rate. | 2106| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 2107 2108**Example** 2109 2110```ts 2111import { BusinessError } from '@kit.BasicServicesKit'; 2112 2113async function Opacity() { 2114 let rate: number = 0.5; 2115 if (pixelMap != undefined) { 2116 pixelMap.opacity(rate, (err: BusinessError) => { 2117 if (err) { 2118 console.error(`Failed to set opacity. code is ${err.code}, message is ${err.message}`); 2119 return; 2120 } else { 2121 console.info("Succeeded in setting opacity."); 2122 } 2123 }) 2124 } 2125} 2126``` 2127 2128### opacity<sup>9+</sup> 2129 2130opacity(rate: number): Promise\<void> 2131 2132Sets an opacity rate for this image. This API uses a promise to return the result. It is invalid for YUV images. 2133 2134**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2135 2136**Atomic service API**: This API can be used in atomic services since API version 11. 2137 2138**System capability**: SystemCapability.Multimedia.Image.Core 2139 2140**Parameters** 2141 2142| Name| Type | Mandatory| Description | 2143| ------ | ------ | ---- | --------------------------- | 2144| rate | number | Yes | Opacity rate.| 2145 2146**Return value** 2147 2148| Type | Description | 2149| -------------- | ----------------------------------------------- | 2150| Promise\<void> | Promise that returns no value. | 2151 2152**Example** 2153 2154```ts 2155import { BusinessError } from '@kit.BasicServicesKit'; 2156 2157async function Opacity() { 2158 let rate: number = 0.5; 2159 if (pixelMap != undefined) { 2160 pixelMap.opacity(rate).then(() => { 2161 console.info('Succeeded in setting opacity.'); 2162 }).catch((err: BusinessError) => { 2163 console.error(`Failed to set opacity. code is ${err.code}, message is ${err.message}`); 2164 }) 2165 } 2166} 2167``` 2168 2169### opacitySync<sup>12+</sup> 2170 2171opacitySync(rate: number): void 2172 2173Sets an opacity rate for this image. This API returns the result synchronously. It is invalid for YUV images. 2174 2175**Atomic service API**: This API can be used in atomic services since API version 12. 2176 2177**System capability**: SystemCapability.Multimedia.Image.Core 2178 2179**Parameters** 2180 2181| Name | Type | Mandatory| Description | 2182| -------- | -------------------- | ---- | ------------------------------ | 2183| rate | number | Yes | Opacity rate. | 2184 2185**Error codes** 2186 2187For details about the error codes, see [Image Error Codes](errorcode-image.md). 2188 2189| ID| Error Message| 2190| ------- | --------------------------------------------| 2191| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2192| 501 | Resource Unavailable | 2193 2194**Example** 2195 2196```ts 2197import { BusinessError } from '@kit.BasicServicesKit'; 2198 2199async function OpacitySync() { 2200 let rate : number = 0.5; 2201 if (pixelMap != undefined) { 2202 pixelMap.opacitySync(rate); 2203 } 2204} 2205``` 2206 2207### createAlphaPixelmap<sup>9+</sup> 2208 2209createAlphaPixelmap(): Promise\<PixelMap> 2210 2211Creates 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. 2212 2213**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2214 2215**Atomic service API**: This API can be used in atomic services since API version 11. 2216 2217**System capability**: SystemCapability.Multimedia.Image.Core 2218 2219**Return value** 2220 2221| Type | Description | 2222| -------------------------------- | --------------------------- | 2223| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.| 2224 2225**Example** 2226 2227```ts 2228import { BusinessError } from '@kit.BasicServicesKit'; 2229 2230async function CreateAlphaPixelmap() { 2231 if (pixelMap != undefined) { 2232 pixelMap.createAlphaPixelmap().then((alphaPixelMap: image.PixelMap) => { 2233 console.info('Succeeded in creating alpha pixelmap.'); 2234 }).catch((error: BusinessError) => { 2235 console.error(`Failed to create alpha pixelmap. code is ${error.code}, message is ${error.message}`); 2236 }) 2237 } 2238} 2239``` 2240 2241### createAlphaPixelmap<sup>9+</sup> 2242 2243createAlphaPixelmap(callback: AsyncCallback\<PixelMap>): void 2244 2245Creates 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. 2246 2247**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2248 2249**Atomic service API**: This API can be used in atomic services since API version 11. 2250 2251**System capability**: SystemCapability.Multimedia.Image.Core 2252 2253**Parameters** 2254 2255| Name | Type | Mandatory| Description | 2256| -------- | ------------------------ | ---- | ------------------------ | 2257| 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.| 2258 2259**Example** 2260 2261```ts 2262import { BusinessError } from '@kit.BasicServicesKit'; 2263 2264async function CreateAlphaPixelmap() { 2265 if (pixelMap != undefined) { 2266 pixelMap.createAlphaPixelmap((err: BusinessError, alphaPixelMap: image.PixelMap) => { 2267 if (alphaPixelMap == undefined) { 2268 console.error(`Failed to obtain new pixel map. code is ${err.code}, message is ${err.message}`); 2269 return; 2270 } else { 2271 console.info('Succeeded in obtaining new pixel map.'); 2272 } 2273 }) 2274 } 2275} 2276``` 2277 2278### createAlphaPixelmapSync<sup>12+</sup> 2279 2280createAlphaPixelmapSync(): PixelMap 2281 2282Creates 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. 2283 2284**Atomic service API**: This API can be used in atomic services since API version 12. 2285 2286**System capability**: SystemCapability.Multimedia.Image.Core 2287 2288**Return value** 2289 2290| Type | Description | 2291| -------------------------------- | --------------------- | 2292| [PixelMap](#pixelmap7) | Returns a **PixelMap** object if the operation is successful; throws an error otherwise.| 2293 2294**Error codes** 2295 2296For details about the error codes, see [Image Error Codes](errorcode-image.md). 2297 2298| ID| Error Message| 2299| ------- | --------------------------------------------| 2300| 401 | Parameter error. Possible causes: 1.Parameter verification failed | 2301| 501 | Resource Unavailable | 2302 2303**Example** 2304 2305```ts 2306import { BusinessError } from '@kit.BasicServicesKit'; 2307 2308async function CreateAlphaPixelmapSync() { 2309 if (pixelMap != undefined) { 2310 let pixelmap : image.PixelMap = pixelMap.createAlphaPixelmapSync(); 2311 return pixelmap; 2312 } 2313 return undefined; 2314} 2315``` 2316 2317### scale<sup>9+</sup> 2318 2319scale(x: number, y: number, callback: AsyncCallback\<void>): void 2320 2321Scales this image based on the scale factors of the width and height. This API uses an asynchronous callback to return the result. 2322 2323> **NOTE** 2324> 2325> You are advised to set the scale factors to non-negative numbers to avoid a flipping effect. 2326> 2327> Scale factors of the width and height = Width and height of the resized image/Width and height of the original image 2328 2329**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2330 2331**Atomic service API**: This API can be used in atomic services since API version 11. 2332 2333**System capability**: SystemCapability.Multimedia.Image.Core 2334 2335**Parameters** 2336 2337| Name | Type | Mandatory| Description | 2338| -------- | -------------------- | ---- | ------------------------------- | 2339| x | number | Yes | Scale factor of the width.| 2340| y | number | Yes | Scale factor of the height.| 2341| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 2342 2343**Example** 2344 2345```ts 2346import { BusinessError } from '@kit.BasicServicesKit'; 2347 2348async function Scale() { 2349 let scaleX: number = 2.0; 2350 let scaleY: number = 1.0; 2351 if (pixelMap != undefined) { 2352 pixelMap.scale(scaleX, scaleY, (err: BusinessError) => { 2353 if (err) { 2354 console.error(`Failed to scale pixelmap. code is ${err.code}, message is ${err.message}`); 2355 return; 2356 } else { 2357 console.info("Succeeded in scaling pixelmap."); 2358 } 2359 }) 2360 } 2361} 2362``` 2363 2364### scale<sup>9+</sup> 2365 2366scale(x: number, y: number): Promise\<void> 2367 2368Scales this image based on the scale factors of the width and height. This API uses a promise to return the result. 2369 2370> **NOTE** 2371> 2372> You are advised to set the scale factors to non-negative numbers to avoid a flipping effect. 2373> 2374> Scale factors of the width and height = Width and height of the resized image/Width and height of the original image 2375 2376**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2377 2378**Atomic service API**: This API can be used in atomic services since API version 11. 2379 2380**System capability**: SystemCapability.Multimedia.Image.Core 2381 2382**Parameters** 2383 2384| Name| Type | Mandatory| Description | 2385| ------ | ------ | ---- | ------------------------------- | 2386| x | number | Yes | Scale factor of the width.| 2387| y | number | Yes | Scale factor of the height.| 2388 2389**Return value** 2390 2391| Type | Description | 2392| -------------- | --------------------------- | 2393| Promise\<void> | Promise that returns no value.| 2394 2395**Example** 2396 2397```ts 2398import { BusinessError } from '@kit.BasicServicesKit'; 2399 2400async function Scale() { 2401 let scaleX: number = 2.0; 2402 let scaleY: number = 1.0; 2403 if (pixelMap != undefined) { 2404 pixelMap.scale(scaleX, scaleY).then(() => { 2405 console.info('Succeeded in scaling pixelmap.'); 2406 }).catch((err: BusinessError) => { 2407 console.error(`Failed to scale pixelmap. code is ${err.code}, message is ${err.message}`); 2408 2409 }) 2410 } 2411} 2412``` 2413 2414### scaleSync<sup>12+</sup> 2415 2416scaleSync(x: number, y: number): void 2417 2418Scales this image based on the scale factors of the width and height. This API returns the result synchronously. 2419 2420> **NOTE** 2421> 2422> You are advised to set the scale factors to non-negative numbers to avoid a flipping effect. 2423> 2424> Scale factors of the width and height = Width and height of the resized image/Width and height of the original image 2425 2426**Atomic service API**: This API can be used in atomic services since API version 12. 2427 2428**System capability**: SystemCapability.Multimedia.Image.Core 2429 2430**Parameters** 2431 2432| Name| Type | Mandatory| Description | 2433| ------ | ------ | ---- | ------------------------------- | 2434| x | number | Yes | Scale factor of the width.| 2435| y | number | Yes | Scale factor of the height.| 2436 2437**Error codes** 2438 2439For details about the error codes, see [Image Error Codes](errorcode-image.md). 2440 2441| ID| Error Message| 2442| ------- | --------------------------------------------| 2443| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2444| 501 | Resource Unavailable | 2445 2446**Example** 2447 2448```ts 2449import { BusinessError } from '@kit.BasicServicesKit'; 2450 2451async function ScaleSync() { 2452 let scaleX: number = 2.0; 2453 let scaleY: number = 1.0; 2454 if (pixelMap != undefined) { 2455 pixelMap.scaleSync(scaleX, scaleY); 2456 } 2457} 2458``` 2459 2460### scale<sup>12+</sup> 2461 2462scale(x: number, y: number, level: AntiAliasingLevel): Promise\<void> 2463 2464Scales this image based on the specified anti-aliasing level and the scale factors for the width and height. This API uses a promise to return the result. 2465 2466> **NOTE** 2467> 2468> You are advised to set the scale factors to non-negative numbers to avoid a flipping effect. 2469> 2470> Scale factors of the width and height = Width and height of the resized image/Width and height of the original image 2471 2472**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2473 2474**Atomic service API**: This API can be used in atomic services since API version 12. 2475 2476**System capability**: SystemCapability.Multimedia.Image.Core 2477 2478**Parameters** 2479 2480| Name| Type | Mandatory| Description | 2481| ------ | ------ | ---- | ------------------------------- | 2482| x | number | Yes | Scale factor of the width.| 2483| y | number | Yes | Scale factor of the height.| 2484| level | [AntiAliasingLevel](#antialiasinglevel12) | Yes | Anti-aliasing level.| 2485 2486**Return value** 2487 2488| Type | Description | 2489| -------------- | --------------------------- | 2490| Promise\<void> | Promise that returns no value.| 2491 2492**Error codes** 2493 2494For details about the error codes, see [Image Error Codes](errorcode-image.md). 2495 2496| ID| Error Message| 2497| ------- | --------------------------------------------| 2498| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2499| 501 | Resource Unavailable | 2500 2501**Example** 2502 2503```ts 2504import { BusinessError } from '@kit.BasicServicesKit'; 2505 2506async function Scale() { 2507 let scaleX: number = 2.0; 2508 let scaleY: number = 1.0; 2509 if (pixelMap != undefined) { 2510 pixelMap.scale(scaleX, scaleY, image.AntiAliasingLevel.LOW).then(() => { 2511 console.info('Succeeded in scaling pixelmap.'); 2512 }).catch((err: BusinessError) => { 2513 console.error(`Failed to scale pixelmap. code is ${err.code}, message is ${err.message}`); 2514 2515 }) 2516 } 2517} 2518``` 2519 2520### scaleSync<sup>12+</sup> 2521 2522scaleSync(x: number, y: number, level: AntiAliasingLevel): void 2523 2524Scales this image based on the specified anti-aliasing level and the scale factors for the width and height. This API returns the result synchronously. 2525 2526> **NOTE** 2527> 2528> You are advised to set the scale factors to non-negative numbers to avoid a flipping effect. 2529> 2530> Scale factors of the width and height = Width and height of the resized image/Width and height of the original image 2531 2532**Atomic service API**: This API can be used in atomic services since API version 12. 2533 2534**System capability**: SystemCapability.Multimedia.Image.Core 2535 2536**Parameters** 2537 2538| Name| Type | Mandatory| Description | 2539| ------ | ------ | ---- | ------------------------------- | 2540| x | number | Yes | Scale factor of the width.| 2541| y | number | Yes | Scale factor of the height.| 2542| level | [AntiAliasingLevel](#antialiasinglevel12) | Yes | Anti-aliasing level.| 2543 2544**Error codes** 2545 2546For details about the error codes, see [Image Error Codes](errorcode-image.md). 2547 2548| ID| Error Message| 2549| ------- | --------------------------------------------| 2550| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2551| 501 | Resource Unavailable | 2552 2553**Example** 2554 2555```ts 2556import { BusinessError } from '@kit.BasicServicesKit'; 2557 2558async function ScaleSync() { 2559 let scaleX: number = 2.0; 2560 let scaleY: number = 1.0; 2561 if (pixelMap != undefined) { 2562 pixelMap.scaleSync(scaleX, scaleY, image.AntiAliasingLevel.LOW); 2563 } 2564} 2565``` 2566 2567### createScaledPixelMap<sup>18+</sup> 2568 2569createScaledPixelMap(x: number, y: number, level?: AntiAliasingLevel): Promise\<PixelMap> 2570 2571Creates an image that has been resized based on the specified anti-aliasing level and the scale factors of the width and height. This API uses a promise to return the result. 2572 2573**System capability**: SystemCapability.Multimedia.Image.Core 2574 2575**Parameters** 2576 2577| Name| Type | Mandatory| Description | 2578| ------ | ------ | ---- | ------------------------------- | 2579| x | number | Yes | Scale factor of the width.| 2580| y | number | Yes | Scale factor of the height.| 2581| level | [AntiAliasingLevel](#antialiasinglevel12) | No | Anti-aliasing level.| 2582 2583**Return value** 2584 2585| Type | Description | 2586| -------------- | --------------------------- | 2587| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.| 2588 2589**Error codes** 2590 2591For details about the error codes, see [Image Error Codes](errorcode-image.md). 2592 2593| ID| Error Message| 2594| ------- | --------------------------------------------| 2595| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2596| 501 | Resource Unavailable | 2597 2598**Example** 2599 2600```ts 2601import { BusinessError } from '@kit.BasicServicesKit'; 2602 2603async function CreateScaledPixelMap() { 2604 let scaleX: number = 2.0; 2605 let scaleY: number = 1.0; 2606 if (pixelMap != undefined) { 2607 pixelMap.createScaledPixelMap(scaleX, scaleY, image.AntiAliasingLevel.LOW).then((scaledPixelMap: image.PixelMap) => { 2608 console.info('Succeeded in creating scaledPixelMap.'); 2609 }).catch((error: BusinessError) => { 2610 console.error(`Failed to create scaledPixelMap. Error code is ${error.code}, error message is ${error.message}`); 2611 }) 2612 } 2613} 2614``` 2615 2616### createScaledPixelMapSync<sup>18+</sup> 2617 2618createScaledPixelMapSync(x: number, y: number, level?: AntiAliasingLevel): PixelMap 2619 2620Creates an image that has been resized based on the specified anti-aliasing level and the scale factors of the width and height. This API returns the result synchronously. 2621 2622**System capability**: SystemCapability.Multimedia.Image.Core 2623 2624**Parameters** 2625 2626| Name| Type | Mandatory| Description | 2627| ------ | ------ | ---- | ------------------------------- | 2628| x | number | Yes | Scale factor of the width.| 2629| y | number | Yes | Scale factor of the height.| 2630| level | [AntiAliasingLevel](#antialiasinglevel12) | No | Anti-aliasing level.| 2631 2632**Return value** 2633 2634| Type | Description | 2635| -------------------------------- | --------------------- | 2636| [PixelMap](#pixelmap7) | Returns a **PixelMap** object if the operation is successful; throws an error otherwise.| 2637 2638**Error codes** 2639 2640For details about the error codes, see [Image Error Codes](errorcode-image.md). 2641 2642| ID| Error Message| 2643| ------- | --------------------------------------------| 2644| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2645| 501 | Resource Unavailable | 2646 2647**Example** 2648 2649```ts 2650import { BusinessError } from '@kit.BasicServicesKit'; 2651 2652async function CreateScaledPixelMapSync() { 2653 let scaleX: number = 2.0; 2654 let scaleY: number = 1.0; 2655 if (pixelMap != undefined) { 2656 let scaledPixelMap = pixelMap.createScaledPixelMapSync(scaleX, scaleY, image.AntiAliasingLevel.LOW); 2657 } 2658} 2659``` 2660 2661### clone<sup>18+</sup> 2662 2663clone(): Promise\<PixelMap> 2664 2665Copies this **PixelMap** object. This API uses a promise to return the result. 2666 2667**System capability**: SystemCapability.Multimedia.Image.Core 2668 2669**Return value** 2670 2671| Type | Description | 2672| -------------------------------- | --------------------------- | 2673| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.| 2674 2675**Error codes** 2676 2677For details about the error codes, see [Image Error Codes](errorcode-image.md). 2678 2679| ID| Error Message| 2680| ------- | --------------------------------------------| 2681| 501 | Resource unavailable. | 2682| 62980102 | Image malloc abnormal. This status code is thrown when an error occurs during the process of copying data. | 2683| 62980103 | Image YUV And ASTC types are not supported. | 2684| 62980104 | Image initialization abnormal. This status code is thrown when an error occurs during the process of createing empty pixelmap. | 2685| 62980106 | The image data is to large.This status code is thrown when an error occurs during the process of checking size. | 2686 2687**Example** 2688 2689```ts 2690import { BusinessError } from '@kit.BasicServicesKit'; 2691 2692async function Demo() { 2693 if (pixelMap != undefined) { 2694 pixelMap.clone().then((clonePixelMap: image.PixelMap) => { 2695 console.info('Succeeded clone pixelmap.'); 2696 }).catch((error: BusinessError) => { 2697 console.error(`Failed to clone pixelmap. code is ${error.code}, message is ${error.message}`); 2698 }) 2699 } 2700} 2701``` 2702 2703### cloneSync<sup>18+</sup> 2704 2705cloneSync(): PixelMap 2706 2707Copies this **PixelMap** object. This API returns the result synchronously. 2708 2709**System capability**: SystemCapability.Multimedia.Image.Core 2710 2711**Return value** 2712 2713| Type | Description | 2714| -------------------------------- | --------------------------- | 2715| [PixelMap](#pixelmap7) | Returns a **PixelMap** object if the operation is successful; throws an error otherwise.| 2716 2717**Error codes** 2718 2719For details about the error codes, see [Image Error Codes](errorcode-image.md). 2720 2721| ID| Error Message| 2722| ------- | --------------------------------------------| 2723| 501 | Resource unavailable. | 2724| 62980102 | Image malloc abnormal. This status code is thrown when an error occurs during the process of copying data. | 2725| 62980103 | Image YUV And ASTC types are not supported. | 2726| 62980104 | Image initialization abnormal. This status code is thrown when an error occurs during the process of createing empty pixelmap. | 2727| 62980106 | The image data is to large.This status code is thrown when an error occurs during the process of checking size. | 2728 2729**Example** 2730 2731```ts 2732import { BusinessError } from '@kit.BasicServicesKit'; 2733 2734async Demo() { 2735 if (pixelMap != undefined) { 2736 try { 2737 let clonedPixelMap = pixelMap.cloneSync(); 2738 } catch(e) { 2739 let error = e as BusinessError; 2740 console.error(`clone pixelmap error. code is ${error.code}, message is ${error.message}`); 2741 } 2742 } 2743} 2744``` 2745 2746### translate<sup>9+</sup> 2747 2748translate(x: number, y: number, callback: AsyncCallback\<void>): void 2749 2750Translates this image based on given coordinates. This API uses an asynchronous callback to return the result. 2751 2752The size of the translated image is changed to width+X and height+Y. It is recommended that the new width and height not exceed the width and height of the screen. 2753 2754**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2755 2756**Atomic service API**: This API can be used in atomic services since API version 11. 2757 2758**System capability**: SystemCapability.Multimedia.Image.Core 2759 2760**Parameters** 2761 2762| Name | Type | Mandatory| Description | 2763| -------- | -------------------- | ---- | ----------------------------- | 2764| x | number | Yes | X coordinate to translate, in pixels.| 2765| y | number | Yes | Y coordinate to translate, in pixels.| 2766| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 2767 2768**Example** 2769 2770```ts 2771import { BusinessError } from '@kit.BasicServicesKit'; 2772 2773async function Translate() { 2774 let translateX: number = 50.0; 2775 let translateY: number = 10.0; 2776 if (pixelMap != undefined) { 2777 pixelMap.translate(translateX, translateY, (err: BusinessError) => { 2778 if (err) { 2779 console.error(`Failed to translate pixelmap. code is ${err.code}, message is ${err.message}`); 2780 return; 2781 } else { 2782 console.info("Succeeded in translating pixelmap."); 2783 } 2784 }) 2785 } 2786} 2787``` 2788 2789### translate<sup>9+</sup> 2790 2791translate(x: number, y: number): Promise\<void> 2792 2793Translates this image based on given coordinates. This API uses a promise to return the result. 2794 2795The size of the translated image is changed to width+X and height+Y. It is recommended that the new width and height not exceed the width and height of the screen. 2796 2797**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2798 2799**Atomic service API**: This API can be used in atomic services since API version 11. 2800 2801**System capability**: SystemCapability.Multimedia.Image.Core 2802 2803**Parameters** 2804 2805| Name| Type | Mandatory| Description | 2806| ------ | ------ | ---- | ----------- | 2807| x | number | Yes | X coordinate to translate, in pixels.| 2808| y | number | Yes | Y coordinate to translate, in pixels.| 2809 2810**Return value** 2811 2812| Type | Description | 2813| -------------- | --------------------------- | 2814| Promise\<void> | Promise that returns no value.| 2815 2816**Example** 2817 2818```ts 2819import { BusinessError } from '@kit.BasicServicesKit'; 2820 2821async function Translate() { 2822 let translateX: number = 50.0; 2823 let translateY: number = 10.0; 2824 if (pixelMap != undefined) { 2825 pixelMap.translate(translateX, translateY).then(() => { 2826 console.info('Succeeded in translating pixelmap.'); 2827 }).catch((err: BusinessError) => { 2828 console.error(`Failed to translate pixelmap. code is ${err.code}, message is ${err.message}`); 2829 }) 2830 } 2831} 2832``` 2833 2834### translateSync<sup>12+</sup> 2835 2836translateSync(x: number, y: number): void 2837 2838Translates this image based on given coordinates. This API returns the result synchronously. 2839 2840The size of the translated image is changed to width+X and height+Y. It is recommended that the new width and height not exceed the width and height of the screen. 2841 2842**Atomic service API**: This API can be used in atomic services since API version 12. 2843 2844**System capability**: SystemCapability.Multimedia.Image.Core 2845 2846**Parameters** 2847 2848| Name | Type | Mandatory| Description | 2849| -------- | -------------------- | ---- | ------------------------------- | 2850| x | number | Yes | X coordinate to translate, in pixels.| 2851| y | number | Yes | Y coordinate to translate, in pixels.| 2852 2853**Error codes** 2854 2855For details about the error codes, see [Image Error Codes](errorcode-image.md). 2856 2857| ID| Error Message| 2858| ------- | --------------------------------------------| 2859| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2860| 501 | Resource Unavailable | 2861 2862**Example** 2863 2864```ts 2865import { BusinessError } from '@kit.BasicServicesKit'; 2866 2867async function TranslateSync() { 2868 let translateX : number = 50.0; 2869 let translateY : number = 10.0; 2870 if (pixelMap != undefined) { 2871 pixelMap.translateSync(translateX, translateY); 2872 } 2873} 2874``` 2875 2876### rotate<sup>9+</sup> 2877 2878rotate(angle: number, callback: AsyncCallback\<void>): void 2879 2880Rotates this image based on a given angle. This API uses an asynchronous callback to return the result. 2881 2882> **NOTE** 2883> 2884> The allowable range for image rotation angles is between 0 and 360 degrees. Angles outside this range are automatically adjusted according to the 360-degree cycle. For example, an angle of -100 degrees will produce the same result as 260 degrees. 2885> 2886> If the rotation angle is not an integer multiple of 90 degrees, the image size will change after rotation. 2887 2888**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2889 2890**Atomic service API**: This API can be used in atomic services since API version 11. 2891 2892**System capability**: SystemCapability.Multimedia.Image.Core 2893 2894**Parameters** 2895 2896| Name | Type | Mandatory| Description | 2897| -------- | -------------------- | ---- | ----------------------------- | 2898| angle | number | Yes | Angle to rotate.| 2899| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 2900 2901**Example** 2902 2903```ts 2904import { BusinessError } from '@kit.BasicServicesKit'; 2905 2906async function Rotate() { 2907 let angle: number = 90.0; 2908 if (pixelMap != undefined) { 2909 pixelMap.rotate(angle, (err: BusinessError) => { 2910 if (err) { 2911 console.error(`Failed to rotate pixelmap. code is ${err.code}, message is ${err.message}`); 2912 return; 2913 } else { 2914 console.info("Succeeded in rotating pixelmap."); 2915 } 2916 }) 2917 } 2918} 2919``` 2920 2921### rotate<sup>9+</sup> 2922 2923rotate(angle: number): Promise\<void> 2924 2925Rotates this image based on a given angle. This API uses a promise to return the result. 2926 2927> **NOTE** 2928> 2929> The allowable range for image rotation angles is between 0 and 360 degrees. Angles outside this range are automatically adjusted according to the 360-degree cycle. For example, an angle of -100 degrees will produce the same result as 260 degrees. 2930> 2931> If the rotation angle is not an integer multiple of 90 degrees, the image size will change after rotation. 2932 2933**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2934 2935**Atomic service API**: This API can be used in atomic services since API version 11. 2936 2937**System capability**: SystemCapability.Multimedia.Image.Core 2938 2939**Parameters** 2940 2941| Name| Type | Mandatory| Description | 2942| ------ | ------ | ---- | ----------------------------- | 2943| angle | number | Yes | Angle to rotate.| 2944 2945**Return value** 2946 2947| Type | Description | 2948| -------------- | --------------------------- | 2949| Promise\<void> | Promise that returns no value.| 2950 2951**Example** 2952 2953```ts 2954import { BusinessError } from '@kit.BasicServicesKit'; 2955 2956async function Rotate() { 2957 let angle: number = 90.0; 2958 if (pixelMap != undefined) { 2959 pixelMap.rotate(angle).then(() => { 2960 console.info('Succeeded in rotating pixelmap.'); 2961 }).catch((err: BusinessError) => { 2962 console.error(`Failed to rotate pixelmap. code is ${err.code}, message is ${err.message}`); 2963 }) 2964 } 2965} 2966``` 2967 2968### rotateSync<sup>12+</sup> 2969 2970rotateSync(angle: number): void 2971 2972Rotates this image based on a given angle. This API returns the result synchronously. 2973 2974> **NOTE** 2975> 2976> The allowable range for image rotation angles is between 0 and 360 degrees. Angles outside this range are automatically adjusted according to the 360-degree cycle. For example, an angle of -100 degrees will produce the same result as 260 degrees. 2977> 2978> If the rotation angle is not an integer multiple of 90 degrees, the image size will change after rotation. 2979 2980**Atomic service API**: This API can be used in atomic services since API version 12. 2981 2982**System capability**: SystemCapability.Multimedia.Image.Core 2983 2984**Parameters** 2985 2986| Name | Type | Mandatory| Description | 2987| -------- | -------------------- | ---- | ----------------------------- | 2988| angle | number | Yes | Angle to rotate.| 2989 2990**Error codes** 2991 2992For details about the error codes, see [Image Error Codes](errorcode-image.md). 2993 2994| ID| Error Message| 2995| ------- | --------------------------------------------| 2996| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2997| 501 | Resource Unavailable | 2998 2999**Example** 3000 3001```ts 3002import { BusinessError } from '@kit.BasicServicesKit'; 3003 3004async function RotateSync() { 3005 let angle : number = 90.0; 3006 if (pixelMap != undefined) { 3007 pixelMap.rotateSync(angle); 3008 } 3009} 3010``` 3011 3012### flip<sup>9+</sup> 3013 3014flip(horizontal: boolean, vertical: boolean, callback: AsyncCallback\<void>): void 3015 3016Flips this image horizontally or vertically, or both. This API uses an asynchronous callback to return the result. 3017 3018**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3019 3020**Atomic service API**: This API can be used in atomic services since API version 11. 3021 3022**System capability**: SystemCapability.Multimedia.Image.Core 3023 3024**Parameters** 3025 3026| Name | Type | Mandatory| Description | 3027| ---------- | -------------------- | ---- | ----------------------------- | 3028| horizontal | boolean | Yes | Whether to flip the image horizontally. | 3029| vertical | boolean | Yes | Whether to flip the image vertically. | 3030| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 3031 3032**Example** 3033 3034```ts 3035import { BusinessError } from '@kit.BasicServicesKit'; 3036 3037async function Flip() { 3038 let horizontal: boolean = true; 3039 let vertical: boolean = false; 3040 if (pixelMap != undefined) { 3041 pixelMap.flip(horizontal, vertical, (err: BusinessError) => { 3042 if (err) { 3043 console.error(`Failed to flip pixelmap. code is ${err.code}, message is ${err.message}`); 3044 return; 3045 } else { 3046 console.info("Succeeded in flipping pixelmap."); 3047 } 3048 }) 3049 } 3050} 3051``` 3052 3053### flip<sup>9+</sup> 3054 3055flip(horizontal: boolean, vertical: boolean): Promise\<void> 3056 3057Flips this image horizontally or vertically, or both. This API uses a promise to return the result. 3058 3059**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3060 3061**Atomic service API**: This API can be used in atomic services since API version 11. 3062 3063**System capability**: SystemCapability.Multimedia.Image.Core 3064 3065**Parameters** 3066 3067| Name | Type | Mandatory| Description | 3068| ---------- | ------- | ---- | --------- | 3069| horizontal | boolean | Yes | Whether to flip the image horizontally. The value **true** means to flip the image horizontally.| 3070| vertical | boolean | Yes | Whether to flip the image vertically. The value **true** means to flip the image vertically.| 3071 3072**Return value** 3073 3074| Type | Description | 3075| -------------- | --------------------------- | 3076| Promise\<void> | Promise that returns no value.| 3077 3078**Example** 3079 3080```ts 3081import { BusinessError } from '@kit.BasicServicesKit'; 3082 3083async function Flip() { 3084 let horizontal: boolean = true; 3085 let vertical: boolean = false; 3086 if (pixelMap != undefined) { 3087 pixelMap.flip(horizontal, vertical).then(() => { 3088 console.info('Succeeded in flipping pixelmap.'); 3089 }).catch((err: BusinessError) => { 3090 console.error(`Failed to flip pixelmap. code is ${err.code}, message is ${err.message}`); 3091 }) 3092 } 3093} 3094``` 3095 3096### flipSync<sup>12+</sup> 3097 3098flipSync(horizontal: boolean, vertical: boolean): void 3099 3100Flips this image horizontally or vertically, or both. This API returns the result synchronously. 3101 3102**Atomic service API**: This API can be used in atomic services since API version 12. 3103 3104**System capability**: SystemCapability.Multimedia.Image.Core 3105 3106**Parameters** 3107 3108| Name | Type | Mandatory| Description | 3109| ---------- | -------------------- | ---- | ----------------------------- | 3110| horizontal | boolean | Yes | Whether to flip the image horizontally. | 3111| vertical | boolean | Yes | Whether to flip the image vertically. | 3112 3113**Error codes** 3114 3115For details about the error codes, see [Image Error Codes](errorcode-image.md). 3116 3117| ID| Error Message| 3118| ------- | --------------------------------------------| 3119| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 3120| 501 | Resource Unavailable | 3121 3122**Example** 3123 3124```ts 3125import { BusinessError } from '@kit.BasicServicesKit'; 3126 3127async function FlipSync() { 3128 let horizontal : boolean = true; 3129 let vertical : boolean = false; 3130 if (pixelMap != undefined) { 3131 pixelMap.flipSync(horizontal, vertical); 3132 } 3133} 3134``` 3135 3136### crop<sup>9+</sup> 3137 3138crop(region: Region, callback: AsyncCallback\<void>): void 3139 3140Crops this image based on a given size. This API uses an asynchronous callback to return the result. 3141 3142**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3143 3144**Atomic service API**: This API can be used in atomic services since API version 11. 3145 3146**System capability**: SystemCapability.Multimedia.Image.Core 3147 3148**Parameters** 3149 3150| Name | Type | Mandatory| Description | 3151| -------- | -------------------- | ---- | ----------------------------- | 3152| region | [Region](#region8) | Yes | Size of the image after cropping. The value cannot exceed the width or height of the image.| 3153| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 3154 3155**Example** 3156 3157```ts 3158import { BusinessError } from '@kit.BasicServicesKit'; 3159 3160async function Crop() { 3161 let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 3162 if (pixelMap != undefined) { 3163 pixelMap.crop(region, (err: BusinessError) => { 3164 if (err) { 3165 console.error(`Failed to crop pixelmap. code is ${err.code}, message is ${err.message}`); 3166 return; 3167 } else { 3168 console.info("Succeeded in cropping pixelmap."); 3169 } 3170 }) 3171 } 3172} 3173``` 3174 3175### crop<sup>9+</sup> 3176 3177crop(region: Region): Promise\<void> 3178 3179Crops this image based on a given size. This API uses a promise to return the result. 3180 3181**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3182 3183**Atomic service API**: This API can be used in atomic services since API version 11. 3184 3185**System capability**: SystemCapability.Multimedia.Image.Core 3186 3187**Parameters** 3188 3189| Name| Type | Mandatory| Description | 3190| ------ | ------------------ | ---- | ----------- | 3191| region | [Region](#region8) | Yes | Size of the image after cropping. The value cannot exceed the width or height of the image.| 3192 3193**Return value** 3194 3195| Type | Description | 3196| -------------- | --------------------------- | 3197| Promise\<void> | Promise that returns no value.| 3198 3199**Example** 3200 3201```ts 3202import { BusinessError } from '@kit.BasicServicesKit'; 3203 3204async function Crop() { 3205 let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 3206 if (pixelMap != undefined) { 3207 pixelMap.crop(region).then(() => { 3208 console.info('Succeeded in cropping pixelmap.'); 3209 }).catch((err: BusinessError) => { 3210 console.error(`Failed to crop pixelmap. code is ${err.code}, message is ${err.message}`); 3211 3212 }); 3213 } 3214} 3215``` 3216 3217### cropSync<sup>12+</sup> 3218 3219cropSync(region: Region): void 3220 3221Crops this image based on a given size. This API returns the result synchronously. 3222 3223**Atomic service API**: This API can be used in atomic services since API version 12. 3224 3225**System capability**: SystemCapability.Multimedia.Image.Core 3226 3227**Parameters** 3228 3229| Name | Type | Mandatory| Description | 3230| -------- | -------------------- | ---- | ----------------------------- | 3231| region | [Region](#region8) | Yes | Size of the image after cropping. The value cannot exceed the width or height of the image.| 3232 3233**Error codes** 3234 3235For details about the error codes, see [Image Error Codes](errorcode-image.md). 3236 3237| ID| Error Message| 3238| ------- | --------------------------------------------| 3239| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 3240| 501 | Resource Unavailable | 3241 3242**Example** 3243 3244```ts 3245import { BusinessError } from '@kit.BasicServicesKit'; 3246 3247async function CropSync() { 3248 let region : image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 3249 if (pixelMap != undefined) { 3250 pixelMap.cropSync(region); 3251 } 3252} 3253``` 3254 3255### getColorSpace<sup>10+</sup> 3256 3257getColorSpace(): colorSpaceManager.ColorSpaceManager 3258 3259Obtains the color space of this image. 3260 3261**System capability**: SystemCapability.Multimedia.Image.Core 3262 3263**Return value** 3264 3265| Type | Description | 3266| ----------------------------------- | ---------------- | 3267| [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | Color space obtained.| 3268 3269**Error codes** 3270 3271For details about the error codes, see [Image Error Codes](errorcode-image.md). 3272 3273| ID| Error Message| 3274| ------- | --------------------------------------------| 3275| 62980101| If the image data abnormal. | 3276| 62980103| If the image data unsupport. | 3277| 62980115| If the image parameter invalid. | 3278 3279**Example** 3280 3281```ts 3282async function GetColorSpace() { 3283 if (pixelMap != undefined) { 3284 let csm = pixelMap.getColorSpace(); 3285 } 3286} 3287``` 3288 3289### setColorSpace<sup>10+</sup> 3290 3291setColorSpace(colorSpace: colorSpaceManager.ColorSpaceManager): void 3292 3293Sets the color space for this image. 3294 3295**System capability**: SystemCapability.Multimedia.Image.Core 3296 3297**Parameters** 3298 3299| Name | Type | Mandatory| Description | 3300| ---------- | ----------------------------------- | ---- | --------------- | 3301| colorSpace | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | Yes | Color space to set.| 3302 3303**Error codes** 3304 3305For details about the error codes, see [Image Error Codes](errorcode-image.md). 3306 3307| ID| Error Message| 3308| ------- | --------------------------------------------| 3309| 62980111| The image source data is incomplete. | 3310| 62980115| If the image parameter invalid. | 3311 3312**Example** 3313 3314```ts 3315import { colorSpaceManager } from '@kit.ArkGraphics2D'; 3316async function SetColorSpace() { 3317 let colorSpaceName = colorSpaceManager.ColorSpace.SRGB; 3318 let csm: colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName); 3319 if (pixelMap != undefined) { 3320 pixelMap.setColorSpace(csm); 3321 } 3322} 3323``` 3324 3325### applyColorSpace<sup>11+</sup> 3326 3327applyColorSpace(targetColorSpace: colorSpaceManager.ColorSpaceManager, callback: AsyncCallback\<void>): void 3328 3329Performs 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. 3330 3331**System capability**: SystemCapability.Multimedia.Image.Core 3332 3333**Parameters** 3334 3335| Name | Type | Mandatory| Description | 3336| -------- | -------------------- | ---- | ----------------------------- | 3337| 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.| 3338| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 3339 3340**Error codes** 3341 3342For details about the error codes, see [Image Error Codes](errorcode-image.md). 3343 3344| ID| Error Message| 3345| ------- | ------------------------------------------| 3346| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 3347| 62980104| Failed to initialize the internal object. | 3348| 62980108| Failed to convert the color space. | 3349| 62980115| Invalid image parameter. | 3350 3351**Example** 3352 3353```ts 3354import { colorSpaceManager } from '@kit.ArkGraphics2D'; 3355import { BusinessError } from '@kit.BasicServicesKit'; 3356 3357async function ApplyColorSpace() { 3358 let colorSpaceName = colorSpaceManager.ColorSpace.SRGB; 3359 let targetColorSpace: colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName); 3360 if (pixelMap != undefined) { 3361 pixelMap.applyColorSpace(targetColorSpace, (err: BusinessError) => { 3362 if (err) { 3363 console.error(`Failed to apply color space for pixelmap object. code is ${err.code}, message is ${err.message}`); 3364 return; 3365 } else { 3366 console.info('Succeeded in applying color space for pixelmap object.'); 3367 } 3368 }) 3369 } 3370} 3371``` 3372 3373### applyColorSpace<sup>11+</sup> 3374 3375applyColorSpace(targetColorSpace: colorSpaceManager.ColorSpaceManager): Promise\<void> 3376 3377Performs CSC on the image pixel color based on a given color space. This API uses a promise to return the result. 3378 3379**System capability**: SystemCapability.Multimedia.Image.Core 3380 3381**Parameters** 3382 3383| Name| Type | Mandatory| Description | 3384| ------ | ------------------ | ---- | ----------- | 3385| 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.| 3386 3387**Return value** 3388 3389| Type | Description | 3390| -------------- | --------------------------- | 3391| Promise\<void> | Promise that returns no value.| 3392 3393**Error codes** 3394 3395For details about the error codes, see [Image Error Codes](errorcode-image.md). 3396 3397| ID| Error Message| 3398| ------- | ------------------------------------------| 3399| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 3400| 62980104| Failed to initialize the internal object. | 3401| 62980108| Failed to convert the color space. | 3402| 62980115| Invalid image parameter. | 3403 3404**Example** 3405 3406```ts 3407import { colorSpaceManager } from '@kit.ArkGraphics2D'; 3408import { BusinessError } from '@kit.BasicServicesKit'; 3409 3410async function ApplyColorSpace() { 3411 let colorSpaceName = colorSpaceManager.ColorSpace.SRGB; 3412 let targetColorSpace: colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName); 3413 if (pixelMap != undefined) { 3414 pixelMap.applyColorSpace(targetColorSpace).then(() => { 3415 console.info('Succeeded in applying color space for pixelmap object.'); 3416 }).catch((error: BusinessError) => { 3417 console.error(`Failed to apply color space for pixelmap object. code is ${error.code}, message is ${error.message}`); 3418 }) 3419 } 3420} 3421``` 3422 3423### toSdr<sup>12+<sup> 3424 3425toSdr(): Promise\<void> 3426 3427Converts an HDR image into an SDR image. This API uses a promise to return the result. 3428 3429**System capability**: SystemCapability.Multimedia.Image.Core 3430 3431**Return value** 3432 3433| Type | Description | 3434| -------------- | --------------------------- | 3435| Promise\<void> | Promise that returns no value.| 3436 3437**Error codes** 3438 3439For details about the error codes, see [Image Error Codes](errorcode-image.md). 3440 3441| ID| Error Message| 3442| ------- | --------------------------------------------| 3443| 62980137 | Invalid image operation. | 3444 3445**Example** 3446 3447```ts 3448import image from '@ohos.multimedia.image' 3449import resourceManager from '@ohos.resourceManager' 3450import { BusinessError } from '@kit.BasicServicesKit'; 3451 3452// '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. 3453let img = getContext().resourceManager.getMediaContentSync($r('app.media.hdr')); 3454let imageSource = image.createImageSource(img.buffer.slice(0)); 3455let decodingOptions: image.DecodingOptions = { 3456 desiredDynamicRange: image.DecodingDynamicRange.AUTO 3457}; 3458let pixelmap = imageSource.createPixelMapSync(decodingOptions); 3459if (pixelmap != undefined) { 3460 console.info('Succeeded in creating pixelMap object.'); 3461 pixelmap.toSdr().then(() => { 3462 let imageInfo = pixelmap.getImageInfoSync(); 3463 console.info("after toSdr ,imageInfo isHdr:" + imageInfo.isHdr); 3464 }).catch((err: BusinessError) => { 3465 console.error(`Failed to set sdr. code is ${err.code}, message is ${err.message}`); 3466 }); 3467} else { 3468 console.info('Failed to create pixelMap.'); 3469} 3470``` 3471 3472### getMetadata<sup>12+</sup> 3473 3474getMetadata(key: HdrMetadataKey): HdrMetadataValue 3475 3476Obtains the value of the metadata with a given key in this PixelMap. 3477 3478**System capability**: SystemCapability.Multimedia.Image.Core 3479 3480**Parameters** 3481 3482| Name | Type | Mandatory| Description | 3483| ------------- | -------------------------------- | ---- | ---------------- | 3484| key | [HdrMetadataKey](#hdrmetadatakey12) | Yes | Key of the HDR metadata.| 3485 3486**Return value** 3487 3488| Type | Description | 3489| --------------------------------- | --------------------------------- | 3490| [HdrMetadataValue](#hdrmetadatavalue12) | Value of the metadata with the given key.| 3491 3492**Error codes** 3493 3494For details about the error codes, see [Image Error Codes](errorcode-image.md). 3495 3496| ID| Error Message| 3497| ------- | --------------------------------------------| 3498| 401| Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 3499| 501 | Resource unavailable. | 3500| 62980173 | The DMA memory does not exist. | 3501| 62980302 | Memory copy failed. | 3502 3503**Example** 3504 3505```ts 3506import { BusinessError } from '@kit.BasicServicesKit'; 3507import image from '@ohos.multimedia.image' 3508 3509// Replace 'app.media.test' with a local HDR image. 3510let img = getContext().resourceManager.getMediaContentSync($r('app.media.test')); 3511let imageSource = image.createImageSource(img.buffer.slice(0)); 3512let decodingOptions: image.DecodingOptions = { 3513 desiredDynamicRange: image.DecodingDynamicRange.AUTO 3514}; 3515let pixelmap = imageSource.createPixelMapSync(decodingOptions); 3516if (pixelmap != undefined) { 3517 console.info('Succeeded in creating pixelMap object.'); 3518 try { 3519 let staticMetadata = pixelmap.getMetadata(image.HdrMetadataKey.HDR_STATIC_METADATA); 3520 console.info("getmetadata:" + JSON.stringify(staticMetadata)); 3521 } catch (e) { 3522 console.info('pixelmap create failed' + e); 3523 } 3524} else { 3525 console.info('Failed to create pixelMap.'); 3526} 3527``` 3528 3529### setMetadata<sup>12+</sup> 3530 3531setMetadata(key: HdrMetadataKey, value: HdrMetadataValue): Promise\<void> 3532 3533Sets the value for the metadata with a given key in this PixelMap. 3534 3535**System capability**: SystemCapability.Multimedia.Image.Core 3536 3537**Parameters** 3538 3539| Name | Type | Mandatory| Description | 3540| ------------- | -------------------------------- | ---- | ---------------- | 3541| key | [HdrMetadataKey](#hdrmetadatakey12) | Yes | Key of the HDR metadata.| 3542| value | [HdrMetadataValue](#hdrmetadatavalue12) | Yes | Value of the metadata.| 3543 3544**Return value** 3545 3546| Type | Description | 3547| -------------- | --------------------- | 3548| Promise\<void> | Promise that returns no value.| 3549 3550**Error codes** 3551 3552For details about the error codes, see [Image Error Codes](errorcode-image.md). 3553 3554| ID| Error Message| 3555| ------- | --------------------------------------------| 3556| 401| Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 3557| 501 | Resource unavailable. | 3558| 62980173 | The DMA memory does not exist. | 3559| 62980302 | Memory copy failed. | 3560 3561**Example** 3562 3563```ts 3564import image from '@ohos.multimedia.image' 3565import { BusinessError } from '@kit.BasicServicesKit'; 3566 3567let staticMetadata: image.HdrStaticMetadata = { 3568 displayPrimariesX: [1.1, 1.1, 1.1], 3569 displayPrimariesY: [1.2, 1.2, 1.2], 3570 whitePointX: 1.1, 3571 whitePointY: 1.2, 3572 maxLuminance: 2.1, 3573 minLuminance: 1.0, 3574 maxContentLightLevel: 2.1, 3575 maxFrameAverageLightLevel: 2.1, 3576} 3577const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 3578let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 3579image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => { 3580 pixelMap.setMetadata(image.HdrMetadataKey.HDR_STATIC_METADATA, staticMetadata).then(() => { 3581 console.info('Succeeded in setting pixelMap metadata.'); 3582 }).catch((error: BusinessError) => { 3583 console.error(`Failed to set the metadata.code ${error.code},message is ${error.message}`); 3584 }) 3585}).catch((error: BusinessError) => { 3586 console.error(`Failed to create the PixelMap.code ${error.code},message is ${error.message}`); 3587}) 3588 3589``` 3590 3591### setTransferDetached<sup>12+<sup> 3592 3593setTransferDetached(detached: boolean): void 3594 3595Sets whether to detach from the original thread when this PixelMap is transmitted across threads. This API applies to the scenario where the PixelMap needs to be released immediately. 3596 3597**System capability**: SystemCapability.Multimedia.Image.Core 3598 3599**Parameters** 3600 3601| Name | Type | Mandatory| Description | 3602| ------- | ------------------ | ---- | ----------------------------- | 3603| detached | boolean | Yes | Whether to detach from the original thread. | 3604 3605**Error codes** 3606 3607For details about the error codes, see [Image Error Codes](errorcode-image.md). 3608 3609| ID| Error Message| 3610| ------- | --------------------------------------------| 3611| 501 | Resource Unavailable | 3612 3613**Example** 3614 3615```ts 3616import { BusinessError } from '@kit.BasicServicesKit'; 3617import image from '@ohos.multimedia.image'; 3618import taskpool from '@ohos.taskpool'; 3619 3620@Concurrent 3621// Child thread method. 3622async function loadPixelMap(rawFileDescriptor: number): Promise<PixelMap> { 3623 // Create an ImageSource instance. 3624 const imageSource = image.createImageSource(rawFileDescriptor); 3625 // Create a pixelMap. 3626 const pixelMap = imageSource.createPixelMapSync(); 3627 // Release the ImageSource instance. 3628 imageSource.release(); 3629 // Disconnect the reference of the original thread after the cross-thread transfer of the pixelMap is complete. 3630 pixelMap.setTransferDetached(true); 3631 // Return the pixelMap to the main thread. 3632 return pixelMap; 3633} 3634 3635struct Demo { 3636 @State pixelMap: PixelMap | undefined = undefined; 3637 // Main thread method. 3638 private loadImageFromThread(): void { 3639 const resourceMgr = getContext(this).resourceManager; 3640 // 'example.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. 3641 resourceMgr.getRawFd('example.jpg').then(rawFileDescriptor => { 3642 taskpool.execute(loadPixelMap, rawFileDescriptor).then(pixelMap => { 3643 if (pixelMap) { 3644 this.pixelMap = pixelMap as PixelMap; 3645 console.log('Succeeded in creating pixelMap.'); 3646 // The main thread releases the pixelMap. Because setTransferDetached has been called when the child thread returns pixelMap, the pixelMap can be released immediately. 3647 this.pixelMap.release(); 3648 } else { 3649 console.error('Failed to create pixelMap.'); 3650 } 3651 }); 3652 }); 3653 } 3654} 3655``` 3656 3657### marshalling<sup>10+</sup> 3658 3659marshalling(sequence: rpc.MessageSequence): void 3660 3661Marshals this **PixelMap** object and writes it to a **MessageSequence** object. 3662 3663**System capability**: SystemCapability.Multimedia.Image.Core 3664 3665**Parameters** 3666 3667| Name | Type | Mandatory| Description | 3668| ---------------------- | ------------------------------------------------------ | ---- | ---------------------------------------- | 3669| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | Yes | **MessageSequence** object. | 3670 3671**Error codes** 3672 3673For details about the error codes, see [Image Error Codes](errorcode-image.md). 3674 3675| ID| Error Message| 3676| ------- | --------------------------------------------| 3677| 62980115 | Invalid image parameter. | 3678| 62980097 | IPC error. | 3679 3680**Example** 3681 3682```ts 3683import { image } from '@kit.ImageKit'; 3684import { rpc } from '@kit.IPCKit'; 3685 3686class MySequence implements rpc.Parcelable { 3687 pixel_map: image.PixelMap; 3688 constructor(conPixelMap : image.PixelMap) { 3689 this.pixel_map = conPixelMap; 3690 } 3691 marshalling(messageSequence : rpc.MessageSequence) { 3692 this.pixel_map.marshalling(messageSequence); 3693 console.info('marshalling'); 3694 return true; 3695 } 3696 unmarshalling(messageSequence : rpc.MessageSequence) { 3697 image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}}).then((pixelParcel: image.PixelMap) => { 3698 pixelParcel.unmarshalling(messageSequence).then(async (pixelMap: image.PixelMap) => { 3699 this.pixel_map = pixelMap; 3700 pixelMap.getImageInfo().then((imageInfo: image.ImageInfo) => { 3701 console.info("unmarshalling information h:" + imageInfo.size.height + "w:" + imageInfo.size.width); 3702 }) 3703 }) 3704 }); 3705 return true; 3706 } 3707} 3708async function Marshalling() { 3709 const color: ArrayBuffer = new ArrayBuffer(96); 3710 let bufferArr: Uint8Array = new Uint8Array(color); 3711 for (let i = 0; i < bufferArr.length; i++) { 3712 bufferArr[i] = 0x80; 3713 } 3714 let opts: image.InitializationOptions = { 3715 editable: true, 3716 pixelFormat: image.PixelMapFormat.BGRA_8888, 3717 size: { height: 4, width: 6 }, 3718 alphaType: image.AlphaType.UNPREMUL 3719 } 3720 let pixelMap: image.PixelMap | undefined = undefined; 3721 image.createPixelMap(color, opts).then((srcPixelMap: image.PixelMap) => { 3722 pixelMap = srcPixelMap; 3723 }) 3724 if (pixelMap != undefined) { 3725 // Implement serialization. 3726 let parcelable: MySequence = new MySequence(pixelMap); 3727 let data: rpc.MessageSequence = rpc.MessageSequence.create(); 3728 data.writeParcelable(parcelable); 3729 3730 // Implement deserialization to obtain data through the RPC. 3731 let ret: MySequence = new MySequence(pixelMap); 3732 data.readParcelable(ret); 3733 } 3734} 3735``` 3736 3737### unmarshalling<sup>10+</sup> 3738 3739unmarshalling(sequence: rpc.MessageSequence): Promise\<PixelMap> 3740 3741Unmarshals a **MessageSequence** object to obtain a **PixelMap** object. 3742To create a **PixelMap** object in synchronous mode, use [createPixelMapFromParcel](#imagecreatepixelmapfromparcel11). 3743 3744**System capability**: SystemCapability.Multimedia.Image.Core 3745 3746**Parameters** 3747 3748| Name | Type | Mandatory| Description | 3749| ---------------------- | ----------------------------------------------------- | ---- | ---------------------------------------- | 3750| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | Yes | **MessageSequence** object that stores the **PixelMap** information. | 3751 3752**Return value** 3753 3754| Type | Description | 3755| -------------------------------- | --------------------- | 3756| Promise\<[PixelMap](#pixelmap7)> |Promise used to return the **PixelMap** object.| 3757 3758**Error codes** 3759 3760For details about the error codes, see [Image Error Codes](errorcode-image.md). 3761 3762| ID| Error Message| 3763| ------- | --------------------------------------------| 3764| 62980115 | Invalid image parameter. | 3765| 62980097 | IPC error. | 3766| 62980096 | The operation failed. | 3767 3768**Example** 3769 3770```ts 3771import { image } from '@kit.ImageKit'; 3772import { rpc } from '@kit.IPCKit'; 3773 3774class MySequence implements rpc.Parcelable { 3775 pixel_map: image.PixelMap; 3776 constructor(conPixelMap: image.PixelMap) { 3777 this.pixel_map = conPixelMap; 3778 } 3779 marshalling(messageSequence: rpc.MessageSequence) { 3780 this.pixel_map.marshalling(messageSequence); 3781 console.info('marshalling'); 3782 return true; 3783 } 3784 unmarshalling(messageSequence: rpc.MessageSequence) { 3785 image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}}).then((pixelParcel : image.PixelMap) => { 3786 pixelParcel.unmarshalling(messageSequence).then(async (pixelMap : image.PixelMap) => { 3787 this.pixel_map = pixelMap; 3788 pixelMap.getImageInfo().then((imageInfo : image.ImageInfo) => { 3789 console.info("unmarshalling information h:" + imageInfo.size.height + "w:" + imageInfo.size.width); 3790 }) 3791 }) 3792 }); 3793 return true; 3794 } 3795} 3796async function Unmarshalling() { 3797 const color: ArrayBuffer = new ArrayBuffer(96); 3798 let bufferArr: Uint8Array = new Uint8Array(color); 3799 for (let i = 0; i < bufferArr.length; i++) { 3800 bufferArr[i] = 0x80; 3801 } 3802 let opts: image.InitializationOptions = { 3803 editable: true, 3804 pixelFormat: image.PixelMapFormat.BGRA_8888, 3805 size: { height: 4, width: 6 }, 3806 alphaType: image.AlphaType.UNPREMUL 3807 } 3808 let pixelMap: image.PixelMap | undefined = undefined; 3809 image.createPixelMap(color, opts).then((srcPixelMap : image.PixelMap) => { 3810 pixelMap = srcPixelMap; 3811 }) 3812 if (pixelMap != undefined) { 3813 // Implement serialization. 3814 let parcelable: MySequence = new MySequence(pixelMap); 3815 let data : rpc.MessageSequence = rpc.MessageSequence.create(); 3816 data.writeParcelable(parcelable); 3817 3818 // Implement deserialization to obtain data through the RPC. 3819 let ret : MySequence = new MySequence(pixelMap); 3820 data.readParcelable(ret); 3821 } 3822} 3823``` 3824 3825### release<sup>7+</sup> 3826 3827release():Promise\<void> 3828 3829Releases this **PixelMap** object. This API uses a promise to return the result. 3830 3831ArkTS 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 object is no longer required. 3832 3833**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3834 3835**Atomic service API**: This API can be used in atomic services since API version 11. 3836 3837**System capability**: SystemCapability.Multimedia.Image.Core 3838 3839**Return value** 3840 3841| Type | Description | 3842| -------------- | ------------------------------- | 3843| Promise\<void> | Promise that returns no value.| 3844 3845**Example** 3846 3847```ts 3848import { BusinessError } from '@kit.BasicServicesKit'; 3849 3850async function Release() { 3851 if (pixelMap != undefined) { 3852 pixelMap.release().then(() => { 3853 console.info('Succeeded in releasing pixelmap object.'); 3854 }).catch((error: BusinessError) => { 3855 console.error(`Failed to release pixelmap object. code is ${error.code}, message is ${error.message}`); 3856 }) 3857 } 3858} 3859``` 3860 3861### release<sup>7+</sup> 3862 3863release(callback: AsyncCallback\<void>): void 3864 3865Releases this **PixelMap** object. This API uses an asynchronous callback to return the result. 3866 3867ArkTS 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 object is no longer required. 3868 3869**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3870 3871**Atomic service API**: This API can be used in atomic services since API version 11. 3872 3873**System capability**: SystemCapability.Multimedia.Image.Core 3874 3875**Parameters** 3876 3877| Name | Type | Mandatory| Description | 3878| -------- | -------------------- | ---- | ------------------ | 3879| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 3880 3881**Example** 3882 3883```ts 3884import { BusinessError } from '@kit.BasicServicesKit'; 3885 3886async function Release() { 3887 if (pixelMap != undefined) { 3888 pixelMap.release((err: BusinessError) => { 3889 if (err) { 3890 console.error(`Failed to release pixelmap object. code is ${err.code}, message is ${err.message}`); 3891 return; 3892 } else { 3893 console.info('Succeeded in releasing pixelmap object.'); 3894 } 3895 }) 3896 } 3897} 3898``` 3899 3900### convertPixelFormat<sup>12+</sup> 3901 3902convertPixelFormat(targetPixelFormat: PixelMapFormat): Promise\<void> 3903 3904Performs a conversion between YUV and RGB formats. Currently, only conversion between NV12/NV21 and RGB888/RGBA8888/RGB565/BGRA8888/RGBAF16 and conversion between YCRCB_P010/YCBCR_P010 and RGBA1010102 are supported. 3905 3906Since API version 18, this API can be used for conversion from ASTC_4x4 to RGBA_8888. 3907 3908> **NOTE** 3909> 3910> Call this API to convert the format from ASTC_4x4 to RGBA_8888 only when you need to access pixels of images in ASTC_4x4 format. The conversion from ASTC_4x4 to RGBA_8888 is slow and is not recommended in other cases. 3911 3912**System capability**: SystemCapability.Multimedia.Image.Core 3913 3914**Parameters** 3915 3916| Name | Type | Mandatory| Description | 3917| -------- | -------------------- | ---- | ------------------ | 3918| targetPixelFormat | [PixelMapFormat](#pixelmapformat7) | Yes | Target pixel format. Currently, only conversion between NV12/NV21 and RGB888/RGBA8888/RGB565/BGRA8888/RGBAF16, conversion between YCRCB_P010/YCBCR_P010 and RGBA1010102, and conversion from ASTC_4x4 to RGBA_8888 are supported.| 3919 3920**Return value** 3921 3922| Type | Description | 3923| -------------- | ------------------------------- | 3924| Promise\<void> | Promise that returns no value.| 3925 3926**Error codes** 3927 3928For details about the error codes, see [Image Error Codes](errorcode-image.md). 3929 3930| ID| Error Message| 3931| ------- | --------------------------------------------| 3932| 62980111 | The image source data is incomplete. | 3933| 62980115 | Invalid input parameter. | 3934| 62980178 | Failed to create the pixelmap. | 3935| 62980274 | The conversion failed | 3936| 62980276 | The type to be converted is an unsupported target pixel format| 3937 3938**Example** 3939 3940```ts 3941import { BusinessError } from '@kit.BasicServicesKit'; 3942 3943if (pixelMap != undefined) { 3944 // Set the target pixel format to NV12. 3945 let targetPixelFormat = image.PixelMapFormat.NV12; 3946 pixelMap.convertPixelFormat(targetPixelFormat).then(() => { 3947 // The pixelMap is converted to the NV12 format. 3948 console.info('PixelMapFormat convert Succeeded'); 3949 }).catch((error: BusinessError) => { 3950 // The pixelMap fails to be converted to the NV12 format. 3951 console.error(`PixelMapFormat convert Failed. code is ${error.code}, message is ${error.message}`); 3952 }) 3953} 3954``` 3955 3956### setMemoryNameSync<sup>13+</sup> 3957 3958setMemoryNameSync(name: string): void 3959 3960Sets a memory name for this PixelMap. 3961 3962**System capability**: SystemCapability.Multimedia.Image.Core 3963 3964**Parameters** 3965 3966| Name | Type | Mandatory| Description | 3967| ------------- | -------------------------------- | ---- | ---------------- | 3968| name | string | Yes | Memory name, which can be set only for a PixelMap with the DMA or ASHMEM memory format. The length ranges from 1 to 31 bits.| 3969 3970**Error codes** 3971 3972For details about the error codes, see [Image Error Codes](errorcode-image.md). 3973 3974| ID| Error Message| 3975| ------- | --------------------------------------------| 3976| 401 | Parameter error. Possible causes: 1.The length of the input parameter is too long. 2.Parameter verification failed. | 3977| 62980286 | Memory format not supported. | 3978 3979**Example** 3980 3981```ts 3982import { BusinessError } from '@ohos.base'; 3983 3984async function SetMemoryNameSync() { 3985 if (pixelMap != undefined) { 3986 try { 3987 pixelMap.setMemoryNameSync("PixelMapName Test"); 3988 } catch(e) { 3989 let error = e as BusinessError; 3990 console.error(`setMemoryNameSync error. code is ${error.code}, message is ${error.message}`); 3991 } 3992 } 3993} 3994``` 3995 3996## image.createImageSource 3997 3998createImageSource(uri: string): ImageSource 3999 4000Creates an **ImageSource** instance based on a given URI. 4001 4002 4003**Atomic service API**: This API can be used in atomic services since API version 11. 4004 4005**System capability**: SystemCapability.Multimedia.Image.ImageSource 4006 4007**Parameters** 4008 4009| Name| Type | Mandatory| Description | 4010| ------ | ------ | ---- | ---------------------------------- | 4011| 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, .heic<sup>12+</sup> (depending on the hardware), [.svg<sup>10+</sup>](#svg-tags), and .ico<sup>11+</sup>.| 4012 4013**Return value** 4014 4015| Type | Description | 4016| --------------------------- | -------------------------------------------- | 4017| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 4018 4019**Example** 4020 4021```ts 4022const context: Context = getContext(this); 4023// '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. 4024const path: string = context.filesDir + "/test.jpg"; 4025const imageSourceApi: image.ImageSource = image.createImageSource(path); 4026``` 4027 4028## image.createImageSource<sup>9+</sup> 4029 4030createImageSource(uri: string, options: SourceOptions): ImageSource 4031 4032Creates an **ImageSource** instance based on a given URI. 4033 4034**Widget capability**: This API can be used in ArkTS widgets since API version 12. 4035 4036**Atomic service API**: This API can be used in atomic services since API version 11. 4037 4038**System capability**: SystemCapability.Multimedia.Image.ImageSource 4039 4040**Parameters** 4041 4042| Name | Type | Mandatory| Description | 4043| ------- | ------------------------------- | ---- | ----------------------------------- | 4044| 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, .heic<sup>12+</sup> (depending on the hardware), [.svg<sup>10+</sup>](#svg-tags), and .ico<sup>11+</sup>.| 4045| options | [SourceOptions](#sourceoptions9) | Yes | Image properties, including the image pixel density, pixel format, and image size.| 4046 4047**Return value** 4048 4049| Type | Description | 4050| --------------------------- | -------------------------------------------- | 4051| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 4052 4053**Example** 4054 4055```ts 4056let sourceOptions: image.SourceOptions = { sourceDensity: 120 }; 4057const context: Context = getContext(this); 4058// '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. 4059const path: string = context.filesDir + "/test.png"; 4060let imageSourceApi: image.ImageSource = image.createImageSource(path, sourceOptions); 4061``` 4062 4063## image.createImageSource<sup>7+</sup> 4064 4065createImageSource(fd: number): ImageSource 4066 4067Creates an **ImageSource** instance based on a given file descriptor. 4068 4069**Atomic service API**: This API can be used in atomic services since API version 11. 4070 4071**System capability**: SystemCapability.Multimedia.Image.ImageSource 4072 4073**Parameters** 4074 4075| Name| Type | Mandatory| Description | 4076| ------ | ------ | ---- | ------------- | 4077| fd | number | Yes | File descriptor.| 4078 4079**Return value** 4080 4081| Type | Description | 4082| --------------------------- | -------------------------------------------- | 4083| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 4084 4085**Example** 4086 4087```ts 4088import { fileIo as fs } from '@kit.CoreFileKit'; 4089 4090const context: Context = getContext(this); 4091// '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. 4092let filePath: string = context.filesDir + "/test.jpg"; 4093let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 4094const imageSourceApi: image.ImageSource = image.createImageSource(file.fd); 4095``` 4096 4097## image.createImageSource<sup>9+</sup> 4098 4099createImageSource(fd: number, options: SourceOptions): ImageSource 4100 4101Creates an **ImageSource** instance based on a given file descriptor. 4102 4103**Widget capability**: This API can be used in ArkTS widgets since API version 12. 4104 4105**Atomic service API**: This API can be used in atomic services since API version 11. 4106 4107**System capability**: SystemCapability.Multimedia.Image.ImageSource 4108 4109**Parameters** 4110 4111| Name | Type | Mandatory| Description | 4112| ------- | ------------------------------- | ---- | ----------------------------------- | 4113| fd | number | Yes | File descriptor. | 4114| options | [SourceOptions](#sourceoptions9) | Yes | Image properties, including the image pixel density, pixel format, and image size.| 4115 4116**Return value** 4117 4118| Type | Description | 4119| --------------------------- | -------------------------------------------- | 4120| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 4121 4122**Example** 4123 4124```ts 4125import { fileIo as fs } from '@kit.CoreFileKit'; 4126 4127let sourceOptions: image.SourceOptions = { sourceDensity: 120 }; 4128const context: Context = getContext(); 4129// '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. 4130const filePath: string = context.filesDir + "/test.jpg"; 4131let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 4132const imageSourceApi: image.ImageSource = image.createImageSource(file.fd, sourceOptions); 4133``` 4134 4135## image.createImageSource<sup>9+</sup> 4136 4137createImageSource(buf: ArrayBuffer): ImageSource 4138 4139Creates an **ImageSource** instance based on buffers. The data passed by **buf** must be undecoded. Do not pass the pixel buffer data such as RBGA and YUV. If you want to create a PixelMap based on the pixel buffer data, call [image.createPixelMapSync](#createpixelmapsync12). 4140 4141**Widget capability**: This API can be used in ArkTS widgets since API version 12. 4142 4143**Atomic service API**: This API can be used in atomic services since API version 11. 4144 4145**System capability**: SystemCapability.Multimedia.Image.ImageSource 4146 4147**Parameters** 4148 4149| Name| Type | Mandatory| Description | 4150| ------ | ----------- | ---- | ---------------- | 4151| buf | ArrayBuffer | Yes | Array of image buffers.| 4152 4153**Return value** 4154 4155| Type | Description | 4156| --------------------------- | -------------------------------------------- | 4157| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 4158 4159 4160**Example** 4161 4162```ts 4163const buf: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 4164const imageSourceApi: image.ImageSource = image.createImageSource(buf); 4165``` 4166 4167## image.createImageSource<sup>9+</sup> 4168 4169createImageSource(buf: ArrayBuffer, options: SourceOptions): ImageSource 4170 4171Creates an **ImageSource** instance based on buffers. The data passed by **buf** must be undecoded. Do not pass the pixel buffer data such as RBGA and YUV. If you want to create a PixelMap based on the pixel buffer data, call [image.createPixelMapSync](#createpixelmapsync12). 4172 4173**Widget capability**: This API can be used in ArkTS widgets since API version 12. 4174 4175**Atomic service API**: This API can be used in atomic services since API version 11. 4176 4177**System capability**: SystemCapability.Multimedia.Image.ImageSource 4178 4179**Parameters** 4180 4181| Name| Type | Mandatory| Description | 4182| ------ | -------------------------------- | ---- | ------------------------------------ | 4183| buf | ArrayBuffer | Yes | Array of image buffers. | 4184| options | [SourceOptions](#sourceoptions9) | Yes | Image properties, including the image pixel density, pixel format, and image size.| 4185 4186**Return value** 4187 4188| Type | Description | 4189| --------------------------- | -------------------------------------------- | 4190| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 4191 4192**Example** 4193 4194```ts 4195const data: ArrayBuffer = new ArrayBuffer(112); 4196let sourceOptions: image.SourceOptions = { sourceDensity: 120 }; 4197const imageSourceApi: image.ImageSource = image.createImageSource(data, sourceOptions); 4198``` 4199 4200## image.createImageSource<sup>11+</sup> 4201 4202createImageSource(rawfile: resourceManager.RawFileDescriptor, options?: SourceOptions): ImageSource 4203 4204Creates an **ImageSource** instance based on the raw file descriptor of an image resource file. 4205 4206**Atomic service API**: This API can be used in atomic services since API version 11. 4207 4208**System capability**: SystemCapability.Multimedia.Image.ImageSource 4209 4210**Parameters** 4211 4212| Name| Type | Mandatory| Description | 4213| ------ | -------------------------------- | ---- | ------------------------------------ | 4214| rawfile | [resourceManager.RawFileDescriptor](../apis-localization-kit/js-apis-resource-manager.md#rawfiledescriptor9) | Yes| Raw file descriptor of the image resource file.| 4215| options | [SourceOptions](#sourceoptions9) | No| Image properties, including the image pixel density, pixel format, and image size.| 4216 4217**Return value** 4218 4219| Type | Description | 4220| --------------------------- | -------------------------------------------- | 4221| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 4222 4223**Example** 4224 4225```ts 4226import { resourceManager } from '@kit.LocalizationKit'; 4227 4228const context: Context = getContext(this); 4229// Obtain a resource manager. 4230const resourceMgr: resourceManager.ResourceManager = context.resourceManager; 4231// '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. 4232resourceMgr.getRawFd('test.jpg').then((rawFileDescriptor: resourceManager.RawFileDescriptor) => { 4233 const imageSourceApi: image.ImageSource = image.createImageSource(rawFileDescriptor); 4234}).catch((error: BusinessError) => { 4235 console.error(`Failed to get RawFileDescriptor.code is ${error.code}, message is ${error.message}`); 4236}) 4237``` 4238 4239## image.CreateIncrementalSource<sup>9+</sup> 4240 4241CreateIncrementalSource(buf: ArrayBuffer): ImageSource 4242 4243Creates an **ImageSource** instance in incremental mode based on buffers. Such an instance does not support reading or writing of EXIF information. 4244 4245The **ImageSource** instance created in incremental mode supports the following capabilities (applicable to synchronous, callback, and promise modes): 4246- Obtaining image information: Call [getImageInfo](#getimageinfo) to obtain image information by index, or call [getImageInfo](#getimageinfo-1) to directly obtain image information. 4247- Obtaining an image property: Call [getImageProperty](#getimageproperty11) to obtain the value of a property with the specified index in an image. 4248- Obtaining image properties: Call [getImageProperties](#getimageproperties12) to obtain the values of properties with the given names in an image. 4249- Updating incremental data: Call [updateData](#updatedata9) to update data. 4250- Creating a **PixelMap** object: Call [createPixelMap](#createpixelmap7) or [createPixelMap](#createpixelmap7-2) to create a PixelMap based on decoding options, or call [createPixelMap](#createpixelmap7-1) to create a PixelMap based on default parameters. 4251- Releasing an **ImageSource** instance: Call [release](#release) to release an image source. 4252 4253**System capability**: SystemCapability.Multimedia.Image.ImageSource 4254 4255**Parameters** 4256 4257| Name | Type | Mandatory| Description | 4258| ------- | ------------| ---- | ----------| 4259| buf | ArrayBuffer | Yes | Incremental data.| 4260 4261**Return value** 4262 4263| Type | Description | 4264| --------------------------- | --------------------------------- | 4265| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns undefined otherwise.| 4266 4267**Example** 4268 4269```ts 4270const context: Context = getContext(this) 4271let imageArray = context.resourceManager.getMediaContentSync($r('app.media.startIcon')) // Obtain the image resource. 4272// '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. 4273let splitBuff1 = imageArray.slice(0, imageArray.byteLength / 2) // Image slice. 4274let splitBuff2 = imageArray.slice(imageArray.byteLength / 2) 4275const imageSourceIncrementalSApi: image.ImageSource = image.CreateIncrementalSource(new ArrayBuffer(imageArray.byteLength)); 4276imageSourceIncrementalSApi.updateData(splitBuff1, false, 0, splitBuff1.byteLength).then(() => { 4277 imageSourceIncrementalSApi.updateData(splitBuff2, true, 0, splitBuff2.byteLength).then(() => { 4278 let pixelMap = imageSourceIncrementalSApi.createPixelMapSync() 4279 let imageInfo = pixelMap.getImageInfoSync() 4280 console.info('Succeeded in creating pixelMap') 4281 }).catch((error : BusinessError) => { 4282 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`) 4283 }) 4284}).catch((error : BusinessError) => { 4285 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`) 4286}) 4287``` 4288 4289## image.CreateIncrementalSource<sup>9+</sup> 4290 4291CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource 4292 4293Creates an **ImageSource** instance in incremental mode based on buffers. Such an instance does not support reading or writing of EXIF information. 4294 4295The 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). 4296 4297**System capability**: SystemCapability.Multimedia.Image.ImageSource 4298 4299**Parameters** 4300 4301| Name | Type | Mandatory| Description | 4302| ------- | ------------------------------- | ---- | ------------------------------------ | 4303| buf | ArrayBuffer | Yes | Incremental data. | 4304| options | [SourceOptions](#sourceoptions9) | No | Image properties, including the image pixel density, pixel format, and image size.| 4305 4306**Return value** 4307 4308| Type | Description | 4309| --------------------------- | --------------------------------- | 4310| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns undefined otherwise.| 4311 4312**Example** 4313 4314```ts 4315const context: Context = getContext(this) 4316let imageArray = context.resourceManager.getMediaContentSync($r('app.media.startIcon')) // Obtain the image resource. 4317// '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. 4318let splitBuff1 = imageArray.slice(0, imageArray.byteLength / 2) // Image slice. 4319let splitBuff2 = imageArray.slice(imageArray.byteLength / 2) 4320let sourceOptions: image.SourceOptions = { sourceDensity: 120}; 4321 4322const imageSourceIncrementalSApi: image.ImageSource = image.CreateIncrementalSource(new ArrayBuffer(imageArray.byteLength), sourceOptions); 4323imageSourceIncrementalSApi.updateData(splitBuff1, false, 0, splitBuff1.byteLength).then(() => { 4324 imageSourceIncrementalSApi.updateData(splitBuff2, true, 0, splitBuff2.byteLength).then(() => { 4325 let pixelMap = imageSourceIncrementalSApi.createPixelMapSync() 4326 let imageInfo = pixelMap.getImageInfoSync() 4327 console.info('Succeeded in creating pixelMap') 4328 }).catch((error : BusinessError) => { 4329 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`) 4330 }) 4331}).catch((error : BusinessError) => { 4332 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`) 4333}) 4334``` 4335 4336## ImageSource 4337 4338Provides APIs to obtain image information. Before calling any API in **ImageSource**, you must use [createImageSource](#imagecreateimagesource) to create an **ImageSource** instance. 4339 4340### Properties 4341 4342**System capability**: SystemCapability.Multimedia.Image.ImageSource 4343 4344| Name | Type | Readable| Writable| Description | 4345| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | 4346| supportedFormats | Array\<string> | Yes | No | Supported formats, including .png, .jpeg, .bmp, .gif, .webp, .dng. and .heic<sup>12+</sup> (depending on the hardware).| 4347 4348### getImageInfo 4349 4350getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void 4351 4352Obtains information about an image with the specified index. This API uses an asynchronous callback to return the result. 4353 4354**Widget capability**: This API can be used in ArkTS widgets since API version 12. 4355 4356**Atomic service API**: This API can be used in atomic services since API version 11. 4357 4358**System capability**: SystemCapability.Multimedia.Image.ImageSource 4359 4360**Parameters** 4361 4362| Name | Type | Mandatory| Description | 4363| -------- | -------------------------------------- | ---- | ---------------------------------------- | 4364| index | number | Yes | Index of the image. | 4365| 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.| 4366 4367**Example** 4368 4369```ts 4370import { BusinessError } from '@kit.BasicServicesKit'; 4371 4372imageSourceApi.getImageInfo(0, (error: BusinessError, imageInfo: image.ImageInfo) => { 4373 if (error) { 4374 console.error(`Failed to obtain the image information.code is ${error.code}, message is ${error.message}`); 4375 } else { 4376 console.info('Succeeded in obtaining the image information.'); 4377 } 4378}) 4379``` 4380 4381### getImageInfo 4382 4383getImageInfo(callback: AsyncCallback\<ImageInfo>): void 4384 4385Obtains information about this image. This API uses an asynchronous callback to return the result. 4386 4387**Widget capability**: This API can be used in ArkTS widgets since API version 12. 4388 4389**Atomic service API**: This API can be used in atomic services since API version 11. 4390 4391**System capability**: SystemCapability.Multimedia.Image.ImageSource 4392 4393**Parameters** 4394 4395| Name | Type | Mandatory| Description | 4396| -------- | -------------------------------------- | ---- | ---------------------------------------- | 4397| 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.| 4398 4399**Example** 4400 4401```ts 4402import { BusinessError } from '@kit.BasicServicesKit'; 4403 4404imageSourceApi.getImageInfo((err: BusinessError, imageInfo: image.ImageInfo) => { 4405 if (err) { 4406 console.error(`Failed to obtain the image information.code is ${err.code}, message is ${err.message}`); 4407 } else { 4408 console.info('Succeeded in obtaining the image information.'); 4409 } 4410}) 4411``` 4412 4413### getImageInfo 4414 4415getImageInfo(index?: number): Promise\<ImageInfo> 4416 4417Obtains information about an image with the specified index. This API uses a promise to return the result. 4418 4419**Widget capability**: This API can be used in ArkTS widgets since API version 12. 4420 4421**Atomic service API**: This API can be used in atomic services since API version 11. 4422 4423**System capability**: SystemCapability.Multimedia.Image.ImageSource 4424 4425**Parameters** 4426 4427| Name| Type | Mandatory| Description | 4428| ----- | ------ | ---- | ------------------------------------- | 4429| index | number | No | Index of the image. If this parameter is not set, the default value **0** is used.| 4430 4431**Return value** 4432 4433| Type | Description | 4434| -------------------------------- | ---------------------- | 4435| Promise<[ImageInfo](#imageinfo)> | Promise used to return the image information.| 4436 4437**Example** 4438 4439```ts 4440import { BusinessError } from '@kit.BasicServicesKit'; 4441 4442imageSourceApi.getImageInfo(0) 4443 .then((imageInfo: image.ImageInfo) => { 4444 console.info('Succeeded in obtaining the image information.'); 4445 }).catch((error: BusinessError) => { 4446 console.error(`Failed to obtain the image information.code is ${error.code}, message is ${error.message}`); 4447 }) 4448``` 4449 4450### getImageInfoSync<sup>12+</sup> 4451 4452getImageInfoSync(index?: number): ImageInfo 4453 4454Obtains information about an image with the specified index. This API returns the result synchronously. 4455 4456**System capability**: SystemCapability.Multimedia.Image.ImageSource 4457 4458**Parameters** 4459 4460| Name| Type | Mandatory| Description | 4461| ----- | ------ | ---- | ------------------------------------- | 4462| index | number | No | Index of the image. If this parameter is not set, the default value **0** is used.| 4463 4464**Return value** 4465 4466| Type | Description | 4467| -------------------------------- | ---------------------- | 4468| [ImageInfo](#imageinfo) | Image information.| 4469 4470**Example** 4471 4472```ts 4473import { image } from '@kit.ImageKit'; 4474 4475const context: Context = getContext(); 4476// '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. 4477let filePath: string = context.filesDir + "/test.jpg"; 4478let imageSource = image.createImageSource(filePath); 4479let imageInfo = imageSource.getImageInfoSync(0); 4480if (imageInfo == undefined) { 4481 console.error('Failed to obtain the image information.'); 4482} else { 4483 console.info('Succeeded in obtaining the image information.'); 4484 console.info('imageInfo.size.height:' + imageInfo.size.height); 4485 console.info('imageInfo.size.width:' + imageInfo.size.width); 4486} 4487``` 4488 4489### getImageProperty<sup>11+</sup> 4490 4491getImageProperty(key:PropertyKey, options?: ImagePropertyOptions): Promise\<string> 4492 4493Obtains the value of a property with the specified index in this image. This API uses a promise to return the result. This API applies only to images that are in JPEG, PNG, or HEIF<sup>12+</sup> (depending on the hardware) format and contain the EXIF information. You can use the **supportedFormats** property to check whether the EXIF read/write operation for images in HEIF format is supported. 4494 4495**System capability**: SystemCapability.Multimedia.Image.ImageSource 4496 4497**Parameters** 4498 4499| Name | Type | Mandatory| Description | 4500| ------- | ---------------------------------------------------- | ---- | ------------------------------------ | 4501| key | [PropertyKey](#propertykey7) | Yes | Name of the property. | 4502| options | [ImagePropertyOptions](#imagepropertyoptions11) | No | Image properties, including the image index and default property value.| 4503 4504**Return value** 4505 4506| Type | Description | 4507| ---------------- | ----------------------------------------------------------------- | 4508| Promise\<string> | Promise used to return the property value. If the operation fails, the default value is returned.| 4509 4510**Error codes** 4511 4512For details about the error codes, see [Image Error Codes](errorcode-image.md). 4513 4514| ID| Error Message| 4515| ------- | --------------------------------------------| 4516| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 4517| 62980096 | The operation failed. | 4518| 62980103 | The image data is not supported. | 4519| 62980110 | The image source data is incorrect. | 4520| 62980111 | The image source data is incomplete. | 4521| 62980112 | The image format does not match. | 4522| 62980113 | Unknown image format. | 4523| 62980115 | Invalid image parameter. | 4524| 62980116| Failed to decode the image. | 4525| 62980118 | Failed to create the image plugin. | 4526| 62980122 | Failed to decode the image header. | 4527| 62980123| Images in EXIF format are not supported. | 4528| 62980135| The EXIF value is invalid. | 4529 4530**Example** 4531 4532```ts 4533import { BusinessError } from '@kit.BasicServicesKit'; 4534 4535let options: image.ImagePropertyOptions = { index: 0, defaultValue: '9999' } 4536imageSourceApi.getImageProperty(image.PropertyKey.BITS_PER_SAMPLE, options) 4537.then((data: string) => { 4538 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 4539}).catch((error: BusinessError) => { 4540 console.error('Failed to get the value of the specified attribute key of the image.'); 4541}) 4542``` 4543 4544### getImageProperty<sup>(deprecated)</sup> 4545 4546getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\<string> 4547 4548Obtains the value of a property with the specified index in this image. This API uses a promise to return the result. This API applies only to images that are in JPEG, PNG, or HEIF<sup>12+</sup> (depending on the hardware) format and contain the EXIF information. You can use the **supportedFormats** property to check whether the EXIF read/write operation for images in HEIF format is supported. 4549 4550> **NOTE** 4551> 4552> This API is deprecated since API version 11. You are advised to use [getImageProperty](#getimageproperty11). 4553 4554**System capability**: SystemCapability.Multimedia.Image.ImageSource 4555 4556**Parameters** 4557 4558| Name | Type | Mandatory| Description | 4559| ------- | ---------------------------------------------------- | ---- | ------------------------------------ | 4560| key | string | Yes | Name of the property. | 4561| options | [GetImagePropertyOptions](#getimagepropertyoptionsdeprecated) | No | Image properties, including the image index and default property value.| 4562 4563**Return value** 4564 4565| Type | Description | 4566| ---------------- | ----------------------------------------------------------------- | 4567| Promise\<string> | Promise used to return the property value. If the operation fails, the default value is returned.| 4568 4569**Example** 4570 4571```ts 4572import { BusinessError } from '@kit.BasicServicesKit'; 4573 4574imageSourceApi.getImageProperty("BitsPerSample") 4575 .then((data: string) => { 4576 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 4577 }).catch((error: BusinessError) => { 4578 console.error('Failed to get the value of the specified attribute key of the image.'); 4579 }) 4580``` 4581 4582### getImageProperty<sup>(deprecated)</sup> 4583 4584getImageProperty(key:string, callback: AsyncCallback\<string>): void 4585 4586Obtains the value of a property with the specified index in this image. This API uses an asynchronous callback to return the result. This API applies only to images that are in JPEG, PNG, or HEIF<sup>12+</sup> (depending on the hardware) format and contain the EXIF information. You can use the **supportedFormats** property to check whether the EXIF read/write operation for images in HEIF format is supported. 4587 4588> **NOTE** 4589> 4590> This API is deprecated since API version 11. You are advised to use [getImageProperty](#getimageproperty11). 4591 4592**System capability**: SystemCapability.Multimedia.Image.ImageSource 4593 4594**Parameters** 4595 4596| Name | Type | Mandatory| Description | 4597| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 4598| key | string | Yes | Name of the property. | 4599| 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.| 4600 4601**Example** 4602 4603```ts 4604import { BusinessError } from '@kit.BasicServicesKit'; 4605 4606imageSourceApi.getImageProperty("BitsPerSample", (error: BusinessError, data: string) => { 4607 if (error) { 4608 console.error('Failed to get the value of the specified attribute key of the image.'); 4609 } else { 4610 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 4611 } 4612}) 4613``` 4614 4615### getImageProperty<sup>(deprecated)</sup> 4616 4617getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCallback\<string>): void 4618 4619Obtains the value of a property in this image. This API uses an asynchronous callback to return the result. This API applies only to images that are in JPEG, PNG, or HEIF<sup>12+</sup> (depending on the hardware) format and contain the EXIF information. You can use the **supportedFormats** property to check whether the EXIF read/write operation for images in HEIF format is supported. 4620 4621> **NOTE** 4622> 4623> This API is deprecated since API version 11. You are advised to use [getImageProperty](#getimageproperty11). 4624 4625**System capability**: SystemCapability.Multimedia.Image.ImageSource 4626 4627**Parameters** 4628 4629| Name | Type | Mandatory| Description | 4630| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------- | 4631| key | string | Yes | Name of the property. | 4632| options | [GetImagePropertyOptions](#getimagepropertyoptionsdeprecated) | Yes | Image properties, including the image index and default property value. | 4633| 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.| 4634 4635**Example** 4636 4637```ts 4638import { BusinessError } from '@kit.BasicServicesKit'; 4639 4640let property: image.GetImagePropertyOptions = { index: 0, defaultValue: '9999' } 4641imageSourceApi.getImageProperty("BitsPerSample", property, (error: BusinessError, data: string) => { 4642 if (error) { 4643 console.error('Failed to get the value of the specified attribute key of the image.'); 4644 } else { 4645 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 4646 } 4647}) 4648``` 4649 4650### getImageProperties<sup>12+</sup> 4651 4652getImageProperties(key: Array<PropertyKey>): Promise<Record<PropertyKey, string|null>> 4653 4654Obtains the values of properties with the given names in this image. This API uses a promise to return the result. This API applies only to images that are in JPEG, PNG, or HEIF<sup>12+</sup> (depending on the hardware) format and contain the EXIF information. You can use the **supportedFormats** property to check whether the EXIF read/write operation for images in HEIF format is supported. 4655 4656**System capability**: SystemCapability.Multimedia.Image.ImageSource 4657 4658**Parameters** 4659 4660| Name | Type | Mandatory| Description | 4661| ------- | ---------------------------------------------------- | ---- | ------------------------------------ | 4662| key | Array\<[PropertyKey](#propertykey7)> | Yes | Array of properties names. | 4663 4664**Return value** 4665 4666| Type | Description | 4667| ---------------- | ----------------------------------------------------------------- | 4668| Promise\<Record<[PropertyKey](#propertykey7), string \| null>> | Promise used to return the property values. If the operation fails, **null** is returned.| 4669 4670**Error codes** 4671 4672For details about the error codes, see [Image Error Codes](errorcode-image.md). 4673 4674| ID| Error Message| 4675| ------- | --------------------------------------------| 4676| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 4677| 62980096| The operation failed. | 4678| 62980110| The image source data is incorrect. | 4679| 62980113| Unknown image format. | 4680| 62980116| Failed to decode the image. | 4681 4682**Example** 4683 4684```ts 4685import { image } from '@kit.ImageKit'; 4686import { BusinessError } from '@kit.BasicServicesKit'; 4687 4688let key = [image.PropertyKey.IMAGE_WIDTH, image.PropertyKey.IMAGE_LENGTH]; 4689imageSourceApi.getImageProperties(key).then((data) => { 4690 console.info(JSON.stringify(data)); 4691}).catch((err: BusinessError) => { 4692 console.error(JSON.stringify(err)); 4693}); 4694``` 4695 4696### modifyImageProperty<sup>11+</sup> 4697 4698modifyImageProperty(key: PropertyKey, value: string): Promise\<void> 4699 4700Modifies the value of a property in this image. This API uses a promise to return the result. This API applies only to images that are in JPEG, PNG, or HEIF<sup>12+</sup> (depending on the hardware) format and contain the EXIF information. You can use the **supportedFormats** property to check whether the EXIF read/write operation for images in HEIF format is supported. 4701 4702> **NOTE** 4703> 4704> 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. 4705 4706**System capability**: SystemCapability.Multimedia.Image.ImageSource 4707 4708**Parameters** 4709 4710| Name | Type | Mandatory| Description | 4711| ------- | ------ | ---- | ------------ | 4712| key | [PropertyKey](#propertykey7) | Yes | Name of the property.| 4713| value | string | Yes | New value of the property. | 4714 4715**Return value** 4716 4717| Type | Description | 4718| -------------- | --------------------------- | 4719| Promise\<void> | Promise that returns no value.| 4720 4721**Error codes** 4722 4723For details about the error codes, see [Image Error Codes](errorcode-image.md). 4724 4725| ID| Error Message| 4726| ------- | --------------------------------------------| 4727| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; | 4728| 62980123| The image does not support EXIF decoding. | 4729| 62980133| The EXIF data is out of range. | 4730| 62980135| The EXIF value is invalid. | 4731| 62980146| The EXIF data failed to be written to the file. | 4732 4733**Example** 4734 4735```ts 4736import { BusinessError } from '@kit.BasicServicesKit'; 4737 4738imageSourceApi.modifyImageProperty(image.PropertyKey.IMAGE_WIDTH, "120").then(() => { 4739 imageSourceApi.getImageProperty(image.PropertyKey.IMAGE_WIDTH).then((width: string) => { 4740 console.info(`ImageWidth is :${width}`); 4741 }).catch((error: BusinessError) => { 4742 console.error('Failed to get the Image Width.'); 4743 }) 4744}).catch((error: BusinessError) => { 4745 console.error('Failed to modify the Image Width'); 4746}) 4747``` 4748 4749### modifyImageProperty<sup>(deprecated)</sup> 4750 4751modifyImageProperty(key: string, value: string): Promise\<void> 4752 4753Modifies the value of a property in this image. This API uses a promise to return the result. This API applies only to images that are in JPEG, PNG, or HEIF<sup>12+</sup> (depending on the hardware) format and contain the EXIF information. You can use the **supportedFormats** property to check whether the EXIF read/write operation for images in HEIF format is supported. 4754 4755> **NOTE** 4756> 4757> 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. 4758> 4759> This API is deprecated since API version 11. You are advised to use [modifyImageProperty](#modifyimageproperty11). 4760 4761**System capability**: SystemCapability.Multimedia.Image.ImageSource 4762 4763**Parameters** 4764 4765| Name | Type | Mandatory| Description | 4766| ------- | ------ | ---- | ------------ | 4767| key | string | Yes | Name of the property.| 4768| value | string | Yes | New value of the property. | 4769 4770**Return value** 4771 4772| Type | Description | 4773| -------------- | --------------------------- | 4774| Promise\<void> | Promise that returns no value.| 4775 4776**Example** 4777 4778```ts 4779import { BusinessError } from '@kit.BasicServicesKit'; 4780 4781imageSourceApi.modifyImageProperty("ImageWidth", "120").then(() => { 4782 imageSourceApi.getImageProperty("ImageWidth").then((width: string) => { 4783 console.info(`ImageWidth is :${width}`); 4784 }).catch((error: BusinessError) => { 4785 console.error('Failed to get the Image Width.'); 4786 }) 4787}).catch((error: BusinessError) => { 4788 console.error('Failed to modify the Image Width'); 4789}) 4790``` 4791 4792### modifyImageProperty<sup>(deprecated)</sup> 4793 4794modifyImageProperty(key: string, value: string, callback: AsyncCallback\<void>): void 4795 4796Modifies the value of a property in this image. This API uses an asynchronous callback to return the result. This API applies only to images that are in JPEG, PNG, or HEIF<sup>12+</sup> (depending on the hardware) format and contain the EXIF information. You can use the **supportedFormats** property to check whether the EXIF read/write operation for images in HEIF format is supported. 4797 4798> **NOTE** 4799> 4800> 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. 4801> 4802>This API is deprecated since API version 11. You are advised to use [modifyImageProperty](#modifyimageproperty11). 4803 4804**System capability**: SystemCapability.Multimedia.Image.ImageSource 4805 4806**Parameters** 4807 4808| Name | Type | Mandatory| Description | 4809| -------- | ------------------- | ---- | ------------------------------ | 4810| key | string | Yes | Name of the property. | 4811| value | string | Yes | New value of the property. | 4812| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 4813 4814**Example** 4815 4816```ts 4817import { BusinessError } from '@kit.BasicServicesKit'; 4818 4819imageSourceApi.modifyImageProperty("ImageWidth", "120", (err: BusinessError) => { 4820 if (err) { 4821 console.error(`Failed to modify the Image Width.code is ${err.code}, message is ${err.message}`); 4822 } else { 4823 console.info('Succeeded in modifying the Image Width.'); 4824 } 4825}) 4826``` 4827 4828### modifyImageProperties<sup>12+</sup> 4829 4830modifyImageProperties(records: Record<PropertyKey, string|null>): Promise\<void> 4831 4832Modifies the values of properties in this image. This API uses a promise to return the result. This API applies only to images that are in JPEG, PNG, or HEIF<sup>12+</sup> (depending on the hardware) format and contain the EXIF information. You can use the **supportedFormats** property to check whether the EXIF read/write operation for images in HEIF format is supported. 4833 4834> **NOTE** 4835> 4836> 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. 4837> 4838 4839**System capability**: SystemCapability.Multimedia.Image.ImageSource 4840 4841**Parameters** 4842 4843| Name | Type | Mandatory| Description | 4844| ------- | ------ | ---- | ------------ | 4845| records | Record<[PropertyKey](#propertykey7), string \| null> | Yes | Array of property names and property values.| 4846 4847**Return value** 4848 4849| Type | Description | 4850| -------------- | --------------------------- | 4851| Promise\<void> | Promise that returns no value.| 4852 4853**Error codes** 4854 4855For details about the error codes, see [Image Error Codes](errorcode-image.md). 4856 4857| ID| Error Message| 4858| ------- | --------------------------------------------| 4859| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 4860| 62980123| The image does not support EXIF decoding. | 4861| 62980133| The EXIF data is out of range. | 4862| 62980135| The EXIF value is invalid. | 4863| 62980146| The EXIF data failed to be written to the file. | 4864 4865**Example** 4866 4867```ts 4868import { image } from '@kit.ImageKit'; 4869import { BusinessError } from '@kit.BasicServicesKit'; 4870 4871let keyValues: Record<PropertyKey, string|null> = { 4872 [image.PropertyKey.IMAGE_WIDTH] : "1024", 4873 [image.PropertyKey.IMAGE_LENGTH] : "1024" 4874}; 4875let checkKey = [image.PropertyKey.IMAGE_WIDTH, image.PropertyKey.IMAGE_LENGTH]; 4876imageSourceApi.modifyImageProperties(keyValues).then(() => { 4877 imageSourceApi.getImageProperties(checkKey).then((data) => { 4878 console.info(JSON.stringify(data)); 4879 }).catch((err: BusinessError) => { 4880 console.error(JSON.stringify(err)); 4881 }); 4882}).catch((err: BusinessError) => { 4883 console.error(JSON.stringify(err)); 4884}); 4885``` 4886 4887### updateData<sup>9+</sup> 4888 4889updateData(buf: ArrayBuffer, isFinished: boolean, offset: number, length: number): Promise\<void> 4890 4891Updates incremental data. This API uses a promise to return the result. 4892 4893**System capability**: SystemCapability.Multimedia.Image.ImageSource 4894 4895**Parameters** 4896 4897| Name | Type | Mandatory| Description | 4898| ---------- | ----------- | ---- | ------------ | 4899| buf | ArrayBuffer | Yes | Incremental data. | 4900| isFinished | boolean | Yes | Whether the update is complete.| 4901| offset | number | Yes | Offset for data reading. | 4902| length | number | Yes | Array length. | 4903 4904**Return value** 4905 4906| Type | Description | 4907| -------------- | -------------------------- | 4908| Promise\<void> | Promise that returns no value.| 4909 4910**Example** 4911 4912```ts 4913import { BusinessError } from '@kit.BasicServicesKit'; 4914 4915const array: ArrayBuffer = new ArrayBuffer(100); 4916imageSourceApi.updateData(array, false, 0, 10).then(() => { 4917 console.info('Succeeded in updating data.'); 4918}).catch((err: BusinessError) => { 4919 console.error(`Failed to update data.code is ${err.code},message is ${err.message}`); 4920}) 4921``` 4922 4923 4924### updateData<sup>9+</sup> 4925 4926updateData(buf: ArrayBuffer, isFinished: boolean, offset: number, length: number, callback: AsyncCallback\<void>): void 4927 4928Updates incremental data. This API uses an asynchronous callback to return the result. 4929 4930**System capability**: SystemCapability.Multimedia.Image.ImageSource 4931 4932**Parameters** 4933 4934| Name | Type | Mandatory| Description | 4935| ---------- | ------------------- | ---- | -------------------- | 4936| buf | ArrayBuffer | Yes | Incremental data. | 4937| isFinished | boolean | Yes | Whether the update is complete. | 4938| offset | number | Yes | Offset for data reading. | 4939| length | number | Yes | Size of the array. | 4940| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 4941 4942**Example** 4943 4944```ts 4945import { BusinessError } from '@kit.BasicServicesKit'; 4946 4947const array: ArrayBuffer = new ArrayBuffer(100); 4948imageSourceApi.updateData(array, false, 0, 10, (err: BusinessError) => { 4949 if (err) { 4950 console.error(`Failed to update data.code is ${err.code},message is ${err.message}`); 4951 } else { 4952 console.info('Succeeded in updating data.'); 4953 } 4954}) 4955``` 4956 4957### createPicture<sup>13+</sup> 4958 4959createPicture(options?: DecodingOptionsForPicture): Promise\<Picture> 4960 4961Creates a **Picture** object based on decoding options. This API uses a promise to return the result. 4962 4963**System capability**: SystemCapability.Multimedia.Image.ImageSource 4964 4965**Parameters** 4966 4967| Name | Type | Mandatory| Description | 4968| ------- | ------------------------------------------------------ | ---- | ---------- | 4969| options | [DecodingOptionsForPicture](#decodingoptionsforpicture13) | No | Decoding options.| 4970 4971**Return value** 4972 4973| Type | Description | 4974| ---------------------------- | -------------------------- | 4975| Promise\<[Picture](#picture13)> | Promise used to return the **Picture** object.| 4976 4977**Error codes** 4978 4979For details about the error codes, see [Image Error Codes](errorcode-image.md). 4980 4981| ID| Error Message | 4982| -------- | ------------------------------------------------------------ | 4983| 401 | Parameter error.Possible causes: 1.Mandatory parameters are left unspecified.2.Incorrect parameter types; 3.Parameter verification failed. | 4984| 7700301 | Decode failed. | 4985 4986**Example** 4987 4988```ts 4989import { image } from '@kit.ImageKit'; 4990 4991async function CreatePicture() { 4992 let options: image.DecodingOptionsForPicture = { 4993 desiredAuxiliaryPictures: [image.AuxiliaryPictureType.GAINMAP] // GAINMAP indicates the type of the auxiliary picture to be decoded. 4994 }; 4995 let pictureObj: image.Picture = await imageSourceApi.createPicture(options); 4996 if (pictureObj != null) { 4997 console.info('Create picture succeeded'); 4998 } else { 4999 console.info('Create picture failed'); 5000 } 5001} 5002``` 5003 5004### createPixelMap<sup>7+</sup> 5005 5006createPixelMap(options?: DecodingOptions): Promise\<PixelMap> 5007 5008Creates a **PixelMap** object based on decoding options. This API uses a promise to return the result. 5009 5010**Widget capability**: This API can be used in ArkTS widgets since API version 12. 5011 5012**Atomic service API**: This API can be used in atomic services since API version 11. 5013 5014**System capability**: SystemCapability.Multimedia.Image.ImageSource 5015 5016**Parameters** 5017 5018| Name | Type | Mandatory| Description | 5019| ------- | ------------------------------------ | ---- | ---------- | 5020| options | [DecodingOptions](#decodingoptions7) | No | Decoding options.| 5021 5022**Return value** 5023 5024| Type | Description | 5025| -------------------------------- | --------------------- | 5026| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.| 5027 5028**Example** 5029 5030```ts 5031import { BusinessError } from '@kit.BasicServicesKit'; 5032 5033imageSourceApi.createPixelMap().then((pixelMap: image.PixelMap) => { 5034 console.info('Succeeded in creating pixelMap object through image decoding parameters.'); 5035}).catch((error: BusinessError) => { 5036 console.error('Failed to create pixelMap object through image decoding parameters.'); 5037}) 5038``` 5039 5040### createPixelMap<sup>7+</sup> 5041 5042createPixelMap(callback: AsyncCallback\<PixelMap>): void 5043 5044Creates a **PixelMap** object based on the default parameters. This API uses an asynchronous callback to return the result. 5045 5046**Widget capability**: This API can be used in ArkTS widgets since API version 12. 5047 5048**Atomic service API**: This API can be used in atomic services since API version 11. 5049 5050**System capability**: SystemCapability.Multimedia.Image.ImageSource 5051 5052**Parameters** 5053 5054| Name | Type | Mandatory| Description | 5055| -------- | ------------------------------------- | ---- | -------------------------- | 5056| 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.| 5057 5058**Example** 5059 5060```ts 5061import { BusinessError } from '@kit.BasicServicesKit'; 5062 5063imageSourceApi.createPixelMap((err: BusinessError, pixelMap: image.PixelMap) => { 5064 if (err) { 5065 console.error(`Failed to create pixelMap.code is ${err.code},message is ${err.message}`); 5066 } else { 5067 console.info('Succeeded in creating pixelMap object.'); 5068 } 5069}) 5070``` 5071 5072### createPixelMap<sup>7+</sup> 5073 5074createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): void 5075 5076Creates a **PixelMap** object based on decoding options. This API uses an asynchronous callback to return the result. 5077 5078**Widget capability**: This API can be used in ArkTS widgets since API version 12. 5079 5080**Atomic service API**: This API can be used in atomic services since API version 11. 5081 5082**System capability**: SystemCapability.Multimedia.Image.ImageSource 5083 5084**Parameters** 5085 5086| Name | Type | Mandatory| Description | 5087| -------- | ------------------------------------- | ---- | -------------------------- | 5088| options | [DecodingOptions](#decodingoptions7) | Yes | Decoding options. | 5089| 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.| 5090 5091**Example** 5092 5093```ts 5094import { BusinessError } from '@kit.BasicServicesKit'; 5095 5096let decodingOptions: image.DecodingOptions = { 5097 sampleSize: 1, 5098 editable: true, 5099 desiredSize: { width: 1, height: 2 }, 5100 rotate: 10, 5101 desiredPixelFormat: image.PixelMapFormat.RGBA_8888, 5102 desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 }, 5103 index: 0 5104}; 5105imageSourceApi.createPixelMap(decodingOptions, (err: BusinessError, pixelMap: image.PixelMap) => { 5106 if (err) { 5107 console.error(`Failed to create pixelMap.code is ${err.code},message is ${err.message}`); 5108 } else { 5109 console.info('Succeeded in creating pixelMap object.'); 5110 } 5111}) 5112``` 5113 5114### createPixelMapSync<sup>12+</sup> 5115 5116createPixelMapSync(options?: DecodingOptions): PixelMap 5117 5118Creates a **PixelMap** object based on decoding options. This API returns the result synchronously. 5119 5120**System capability**: SystemCapability.Multimedia.Image.ImageSource 5121 5122**Parameters** 5123 5124| Name | Type | Mandatory| Description | 5125| -------- | ------------------------------------- | ---- | -------------------------- | 5126| options | [DecodingOptions](#decodingoptions7) | No | Decoding options. | 5127 5128**Return value** 5129 5130| Type | Description | 5131| -------------------------------- | --------------------- | 5132| [PixelMap](#pixelmap7) | **PixelMap** object.| 5133 5134**Example** 5135 5136```ts 5137import { image } from '@kit.ImageKit'; 5138 5139const context: Context = getContext(); 5140// '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. 5141let filePath: string = context.filesDir + "/test.jpg"; 5142let imageSource = image.createImageSource(filePath); 5143let decodingOptions: image.DecodingOptions = { 5144 sampleSize: 1, 5145 editable: true, 5146 desiredSize: { width: 1, height: 2 }, 5147 rotate: 10, 5148 desiredPixelFormat: image.PixelMapFormat.RGBA_8888, 5149 desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 }, 5150 index: 0 5151}; 5152let pixelmap = imageSource.createPixelMapSync(decodingOptions); 5153if (pixelmap != undefined) { 5154 console.info('Succeeded in creating pixelMap object.'); 5155} else { 5156 console.info('Failed to create pixelMap.'); 5157} 5158``` 5159 5160### createPixelMapList<sup>10+</sup> 5161 5162createPixelMapList(options?: DecodingOptions): Promise<Array\<PixelMap>> 5163 5164Creates an array of **PixelMap** objects based on decoding options. 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. 5165 5166> **NOTE** 5167> 5168> This function decodes all frames at once. If the number of frames is high or the size of individual frames is large, it can lead to significant memory usage. In these cases, you are advised to use the** Image** component for displaying animations. The **Image** component decodes frames one by one, which uses less memory than this function. 5169 5170**System capability**: SystemCapability.Multimedia.Image.ImageSource 5171 5172**Parameters** 5173 5174| Name | Type | Mandatory| Description | 5175| -------- | ------------------------------------- | ---- | -------------------------- | 5176| options | [DecodingOptions](#decodingoptions7) | No | Decoding options. | 5177 5178**Return value** 5179 5180| Type | Description | 5181| -------------------------------- | --------------------- | 5182| Promise<Array<[PixelMap](#pixelmap7)>> | Promise used to return an array of **PixelMap** objects.| 5183 5184**Error codes** 5185 5186For details about the error codes, see [Image Error Codes](errorcode-image.md). 5187 5188| ID| Error Message| 5189| ------- | --------------------------------------------| 5190| 62980096| The operation failed. | 5191| 62980099 | The shared memory data is abnormal. | 5192| 62980101 | The image data is abnormal. | 5193| 62980103| The image data is not supported. | 5194| 62980106 | The image is too large. | 5195| 62980109 | Failed to crop the image. | 5196| 62980110| The image source data is incorrect. | 5197| 62980111| The image source data is incomplete. | 5198| 62980112 | The image format does not match. | 5199| 62980113 | Unknown image format. | 5200| 62980115 | Invalid image parameter. | 5201| 62980116 | Failed to decode the image. | 5202| 62980118| Failed to create the image plugin. | 5203| 62980122 | Failed to decode the image header. | 5204| 62980137 | Invalid media operation. | 5205| 62980173 | The DMA memory does not exist. | 5206| 62980174 | The DMA memory data is abnormal. | 5207 5208**Example** 5209 5210```ts 5211import { BusinessError } from '@kit.BasicServicesKit'; 5212 5213let decodeOpts: image.DecodingOptions = { 5214 sampleSize: 1, 5215 editable: true, 5216 desiredSize: { width: 198, height: 202 }, 5217 rotate: 0, 5218 desiredPixelFormat: image.PixelMapFormat.RGBA_8888, 5219 index: 0, 5220}; 5221imageSourceApi.createPixelMapList(decodeOpts).then((pixelMapList: Array<image.PixelMap>) => { 5222 console.info('Succeeded in creating pixelMapList object.'); 5223}).catch((err: BusinessError) => { 5224 console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`); 5225}) 5226``` 5227 5228### createPixelMapList<sup>10+</sup> 5229 5230createPixelMapList(callback: AsyncCallback<Array\<PixelMap>>): void 5231 5232Creates 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. 5233 5234> **NOTE** 5235> 5236> This function decodes all frames at once. If the number of frames is high or the size of individual frames is large, it can lead to significant memory usage. In these cases, you are advised to use the** Image** component for displaying animations. The **Image** component decodes frames one by one, which uses less memory than this function. 5237 5238**System capability**: SystemCapability.Multimedia.Image.ImageSource 5239 5240**Parameters** 5241 5242| Name | Type | Mandatory| Description | 5243| -------- | ------------------------------------- | ---- | -------------------------- | 5244| 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. | 5245 5246**Error codes** 5247 5248For details about the error codes, see [Image Error Codes](errorcode-image.md). 5249 5250| ID| Error Message| 5251| ------- | --------------------------------------------| 5252| 62980096 | The operation failed. | 5253| 62980099 | The shared memory data is abnormal. | 5254| 62980101 | The image data is abnormal. | 5255| 62980103 | The image data is not supported. | 5256| 62980106 | The image is too large. | 5257| 62980109 | Failed to crop the image. | 5258| 62980110 | The image source data is incorrect. | 5259| 62980111 | The image source data is incomplete. | 5260| 62980112 | The image format does not match. | 5261| 62980113 | Unknown image format. | 5262| 62980115 | Invalid image parameter. | 5263| 62980116 | Failed to decode the image. | 5264| 62980118 | Failed to create the image plugin. | 5265| 62980122 | Failed to decode the image header. | 5266| 62980137 | Invalid media operation. | 5267| 62980173 | The DMA memory does not exist. | 5268| 62980174 | The DMA memory data is abnormal. | 5269 5270**Example** 5271 5272```ts 5273import { BusinessError } from '@kit.BasicServicesKit'; 5274 5275imageSourceApi.createPixelMapList((err: BusinessError, pixelMapList: Array<image.PixelMap>) => { 5276 if (err) { 5277 console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`); 5278 } else { 5279 console.info('Succeeded in creating pixelMapList object.'); 5280 } 5281}) 5282``` 5283 5284### createPixelMapList<sup>10+</sup> 5285 5286createPixelMapList(options: DecodingOptions, callback: AsyncCallback<Array\<PixelMap>>): void 5287 5288Creates an array of **PixelMap** objects based on decoding options. 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. 5289 5290> **NOTE** 5291> 5292> This function decodes all frames at once. If the number of frames is high or the size of individual frames is large, it can lead to significant memory usage. In these cases, you are advised to use the** Image** component for displaying animations. The **Image** component decodes frames one by one, which uses less memory than this function. 5293 5294**System capability**: SystemCapability.Multimedia.Image.ImageSource 5295 5296**Parameters** 5297 5298| Name | Type | Mandatory| Description | 5299| -------- | -------------------- | ---- | ---------------------------------- | 5300| options | [DecodingOptions](#decodingoptions7) | Yes| Decoding options.| 5301| 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. | 5302 5303**Error codes** 5304 5305For details about the error codes, see [Image Error Codes](errorcode-image.md). 5306 5307| ID| Error Message| 5308| ------- | --------------------------------------------| 5309| 62980096 | The operation failed. | 5310| 62980099 | The shared memory data is abnormal. | 5311| 62980101 | The image data is abnormal. | 5312| 62980103 | The image data is not supported. | 5313| 62980106 | The image is too large. | 5314| 62980109 | Failed to crop the image. | 5315| 62980110 | The image source data is incorrect. | 5316| 62980111 | The image source data is incomplete. | 5317| 62980112 | The image format does not match. | 5318| 62980113 | Unknown image format. | 5319| 62980115 | Invalid image parameter. | 5320| 62980116 | Failed to decode the image. | 5321| 62980118 | Failed to create the image plugin. | 5322| 62980122 | Failed to decode the image header. | 5323| 62980137 | Invalid media operation. | 5324| 62980173 | The DMA memory does not exist. | 5325| 62980174 | The DMA memory data is abnormal. | 5326 5327**Example** 5328 5329```ts 5330import { BusinessError } from '@kit.BasicServicesKit'; 5331 5332let decodeOpts: image.DecodingOptions = { 5333 sampleSize: 1, 5334 editable: true, 5335 desiredSize: { width: 198, height: 202 }, 5336 rotate: 0, 5337 desiredPixelFormat: image.PixelMapFormat.RGBA_8888, 5338 index: 0, 5339}; 5340imageSourceApi.createPixelMapList(decodeOpts, (err: BusinessError, pixelMapList: Array<image.PixelMap>) => { 5341 if (err) { 5342 console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`); 5343 } else { 5344 console.info('Succeeded in creating pixelMapList object.'); 5345 } 5346}) 5347``` 5348 5349### createPixelMapUsingAllocator<sup>15+</sup> 5350 5351createPixelMapUsingAllocator(options?: DecodingOptions, allocatorType?: AllocatorType): Promise\<PixelMap> 5352 5353Creates a **PixelMap** object based on decoding options and memory type. This API uses a Promise to return the result. 5354 5355**System capability**: SystemCapability.Multimedia.Image.ImageSource 5356 5357**Parameters** 5358 5359| Name | Type | Mandatory| Description | 5360| ------------- | ------------------------------------ | ---- | ------------------------ | 5361| options | [DecodingOptions](#decodingoptions7) | No | Decoding options. | 5362| allocatorType | [AllocatorType](#allocatortype15) | No | Type of the memory. The default value is **AllocatorType.AUTO**.| 5363 5364**Return value** 5365 5366| Type | Description | 5367| -------------------------------- | --------------------------- | 5368| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.| 5369 5370**Error codes** 5371 5372For details about the error codes, see [Image Error Codes](errorcode-image.md). 5373 5374| ID| Error Message | 5375| -------- | ------------------------------------------------------------ | 5376| 401 | Parameter error.Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types;3.Parameter verification failed. | 5377| 7700101 | Bad source. | 5378| 7700102 | Unsupported mimetype. | 5379| 7700103 | Image too large. | 5380| 7700201 | Unsupported allocator type, e.g., use share memory to decode a HDR image as only DMA supported hdr metadata. | 5381| 7700203 | Unsupported options, e.g., cannot convert image into desired pixel format. | 5382| 7700301 | Decode failed. | 5383| 7700302 | Memory allocation failed. | 5384 5385**Example** 5386 5387```ts 5388import image from '@ohos.multimedia.image'; 5389 5390const context: Context = getContext(this); 5391// '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. 5392let filePath: string = context.filesDir + "/test.jpg"; 5393let imageSource = image.createImageSource(filePath); 5394let decodingOptions: image.DecodingOptions = { 5395 editable: true, 5396 desiredSize: { width: 3072, height: 4096 }, 5397 rotate: 10, 5398 desiredPixelFormat: image.PixelMapFormat.RGBA_8888, 5399 desiredRegion: { size: { height: 3072, width: 4096 }, x: 0, y: 0 }, 5400 index: 0 5401}; 5402let pixelmap = await imageSource.createPixelMapUsingAllocator(decodingOptions, image.AllocatorType.AUTO); 5403if (pixelmap != undefined) { 5404 console.info('Succeeded in creating pixelMap object.'); 5405} else { 5406 console.info('Failed to create pixelMap.'); 5407} 5408``` 5409 5410### createPixelMapUsingAllocatorSync<sup>15+</sup> 5411 5412createPixelMapUsingAllocatorSync(options?: DecodingOptions, allocatorType?: AllocatorType): PixelMap 5413 5414Creates a **PixelMap** object based on decoding options and memory type. This API returns the result synchronously. 5415 5416**System capability**: SystemCapability.Multimedia.Image.ImageSource 5417 5418**Parameters** 5419 5420| Name | Type | Mandatory| Description | 5421| ------------- | ------------------------------------ | ---- | ------------------------ | 5422| options | [DecodingOptions](#decodingoptions7) | No | Decoding options. | 5423| allocatorType | [AllocatorType](#allocatortype15) | No | Type of the memory. The default value is **AllocatorType.AUTO**.| 5424 5425**Return value** 5426 5427| Type | Description | 5428| ---------------------- | ---------------------- | 5429| [PixelMap](#pixelmap7) | **PixelMap** object.| 5430 5431**Error codes** 5432 5433For details about the error codes, see [Image Error Codes](errorcode-image.md). 5434 5435| ID| Error Message | 5436| -------- | ------------------------------------------------------------ | 5437| 401 | Parameter error.Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types;3.Parameter verification failed. | 5438| 7700101 | Bad source. | 5439| 7700102 | Unsupported mimetype. | 5440| 7700103 | Image too large. | 5441| 7700201 | Unsupported allocator type, e.g., use share memory to decode a HDR image as only DMA supported hdr metadata. | 5442| 7700203 | Unsupported options, e.g., cannot convert image into desired pixel format. | 5443| 7700301 | Decode failed. | 5444| 7700302 | Memory allocation failed. | 5445 5446**Example** 5447 5448```ts 5449import image from '@ohos.multimedia.image'; 5450 5451const context: Context = getContext(this); 5452// '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. 5453let filePath: string = context.filesDir + "/test.jpg"; 5454let imageSource = image.createImageSource(filePath); 5455let decodingOptions: image.DecodingOptions = { 5456 editable: true, 5457 desiredSize: { width: 3072, height: 4096 }, 5458 rotate: 10, 5459 desiredPixelFormat: image.PixelMapFormat.RGBA_8888, 5460 desiredRegion: { size: { height: 3072, width: 4096 }, x: 0, y: 0 }, 5461 index: 0 5462}; 5463let pixelmap = imageSource.createPixelMapUsingAllocatorSync(decodingOptions, image.AllocatorType.AUTO); 5464if (pixelmap != undefined) { 5465 console.info('Succeeded in creating pixelMap object.'); 5466} else { 5467 console.info('Failed to create pixelMap.'); 5468} 5469``` 5470 5471### getDelayTimeList<sup>10+</sup> 5472 5473getDelayTimeList(callback: AsyncCallback<Array\<number>>): void 5474 5475Obtains 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. 5476 5477**System capability**: SystemCapability.Multimedia.Image.ImageSource 5478 5479**Parameters** 5480 5481| Name | Type | Mandatory| Description | 5482| -------- | -------------------- | ---- | ---------------------------------- | 5483| 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.| 5484 5485**Error codes** 5486 5487For details about the error codes, see [Image Error Codes](errorcode-image.md). 5488 5489| ID| Error Message| 5490| ------- | --------------------------------------------| 5491| 62980096| The operation failed. | 5492| 62980110| The image source data is incorrect. | 5493| 62980111| The image source data is incomplete. | 5494| 62980112 | The image format does not match. | 5495| 62980113| Unknown image format. | 5496| 62980115 | Invalid image parameter. | 5497| 62980116| Failed to decode the image. | 5498| 62980118| Failed to create the image plugin. | 5499| 62980122| Failed to decode the image header. | 5500| 62980137 | Invalid media operation. | 5501| 62980149 | Invalid MIME type for the image source. | 5502 5503**Example** 5504 5505```ts 5506import { BusinessError } from '@kit.BasicServicesKit'; 5507 5508imageSourceApi.getDelayTimeList((err: BusinessError, delayTimes: Array<number>) => { 5509 if (err) { 5510 console.error(`Failed to get delayTimes object.code is ${err.code},message is ${err.message}`); 5511 } else { 5512 console.info('Succeeded in getting delayTimes object.'); 5513 } 5514}) 5515``` 5516 5517### getDelayTimeList<sup>10+</sup> 5518 5519getDelayTimeList(): Promise<Array\<number>> 5520 5521Obtains 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. 5522 5523**System capability**: SystemCapability.Multimedia.Image.ImageSource 5524 5525**Return value** 5526 5527| Type | Description | 5528| -------------- | --------------------------- | 5529| Promise<Array\<number>> | Promise used to return an array of delay times.| 5530 5531**Error codes** 5532 5533For details about the error codes, see [Image Error Codes](errorcode-image.md). 5534 5535| ID| Error Message| 5536| ------- | --------------------------------------------| 5537| 62980096 | The operation failed. | 5538| 62980110 | The image source data is incorrect. | 5539| 62980111 | The image source data is incomplete. | 5540| 62980112 | The image format does not match. | 5541| 62980113 | Unknown image format. | 5542| 62980115 | Invalid image parameter. | 5543| 62980116 | Failed to decode the image. | 5544| 62980118 | Failed to create the image plugin. | 5545| 62980122 | Failed to decode the image header. | 5546| 62980137 | Invalid media operation. | 5547| 62980149 | Invalid MIME type for the image source. | 5548 5549**Example** 5550 5551```ts 5552import { BusinessError } from '@kit.BasicServicesKit'; 5553 5554imageSourceApi.getDelayTimeList().then((delayTimes: Array<number>) => { 5555 console.info('Succeeded in getting delayTimes object.'); 5556}).catch((err: BusinessError) => { 5557 console.error(`Failed to get delayTimes object.code is ${err.code},message is ${err.message}`); 5558}) 5559``` 5560 5561### getFrameCount<sup>10+</sup> 5562 5563getFrameCount(callback: AsyncCallback\<number>): void 5564 5565Obtains the number of frames. This API uses an asynchronous callback to return the result. 5566 5567**System capability**: SystemCapability.Multimedia.Image.ImageSource 5568 5569**Parameters** 5570 5571| Name | Type | Mandatory| Description | 5572| -------- | -------------------- | ---- | ---------------------------------- | 5573| 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.| 5574 5575**Error codes** 5576 5577For details about the error codes, see [Image Error Codes](errorcode-image.md). 5578 5579| ID| Error Message| 5580| ------- | --------------------------------------------| 5581| 62980096| The operation failed. | 5582| 62980110| The image source data is incorrect. | 5583| 62980111| The image source data is incomplete. | 5584| 62980112| The image format does not match. | 5585| 62980113| Unknown image format. | 5586| 62980115| Invalid image parameter. | 5587| 62980116| Failed to decode the image. | 5588| 62980118| Failed to create the image plugin. | 5589| 62980122| Failed to decode the image header. | 5590| 62980137| Invalid media operation. | 5591 5592**Example** 5593 5594```ts 5595import { BusinessError } from '@kit.BasicServicesKit'; 5596 5597imageSourceApi.getFrameCount((err: BusinessError, frameCount: number) => { 5598 if (err) { 5599 console.error(`Failed to get frame count.code is ${err.code},message is ${err.message}`); 5600 } else { 5601 console.info('Succeeded in getting frame count.'); 5602 } 5603}) 5604``` 5605 5606### getFrameCount<sup>10+</sup> 5607 5608getFrameCount(): Promise\<number> 5609 5610Obtains the number of frames. This API uses a promise to return the result. 5611 5612**System capability**: SystemCapability.Multimedia.Image.ImageSource 5613 5614**Return value** 5615 5616| Type | Description | 5617| -------------- | --------------------------- | 5618| Promise\<number> | Promise used to return the number of frames.| 5619 5620**Error codes** 5621 5622For details about the error codes, see [Image Error Codes](errorcode-image.md). 5623 5624| ID| Error Message| 5625| ------- | --------------------------------------------| 5626| 62980096 | The operation failed. | 5627| 62980110 | The image source data is incorrect. | 5628| 62980111 | The image source data is incomplete. | 5629| 62980112 | The image format does not match. | 5630| 62980113 | Unknown image format. | 5631| 62980115 | Invalid image parameter. | 5632| 62980116 | Failed to decode the image. | 5633| 62980118 | Failed to create the image plugin. | 5634| 62980122 | Failed to decode the image header. | 5635| 62980137 | Invalid media operation. | 5636 5637**Example** 5638 5639```ts 5640import { BusinessError } from '@kit.BasicServicesKit'; 5641 5642imageSourceApi.getFrameCount().then((frameCount: number) => { 5643 console.info('Succeeded in getting frame count.'); 5644}).catch((err: BusinessError) => { 5645 console.error(`Failed to get frame count.code is ${err.code},message is ${err.message}`); 5646}) 5647``` 5648 5649### getDisposalTypeList<sup>12+</sup> 5650 5651getDisposalTypeList(): Promise\<Array\<number>> 5652 5653Obtains the list of disposal types. This API uses a promise to return the result. It is used only for GIF images. 5654 5655**System capability**: SystemCapability.Multimedia.Image.ImageSource 5656 5657**Return value** 5658 5659| Type | Description | 5660| -------------- | --------------------------- | 5661| Promise\<Array\<number>> | Promise used to return an array of disposal types.| 5662 5663**Error codes** 5664 5665For details about the error codes, see [Image Error Codes](errorcode-image.md). 5666 5667| ID| Error Message| 5668| ------- | --------------------------------------------| 5669| 62980096 | The operation failed. | 5670| 62980101 | The image data is abnormal. | 5671| 62980137 | Invalid media operation. | 5672| 62980149 | Invalid MIME type for the image source. | 5673 5674**Example** 5675 5676```ts 5677import { BusinessError } from '@kit.BasicServicesKit'; 5678imageSourceApi.getDisposalTypeList().then((disposalTypes: Array<number>) => { 5679 console.info('Succeeded in getting disposalTypes object.'); 5680}).catch((err: BusinessError) => { 5681 console.error(`Failed to get disposalTypes object.code ${err.code},message is ${err.message}`); 5682}) 5683``` 5684 5685### release 5686 5687release(callback: AsyncCallback\<void>): void 5688 5689Releases this **ImageSource** instance. This API uses an asynchronous callback to return the result. 5690 5691ArkTS 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. 5692 5693**System capability**: SystemCapability.Multimedia.Image.ImageSource 5694 5695**Parameters** 5696 5697| Name | Type | Mandatory| Description | 5698| -------- | -------------------- | ---- | ---------------------------------- | 5699| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 5700 5701**Example** 5702 5703```ts 5704import { BusinessError } from '@kit.BasicServicesKit'; 5705 5706imageSourceApi.release((err: BusinessError) => { 5707 if (err) { 5708 console.error(`Failed to release the image source instance.code ${err.code},message is ${err.message}`); 5709 } else { 5710 console.info('Succeeded in releasing the image source instance.'); 5711 } 5712}) 5713``` 5714 5715### release 5716 5717release(): Promise\<void> 5718 5719Releases this **ImageSource** instance. This API uses a promise to return the result. 5720 5721ArkTS 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. 5722 5723**System capability**: SystemCapability.Multimedia.Image.ImageSource 5724 5725**Return value** 5726 5727| Type | Description | 5728| -------------- | --------------------------- | 5729| Promise\<void> | Promise that returns no value.| 5730 5731**Example** 5732 5733```ts 5734import { BusinessError } from '@kit.BasicServicesKit'; 5735 5736imageSourceApi.release().then(() => { 5737 console.info('Succeeded in releasing the image source instance.'); 5738}).catch((error: BusinessError) => { 5739 console.error(`Failed to release the image source instance.code ${error.code},message is ${error.message}`); 5740}) 5741``` 5742 5743## image.createImagePacker 5744 5745createImagePacker(): ImagePacker 5746 5747Creates an **ImagePacker** instance. 5748 5749**Atomic service API**: This API can be used in atomic services since API version 11. 5750 5751**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5752 5753**Return value** 5754 5755| Type | Description | 5756| --------------------------- | --------------------- | 5757| [ImagePacker](#imagepacker) | **ImagePacker** instance created.| 5758 5759**Example** 5760 5761```ts 5762const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5763``` 5764 5765## ImagePacker 5766 5767Provides APIs to pack images. Before calling any API in **ImagePacker**, you must use [createImagePacker](#imagecreateimagepacker) to create an **ImagePacker** object. Currently, this class applies only to images in .jpeg, .webp, .png, or heif<sup>12+</sup> (depending on the hardware). 5768 5769### Properties 5770 5771**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5772 5773| Name | Type | Readable| Writable| Description | 5774| ---------------- | -------------- | ---- | ---- | -------------------------- | 5775| supportedFormats | Array\<string> | Yes | No | Supported formats, including .jpeg, .webp, .png, and heic<sup>12+</sup> (depending on the hardware).| 5776 5777### packToData<sup>13+</sup> 5778 5779packToData(source: ImageSource, options: PackingOption): Promise\<ArrayBuffer> 5780 5781Packs an image. This API uses a promise to return the result. 5782 5783**Atomic service API**: This API can be used in atomic services since API version 13. 5784 5785**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5786 5787**Parameters** 5788 5789| Name| Type | Mandatory| Description | 5790| ------ | ------------------------------- | ---- | -------------- | 5791| source | [ImageSource](#imagesource) | Yes | Image to pack.| 5792| options | [PackingOption](#packingoption) | Yes | Option for image packing.| 5793 5794**Error codes** 5795 5796For details about the error codes, see [Image Error Codes](errorcode-image.md). 5797 5798| ID| Error Message| 5799| ------- | --------------------------------------------| 5800| 401 | If the parameter is invalid. | 5801| 62980096| The Operation failed. | 5802| 62980101 | The image data is abnormal. | 5803| 62980106 | The image is too large. | 5804| 62980113 | Unknown image format. | 5805| 62980119 | If encoder occur error during encoding. | 5806| 62980120 | Add pixelmap out of range. | 5807| 62980172 | Failed to encode icc. | 5808| 62980252 | Failed to create surface. | 5809 5810**Return value** 5811 5812| Type | Description | 5813| ---------------------------- | --------------------------------------------- | 5814| Promise\<ArrayBuffer> | Promise used to return the packed image data.| 5815 5816**Example** 5817 5818```ts 5819import { BusinessError } from '@kit.BasicServicesKit'; 5820 5821const context: Context = getContext(); 5822// '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. 5823let filePath: string = context.filesDir + "/test.jpg"; 5824const imageSourceApi: image.ImageSource = image.createImageSource(filePath); 5825let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 5826const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5827imagePackerApi.packToData(imageSourceApi, packOpts) 5828 .then((data: ArrayBuffer) => { 5829 console.info('Succeeded in packing the image.'); 5830 }).catch((error: BusinessError) => { 5831 console.error(`Failed to pack the image.code ${error.code},message is ${error.message}`); 5832 }) 5833``` 5834 5835### packToData<sup>13+</sup> 5836 5837packToData(source: PixelMap, options: PackingOption): Promise\<ArrayBuffer> 5838 5839Packs an image. This API uses a promise to return the result. 5840 5841> **NOTE** 5842> 5843> If error code 401 is returned, the parameters are abnormal. The possible cause is that the **PixelMap** object is released in advance. You need to check the code and ensure that the **PixelMap** object is released after this API is called. 5844 5845**Atomic service API**: This API can be used in atomic services since API version 13. 5846 5847**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5848 5849**Parameters** 5850 5851| Name| Type | Mandatory| Description | 5852| ------ | ------------------------------- | ---- | ------------------ | 5853| source | [PixelMap](#pixelmap7) | Yes | **PixelMap** object to pack.| 5854| options | [PackingOption](#packingoption) | Yes | Option for image packing. | 5855 5856**Return value** 5857 5858| Type | Description | 5859| --------------------- | -------------------------------------------- | 5860| Promise\<ArrayBuffer> | Promise used to return the packed image data.| 5861 5862**Error codes** 5863 5864For details about the error codes, see [Image Error Codes](errorcode-image.md). 5865 5866| ID| Error Message| 5867| ------- | --------------------------------------------| 5868| 401 | If the parameter is invalid. | 5869| 62980096| The Operation failed. | 5870| 62980101 | The image data is abnormal. | 5871| 62980106 | The image is too large. | 5872| 62980113 | Unknown image format. | 5873| 62980119 | If encoder occur error during encoding. | 5874| 62980120 | Add pixelmap out of range. | 5875| 62980172 | Failed to encode icc. | 5876| 62980252 | Failed to create surface. | 5877 5878**Example** 5879 5880```ts 5881import { BusinessError } from '@kit.BasicServicesKit'; 5882 5883const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 5884let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } 5885image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => { 5886 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 5887 const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5888 imagePackerApi.packToData(pixelMap, packOpts) 5889 .then((data: ArrayBuffer) => { 5890 console.info('Succeeded in packing the image.'); 5891 }).catch((error: BusinessError) => { 5892 console.error(`Failed to pack the image.code ${error.code},message is ${error.message}`); 5893 }) 5894}).catch((error: BusinessError) => { 5895 console.error(`Failed to create PixelMap.code ${error.code},message is ${error.message}`); 5896}) 5897``` 5898 5899### packing<sup>13+</sup> 5900 5901packing(picture: Picture, options: PackingOption): Promise\<ArrayBuffer> 5902 5903Packs a picture. This API uses a promise to return the result. 5904 5905**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5906 5907**Parameters** 5908 5909| Name | Type | Mandatory| Description | 5910| ---------------- | ---------------------------------------------------- | ---- | -------------------- | 5911| picture | [Picture](#picture13) | Yes | **Picture** object to pack.| 5912| options | [PackingOption](#packingoption) | Yes | Option for image packing. | 5913 5914**Return value** 5915 5916| Type | Description | 5917| --------------------- | ------------------------------------- | 5918| Promise\<ArrayBuffer> | Promise used to return the packed image data.| 5919 5920**Error codes** 5921 5922For details about the error codes, see [Image Error Codes](errorcode-image.md). 5923 5924| ID| Error Message | 5925| -------- | ------------------------------------------------------------ | 5926| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 5927| 7800301 | Encode failed. | 5928 5929**Example** 5930 5931```ts 5932import { BusinessError } from '@kit.BasicServicesKit'; 5933import { image } from '@kit.ImageKit'; 5934 5935async function Packing() { 5936 const context = getContext(); 5937 const resourceMgr = context.resourceManager; 5938 const rawFile = await resourceMgr.getRawFileContent("test.jpg"); 5939 let ops: image.SourceOptions = { 5940 sourceDensity: 98, 5941 } 5942 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 5943 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 5944 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 5945 const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5946 let funcName = "Packing"; 5947 if (imagePackerApi != null) { 5948 let opts: image.PackingOption = { 5949 format: "image/jpeg", 5950 quality: 98, 5951 bufferSize: 10, 5952 desiredDynamicRange: image.PackingDynamicRange.AUTO, 5953 needsPackProperties: true}; 5954 await imagePackerApi.packing(pictureObj, opts).then((data: ArrayBuffer) => { 5955 console.info(funcName, 'Succeeded in packing the image.'+ data); 5956 }).catch((error: BusinessError) => { 5957 console.error(funcName, 'Failed to pack the image.code ${error.code},message is ${error.message}'); 5958 }); 5959 } 5960} 5961``` 5962 5963### packing<sup>(deprecated)</sup> 5964 5965packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void 5966 5967Packs an image. This API uses an asynchronous callback to return the result. 5968 5969> **NOTE** 5970> 5971> This API is supported since API version 6 and deprecated since API version 13. Use [packToData](#packtodata13) instead. 5972 5973**Atomic service API**: This API can be used in atomic services since API version 11. 5974 5975**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5976 5977**Parameters** 5978 5979| Name | Type | Mandatory| Description | 5980| -------- | ---------------------------------- | ---- | ---------------------------------- | 5981| source | [ImageSource](#imagesource) | Yes | Image to pack. | 5982| option | [PackingOption](#packingoption) | Yes | Option for image packing. | 5983| 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. | 5984 5985**Example** 5986 5987```ts 5988import { BusinessError } from '@kit.BasicServicesKit'; 5989 5990const context: Context = getContext(); 5991// '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. 5992let filePath: string = context.filesDir + "/test.jpg"; 5993const imageSourceApi: image.ImageSource = image.createImageSource(filePath); 5994let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }; 5995const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5996imagePackerApi.packing(imageSourceApi, packOpts, (err: BusinessError, data: ArrayBuffer) => { 5997 if (err) { 5998 console.error(`Failed to pack the image.code ${err.code},message is ${err.message}`); 5999 } else { 6000 console.info('Succeeded in packing the image.'); 6001 } 6002}) 6003``` 6004 6005### packing<sup>(deprecated)</sup> 6006 6007packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer> 6008 6009Packs an image. This API uses a promise to return the result. 6010 6011> **NOTE** 6012> 6013> This API is supported since API version 6 and deprecated since API version 13. Use [packToData](#packtodata13) instead. 6014 6015**Atomic service API**: This API can be used in atomic services since API version 11. 6016 6017**System capability**: SystemCapability.Multimedia.Image.ImagePacker 6018 6019**Parameters** 6020 6021| Name| Type | Mandatory| Description | 6022| ------ | ------------------------------- | ---- | -------------- | 6023| source | [ImageSource](#imagesource) | Yes | Image to pack.| 6024| option | [PackingOption](#packingoption) | Yes | Option for image packing.| 6025 6026**Return value** 6027 6028| Type | Description | 6029| ---------------------------- | --------------------------------------------- | 6030| Promise\<ArrayBuffer> | Promise used to return the packed image data.| 6031 6032**Example** 6033 6034```ts 6035import { BusinessError } from '@kit.BasicServicesKit'; 6036 6037const context: Context = getContext(); 6038// '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. 6039let filePath: string = context.filesDir + "/test.jpg"; 6040const imageSourceApi: image.ImageSource = image.createImageSource(filePath); 6041let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 6042const imagePackerApi: image.ImagePacker = image.createImagePacker(); 6043imagePackerApi.packing(imageSourceApi, packOpts) 6044 .then((data: ArrayBuffer) => { 6045 console.info('Succeeded in packing the image.'); 6046 }).catch((error: BusinessError) => { 6047 console.error(`Failed to pack the image.code ${error.code},message is ${error.message}`); 6048 }) 6049``` 6050 6051### packing<sup>(deprecated)</sup> 6052 6053packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void 6054 6055Packs an image. This API uses an asynchronous callback to return the result. 6056 6057> **NOTE** 6058> 6059> This API is supported since API version 8 and deprecated since API version 13. Use [packToData](#packtodata13) instead. 6060 6061> **NOTE** 6062> If the message "PixelMap mismatch" is returned, the parameters are abnormal. The possible cause is that the **PixelMap** object is released in advance. You need to check the code and ensure that the **PixelMap** object is released after this API is called. 6063 6064**Atomic service API**: This API can be used in atomic services since API version 11. 6065 6066**System capability**: SystemCapability.Multimedia.Image.ImagePacker 6067 6068**Parameters** 6069 6070| Name | Type | Mandatory| Description | 6071| -------- | ------------------------------- | ---- | ---------------------------------- | 6072| source | [PixelMap](#pixelmap7) | Yes | **PixelMap** object to pack. | 6073| option | [PackingOption](#packingoption) | Yes | Option for image packing. | 6074| 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. | 6075 6076**Example** 6077 6078```ts 6079import { BusinessError } from '@kit.BasicServicesKit'; 6080 6081const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 6082let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 6083image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => { 6084 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 6085 const imagePackerApi: image.ImagePacker = image.createImagePacker(); 6086 imagePackerApi.packing(pixelMap, packOpts, (err: BusinessError, data: ArrayBuffer) => { 6087 if (err) { 6088 console.error(`Failed to pack the image.code ${err.code},message is ${err.message}`); 6089 } else { 6090 console.info('Succeeded in packing the image.'); 6091 } 6092 }) 6093}).catch((error: BusinessError) => { 6094 console.error(`Failed to create the PixelMap.code ${error.code},message is ${error.message}`); 6095}) 6096``` 6097 6098### packing<sup>(deprecated)</sup> 6099 6100packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer> 6101 6102Packs an image. This API uses a promise to return the result. 6103 6104> **NOTE** 6105> 6106> This API is supported since API version 8 and deprecated since API version 13. Use [packToData](#packtodata13) instead. 6107> 6108> If the message "PixelMap mismatch" is returned, the parameters are abnormal. The possible cause is that the **PixelMap** object is released in advance. You need to check the code and ensure that the **PixelMap** object is released after this API is called. 6109 6110**Atomic service API**: This API can be used in atomic services since API version 11. 6111 6112**System capability**: SystemCapability.Multimedia.Image.ImagePacker 6113 6114**Parameters** 6115 6116| Name| Type | Mandatory| Description | 6117| ------ | ------------------------------- | ---- | ------------------ | 6118| source | [PixelMap](#pixelmap7) | Yes | **PixelMap** object to pack.| 6119| option | [PackingOption](#packingoption) | Yes | Option for image packing. | 6120 6121**Return value** 6122 6123| Type | Description | 6124| --------------------- | -------------------------------------------- | 6125| Promise\<ArrayBuffer> | Promise used to return the packed image data.| 6126 6127**Example** 6128 6129```ts 6130import { BusinessError } from '@kit.BasicServicesKit'; 6131 6132const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 6133let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 6134image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => { 6135 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 6136 const imagePackerApi: image.ImagePacker = image.createImagePacker(); 6137 imagePackerApi.packing(pixelMap, packOpts) 6138 .then((data: ArrayBuffer) => { 6139 console.info('Succeeded in packing the image.'); 6140 }).catch((error: BusinessError) => { 6141 console.error(`Failed to pack the image.code ${error.code},message is ${error.message}`); 6142 }) 6143}).catch((error: BusinessError) => { 6144 console.error(`Failed to create PixelMap.code ${error.code},message is ${error.message}`); 6145}) 6146``` 6147 6148### release 6149 6150release(callback: AsyncCallback\<void>): void 6151 6152Releases this **ImagePacker** instance. This API uses an asynchronous callback to return the result. 6153 6154ArkTS 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. 6155 6156**System capability**: SystemCapability.Multimedia.Image.ImagePacker 6157 6158**Parameters** 6159 6160| Name | Type | Mandatory| Description | 6161| -------- | -------------------- | ---- | ------------------------------ | 6162| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 6163 6164**Example** 6165 6166```ts 6167import { BusinessError } from '@kit.BasicServicesKit'; 6168 6169const imagePackerApi: image.ImagePacker = image.createImagePacker(); 6170imagePackerApi.release((err: BusinessError)=>{ 6171 if (err) { 6172 console.error(`Failed to release image packaging.code ${err.code},message is ${err.message}`); 6173 } else { 6174 console.info('Succeeded in releasing image packaging.'); 6175 } 6176}) 6177``` 6178 6179### release 6180 6181release(): Promise\<void> 6182 6183Releases this **ImagePacker** instance. This API uses a promise to return the result. 6184 6185ArkTS 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. 6186 6187**System capability**: SystemCapability.Multimedia.Image.ImagePacker 6188 6189**Return value** 6190 6191| Type | Description | 6192| -------------- | ------------------------------------------------------ | 6193| Promise\<void> | Promise that returns no value.| 6194 6195**Example** 6196 6197```ts 6198import { BusinessError } from '@kit.BasicServicesKit'; 6199 6200const imagePackerApi: image.ImagePacker = image.createImagePacker(); 6201imagePackerApi.release().then(() => { 6202 console.info('Succeeded in releasing image packaging.'); 6203}).catch((error: BusinessError) => { 6204 console.error(`Failed to release image packaging.code ${error.code},message is ${error.message}`); 6205}) 6206``` 6207 6208### packToFile<sup>11+</sup> 6209 6210packToFile(source: ImageSource, fd: number, options: PackingOption, callback: AsyncCallback\<void>): void 6211 6212Encodes an **ImageSource** object and packs it into a file. This API uses an asynchronous callback to return the result. 6213 6214**System capability**: SystemCapability.Multimedia.Image.ImagePacker 6215 6216**Parameters** 6217 6218| Name | Type | Mandatory| Description | 6219| -------- | ------------------------------- | ---- | ------------------------------ | 6220| source | [ImageSource](#imagesource) | Yes | Image to pack. | 6221| fd | number | Yes | File descriptor. | 6222| options | [PackingOption](#packingoption) | Yes | Option for image packing. | 6223| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 6224 6225**Error codes** 6226 6227For details about the error codes, see [Image Error Codes](errorcode-image.md). 6228 6229| ID| Error Message| 6230| ------- | --------------------------------------------| 6231| 62980096| The Operation failed. | 6232| 62980101 | The image data is abnormal. | 6233| 62980106 | The image is too large. | 6234| 62980113 | Unknown image format. | 6235| 62980115 | If the parameter is invalid. | 6236| 62980119 | If encoder occur error during encoding. | 6237| 62980120 | Add pixelmap out of range. | 6238| 62980172 | Failed to encode icc. | 6239| 62980252 | Failed to create surface. | 6240 6241**Example** 6242 6243```ts 6244import { BusinessError } from '@kit.BasicServicesKit'; 6245import { fileIo as fs } from '@kit.CoreFileKit'; 6246 6247const context: Context = getContext(this); 6248// '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. 6249const path: string = context.filesDir + "/test.png"; 6250const imageSourceApi: image.ImageSource = image.createImageSource(path); 6251let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }; 6252const filePath: string = context.filesDir + "/image_source.jpg"; 6253let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 6254const imagePackerApi: image.ImagePacker = image.createImagePacker(); 6255imagePackerApi.packToFile(imageSourceApi, file.fd, packOpts, (err: BusinessError) => { 6256 if (err) { 6257 console.error(`Failed to pack the image to file.code ${err.code},message is ${err.message}`); 6258 } else { 6259 console.info('Succeeded in packing the image to file.'); 6260 } 6261}) 6262``` 6263 6264### packToFile<sup>11+</sup> 6265 6266packToFile (source: ImageSource, fd: number, options: PackingOption): Promise\<void> 6267 6268Encodes an **ImageSource** object and packs it into a file. This API uses a promise to return the result. 6269 6270**System capability**: SystemCapability.Multimedia.Image.ImagePacker 6271 6272**Parameters** 6273 6274| Name| Type | Mandatory| Description | 6275| ------ | ------------------------------- | ---- | -------------- | 6276| source | [ImageSource](#imagesource) | Yes | Image to pack.| 6277| fd | number | Yes | File descriptor. | 6278| options | [PackingOption](#packingoption) | Yes | Option for image packing.| 6279 6280**Return value** 6281 6282| Type | Description | 6283| -------------- | --------------------------------- | 6284| Promise\<void> | Promise that returns no value.| 6285 6286**Error codes** 6287 6288For details about the error codes, see [Image Error Codes](errorcode-image.md). 6289 6290| ID| Error Message| 6291| ------- | --------------------------------------------| 6292| 62980096| The Operation failed. | 6293| 62980101 | The image data is abnormal. | 6294| 62980106 | The image is too large. | 6295| 62980113 | Unknown image format. | 6296| 62980115 | If the parameter is invalid. | 6297| 62980119 | If encoder occur error during encoding. | 6298| 62980120 | Add pixelmap out of range. | 6299| 62980172 | Failed to encode icc. | 6300| 62980252 | Failed to create surface. | 6301 6302**Example** 6303 6304```ts 6305import { BusinessError } from '@kit.BasicServicesKit'; 6306import { fileIo as fs } from '@kit.CoreFileKit'; 6307 6308const context: Context = getContext(this); 6309// '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. 6310const path: string = context.filesDir + "/test.png"; 6311const imageSourceApi: image.ImageSource = image.createImageSource(path); 6312let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }; 6313const filePath: string = context.filesDir + "/image_source.jpg"; 6314let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 6315const imagePackerApi: image.ImagePacker = image.createImagePacker(); 6316imagePackerApi.packToFile(imageSourceApi, file.fd, packOpts).then(() => { 6317 console.info('Succeeded in packing the image to file.'); 6318}).catch((error: BusinessError) => { 6319 console.error(`Failed to pack the image to file.code ${error.code},message is ${error.message}`); 6320}) 6321``` 6322 6323### packToFile<sup>11+</sup> 6324 6325packToFile (source: PixelMap, fd: number, options: PackingOption, callback: AsyncCallback\<void>): void 6326 6327Encodes a **PixelMap** object and packs it into a file. This API uses an asynchronous callback to return the result. 6328 6329> **NOTE** 6330> If error code 62980115 is returned, the parameters are abnormal. The possible cause is that the **PixelMap** object is released in advance. You need to check the code and ensure that the **PixelMap** object is released after this API is called. 6331 6332**System capability**: SystemCapability.Multimedia.Image.ImagePacker 6333 6334**Parameters** 6335 6336| Name | Type | Mandatory| Description | 6337| -------- | ------------------------------- | ---- | ------------------------------ | 6338| source | [PixelMap](#pixelmap7) | Yes | **PixelMap** object to pack. | 6339| fd | number | Yes | File descriptor. | 6340| options | [PackingOption](#packingoption) | Yes | Option for image packing. | 6341| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 6342 6343**Error codes** 6344 6345For details about the error codes, see [Image Error Codes](errorcode-image.md). 6346 6347| ID| Error Message| 6348| ------- | --------------------------------------------| 6349| 62980096| The Operation failed. | 6350| 62980101 | The image data is abnormal. | 6351| 62980106 | The image is too large. | 6352| 62980113 | Unknown image format. | 6353| 62980115 | If the parameter is invalid. | 6354| 62980119 | If encoder occur error during encoding. | 6355| 62980120 | Add pixelmap out of range. | 6356| 62980172 | Failed to encode icc. | 6357| 62980252 | Failed to create surface. | 6358 6359**Example** 6360 6361```ts 6362import { BusinessError } from '@kit.BasicServicesKit'; 6363import { fileIo as fs } from '@kit.CoreFileKit'; 6364 6365const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 6366let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 6367const context: Context = getContext(this); 6368const path: string = context.filesDir + "/pixel_map.jpg"; 6369image.createPixelMap(color, opts).then((pixelmap: image.PixelMap) => { 6370 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 6371 let file = fs.openSync(path, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 6372 const imagePackerApi: image.ImagePacker = image.createImagePacker(); 6373 imagePackerApi.packToFile(pixelmap, file.fd, packOpts, (err: BusinessError) => { 6374 if (err) { 6375 console.error(`Failed to pack the image to file.code ${err.code},message is ${err.message}`); 6376 } else { 6377 console.info('Succeeded in packing the image to file.'); 6378 } 6379 }) 6380}) 6381``` 6382 6383### packToFile<sup>11+</sup> 6384 6385packToFile (source: PixelMap, fd: number, options: PackingOption): Promise\<void> 6386 6387Encodes a **PixelMap** object and packs it into a file. This API uses a promise to return the result. 6388 6389> **NOTE** 6390> If error code 62980115 is returned, the parameters are abnormal. The possible cause is that the **PixelMap** object is released in advance. You need to check the code and ensure that the **PixelMap** object is released after this API is called. 6391 6392**System capability**: SystemCapability.Multimedia.Image.ImagePacker 6393 6394**Parameters** 6395 6396| Name| Type | Mandatory| Description | 6397| ------ | ------------------------------- | ---- | -------------------- | 6398| source | [PixelMap](#pixelmap7) | Yes | **PixelMap** object to pack.| 6399| fd | number | Yes | File descriptor. | 6400| options | [PackingOption](#packingoption) | Yes | Option for image packing. | 6401 6402**Return value** 6403 6404| Type | Description | 6405| -------------- | --------------------------------- | 6406| Promise\<void> | Promise that returns no value.| 6407 6408**Error codes** 6409 6410For details about the error codes, see [Image Error Codes](errorcode-image.md). 6411 6412| ID| Error Message| 6413| ------- | --------------------------------------------| 6414| 62980096| The Operation failed. | 6415| 62980101 | The image data is abnormal. | 6416| 62980106 | The image is too large. | 6417| 62980113 | Unknown image format. | 6418| 62980115 | If the parameter is invalid. | 6419| 62980119 | If encoder occur error during encoding. | 6420| 62980120 | Add pixelmap out of range. | 6421| 62980172 | Failed to encode icc. | 6422| 62980252 | Failed to create surface. | 6423 6424**Example** 6425 6426```ts 6427import { BusinessError } from '@kit.BasicServicesKit'; 6428import { fileIo as fs } from '@kit.CoreFileKit'; 6429 6430const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 6431let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 6432const context: Context = getContext(this); 6433const path: string = context.filesDir + "/pixel_map.jpg"; 6434image.createPixelMap(color, opts).then((pixelmap: image.PixelMap) => { 6435 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 6436 let file = fs.openSync(path, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 6437 const imagePackerApi: image.ImagePacker = image.createImagePacker(); 6438 imagePackerApi.packToFile(pixelmap, file.fd, packOpts) 6439 .then(() => { 6440 console.info('Succeeded in packing the image to file.'); 6441 }).catch((error: BusinessError) => { 6442 console.error(`Failed to pack the image to file.code ${error.code},message is ${error.message}`); 6443 }) 6444}) 6445``` 6446 6447### packToFile<sup>13+</sup> 6448 6449packToFile(picture: Picture, fd: number, options: PackingOption): Promise\<void> 6450 6451Encodes a **Picture** object and packs it into a file. This API uses a promise to return the result. 6452 6453**System capability**: SystemCapability.Multimedia.Image.ImagePacker 6454 6455**Parameters** 6456 6457| Name | Type | Mandatory| Description | 6458| ------- | ---------------------------- | ---- | -------------------- | 6459| picture | [Picture](#picture13) | Yes | **Picture** object to pack.| 6460| fd | number | Yes | File descriptor. | 6461| options | [PackingOption](#packingoption) | Yes | Option for image packing. | 6462 6463**Return value** 6464 6465| Type | Description | 6466| -------------- | ------------------------- | 6467| Promise\<void> | that returns no value.| 6468 6469**Error codes** 6470 6471For details about the error codes, see [Image Error Codes](errorcode-image.md). 6472 6473| ID| Error Message | 6474| -------- | ------------------------------------------------------------ | 6475| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6476| 7800301 | Encode failed. | 6477 6478**Example** 6479 6480```ts 6481import { BusinessError } from '@kit.BasicServicesKit'; 6482import { image } from '@kit.ImageKit'; 6483import { fileIo as fs } from '@kit.CoreFileKit'; 6484 6485async function PackToFile() { 6486 const context = getContext(); 6487 const resourceMgr = context.resourceManager; 6488 const rawFile = await resourceMgr.getRawFileContent("test.jpg"); 6489 let ops: image.SourceOptions = { 6490 sourceDensity: 98, 6491 } 6492 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6493 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6494 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6495 6496 let funcName = "PackToFile"; 6497 const imagePackerApi: image.ImagePacker = image.createImagePacker(); 6498 if (imagePackerApi != null) { 6499 const context: Context = getContext(); 6500 const filePath: string = context.filesDir + "/test.jpg"; 6501 let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 6502 let packOpts: image.PackingOption = { 6503 format: "image/jpeg", 6504 quality: 98, 6505 bufferSize: 10, 6506 desiredDynamicRange: image.PackingDynamicRange.AUTO, 6507 needsPackProperties: true}; 6508 await imagePackerApi.packToFile(pictureObj, file.fd, packOpts).then(() => { 6509 console.info(funcName, 'Succeeded in packing the image to file.'); 6510 }).catch((error: BusinessError) => { 6511 console.error(funcName, 'Failed to pack the image to file.code ${error.code},message is ${error.message}'); 6512 }); 6513 } 6514} 6515``` 6516 6517## image.createAuxiliaryPicture<sup>13+</sup> 6518 6519createAuxiliaryPicture(buffer: ArrayBuffer, size: Size, type: AuxiliaryPictureType): AuxiliaryPicture 6520 6521Creates an **AuxiliaryPicture** instance based on the ArrayBuffer image data, auxiliary picture size, and auxiliary picture type. 6522 6523**System capability**: SystemCapability.Multimedia.Image.Core 6524 6525**Parameters** 6526 6527| Name| Type | Mandatory| Description | 6528| ------ | ----------------------------------------------- | ---- | ---------------------------- | 6529| buffer | ArrayBuffer | Yes | Image data stored in the buffer.| 6530| size | [Size](#size) | Yes | Size of the auxiliary picture. | 6531| type | [AuxiliaryPictureType](#auxiliarypicturetype13) | Yes | Type of the auxiliary picture. | 6532 6533**Return value** 6534 6535| Type | Description | 6536| --------------------------------------- | ------------------------------------------ | 6537| [AuxiliaryPicture](#auxiliarypicture13) | **AuxiliaryPicture** instance if the operation is successful.| 6538 6539**Error codes** 6540 6541For details about the error codes, see [Image Error Codes](errorcode-image.md). 6542 6543| ID| Error Message | 6544| -------- | ------------------------------------------------------------ | 6545| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6546 6547**Example** 6548 6549```ts 6550import { image } from '@kit.ImageKit'; 6551 6552async function CreateAuxiliaryPicture() { 6553 let funcName = "CreateAuxiliaryPicture"; 6554 const context = getContext(); 6555 const resourceMgr = context.resourceManager; 6556 const rawFile = await resourceMgr.getRawFileContent("hdr.jpg"); // Support for HDR images is required. 6557 let auxBuffer: ArrayBuffer = rawFile.buffer as ArrayBuffer; 6558 let auxSize: Size = { 6559 height: 180, 6560 width: 240 6561 }; 6562 let auxType: image.AuxiliaryPictureType = image.AuxiliaryPictureType.GAINMAP; 6563 let auxPictureObj: image.AuxiliaryPicture | null = image.createAuxiliaryPicture(auxBuffer, auxSize, auxType); 6564 if(auxPictureObj != null) { 6565 let type: image.AuxiliaryPictureType = auxPictureObj.getType(); 6566 console.info(funcName, 'CreateAuxiliaryPicture succeeded this.Aux_picture.type.' + JSON.stringify(type)); 6567 } else { 6568 console.error(funcName, 'CreateAuxiliaryPicture failed'); 6569 } 6570} 6571``` 6572 6573## AuxiliaryPicture<sup>13+</sup> 6574 6575The auxiliary picture is generally used to assist the main picture in displaying special information, so that the image includes richer information. The **AuxiliaryPicture** class is used to read or write auxiliary picture data of an image and obtain auxiliary picture information of an image. Before calling any API in **AuxiliaryPicture**, you must use [createAuxiliaryPicture](#imagecreateauxiliarypicture13) to create an **AuxiliaryPicture** object. 6576 6577### Properties 6578 6579**System capability**: SystemCapability.Multimedia.Image.Core 6580 6581### writePixelsFromBuffer<sup>13+</sup> 6582 6583writePixelsFromBuffer(data: ArrayBuffer): Promise\<void> 6584 6585Reads pixels from an ArrayBuffer and writes the data to this **AuxiliaryPicture** object. This API uses a promise to return the result. 6586 6587**System capability**: SystemCapability.Multimedia.Image.Core 6588 6589**Parameters** 6590 6591| Name| Type | Mandatory| Description | 6592| ------ | ----------- | ---- | ---------------- | 6593| data | ArrayBuffer | Yes | Pixels of the auxiliary picture.| 6594 6595**Return value** 6596 6597| Type | Description | 6598| -------------- | -------------------------------------- | 6599| Promise\<void> | Promise that returns no value.| 6600 6601**Error codes** 6602 6603For details about the error codes, see [Image Error Codes](errorcode-image.md). 6604 6605| ID| Error Message | 6606| -------- | ------------------------------------------------------------ | 6607| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6608| 7600301 | Memory alloc failed. | 6609| 7600302 | Memory copy failed. | 6610 6611**Example** 6612 6613```ts 6614import { image } from '@kit.ImageKit'; 6615 6616async function WritePixelsFromBuffer() { 6617 const context = getContext(); 6618 const resourceMgr = context.resourceManager; 6619 const rawFile = await resourceMgr.getRawFileContent("hdr.jpg"); // Support for HDR images is required. 6620 let ops: image.SourceOptions = { 6621 sourceDensity: 98, 6622 } 6623 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6624 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6625 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6626 let auxPictureObj: image.AuxiliaryPicture | null = pictureObj.getAuxiliaryPicture(image.AuxiliaryPictureType.GAINMAP); 6627 if(auxPictureObj != null) { 6628 let auxBuffer: ArrayBuffer = await auxPictureObj.readPixelsToBuffer(); 6629 await auxPictureObj.writePixelsFromBuffer(auxBuffer); 6630 console.info('Write pixels from buffer success.'); 6631 } else { 6632 console.error('AuxPictureObj is null.'); 6633 } 6634} 6635``` 6636 6637### readPixelsToBuffer<sup>13+</sup> 6638 6639readPixelsToBuffer(): Promise\<ArrayBuffer> 6640 6641Reads pixels of this auxiliary picture and writes the data to an ArrayBuffer. This API uses a promise to return the result. 6642 6643**System capability**: SystemCapability.Multimedia.Image.Core 6644 6645**Return value** 6646 6647| Type | Description | 6648| --------------------- | --------------------------------- | 6649| Promise\<ArrayBuffer> | Promise used to return the pixels of the auxiliary picture.| 6650 6651**Error codes** 6652 6653For details about the error codes, see [Image Error Codes](errorcode-image.md). 6654 6655| ID| Error Message | 6656| -------- | -------------------- | 6657| 7600301 | Memory alloc failed. | 6658| 7600302 | Memory copy failed. | 6659 6660**Example** 6661 6662```ts 6663import { BusinessError } from '@kit.BasicServicesKit'; 6664import { image } from '@kit.ImageKit'; 6665 6666async function ReadPixelsToBuffer() { 6667 const context = getContext(); 6668 const resourceMgr = context.resourceManager; 6669 const rawFile = await resourceMgr.getRawFileContent("hdr.jpg"); // Support for HDR images is required. 6670 let ops: image.SourceOptions = { 6671 sourceDensity: 98, 6672 } 6673 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6674 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6675 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6676 let auxPictureObj: image.AuxiliaryPicture | null = pictureObj.getAuxiliaryPicture(image.AuxiliaryPictureType.GAINMAP); 6677 if(auxPictureObj != null) { 6678 await auxPictureObj.readPixelsToBuffer().then((pixelsBuffer: ArrayBuffer) => { 6679 console.info('Read pixels to buffer success.' ); 6680 }).catch((error: BusinessError) => { 6681 console.error('Read pixels to buffer failed error.code: ' + JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message)); 6682 }); 6683 } else { 6684 console.error('AuxPictureObj is null.'); 6685 } 6686} 6687``` 6688 6689### getType<sup>13+</sup> 6690 6691getType(): AuxiliaryPictureType 6692 6693Obtains the type of this auxiliary picture. 6694 6695**System capability**: SystemCapability.Multimedia.Image.Core 6696 6697**Return value** 6698 6699| Type | Description | 6700| ----------------------------------------------- | ---------------------------- | 6701| [AuxiliaryPictureType](#auxiliarypicturetype13) | Type of the auxiliary picture.| 6702 6703**Example** 6704 6705```ts 6706import { image } from '@kit.ImageKit'; 6707 6708async function GetAuxiliaryPictureType() { 6709 if (auxPictureObj != null) { 6710 let type: image.AuxiliaryPictureType = auxPictureObj.getType(); 6711 console.info('Success get auxiliary picture type ' + JSON.stringify(type)); 6712 } else { 6713 console.info('Failed get auxiliary picture type '); 6714 } 6715} 6716``` 6717 6718### setMetadata<sup>13+</sup> 6719 6720setMetadata(metadataType: MetadataType, metadata: Metadata): Promise\<void> 6721 6722Sets the metadata for this auxiliary picture. 6723 6724**System capability**: SystemCapability.Multimedia.Image.Core 6725 6726**Parameters** 6727 6728| Name | Type | Mandatory| Description | 6729| ------------ | ------------------------------- | ---- | ------------------------------------ | 6730| metadataType | [MetadataType](#metadatatype13) | Yes | Metadata type, which is used to set the corresponding metadata.| 6731| metadata | [Metadata](#metadata13) | Yes | **Metadata** object. | 6732 6733**Return value** 6734 6735| Type | Description | 6736| -------------- | -------------------------------------- | 6737| Promise\<void> | Promise that returns no value.| 6738 6739**Error codes** 6740 6741For details about the error codes, see [Image Error Codes](errorcode-image.md). 6742 6743| ID| Error Message | 6744| -------- | ------------------------------------------------------------ | 6745| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6746| 7600202 | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. | 6747 6748**Example** 6749 6750```ts 6751import { BusinessError } from '@kit.BasicServicesKit'; 6752import { image } from '@kit.ImageKit'; 6753 6754async function SetAuxPictureObjMetadata() { 6755 const exifContext = getContext(); 6756 const exifResourceMgr = exifContext.resourceManager; 6757 const exifRawFile = await exifResourceMgr.getRawFileContent("exif.jpg");// The image contains EXIF metadata. 6758 let exifOps: image.SourceOptions = { 6759 sourceDensity: 98, 6760 } 6761 let exifImageSource: image.ImageSource = image.createImageSource(exifRawFile.buffer as ArrayBuffer, exifOps); 6762 let exifCommodityPixelMap: image.PixelMap = await exifImageSource.createPixelMap(); 6763 let exifPictureObj: image.Picture = image.createPicture(exifCommodityPixelMap); 6764 if (exifPictureObj != null) { 6765 console.info('Create picture succeeded'); 6766 } else { 6767 console.info('Create picture failed'); 6768 } 6769 6770 if (auxPictureObj != null) { 6771 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 6772 let exifMetaData: image.Metadata = await exifPictureObj.getMetadata(metadataType); 6773 auxPictureObj.setMetadata(metadataType, exifMetaData).then(() => { 6774 console.info('Set metadata success'); 6775 }).catch((error: BusinessError) => { 6776 console.error('Set metadata failed.error.code: ${error.code}, error.message: ${error.message}'); 6777 }); 6778 } else { 6779 console.info('AuxPictureObjMetaData is null'); 6780 } 6781} 6782``` 6783 6784### getMetadata<sup>13+</sup> 6785 6786getMetadata(metadataType: MetadataType): Promise\<Metadata> 6787 6788Obtains the metadata of this auxiliary picture. 6789 6790**System capability**: SystemCapability.Multimedia.Image.Core 6791 6792**Parameters** 6793 6794| Name | Type | Mandatory| Description | 6795| ------------ | ------------------------------- | ---- | -------------------------------------- | 6796| metadataType | [MetadataType](#metadatatype13) | Yes | Metadata type, which is used to obtain metadata of the corresponding type.| 6797 6798**Return value** 6799 6800| Type | Description | 6801| -------------------------------- | ---------------- | 6802| Promise<[Metadata](#metadata13)> | Metadata object.| 6803 6804**Error codes** 6805 6806For details about the error codes, see [Image Error Codes](errorcode-image.md). 6807 6808| ID| Error Message | 6809| -------- | ------------------------------------------------------------ | 6810| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6811| 7600202 | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. | 6812 6813**Example** 6814 6815```ts 6816import { image } from '@kit.ImageKit'; 6817 6818async function GetAuxPictureObjMetadata() { 6819 if (auxPictureObj != null) { 6820 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 6821 let auxPictureObjMetaData: image.Metadata | null = await auxPictureObj.getMetadata(metadataType); 6822 if (auxPictureObjMetaData != null) { 6823 console.info('Get auxpictureobj Metadata success' ); 6824 } else { 6825 console.info('Get auxpictureobj Metadata failed'); 6826 } 6827 } else { 6828 console.info('Get auxpictureobj is null.'); 6829 } 6830} 6831``` 6832 6833### getAuxiliaryPictureinfo<sup>13+</sup> 6834 6835getAuxiliaryPictureInfo(): AuxiliaryPictureInfo 6836 6837Obtains the auxiliary picture information. 6838 6839**System capability**: SystemCapability.Multimedia.Image.Core 6840 6841**Return value** 6842 6843| Type | Description | 6844| ----------------------------------------------- | --------------------------------- | 6845| [AuxiliaryPictureInfo](#auxiliarypictureinfo13) | Promise used to return the auxiliary picture information.| 6846 6847**Example** 6848 6849```ts 6850import { image } from '@kit.ImageKit'; 6851 6852async function GetAuxiliaryPictureInfo() { 6853 if(auxPictureObj != null) { 6854 let auxinfo: image.AuxiliaryPictureInfo = auxPictureObj.getAuxiliaryPictureInfo(); 6855 console.info('GetAuxiliaryPictureInfo Type: ' + auxinfo.auxiliaryPictureType + 6856 ' height: ' + auxinfo.size.height + ' width: ' + auxinfo.size.width + 6857 ' rowStride: ' + auxinfo.rowStride + ' pixelFormat: ' + auxinfo.pixelFormat + 6858 ' colorSpace: ' + auxinfo.colorSpace); 6859 } else { 6860 console.info('Get auxiliary picture information failed'); 6861 } 6862} 6863``` 6864 6865### setAuxiliaryPictureinfo<sup>13+</sup> 6866 6867setAuxiliaryPictureInfo(info: AuxiliaryPictureInfo): void 6868 6869Sets the auxiliary picture information. 6870 6871**System capability**: SystemCapability.Multimedia.Image.Core 6872 6873**Parameters** 6874 6875| Name| Type | Mandatory| Description | 6876| ------ | ----------------------------------------------- | ---- | ------------------ | 6877| info | [AuxiliaryPictureInfo](#auxiliarypictureinfo13) | Yes | Auxiliary picture information.| 6878 6879**Error codes** 6880 6881For details about the error codes, see [Image Error Codes](errorcode-image.md). 6882 6883| ID| Error Message | 6884| -------- | :----------------------------------------------------------- | 6885| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6886 6887**Example** 6888 6889```ts 6890import { colorSpaceManager } from '@kit.ArkGraphics2D'; 6891import { image } from '@kit.ImageKit'; 6892 6893async function SetAuxiliaryPictureInfo() { 6894 if(auxPictureObj != null) { 6895 let colorSpaceName = colorSpaceManager.ColorSpace.SRGB; 6896 let info: image.AuxiliaryPictureInfo = { 6897 auxiliaryPictureType: image.AuxiliaryPictureType.GAINMAP, 6898 size: {height: 100, width: 200}, 6899 pixelFormat: image.PixelMapFormat.RGBA_8888, 6900 rowStride: 0, 6901 colorSpace: colorSpaceManager.create(colorSpaceName), 6902 }; 6903 auxPictureObj.setAuxiliaryPictureInfo(info); 6904 } 6905} 6906``` 6907 6908### release<sup>13+</sup> 6909 6910release():void 6911 6912Releases this AuxiliaryPicture object. No value is returned. 6913 6914**System capability**: SystemCapability.Multimedia.Image.Core 6915 6916**Example** 6917 6918```ts 6919import { image } from '@kit.ImageKit'; 6920 6921async function Release() { 6922 let funcName = "Release"; 6923 if (auxPictureObj != null) { 6924 auxPictureObj.release(); 6925 if (auxPictureObj.getType() == null) { 6926 console.info(funcName, 'Success !'); 6927 } else { 6928 console.info(funcName, 'Failed !'); 6929 } 6930 } else { 6931 console.info('PictureObj is null'); 6932 } 6933} 6934``` 6935 6936## Metadata<sup>13+</sup> 6937 6938A class used to store image metadata. For details about the supported metadata types, see [MetadataType](#metadatatype13). 6939 6940### Properties 6941 6942**System capability**: SystemCapability.Multimedia.Image.Core 6943 6944### getProperties<sup>13+</sup> 6945 6946getProperties(key: Array\<string>): Promise\<Record\<string, string | null>> 6947 6948Obtains the values of properties from the image's metadata. This API uses a promise to return the result. For details about how to obtain the property values, see [PropertyKey](#propertykey7) and [FragmentMapPropertyKey](#fragmentmappropertykey13). 6949 6950**System capability**: SystemCapability.Multimedia.Image.Core 6951 6952**Parameters** 6953 6954| Name| Type | Mandatory| Description | 6955| ------ | -------------- | ---- | ------------------------ | 6956| key | Array\<string> | Yes | Names of the properties.| 6957 6958**Return value** 6959 6960| Type | Description | 6961| ---------------------------------------- | ------------------------------------------------------------ | 6962| Promise\<Record<string, string \| null>> | Promise used to return the property values. If the retrieval operation fails, an error code is returned.| 6963 6964**Error codes** 6965 6966For details about the error codes, see [Image Error Codes](errorcode-image.md). 6967 6968| ID| Error Message | 6969| -------- | ------------------------------------------------------------ | 6970| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 6971| 7600202 | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. | 6972 6973**Example** 6974 6975```ts 6976import { BusinessError } from '@kit.BasicServicesKit'; 6977import { image } from '@kit.ImageKit'; 6978 6979async function GetProperties() { 6980 const context = getContext(); 6981 const resourceMgr = context.resourceManager; 6982 const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); // The image contains EXIF metadata. 6983 let ops: image.SourceOptions = { 6984 sourceDensity: 98, 6985 } 6986 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6987 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6988 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6989 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 6990 let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType); 6991 if (metaData != null) { 6992 await metaData.getProperties(["ImageWidth", "ImageLength"]).then((data2) => { 6993 console.info('Get properties ',JSON.stringify(data2)); 6994 }).catch((error: BusinessError) => { 6995 console.info('Get properties failed error.code: ' +JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message)); 6996 }); 6997 } else { 6998 console.info('Metadata is null.'); 6999 } 7000} 7001``` 7002 7003### setProperties<sup>13+</sup> 7004 7005setProperties(records: Record\<string, string | null>): Promise\<void> 7006 7007Sets the values of properties for the image's metadata. This API uses a promise to return the result. For details about how to obtain the property values, see [PropertyKey](#propertykey7) and [FragmentMapPropertyKey](#fragmentmappropertykey13). 7008 7009**System capability**: SystemCapability.Multimedia.Image.Core 7010 7011**Parameters** 7012 7013| Name | Type | Mandatory| Description | 7014| ------- | ------------------------------ | ---- | ------------------------ | 7015| records | Record<string, string \| null> | Yes | Array of properties and their values.| 7016 7017**Return value** 7018 7019| Type | Description | 7020| -------------- | ------------------------------------- | 7021| Promise\<void> | Promise that returns no value. If the operation fails, an error code is returned.| 7022 7023**Error codes** 7024 7025For details about the error codes, see [Image Error Codes](errorcode-image.md). 7026 7027| ID| Error Message | 7028| -------- | ------------------------------------------------------------ | 7029| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 7030| 7600202 | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. | 7031 7032**Example** 7033 7034```ts 7035import { BusinessError } from '@kit.BasicServicesKit'; 7036import { image } from '@kit.ImageKit'; 7037 7038async function SetProperties() { 7039 const context = getContext(); 7040 const resourceMgr = context.resourceManager; 7041 const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); // The image contains EXIF metadata. 7042 let ops: image.SourceOptions = { 7043 sourceDensity: 98, 7044 } 7045 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 7046 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 7047 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 7048 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 7049 let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType); 7050 if (metaData != null) { 7051 let setkey: Record<string, string | null> = { 7052 "ImageWidth": "200", 7053 "ImageLength": "300" 7054 }; 7055 await metaData.setProperties(setkey).then(async () => { 7056 console.info('Set auxpictureobj properties success.'); 7057 }).catch((error: BusinessError) => { 7058 console.error('Failed to set metadata Properties. code is ${error.code}, message is ${error.message}'); 7059 }) 7060 } else { 7061 console.info('AuxPictureObj metadata is null. '); 7062 } 7063} 7064``` 7065 7066### getAllProperties<sup>13+</sup> 7067 7068getAllProperties(): Promise\<Record<string, string | null>> 7069 7070Obtains all properties and values from the image's metadata. This API uses a promise to return the result. For details about how to obtain the property values, see [PropertyKey](#propertykey7) and [FragmentMapPropertyKey](#fragmentmappropertykey13). 7071 7072**System capability**: SystemCapability.Multimedia.Image.Core 7073 7074**Return value** 7075 7076| Type | Description | 7077| ---------------------------------------- | ------------------------------------------- | 7078| Promise\<Record<string, string \| null>> | Promise used to return the values of all properties.| 7079 7080**Example** 7081 7082```ts 7083import { BusinessError } from '@kit.BasicServicesKit'; 7084import { image } from '@kit.ImageKit'; 7085 7086async function GetAllProperties() { 7087 const context = getContext(); 7088 const resourceMgr = context.resourceManager; 7089 const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); // The image contains EXIF metadata. 7090 let ops: image.SourceOptions = { 7091 sourceDensity: 98, 7092 } 7093 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 7094 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 7095 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 7096 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 7097 let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType); 7098 if (metaData != null) { 7099 await metaData.getAllProperties().then((data2) => { 7100 const count = Object.keys(data2).length; 7101 console.info('Metadata have ', count, ' properties'); 7102 console.info('Get metadata all properties: ', JSON.stringify(data2)); 7103 }).catch((error: BusinessError) => { 7104 console.error('Get metadata all properties failed error.code: ' +JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message)); 7105 }); 7106 } else { 7107 console.info('Metadata is null.'); 7108 } 7109} 7110``` 7111 7112### clone<sup>13+</sup> 7113 7114clone(): Promise\<Metadata> 7115 7116Clones the metadata. This API uses a promise to return the result. 7117 7118**System capability**: SystemCapability.Multimedia.Image.Core 7119 7120**Return value** 7121 7122| Type | Description | 7123| --------------------------------- | --------------------------------- | 7124| Promise\<[Metadata](#metadata13)> | Promise used to return the metadata instance.| 7125 7126**Error codes** 7127 7128For details about the error codes, see [Image Error Codes](errorcode-image.md). 7129 7130| ID| Error Message | 7131| -------- | -------------------- | 7132| 7600301 | Memory alloc failed. | 7133| 7600302 | Memory copy failed. | 7134 7135**Example** 7136 7137```ts 7138import { BusinessError } from '@kit.BasicServicesKit'; 7139import { image } from '@kit.ImageKit'; 7140 7141async function clone() { 7142 const context = getContext(); 7143 const resourceMgr = context.resourceManager; 7144 const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); // The image contains EXIF metadata. 7145 let ops: image.SourceOptions = { 7146 sourceDensity: 98, 7147 } 7148 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 7149 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 7150 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 7151 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 7152 let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType); 7153 if (metaData != null) { 7154 let new_metadata: image.Metadata = await metaData.clone(); 7155 new_metadata.getProperties(["ImageWidth"]).then((data1) => { 7156 console.info('Clone new_metadata and get Properties.', JSON.stringify(data1)); 7157 }).catch((err: BusinessError) => { 7158 console.error('Clone new_metadata failed.', JSON.stringify(err)); 7159 }); 7160 } else { 7161 console.info('Metadata is null.'); 7162 } 7163} 7164``` 7165 7166## image.createImageReceiver<sup>11+</sup> 7167 7168createImageReceiver(size: Size, format: ImageFormat, capacity: number): ImageReceiver 7169 7170Creates an **ImageReceiver** instance by specifying the image size, format, and capacity. 7171 7172**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7173 7174**Parameters** 7175 7176| Name | Type | Mandatory| Description | 7177| -------- | ------ | ---- | ---------------------- | 7178| size | [Size](#size) | Yes | Default size of the image. | 7179| 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.) | 7180| capacity | number | Yes | Maximum number of images that can be accessed at the same time.| 7181 7182**Return value** 7183 7184| Type | Description | 7185| -------------------------------- | --------------------------------------- | 7186| [ImageReceiver](#imagereceiver9) | Returns an **ImageReceiver** instance if the operation is successful.| 7187 7188**Error codes** 7189 7190For details about the error codes, see [Image Error Codes](errorcode-image.md). 7191 7192| ID| Error Message| 7193| ------- | --------------------------------------------| 7194| 401| Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; | 7195 7196**Example** 7197 7198```ts 7199let size: image.Size = { 7200 height: 8192, 7201 width: 8 7202} 7203let receiver: image.ImageReceiver = image.createImageReceiver(size, image.ImageFormat.JPEG, 8); 7204``` 7205 7206## image.createImageReceiver<sup>(deprecated)</sup> 7207 7208createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver 7209 7210Creates an **ImageReceiver** instance by specifying the image width, height, format, and capacity. 7211 7212> **NOTE** 7213> 7214> This API is deprecated since API version 11. You are advised to use [createImageReceiver](#imagecreateimagereceiver11). 7215 7216**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7217 7218**Parameters** 7219 7220| Name | Type | Mandatory| Description | 7221| -------- | ------ | ---- | ---------------------- | 7222| width | number | Yes | Default image width. | 7223| height | number | Yes | Default image height. | 7224| 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.) | 7225| capacity | number | Yes | Maximum number of images that can be accessed at the same time.| 7226 7227**Return value** 7228 7229| Type | Description | 7230| -------------------------------- | --------------------------------------- | 7231| [ImageReceiver](#imagereceiver9) | Returns an **ImageReceiver** instance if the operation is successful.| 7232 7233**Example** 7234 7235```ts 7236let receiver: image.ImageReceiver = image.createImageReceiver(8192, 8, image.ImageFormat.JPEG, 8); 7237``` 7238 7239## ImageReceiver<sup>9+</sup> 7240 7241Provides APIs to obtain the surface ID of a component, read the latest image, read the next image, and release the **ImageReceiver** instance. 7242 7243Before calling any APIs in **ImageReceiver**, you must create an **ImageReceiver** instance. 7244 7245### Properties 7246 7247**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7248 7249| Name | Type | Readable| Writable| Description | 7250| -------- | ---------------------------- | ---- | ---- | ------------------ | 7251| size | [Size](#size) | Yes | No | Image size. | 7252| capacity | number | Yes | No | Maximum number of images that can be accessed at the same time.| 7253| format | [ImageFormat](#imageformat9) | Yes | No | Image format. | 7254 7255### getReceivingSurfaceId<sup>9+</sup> 7256 7257getReceivingSurfaceId(callback: AsyncCallback\<string>): void 7258 7259Obtains a surface ID for the camera or other components. This API uses an asynchronous callback to return the result. 7260 7261**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7262 7263**Parameters** 7264 7265| Name | Type | Mandatory| Description | 7266| -------- | ---------------------- | ---- | -------------------------- | 7267| 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.| 7268 7269**Example** 7270 7271```ts 7272import { BusinessError } from '@kit.BasicServicesKit'; 7273 7274receiver.getReceivingSurfaceId((err: BusinessError, id: string) => { 7275 if (err) { 7276 console.error(`Failed to get the ReceivingSurfaceId.code ${err.code},message is ${err.message}`); 7277 } else { 7278 console.info('Succeeded in getting the ReceivingSurfaceId.'); 7279 } 7280}); 7281``` 7282 7283### getReceivingSurfaceId<sup>9+</sup> 7284 7285getReceivingSurfaceId(): Promise\<string> 7286 7287Obtains a surface ID for the camera or other components. This API uses a promise to return the result. 7288 7289**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7290 7291**Return value** 7292 7293| Type | Description | 7294| ---------------- | -------------------- | 7295| Promise\<string> | Promise used to return the surface ID.| 7296 7297**Example** 7298 7299```ts 7300import { BusinessError } from '@kit.BasicServicesKit'; 7301 7302receiver.getReceivingSurfaceId().then((id: string) => { 7303 console.info('Succeeded in getting the ReceivingSurfaceId.'); 7304}).catch((error: BusinessError) => { 7305 console.error(`Failed to get the ReceivingSurfaceId.code ${error.code},message is ${error.message}`); 7306}) 7307``` 7308 7309### readLatestImage<sup>9+</sup> 7310 7311readLatestImage(callback: AsyncCallback\<Image>): void 7312 7313Reads the latest image from the **ImageReceiver** instance. This API uses an asynchronous callback to return the result. 7314 7315**NOTE**: This API can be called to receive data only after the [on](#on9) callback is triggered. 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. 7316 7317**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7318 7319**Parameters** 7320 7321| Name | Type | Mandatory| Description | 7322| -------- | ------------------------------- | ---- | ------------------------ | 7323| 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. | 7324 7325**Example** 7326 7327```ts 7328import { BusinessError } from '@kit.BasicServicesKit'; 7329 7330receiver.readLatestImage((err: BusinessError, img: image.Image) => { 7331 if (err) { 7332 console.error(`Failed to read the latest Image.code ${err.code},message is ${err.message}`); 7333 } else { 7334 console.info('Succeeded in reading the latest Image.'); 7335 } 7336}); 7337``` 7338 7339### readLatestImage<sup>9+</sup> 7340 7341readLatestImage(): Promise\<Image> 7342 7343Reads the latest image from the **ImageReceiver** instance. This API uses a promise to return the result. 7344 7345**NOTE**: This API can be called to receive data only after the [on](#on9) callback is triggered. 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. 7346 7347**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7348 7349**Return value** 7350 7351| Type | Description | 7352| ------------------------- | ------------------ | 7353| Promise<[Image](#image9)> | Promise used to return the latest image.| 7354 7355**Example** 7356 7357```ts 7358import { BusinessError } from '@kit.BasicServicesKit'; 7359 7360receiver.readLatestImage().then((img: image.Image) => { 7361 console.info('Succeeded in reading the latest Image.'); 7362}).catch((error: BusinessError) => { 7363 console.error(`Failed to read the latest Image.code ${error.code},message is ${error.message}`); 7364}) 7365``` 7366 7367### readNextImage<sup>9+</sup> 7368 7369readNextImage(callback: AsyncCallback\<Image>): void 7370 7371Reads the next image from the **ImageReceiver** instance. This API uses an asynchronous callback to return the result. 7372 7373**NOTE**: This API can be called to receive data only after the [on](#on9) callback is triggered. 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. 7374 7375**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7376 7377**Parameters** 7378 7379| Name | Type | Mandatory| Description | 7380| -------- | ------------------------------- | ---- | -------------------------- | 7381| 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. | 7382 7383**Example** 7384 7385```ts 7386import { BusinessError } from '@kit.BasicServicesKit'; 7387 7388receiver.readNextImage((err: BusinessError, img: image.Image) => { 7389 if (err) { 7390 console.error(`Failed to read the next Image.code ${err.code},message is ${err.message}`); 7391 } else { 7392 console.info('Succeeded in reading the next Image.'); 7393 } 7394}); 7395``` 7396 7397### readNextImage<sup>9+</sup> 7398 7399readNextImage(): Promise\<Image> 7400 7401Reads the next image from the **ImageReceiver** instance. This API uses a promise to return the result. 7402 7403**NOTE**: This API can be called to receive data only after the [on](#on9) callback is triggered. 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. 7404 7405**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7406 7407**Return value** 7408 7409| Type | Description | 7410| ------------------------- | -------------------- | 7411| Promise<[Image](#image9)> | Promise used to return the next image.| 7412 7413**Example** 7414 7415```ts 7416import { BusinessError } from '@kit.BasicServicesKit'; 7417 7418receiver.readNextImage().then((img: image.Image) => { 7419 console.info('Succeeded in reading the next Image.'); 7420}).catch((error: BusinessError) => { 7421 console.error(`Failed to read the next Image.code ${error.code},message is ${error.message}`); 7422}) 7423``` 7424 7425### on<sup>9+</sup> 7426 7427on(type: 'imageArrival', callback: AsyncCallback\<void>): void 7428 7429Listens for image arrival events. 7430 7431**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7432 7433**Parameters** 7434 7435| Name | Type | Mandatory| Description | 7436| -------- | -------------------- | ---- | ------------------------------------------------------ | 7437| type | string | Yes | Type of event to listen for. The value is fixed at **'imageArrival'**, which is triggered when an image is received.| 7438| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 7439 7440**Example** 7441 7442```ts 7443receiver.on('imageArrival', () => { 7444 // image arrival, do something. 7445}) 7446``` 7447 7448### off<sup>13+</sup> 7449 7450off(type: 'imageArrival', callback?: AsyncCallback\<void>): void 7451 7452Unregisters the callback function that is triggered when the buffer is released. 7453 7454**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7455 7456**Parameters** 7457 7458| Name | Type | Mandatory| Description | 7459| -------- | -------------------- |----|----------------------------------------| 7460| type | string | Yes | Type of event, which is **'imageArrival'**.| 7461| callback | AsyncCallback\<void> | No | Callback to unregister. | 7462 7463**Example** 7464 7465```ts 7466let callbackFunc = ()=>{ 7467 // do something. 7468} 7469receiver.on('imageArrival', callbackFunc) 7470receiver.off('imageArrival', callbackFunc) 7471``` 7472 7473### release<sup>9+</sup> 7474 7475release(callback: AsyncCallback\<void>): void 7476 7477Releases this **ImageReceiver** instance. This API uses an asynchronous callback to return the result. 7478 7479ArkTS 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. 7480 7481**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7482 7483**Parameters** 7484 7485| Name | Type | Mandatory| Description | 7486| -------- | -------------------- | ---- | ------------------------ | 7487| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 7488 7489**Example** 7490 7491```ts 7492import { BusinessError } from '@kit.BasicServicesKit'; 7493 7494receiver.release((err: BusinessError) => { 7495 if (err) { 7496 console.error(`Failed to release the receiver.code ${err.code},message is ${err.message}`); 7497 } else { 7498 console.info('Succeeded in releasing the receiver.'); 7499 } 7500}) 7501``` 7502 7503### release<sup>9+</sup> 7504 7505release(): Promise\<void> 7506 7507Releases this **ImageReceiver** instance. This API uses a promise to return the result. 7508 7509ArkTS 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. 7510 7511**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7512 7513**Return value** 7514 7515| Type | Description | 7516| -------------- | ------------------ | 7517| Promise\<void> | Promise that returns no value.| 7518 7519**Example** 7520 7521```ts 7522import { BusinessError } from '@kit.BasicServicesKit'; 7523 7524receiver.release().then(() => { 7525 console.info('Succeeded in releasing the receiver.'); 7526}).catch((error: BusinessError) => { 7527 console.error(`Failed to release the receiver.code ${error.code},message is ${error.message}`); 7528}) 7529``` 7530 7531## image.createImageCreator<sup>11+</sup> 7532 7533createImageCreator(size: Size, format: ImageFormat, capacity: number): ImageCreator 7534 7535Creates an **ImageCreator** instance by specifying the image size, format, and capacity. 7536 7537**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7538 7539**Parameters** 7540 7541| Name | Type | Mandatory| Description | 7542| -------- | ------ | ---- | ---------------------- | 7543| size | [Size](#size) | Yes | Default size of the image. | 7544| format | [ImageFormat](#imageformat9) | Yes | Image format, for example, YCBCR_422_SP or JPEG. | 7545| capacity | number | Yes | Maximum number of images that can be accessed at the same time.| 7546 7547**Return value** 7548 7549| Type | Description | 7550| ------------------------------ | --------------------------------------- | 7551| [ImageCreator](#imagecreator9) | Returns an **ImageCreator** instance if the operation is successful.| 7552 7553 7554**Error codes** 7555 7556For details about the error codes, see [Image Error Codes](errorcode-image.md). 7557 7558| ID| Error Message| 7559| ------- | --------------------------------------------| 7560| 401| Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; | 7561 7562**Example** 7563 7564```ts 7565let size: image.Size = { 7566 height: 8192, 7567 width: 8 7568} 7569let creator: image.ImageCreator = image.createImageCreator(size, image.ImageFormat.JPEG, 8); 7570``` 7571 7572## image.createImageCreator<sup>(deprecated)</sup> 7573 7574createImageCreator(width: number, height: number, format: number, capacity: number): ImageCreator 7575 7576Creates an **ImageCreator** instance by specifying the image width, height, format, and capacity. 7577 7578> **NOTE** 7579> 7580> This API is deprecated since API version 11. You are advised to use [createImageCreator](#imagecreateimagecreator11). 7581 7582**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7583 7584**Parameters** 7585 7586| Name | Type | Mandatory| Description | 7587| -------- | ------ | ---- | ---------------------- | 7588| width | number | Yes | Default image width. | 7589| height | number | Yes | Default image height. | 7590| format | number | Yes | Image format, for example, YCBCR_422_SP or JPEG. | 7591| capacity | number | Yes | Maximum number of images that can be accessed at the same time.| 7592 7593**Return value** 7594 7595| Type | Description | 7596| ------------------------------ | --------------------------------------- | 7597| [ImageCreator](#imagecreator9) | Returns an **ImageCreator** instance if the operation is successful.| 7598 7599**Example** 7600 7601```ts 7602let creator: image.ImageCreator = image.createImageCreator(8192, 8, image.ImageFormat.JPEG, 8); 7603``` 7604 7605## ImageCreator<sup>9+</sup> 7606 7607Provides APIs for applications to request an image native data area and compile native image data. 7608Before calling any APIs in **ImageCreator**, you must create an [ImageCreator](#imagecreator9) instance. **ImageCreator** does not support multiple threads. 7609 7610### Properties 7611 7612**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7613 7614| Name | Type | Readable| Writable| Description | 7615| -------- | ---------------------------- | ---- | ---- | ------------------ | 7616| capacity | number | Yes | No | Maximum number of images that can be accessed at the same time.| 7617| format | [ImageFormat](#imageformat9) | Yes | No | Image format. | 7618 7619### dequeueImage<sup>9+</sup> 7620 7621dequeueImage(callback: AsyncCallback\<Image>): void 7622 7623Obtains an image buffer from the idle queue and writes image data into it. This API uses an asynchronous callback to return the result. 7624 7625**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7626 7627**Parameters** 7628 7629| Name | Type | Mandatory| Description | 7630| ------------- | ---------------------------------------| ---- | -------------------- | 7631| 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. | 7632 7633**Example** 7634 7635```ts 7636import { BusinessError } from '@kit.BasicServicesKit'; 7637 7638creator.dequeueImage((err: BusinessError, img: image.Image) => { 7639 if (err) { 7640 console.error(`Failed to dequeue the Image.code ${err.code},message is ${err.message}`); 7641 } else { 7642 console.info('Succeeded in dequeuing the Image.'); 7643 } 7644}); 7645``` 7646 7647### dequeueImage<sup>9+</sup> 7648 7649dequeueImage(): Promise\<Image> 7650 7651Obtains an image buffer from the idle queue and writes image data into it. This API uses a promise to return the result. 7652 7653**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7654 7655**Return value** 7656 7657| Type | Description | 7658| --------------- | ------------- | 7659| Promise\<[Image](#image9)> | Promise used to return the latest image.| 7660 7661**Example** 7662 7663```ts 7664import { BusinessError } from '@kit.BasicServicesKit'; 7665 7666creator.dequeueImage().then((img: image.Image) => { 7667 console.info('Succeeded in dequeuing the Image.'); 7668}).catch((error: BusinessError) => { 7669 console.error(`Failed to dequeue the Image.code ${error.code},message is ${error.message}`); 7670}) 7671``` 7672 7673### queueImage<sup>9+</sup> 7674 7675queueImage(interface: Image, callback: AsyncCallback\<void>): void 7676 7677Places the drawn image in the dirty queue. This API uses an asynchronous callback to return the result. 7678 7679**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7680 7681**Parameters** 7682 7683| Name | Type | Mandatory| Description | 7684| ------------- | -------------------------| ---- | -------------------- | 7685| interface | [Image](#image9) | Yes | Drawn image.| 7686| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 7687 7688**Example** 7689 7690```ts 7691import { BusinessError } from '@kit.BasicServicesKit'; 7692 7693creator.dequeueImage().then((img: image.Image) => { 7694 // Draw the image. 7695 img.getComponent(4).then((component : image.Component) => { 7696 let bufferArr: Uint8Array = new Uint8Array(component.byteBuffer); 7697 for (let i = 0; i < bufferArr.length; i += 4) { 7698 bufferArr[i] = 0; //B 7699 bufferArr[i + 1] = 0; //G 7700 bufferArr[i + 2] = 255; //R 7701 bufferArr[i + 3] = 255; //A 7702 } 7703 }) 7704 creator.queueImage(img, (err: BusinessError) => { 7705 if (err) { 7706 console.error(`Failed to queue the Image.code ${err.code},message is ${err.message}`); 7707 } else { 7708 console.info('Succeeded in queuing the Image.'); 7709 } 7710 }) 7711}) 7712 7713``` 7714 7715### queueImage<sup>9+</sup> 7716 7717queueImage(interface: Image): Promise\<void> 7718 7719Places the drawn image in the dirty queue. This API uses a promise to return the result. 7720 7721**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7722 7723**Parameters** 7724 7725| Name | Type | Mandatory| Description | 7726| ------------- | --------| ---- | ------------------- | 7727| interface | [Image](#image9) | Yes | Drawn image.| 7728 7729**Return value** 7730 7731| Type | Description | 7732| -------------- | ------------- | 7733| Promise\<void> | Promise that returns no value.| 7734 7735**Example** 7736 7737```ts 7738import { BusinessError } from '@kit.BasicServicesKit'; 7739 7740creator.dequeueImage().then((img: image.Image) => { 7741 // Draw the image. 7742 img.getComponent(4).then((component: image.Component) => { 7743 let bufferArr: Uint8Array = new Uint8Array(component.byteBuffer); 7744 for (let i = 0; i < bufferArr.length; i += 4) { 7745 bufferArr[i] = 0; //B 7746 bufferArr[i + 1] = 0; //G 7747 bufferArr[i + 2] = 255; //R 7748 bufferArr[i + 3] = 255; //A 7749 } 7750 }) 7751 creator.queueImage(img).then(() => { 7752 console.info('Succeeded in queuing the Image.'); 7753 }).catch((error: BusinessError) => { 7754 console.error(`Failed to queue the Image.code ${error.code},message is ${error.message}`); 7755 }) 7756}) 7757 7758``` 7759 7760### on<sup>9+</sup> 7761 7762on(type: 'imageRelease', callback: AsyncCallback\<void>): void 7763 7764Listens for image release events. This API uses an asynchronous callback to return the result. 7765 7766**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7767 7768**Parameters** 7769 7770| Name | Type | Mandatory| Description | 7771| ------------- | -------------------------| ---- | -------------------- | 7772| type | string | Yes | Type of event, which is **'imageRelease'**.| 7773| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 7774 7775**Example** 7776 7777```ts 7778import { BusinessError } from '@kit.BasicServicesKit'; 7779 7780creator.on('imageRelease', (err: BusinessError) => { 7781 if (err) { 7782 console.error(`Failed to get the imageRelease callback.code ${err.code},message is ${err.message}`); 7783 } else { 7784 console.info('Succeeded in getting imageRelease callback.'); 7785 } 7786}) 7787``` 7788 7789### off<sup>13+</sup> 7790 7791off(type: 'imageRelease', callback?: AsyncCallback\<void>): void 7792 7793Unregisters the callback function that is triggered when the buffer is released. 7794 7795**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7796 7797**Parameters** 7798 7799| Name | Type | Mandatory| Description | 7800| ------------- | -------------------------|----|--------------------------------------------| 7801| type | string | Yes | Type of event, which is **'imageRelease'**. | 7802| callback | AsyncCallback\<void> | No | Callback to unregister.| 7803 7804**Example** 7805 7806```ts 7807let callbackFunc = ()=>{ 7808 // do something. 7809} 7810creator.on('imageRelease', callbackFunc) 7811creator.off('imageRelease', callbackFunc) 7812``` 7813 7814### release<sup>9+</sup> 7815 7816release(callback: AsyncCallback\<void>): void 7817 7818Releases this **ImageCreator** instance. This API uses an asynchronous callback to return the result. 7819 7820ArkTS 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. 7821 7822**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7823 7824**Parameters** 7825 7826| Name | Type | Mandatory| Description | 7827| ------------- | -------------------------| ---- | -------------------- | 7828| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 7829 7830**Example** 7831 7832```ts 7833import { BusinessError } from '@kit.BasicServicesKit'; 7834 7835creator.release((err: BusinessError) => { 7836 if (err) { 7837 console.error(`Failed to release the creator.code ${err.code},message is ${err.message}`); 7838 } else { 7839 console.info('Succeeded in releasing creator.'); 7840 } 7841}); 7842``` 7843### release<sup>9+</sup> 7844 7845release(): Promise\<void> 7846 7847Releases this **ImageCreator** instance. This API uses a promise to return the result. 7848 7849ArkTS 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. 7850 7851**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7852 7853**Return value** 7854 7855| Type | Description | 7856| -------------- | ------------- | 7857| Promise\<void> | Promise that returns no value.| 7858 7859**Example** 7860 7861```ts 7862import { BusinessError } from '@kit.BasicServicesKit'; 7863 7864creator.release().then(() => { 7865 console.info('Succeeded in releasing creator.'); 7866}).catch((error: BusinessError) => { 7867 console.error(`Failed to release the creator.code ${error.code},message is ${error.message}`); 7868}) 7869``` 7870 7871## Image<sup>9+</sup> 7872 7873Provides 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. 7874 7875### Properties 7876 7877**System capability**: SystemCapability.Multimedia.Image.Core 7878 7879| Name | Type | Readable| Writable| Description | 7880| -------- | ------------------ | ---- | ---- | -------------------------------------------------- | 7881| clipRect | [Region](#region8) | Yes | Yes | Image area to be cropped. | 7882| size | [Size](#size) | Yes | No | Image size. If the **image** object stores the camera preview stream data (YUV image data), the width and height in **size** obtained correspond to those of the YUV image. If the **image** object stores the camera photo stream data (JPEG image data, which is already encoded), the width in **size** obtained is the JPEG data size, and the height is 1. The type of data stored in the **image** object depends on whether the application passes the surface ID in the receiver to a **previewOutput** or **captureOutput** object of the camera. For details about the best practices of camera preview and photo capture, see [Dual-Channel Preview (ArkTS)](../../media/camera/camera-dual-channel-preview.md) and [Photo Capture Sample (ArkTS)](../../media/camera/camera-shooting-case.md). | 7883| format | number | Yes | No | Image format. For details, see [OH_NativeBuffer_Format](../apis-arkgraphics2d/_o_h___native_buffer.md#oh_nativebuffer_format).| 7884| timestamp<sup>12+</sup> | number | Yes | No | Image timestamp. Timestamps, measured in nanoseconds, are usually monotonically increasing. The specific meaning and baseline of these timestamps are determined by the image producer, which is the camera in the camera preview and photo scenarios. As a result, images from different producers may carry timestamps with distinct meanings and baselines, making direct comparison between them infeasible. To obtain the generation time of a photo, you can use [getImageProperty](#getimageproperty11) to read the related EXIF information.| 7885 7886### getComponent<sup>9+</sup> 7887 7888getComponent(componentType: ComponentType, callback: AsyncCallback\<Component>): void 7889 7890Obtains the component buffer from the **Image** instance based on the color component type. This API uses an asynchronous callback to return the result. 7891 7892**System capability**: SystemCapability.Multimedia.Image.Core 7893 7894**Parameters** 7895 7896| Name | Type | Mandatory| Description | 7897| ------------- | --------------------------------------- | ---- | -------------------- | 7898| 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.) | 7899| 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. | 7900 7901**Example** 7902 7903```ts 7904import { BusinessError } from '@kit.BasicServicesKit'; 7905 7906img.getComponent(4, (err: BusinessError, component: image.Component) => { 7907 if (err) { 7908 console.error(`Failed to get the component.code ${err.code},message is ${err.message}`); 7909 } else { 7910 console.info('Succeeded in getting component.'); 7911 } 7912}) 7913``` 7914 7915### getComponent<sup>9+</sup> 7916 7917getComponent(componentType: ComponentType): Promise\<Component> 7918 7919Obtains the component buffer from the **Image** instance based on the color component type. This API uses a promise to return the result. 7920 7921**System capability**: SystemCapability.Multimedia.Image.Core 7922 7923**Parameters** 7924 7925| Name | Type | Mandatory| Description | 7926| ------------- | -------------------------------- | ---- | ---------------- | 7927| 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.)| 7928 7929**Return value** 7930 7931| Type | Description | 7932| --------------------------------- | --------------------------------- | 7933| Promise<[Component](#component9)> | Promise used to return the component buffer.| 7934 7935**Example** 7936 7937```ts 7938import { BusinessError } from '@kit.BasicServicesKit'; 7939 7940img.getComponent(4).then((component: image.Component) => { 7941 console.info('Succeeded in getting component.'); 7942}).catch((error: BusinessError) => { 7943 console.error(`Failed to get the component.code ${error.code},message is ${error.message}`); 7944}) 7945``` 7946 7947### release<sup>9+</sup> 7948 7949release(callback: AsyncCallback\<void>): void 7950 7951Releases this **Image** instance. This API uses an asynchronous callback to return the result. 7952 7953The corresponding resources must be released before another image arrives. 7954 7955ArkTS 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. 7956 7957**System capability**: SystemCapability.Multimedia.Image.Core 7958 7959**Parameters** 7960 7961| Name | Type | Mandatory| Description | 7962| -------- | -------------------- | ---- | -------------- | 7963| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 7964 7965**Example** 7966 7967```ts 7968import { BusinessError } from '@kit.BasicServicesKit'; 7969 7970img.release((err: BusinessError) => { 7971 if (err) { 7972 console.error(`Failed to release the image instance.code ${err.code},message is ${err.message}`); 7973 } else { 7974 console.info('Succeeded in releasing the image instance.'); 7975 } 7976}) 7977``` 7978 7979### release<sup>9+</sup> 7980 7981release(): Promise\<void> 7982 7983Releases this **Image** instance. This API uses a promise to return the result. 7984 7985The corresponding resources must be released before another image arrives. 7986 7987ArkTS 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. 7988 7989**System capability**: SystemCapability.Multimedia.Image.Core 7990 7991**Return value** 7992 7993| Type | Description | 7994| -------------- | --------------------- | 7995| Promise\<void> | Promise that returns no value.| 7996 7997**Example** 7998 7999```ts 8000import { BusinessError } from '@kit.BasicServicesKit'; 8001 8002img.release().then(() => { 8003 console.info('Succeeded in releasing the image instance.'); 8004}).catch((error: BusinessError) => { 8005 console.error(`Failed to release the image instance.code ${error.code},message is ${error.message}`); 8006}) 8007``` 8008 8009## PositionArea<sup>7+</sup> 8010 8011Describes area information in an image. 8012 8013**Widget capability**: This API can be used in ArkTS widgets since API version 12. 8014 8015**Atomic service API**: This API can be used in atomic services since API version 11. 8016 8017**System capability**: SystemCapability.Multimedia.Image.Core 8018 8019| Name | Type | Read Only| Optional| Description | 8020| ------ | ------------------ | ---| -----|------------------------------------------------------- | 8021| pixels | ArrayBuffer | No| No | Pixels of the image. Only pixel data in BGRA_8888 format is supported.| 8022| offset | number | No| No | Offset for data reading. | 8023| 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. | 8024| region | [Region](#region8) | 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.| 8025 8026## ImageInfo 8027 8028Describes image information. 8029 8030**System capability**: SystemCapability.Multimedia.Image.Core 8031 8032| Name| Type | Read Only| Optional| Description | 8033| ---- | ------------- | --- |-----|---------- | 8034| 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.| 8035| 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.| 8036| 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.| 8037| 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.| 8038| 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.| 8039| mimeType<sup>12+</sup> | string | No | No |Actual image format (MIME type). | 8040| 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 PixelMap is in HDR format.| 8041 8042## Size 8043 8044Describes the size of an image. 8045 8046**Widget capability**: This API can be used in ArkTS widgets since API version 12. 8047 8048**Atomic service API**: This API can be used in atomic services since API version 11. 8049 8050**System capability**: SystemCapability.Multimedia.Image.Core 8051 8052| Name | Type | Read Only| Optional |Description | 8053| ------ | ------ | -- |-----| -------------- | 8054| height | number | No | No |Image height, in px.| 8055| width | number | No | No| Image width, in px.| 8056 8057## PixelMapFormat<sup>7+</sup> 8058 8059Enumerates the pixel formats of images. 8060 8061**System capability**: SystemCapability.Multimedia.Image.Core 8062 8063| Name | Value | Description | 8064| ---------------------- | ------ | ----------------- | 8065| UNKNOWN | 0 | Unknown format.<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. | 8066| ARGB_8888<sup>18+</sup> | 1 | The color information consists of four components: alpha, R (Red), G (Green), and B (Blue). Each component occupies 8 bits, and the total length is 32 bits. Currently, this format supports only PixelMap APIs.| 8067| RGB_565 | 2 | The color information consists of three components: R (Red), G (Green), and B (Blue), which occupies five bits, six bits, and five bits, respectively. The total length is 16 bits.<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. | 8068| RGBA_8888 | 3 | The color information consists of four components: R (Red), G (Green), B (Blue), and alpha. Each component occupies 8 bits, and the total length is 32 bits.<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.| 8069| BGRA_8888<sup>9+</sup> | 4 | The color information consists of four components: B (Blue), G (Green), R (Red), and alpha. Each components occupies 8 bits, and the total length is 32 bits.<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.| 8070| RGB_888<sup>9+</sup> | 5 | The color information consists of three components: R (Red), G (Green), and B (Blue). Each component occupies 8 bits, and the total length is 24 bits.<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. | 8071| ALPHA_8<sup>9+</sup> | 6 | The color information consists of only the alpha component, which occupies eight bits.<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. | 8072| RGBA_F16<sup>9+</sup> | 7 | The color information consists of four components: R (Red), G (Green), B (Blue), and alpha. Each component occupies 16 bits, and the total length is 64 bits.<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. | 8073| NV21<sup>9+</sup> | 8 | The color information consists of the luminance component Y and the interleaved chrominance components V and U. The Y component occupies 8 bits, and the UV components occupies 4 bits on average due to 4:2:0 sampling. The total length is 12 bits on average.<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. | 8074| NV12<sup>9+</sup> | 9 | The color information consists of the luminance component Y and the interleaved chrominance components U and V. The Y component occupies 8 bits, and the UV components occupies 4 bits on average due to 4:2:0 sampling. The total length is 12 bits on average.<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. | 8075| RGBA_1010102<sup>12+</sup> | 10 | The color information consists of four components: R (Red), G (Green), B (Blue), and alpha. R, G, and B each occupy 10 bits, and alpha occupies 2 bits. The total length is 32 bits.| 8076| YCBCR_P010<sup>12+</sup> | 11 | The color information consists of the luminance component Y and the chrominance components Cb and Cr. Each component has effective 10 bits. In storage, the Y plane uses 16 bits per pixel (10 of which are effective). The UV plane is interleaved, with every four pixels taking up 32 bits of data (each chrominance component having 10 effective bits), resulting in an average of 15 effective bits overall. 8077| YCRCB_P010<sup>12+</sup> | 12 | The color information consists of the luminance component Y and the chrominance components Cr and Cb Each component has effective 10 bits. In storage, the Y plane uses 16 bits per pixel (10 of which are effective). The UV plane is interleaved, with every four pixels taking up 32 bits of data (each chrominance component having 10 effective bits), resulting in an average of 15 effective bits overall. | 8078| ASTC_4x4<sup>18+</sup> | 102 | The storage format is ASTC_4x4, and the memory usage is only 1/4 of that of RGBA_8888. This format is used only for direct display and does not support pixel access or post-processing editing. | 8079 8080## AlphaType<sup>9+</sup> 8081 8082Enumerates the alpha types of images. 8083 8084**Widget capability**: This API can be used in ArkTS widgets since API version 12. 8085 8086**Atomic service API**: This API can be used in atomic services since API version 11. 8087 8088**System capability**: SystemCapability.Multimedia.Image.Core 8089 8090| Name | Value | Description | 8091| -------- | ------ | ----------------------- | 8092| UNKNOWN | 0 | Unknown alpha type. | 8093| OPAQUE | 1 | There is no alpha or the image is opaque.| 8094| PREMUL | 2 | Premultiplied alpha. | 8095| UNPREMUL | 3 | RGB non-premultiplied alpha. | 8096 8097## AuxiliaryPictureType<sup>13+</sup> 8098 8099Enumerates the auxiliary pictures types. 8100 8101**System capability**: SystemCapability.Multimedia.Image.Core 8102 8103| Name | Value | Description | 8104| ------------- | ---- | ------------ | 8105| GAINMAP | 1 | Gain map, a mechanism for transforming an SDR image into an HDR image capable of display adjustment. It is a set of combinations describing how to apply gain map metadata. | 8106| DEPTH_MAP | 2 | Depth map, which stores the depth data of an image. It captures the distance between each pixel and the camera to provide 3D scene structure. It is usually used for 3D modeling and scene comprehension. | 8107| UNREFOCUS_MAP | 3 | Defocused portrait original image, which provides a method to emphasize background blur in portrait photographing. It helps users select a focus region in post-processing, allowing for greater creative control. | 8108| LINEAR_MAP | 4 | Linear map, which is used to provide additional viewpoints or supplementary information. It is usually used to enhance visual effects and can contain linear representations of lighting, colors, or other visual elements in a scene. | 8109| FRAGMENT_MAP | 5 | Fragment map, which indicates regions obscured by watermarks in the original image. It is used to remove or correct the watermark interference, thereby enhancing the image completeness and visibility.| 8110 8111## AuxiliaryPictureInfo<sup>13+</sup> 8112 8113Describes the auxiliary picture information. 8114 8115**System capability**: SystemCapability.Multimedia.Image.Core 8116 8117| Name | Type | Read Only| Optional| Description | 8118| ------------------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ | 8119| auxiliaryPictureType | [AuxiliaryPictureType](#auxiliarypicturetype13) | No | No | Auxiliary picture type. | 8120| size | [Size](#size) | No | No | Image size.| 8121| rowStride | number | No | No | Row stride. | 8122| pixelFormat | [PixelMapFormat](#pixelmapformat7) | No | No | Pixel format.| 8123| colorSpace | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | No | No | Color space. | 8124 8125## MetadataType<sup>13+</sup> 8126 8127Enumerates image metadata types. 8128 8129**System capability**: SystemCapability.Multimedia.Image.Core 8130 8131| Name | Value | Description | 8132| ----------------- | ---- | ------------------ | 8133| EXIF_METADATA | 1 | EXIF data. | 8134| FRAGMENT_METADATA | 2 | Fragment map metadata.| 8135 8136## ScaleMode<sup>9+</sup> 8137 8138Enumerates the scale modes of images. 8139 8140**Widget capability**: This API can be used in ArkTS widgets since API version 12. 8141 8142**Atomic service API**: This API can be used in atomic services since API version 11. 8143 8144**System capability**: SystemCapability.Multimedia.Image.Core 8145 8146| Name | Value | Description | 8147| --------------- | ------ | -------------------------------------------------- | 8148| CENTER_CROP | 1 | Scales the image so that it fills the requested bounds of the target and crops the extra.| 8149| FIT_TARGET_SIZE | 0 | Reduces the image size to the dimensions of the target. | 8150 8151## SourceOptions<sup>9+</sup> 8152 8153Defines image source initialization options. 8154 8155**Widget capability**: This API can be used in ArkTS widgets since API version 12. 8156 8157**Atomic service API**: This API can be used in atomic services since API version 11. 8158 8159**System capability**: SystemCapability.Multimedia.Image.Core 8160 8161| Name | Type | Read Only| Optional| Description | 8162| ----------------- | ---------------------------------- | ---- | ---- | ------------------ | 8163| 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 PixelMap 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.| 8164| sourcePixelFormat | [PixelMapFormat](#pixelmapformat7) | No | Yes | Image pixel format. The default value is **UNKNOWN**. | 8165| sourceSize | [Size](#size) | No | Yes | Image pixel size. The default value is null. | 8166 8167 8168## InitializationOptions<sup>8+</sup> 8169 8170Defines PixelMap initialization options. 8171 8172**System capability**: SystemCapability.Multimedia.Image.Core 8173 8174| Name | Type | Read Only|Optional| Description | 8175| ------------------------ | ---------------------------------- | ----| -----| -------------- | 8176| 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. | 8177| 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.| 8178| srcPixelFormat<sup>12+</sup> | [PixelMapFormat](#pixelmapformat7) | No| Yes| Pixel format of the passed-in buffer data. The default value is **BGRA_8888**.| 8179| pixelFormat | [PixelMapFormat](#pixelmapformat7) | No| Yes| Pixel format of the generated PixelMap. 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. | 8180| 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. | 8181| 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.| 8182 8183## DecodingOptions<sup>7+</sup> 8184 8185Describes the image decoding options. 8186 8187**System capability**: SystemCapability.Multimedia.Image.ImageSource 8188 8189| Name | Type | Read Only| Optional| Description | 8190| ------------------ | ---------------------------------- | ---- | ---- | ---------------- | 8191| 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.| 8192| 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. | 8193| 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. | 8194| desiredSize | [Size](#size) | No | Yes | Expected output size. The value must be a positive integer and defaults to the original image size. If the output size is different from the original size, the output is stretched or scaled to the specified 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. | 8195| desiredRegion | [Region](#region8) | No | Yes | Rectangle specified by **Region** in the decoded image. When the original image is large and only a specific part of the image is required, you can set this parameter to improve performance. The default value is the original 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. | 8196| 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.| 8197| 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. | 8198| 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. | 8199| desiredColorSpace<sup>11+</sup> | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | No | Yes | Target color space. The default value is **UNKNOWN**.| 8200| 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.| 8201 8202## DecodingOptionsForPicture<sup>13+</sup> 8203 8204Describes the image decoding options. 8205 8206**System capability**: SystemCapability.Multimedia.Image.ImageSource 8207 8208| Name | Type | Read Only| Optional| Description | 8209| ------------------------ | ------------------------------------------------------- | ---- | ---- | ------------------------------------------------------------ | 8210| desiredAuxiliaryPictures | Array\<[AuxiliaryPictureType](#auxiliarypicturetype13)> | No | No | Auxiliary picture type. By default, all auxiliary picture types are decoded.| 8211 8212## Region<sup>8+</sup> 8213 8214Describes the region information. 8215 8216**Widget capability**: This API can be used in ArkTS widgets since API version 12. 8217 8218**Atomic service API**: This API can be used in atomic services since API version 11. 8219 8220**System capability**: SystemCapability.Multimedia.Image.Core 8221 8222| Name| Type | Read Only| Optional| Description | 8223| ---- | ------------- | ---- | ---- | ------------ | 8224| size<sup>7+</sup> | [Size](#size) | No | No | Region size. | 8225| x<sup>7+</sup> | number | No | No | X coordinate of the upper left corner of the region.| 8226| y<sup>7+</sup> | number | No | No | Y coordinate of the upper left corner of the region.| 8227 8228## PackingOption 8229 8230Describes the options for image packing. 8231 8232**System capability**: SystemCapability.Multimedia.Image.ImagePacker 8233 8234| Name | Type | Read Only| Optional| Description | 8235| ------- | ------ | ---- | ---- | --------------------------------------------------- | 8236| format | string | No | No | Format of the packed image.<br>Currently, only image/jpeg, image/webp, image/png, and image/heic (or image/heif)<sup>12+</sup> (depending on the hardware) are supported.<br>**NOTE**: The JPEG format does not support the alpha channel. If the JPEG format with the alpha channel is used for data encoding, the transparent color turns black.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 8237| 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.| 8238| bufferSize<sup>9+</sup> | number | No | Yes | Size of the buffer for receiving the encoded data, in bytes. If this parameter 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.| 8239| desiredDynamicRange<sup>12+</sup> | [PackingDynamicRange](#packingdynamicrange12) | No | Yes | Desired dynamic range. The default value is **SDR**.| 8240| needsPackProperties<sup>12+</sup> | boolean | No | Yes | Whether to encode image property information, for example, EXIF. The default value is **false**.| 8241 8242## ImagePropertyOptions<sup>11+</sup> 8243 8244Describes the image properties. 8245 8246**System capability**: SystemCapability.Multimedia.Image.ImageSource 8247 8248| Name | Type | Read Only| Optional| Description | 8249| ------------ | ------ | ---- | ---- | ------------ | 8250| index | number | Yes | Yes | Index of the image. The default value is **0**. | 8251| defaultValue | string | Yes | Yes | Default property value. The default value is null.| 8252 8253## GetImagePropertyOptions<sup>(deprecated)</sup> 8254 8255Describes the image properties. 8256 8257> **NOTE** 8258> 8259> This API is deprecated since API version 11. You are advised to use [ImagePropertyOptions](#imagepropertyoptions11). 8260 8261**System capability**: SystemCapability.Multimedia.Image.ImageSource 8262 8263| Name | Type | Read Only| Optional| Description | 8264| ------------ | ------ | ---- | ---- | ------------ | 8265| index | number | No | Yes | Index of the image. The default value is **0**. | 8266| defaultValue | string | No | Yes | Default property value. The default value is null.| 8267 8268## PropertyKey<sup>7+</sup> 8269 8270Describes the exchangeable image file format (EXIF) data of an image. 8271 8272**System capability**: SystemCapability.Multimedia.Image.Core 8273 8274| Name | Value | Description | 8275| ----------------- | ----------------------- |---------------------------| 8276| 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.| 8277| 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.| 8278| IMAGE_WIDTH | "ImageWidth" | **Read/Write capability**: readable and writable<br> Image width.| 8279| IMAGE_LENGTH | "ImageLength" | **Read/Write capability**: readable and writable<br> Image length.| 8280| BITS_PER_SAMPLE | "BitsPerSample" | **Read/Write capability**: readable and writable<br> Number of bits per sample. For example, for RGB, which has three components, the format is 8, 8, 8.| 8281| COMPRESSION <sup>12+</sup> | "Compression" | **Read/Write capability**: readable and writable<br> Compression scheme used on the image data.| 8282| PHOTOMETRIC_INTERPRETATION <sup>12+</sup> | "PhotometricInterpretation" | **Read/Write capability**: readable and writable<br> Color space of the image data, for example, RGB or YCbCr.| 8283| IMAGE_DESCRIPTION<sup>10+</sup> | "ImageDescription" | **Read/Write capability**: readable and writable<br> Image description.| 8284| MAKE<sup>10+</sup> | "Make" | **Read/Write capability**: readable and writable<br> Manufacturer.| 8285| MODEL<sup>10+</sup> | "Model" | **Read/Write capability**: readable and writable<br> Device model.| 8286| STRIP_OFFSETS <sup>12+</sup> | "StripOffsets" | **Read/Write capability**: readable and writable<br> Byte offset of each strip.| 8287| 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.| 8288| 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.| 8289| ROWS_PER_STRIP <sup>12+</sup> | "RowsPerStrip" | **Read/Write capability**: readable and writable<br> Number of rows per strip.| 8290| STRIP_BYTE_COUNTS <sup>12+</sup> | "StripByteCounts" | **Read/Write capability**: readable and writable<br> Number of bytes in each strip after compression.| 8291| X_RESOLUTION <sup>12+</sup> | "XResolution" | **Read/Write capability**: readable and writable<br> Number of pixels per ResolutionUnit in the image width (X) direction.| 8292| Y_RESOLUTION <sup>12+</sup> | "YResolution" | **Read/Write capability**: readable and writable<br> Number of pixels per ResolutionUnit in the image height (Y) direction.| 8293| 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.| 8294| RESOLUTION_UNIT <sup>12+</sup> | "ResolutionUnit" | **Read/Write capability**: readable and writable<br> Unit of measurement for XResolution and YResolution.| 8295| 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.| 8296| SOFTWARE <sup>12+</sup> | "Software" | **Read/Write capability**: readable and writable<br> Name and version number of the software used to create the image.| 8297| DATE_TIME<sup>10+</sup> | "DateTime" | **Read/Write capability**: readable and writable<br> Date and time of image creation. An example in the correct format is 2024:01:25 05:51:34.| 8298| ARTIST <sup>12+</sup> | "Artist" | **Read/Write capability**: readable and writable<br> Person who created the image.| 8299| WHITE_POINT <sup>12+</sup> | "WhitePoint" | **Read/Write capability**: readable and writable<br> Chromaticity of the white point of the image.| 8300| PRIMARY_CHROMATICITIES <sup>12+</sup> | "PrimaryChromaticities" | **Read/Write capability**: readable and writable<br> Chromaticities of the primaries of the image.| 8301| PHOTO_MODE<sup>10+</sup> | "PhotoMode" | **Read/Write capability**: readable and writable<br> Photographing mode.| 8302| 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.| 8303| JPEG_INTERCHANGE_FORMAT_LENGTH <sup>12+</sup> | "JPEGInterchangeFormatLength" | **Read/Write capability**: readable and writable<br> Number of bytes of the JPEG stream.| 8304| YCBCR_COEFFICIENTS <sup>12+</sup> | "YCbCrCoefficients" | **Read/Write capability**: readable and writable<br> Transformation from RGB to YCbCr image data.| 8305| 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.| 8306| YCBCR_POSITIONING <sup>12+</sup> | "YCbCrPositioning" | **Read/Write capability**: readable and writable<br> Positioning of subsampled chrominance components relative to luminance samples.| 8307| 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.| 8308| COPYRIGHT <sup>12+</sup> | "Copyright" | **Read/Write capability**: readable and writable<br> Copyright notice of the image.| 8309| EXPOSURE_TIME<sup>9+</sup> | "ExposureTime" | **Read/Write capability**: readable and writable<br> Exposure time, for example, 1/33 seconds.| 8310| F_NUMBER<sup>9+</sup> | "FNumber" | **Read/Write capability**: readable and writable<br> F number, for example, f/1.8.| 8311| 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.| 8312| SPECTRAL_SENSITIVITY <sup>12+</sup> | "SpectralSensitivity" | **Read/Write capability**: readable and writable<br> Spectral sensitivity of each channel of the camera.| 8313| GPS_VERSION_ID <sup>12+</sup> | "GPSVersionID" | **Read/Write capability**: readable and writable<br> Version of GPSInfoIFD.| 8314| GPS_LATITUDE_REF | "GPSLatitudeRef" | **Read/Write capability**: readable and writable<br> Whether the latitude is north or south latitude.| 8315| GPS_LATITUDE | "GPSLatitude" | **Read/Write capability**: readable and writable<br> Image latitude. The value must be in the format of degree,minute,second, for example, 39,54,7.542.| 8316| GPS_LONGITUDE_REF | "GPSLongitudeRef" | **Read/Write capability**: readable and writable<br> Whether the longitude is east or west longitude.| 8317| GPS_LONGITUDE | "GPSLongitude" | **Read/Write capability**: readable and writable<br> Image longitude. The value must be in the format of degree,minute,second, for example, 116,19,42.16.| 8318| GPS_ALTITUDE_REF <sup>12+</sup> | "GPSAltitudeRef" | **Read/Write capability**: readable and writable<br> Whether the latitude is north or south latitude.| 8319| GPS_ALTITUDE <sup>12+</sup> | "GPSAltitude" | **Read/Write capability**: readable and writable<br> Altitude based on the reference in GPSAltitudeRef.| 8320| GPS_TIME_STAMP<sup>10+</sup> | "GPSTimeStamp" | **Read/Write capability**: readable and writable<br> GPS timestamp.| 8321| GPS_SATELLITES <sup>12+</sup> | "GPSSatellites" | **Read/Write capability**: readable and writable<br> GPS satellites used for measurement.| 8322| GPS_STATUS <sup>12+</sup> | "GPSStatus" | **Read/Write capability**: readable and writable<br> Status of the GPS receiver when the image was recorded.| 8323| GPS_MEASURE_MODE <sup>12+</sup> | "GPSMeasureMode" | **Read/Write capability**: readable and writable<br> GPS measurement pmode.| 8324| GPS_DOP <sup>12+</sup> | "GPSDOP" | **Read/Write capability**: readable and writable<br> GPS DOP (data degree of precision)| 8325| 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.| 8326| GPS_SPEED <sup>12+</sup> | "GPSSpeed" | **Read/Write capability**: readable and writable<br> Movement speed of the GPS receiver.| 8327| GPS_TRACK_REF <sup>12+</sup> | "GPSTrackRef" | **Read/Write capability**: readable and writable<br> Reference of the movement direction of the GPS receiver.| 8328| GPS_TRACK <sup>12+</sup> | "GPSTrack" | **Read/Write capability**: readable and writable<br> Movement direction of the GPS receiver.| 8329| 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.| 8330| GPS_IMG_DIRECTION <sup>12+</sup> | "GPSImgDirection" | **Read/Write capability**: readable and writable<br> Direction of the image when it was captured.| 8331| GPS_MAP_DATUM <sup>12+</sup> | "GPSMapDatum" | **Read/Write capability**: readable and writable<br> Geodetic survey data used by the GPS receiver.| 8332| 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.| 8333| GPS_DEST_LATITUDE <sup>12+</sup> | "GPSDestLatitude" | **Read/Write capability**: readable and writable<br> Latitude of the destination point.| 8334| 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.| 8335| GPS_DEST_LONGITUDE <sup>12+</sup> | "GPSDestLongitude" | **Read/Write capability**: readable and writable<br> Longitude of the destination point.| 8336| GPS_DEST_BEARING_REF <sup>12+</sup> | "GPSDestBearingRef" | **Read/Write capability**: readable and writable<br> Reference of the bearing to the destination point.| 8337| GPS_DEST_BEARING <sup>12+</sup> | "GPSDestBearing" | **Read/Write capability**: readable and writable<br> Bearing to the destination point.| 8338| 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.| 8339| GPS_DEST_DISTANCE <sup>12+</sup> | "GPSDestDistance" | **Read/Write capability**: readable and writable<br> Distance to the destination point.| 8340| 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.| 8341| GPS_AREA_INFORMATION <sup>12+</sup> | "GPSAreaInformation" | **Read/Write capability**: readable and writable<br> String that records the name of the GPS area.| 8342| GPS_DATE_STAMP<sup>10+</sup> | "GPSDateStamp" | **Read/Write capability**: readable and writable<br> GPS date stamp.| 8343| 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.| 8344| GPS_H_POSITIONING_ERROR <sup>12+</sup> | "GPSHPositioningError" | **Read/Write capability**: readable and writable<br> Horizontal positioning error, in meters.| 8345| ISO_SPEED_RATINGS<sup>9+</sup> | "ISOSpeedRatings" | **Read/Write capability**: readable and writable<br> ISO sensitivity or ISO speed, for example, 400.| 8346| 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.| 8347| OECF <sup>12+</sup> | "OECF" | **Read/Write capability**: readable and writable<br> Opto-Electric Conversion Function (OECF) specified in ISO 14524.| 8348| SENSITIVITY_TYPE<sup>10+</sup> | "SensitivityType" | **Read/Write capability**: readable and writable<br> Sensitivity type.| 8349| STANDARD_OUTPUT_SENSITIVITY<sup>10+</sup> | "StandardOutputSensitivity" | **Read/Write capability**: readable and writable<br> Standard output sensitivity.| 8350| RECOMMENDED_EXPOSURE_INDEX<sup>10+</sup> | "RecommendedExposureIndex" | **Read/Write capability**: readable and writable<br> Recommended exposure index.| 8351| ISO_SPEED<sup>10+</sup> | "ISOSpeedRatings" | **Read/Write capability**: readable and writable<br> ISO speed.| 8352| 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.| 8353| 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.| 8354| EXIF_VERSION <sup>12+</sup> | "ExifVersion" | **Read/Write capability**: readable and writable<br> Version of the supported EXIF standard.| 8355| 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.| 8356| 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.| 8357| 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.| 8358| 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.| 8359| 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.| 8360| COMPONENTS_CONFIGURATION <sup>12+</sup> | "ComponentsConfiguration" | **Read/Write capability**: readable and writable<br> Specific information about compressed data.| 8361| 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.| 8362| SHUTTER_SPEED <sup>12+</sup> | "ShutterSpeedValue" | **Read/Write capability**: readable and writable<br> Shutter speed, expressed in Additive System of Photographic Exposure (APEX) values.| 8363| APERTURE_VALUE<sup>10+</sup> | "ApertureValue" | **Read/Write capability**: readable and writable<br> Lens aperture. An example in the correct format is 4/1.| 8364| BRIGHTNESS_VALUE <sup>12+</sup> | "BrightnessValue" | **Read/Write capability**: readable and writable<br> Value of brightness, expressed in APEX values.| 8365| EXPOSURE_BIAS_VALUE<sup>10+</sup> | "ExposureBiasValue" | **Read/Write capability**: readable and writable<br> Exposure bias.| 8366| MAX_APERTURE_VALUE <sup>12+</sup> | "MaxApertureValue" | **Read/Write capability**: readable and writable<br> Smallest F number of the lens.| 8367| SUBJECT_DISTANCE <sup>12+</sup> | "SubjectDistance" | **Read/Write capability**: readable and writable<br> Distance to the subject, in meters.| 8368| METERING_MODE<sup>10+</sup> | "MeteringMode" | **Read/Write capability**: readable and writable<br> Metering mode.| 8369| LIGHT_SOURCE<sup>10+</sup> | "LightSource" | **Read/Write capability**: readable and writable<br> Light source. An example value is **Fluorescent**.| 8370| FLASH <sup>10+</sup> | "Flash" | **Read/Write capability**: readable and writable<br> Flash status.| 8371| FOCAL_LENGTH <sup>10+</sup> | "FocalLength" | **Read/Write capability**: readable and writable<br> Focal length of the lens.| 8372| SUBJECT_AREA <sup>12+</sup> | "SubjectArea" | **Read/Write capability**: readable and writable<br> Location and area of the main subject in the entire scene.| 8373| MAKER_NOTE <sup>12+</sup> | "MakerNote" | **Read/Write capability**: read-only<br> Marker used by EXIF/DCF manufacturers to record any required information.| 8374| SCENE_POINTER <sup>12+</sup> | "HwMnoteScenePointer" | **Read/Write capability**: read-only<br> Pointer to the scene.| 8375| SCENE_VERSION <sup>12+</sup> | "HwMnoteSceneVersion" | **Read/Write capability**: read-only<br> Scene algorithm version.| 8376| SCENE_FOOD_CONF<sup>11+</sup> | "HwMnoteSceneFoodConf" | **Read/Write capability**: read-only<br> Photographing scene: food.| 8377| SCENE_STAGE_CONF<sup>11+</sup> | "HwMnoteSceneStageConf" | **Read/Write capability**: read-only<br> Photographing scene: stage.| 8378| SCENE_BLUE_SKY_CONF<sup>11+</sup> | "HwMnoteSceneBlueSkyConf" | **Read/Write capability**: read-only<br> Photographing scene: blue sky.| 8379| SCENE_GREEN_PLANT_CONF<sup>11+</sup> | "HwMnoteSceneGreenPlantConf" | **Read/Write capability**: read-only<br> Photographing scene: green plant.| 8380| SCENE_BEACH_CONF<sup>11+</sup> | "HwMnoteSceneBeachConf" | **Read/Write capability**: read-only<br> Photographing scene: beach.| 8381| SCENE_SNOW_CONF<sup>11+</sup> | "HwMnoteSceneSnowConf" | **Read/Write capability**: read-only<br> Photographing scene: snow.| 8382| SCENE_SUNSET_CONF<sup>11+</sup> | "HwMnoteSceneSunsetConf" | **Read/Write capability**: read-only<br> Photographing scene: sunset.| 8383| SCENE_FLOWERS_CONF<sup>11+</sup> | "HwMnoteSceneFlowersConf" | **Read/Write capability**: read-only<br> Photographing scene: flowers.| 8384| SCENE_NIGHT_CONF<sup>11+</sup> | "HwMnoteSceneNightConf" | **Read/Write capability**: read-only<br> Photographing scene: night.| 8385| SCENE_TEXT_CONF<sup>11+</sup> | "HwMnoteSceneTextConf" | **Read/Write capability**: read-only<br> Photographing scene: text.| 8386| FACE_POINTER <sup>12+</sup> | "HwMnoteFacePointer" | **Read/Write capability**: read-only<br> Face pointer.| 8387| FACE_VERSION <sup>12+</sup> | "HwMnoteFaceVersion" | **Read/Write capability**: read-only<br> Facial recognition algorithm version.| 8388| FACE_COUNT<sup>11+</sup> | "HwMnoteFaceCount" | **Read/Write capability**: read-only<br> Number of faces.| 8389| FACE_CONF <sup>12+</sup> | "HwMnoteFaceConf" | **Read/Write capability**: read-only<br> Face confidence.| 8390| FACE_SMILE_SCORE <sup>12+</sup> | "HwMnoteFaceSmileScore" | **Read/Write capability**: read-only<br> Smile score of for faces.| 8391| FACE_RECT <sup>12+</sup> | "HwMnoteFaceRect" | **Read/Write capability**: read-only<br> Face rectangle.| 8392| FACE_LEYE_CENTER <sup>12+</sup> | "HwMnoteFaceLeyeCenter" | **Read/Write capability**: read-only<br> Left eye centered.| 8393| FACE_REYE_CENTER <sup>12+</sup> | "HwMnoteFaceReyeCenter" | **Read/Write capability**: read-only<br> Right eye centered.| 8394| FACE_MOUTH_CENTER <sup>12+</sup> | "HwMnoteFaceMouthCenter" | **Read/Write capability**: read-only<br> Mouth centered.| 8395| CAPTURE_MODE <sup>10+</sup> | "HwMnoteCaptureMode" | **Read/Write capability**: readable and writable<br> Capture mode.| 8396| BURST_NUMBER <sup>12+</sup> | "HwMnoteBurstNumber" | **Read/Write capability**: read-only<br> Number of burst shooting times.| 8397| FRONT_CAMERA <sup>12+</sup> | "HwMnoteFrontCamera" | **Read/Write capability**: read-only<br> Whether the front camera is used to take a selfie.| 8398| ROLL_ANGLE <sup>11+</sup> | "HwMnoteRollAngle" | **Read/Write capability**: read-only<br> Roll angle.| 8399| PITCH_ANGLE<sup>11+</sup> | "HwMnotePitchAngle" | **Read/Write capability**: read-only<br> Pitch angle.| 8400| PHYSICAL_APERTURE <sup>10+</sup> | "HwMnotePhysicalAperture" | **Read/Write capability**: read-only<br> Physical aperture.| 8401| FOCUS_MODE<sup>11+</sup> | "HwMnoteFocusMode" | **Read/Write capability**: read-only<br> Focus mode.| 8402| USER_COMMENT <sup>10+</sup> | "UserComment" | **Read/Write capability**: readable and writable<br> User comments.| 8403| SUBSEC_TIME <sup>12+</sup> | "SubsecTime" | **Read/Write capability**: readable and writable<br> Tag used to record fractions of seconds for the **DateTime** tag.| 8404| 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.| 8405| 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.| 8406| 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.| 8407| 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.| 8408| PIXEL_X_DIMENSION <sup>10+</sup> | "PixelXDimension" | **Read/Write capability**: readable and writable<br> Pixel X dimension.| 8409| PIXEL_Y_DIMENSION<sup>10+</sup> | "PixelYDimension" | **Read/Write capability**: readable and writable<br> Pixel Y dimension.| 8410| RELATED_SOUND_FILE <sup>12+</sup> | "RelatedSoundFile" | **Read/Write capability**: readable and writable<br> Name of an audio file related to the image data.| 8411| 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).| 8412| SPATIAL_FREQUENCY_RESPONSE <sup>12+</sup> | "SpatialFrequencyResponse" | **Read/Write capability**: readable and writable<br> Spatial frequency table of the camera or input device.| 8413| 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.| 8414| 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.| 8415| FOCAL_PLANE_RESOLUTION_UNIT <sup>12+</sup> | "FocalPlaneResolutionUnit" | **Read/Write capability**: readable and writable<br> Unit for measuring FocalPlaneXResolution and FocalPlaneYResolution.| 8416| SUBJECT_LOCATION <sup>12+</sup> | "SubjectLocation" | **Read/Write capability**: readable and writable<br> Location of the main subject relative to the left edge.| 8417| EXPOSURE_INDEX <sup>12+</sup> | "ExposureIndex" | **Read/Write capability**: readable and writable<br> Exposure index selected at the time the image is captured.| 8418| SENSING_METHOD <sup>12+</sup> | "SensingMethod" | **Read/Write capability**: readable and writable<br> Type of the image sensor on the camera.| 8419| FILE_SOURCE <sup>12+</sup> | "FileSource" | **Read/Write capability**: readable and writable<br> Image source.| 8420| SCENE_TYPE<sup>9+</sup> | "SceneType" | **Read/Write capability**: readable and writable<br> Type of the scene, for example, portrait, scenery, motion, and night.| 8421| CFA_PATTERN <sup>12+</sup> | "CFAPattern" | **Read/Write capability**: readable and writable<br> Color Filter Array (CFA) geometric pattern of the image sensor.| 8422| CUSTOM_RENDERED <sup>12+</sup> | "CustomRendered" | **Read/Write capability**: readable and writable<br> Special processing on image data.| 8423| EXPOSURE_MODE <sup>12+</sup> | "ExposureMode" | **Read/Write capability**: readable and writable<br> Exposure mode set when the image was captured.| 8424| WHITE_BALANCE <sup>10+</sup> | "WhiteBalance" | **Read/Write capability**: readable and writable<br> White balance.| 8425| DIGITAL_ZOOM_RATIO <sup>12+</sup> | "DigitalZoomRatio" | **Read/Write capability**: readable and writable<br> Digital zoom ratio when the image was captured.| 8426| FOCAL_LENGTH_IN_35_MM_FILM <sup>10+</sup> | "FocalLengthIn35mmFilm" | **Read/Write capability**: readable and writable<br> Focal length in 35mm film.| 8427| SCENE_CAPTURE_TYPE <sup>12+</sup> | "SceneCaptureType" | **Read/Write capability**: readable and writable<br> Type of the scene that was captured.| 8428| GAIN_CONTROL <sup>12+</sup> | "GainControl" | **Read/Write capability**: readable and writable<br> Degree of overall image gain adjustment.| 8429| CONTRAST <sup>12+</sup> | "Contrast" | **Read/Write capability**: readable and writable<br> Direction of contrast processing used by the camera.| 8430| SATURATION <sup>12+</sup> | "Saturation" | **Read/Write capability**: readable and writable<br> Direction of saturation processing used by the camera.| 8431| SHARPNESS <sup>12+</sup> | "Sharpness" | **Read/Write capability**: readable and writable<br> Direction of sharpness processing used by the camera.| 8432| DEVICE_SETTING_DESCRIPTION <sup>12+</sup> | "DeviceSettingDescription" | **Read/Write capability**: readable and writable<br> Information about the photographing conditions of a specific camera model.| 8433| SUBJECT_DISTANCE_RANGE <sup>12+</sup> | "SubjectDistanceRange" | **Read/Write capability**: readable and writable<br> Distance to the subject.| 8434| IMAGE_UNIQUE_ID <sup>12+</sup> | "ImageUniqueID" | **Read/Write capability**: readable and writable<br> Unique identifier assigned to each image.| 8435| CAMERA_OWNER_NAME <sup>12+</sup> | "CameraOwnerName" | **Read/Write capability**: readable and writable<br> Name of the camera owner.| 8436| BODY_SERIAL_NUMBER <sup>12+</sup> | "BodySerialNumber" | **Read/Write capability**: readable and writable<br> Serial number of the camera body.| 8437| LENS_SPECIFICATION <sup>12+</sup> | "LensSpecification" | **Read/Write capability**: readable and writable<br> Specifications of the lens.| 8438| LENS_MAKE <sup>12+</sup> | "LensMake" | **Read/Write capability**: readable and writable<br> Manufacturer of the lens.| 8439| LENS_MODEL <sup>12+</sup> | "LensModel" | **Read/Write capability**: readable and writable<br> Model of the lens.| 8440| LENS_SERIAL_NUMBER <sup>12+</sup> | "LensSerialNumber" | **Read/Write capability**: readable and writable<br> Serial number of the lens.| 8441| COMPOSITE_IMAGE <sup>12+</sup> | "CompositeImage" | **Read/Write capability**: readable and writable<br> Whether the image is a composite image.| 8442| 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.| 8443| 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.| 8444| GAMMA <sup>12+</sup> | "Gamma" | **Read/Write capability**: readable and writable<br> Gamma value.| 8445| DNG_VERSION <sup>12+</sup> | "DNGVersion" | **Read/Write capability**: readable and writable<br> DNG version. It encodes the DNG 4-tier version number.| 8446| 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.| 8447| 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.| 8448| IS_XMAGE_SUPPORTED <sup>12+</sup> | "HwMnoteIsXmageSupported" | **Read/Write capability**: readable and writable<br>Whether XMAGE is supported.| 8449| XMAGE_MODE <sup>12+</sup> | "HwMnoteXmageMode" | **Read/Write capability**: readable and writable<br>XMAGE watermark mode.| 8450| XMAGE_LEFT <sup>12+</sup> | "HwMnoteXmageLeft" | **Read/Write capability**: readable and writable<br>X1 coordinate of the watermark region.| 8451| XMAGE_TOP <sup>12+</sup> | "HwMnoteXmageTop" | **Read/Write capability**: readable and writable<br>Y1 coordinate of the watermark region.| 8452| XMAGE_RIGHT <sup>12+</sup> | "HwMnoteXmageRight" | **Read/Write capability**: readable and writable<br>X2 coordinate of the watermark region.| 8453| XMAGE_BOTTOM <sup>12+</sup> | "HwMnoteXmageBottom" | **Read/Write capability**: readable and writable<br>Y2 coordinate of the watermark region.| 8454| CLOUD_ENHANCEMENT_MODE <sup>12+</sup> | "HwMnoteCloudEnhancementMode" | **Read/Write capability**: readable and writable<br>Cloud enhancement mode.| 8455| WIND_SNAPSHOT_MODE <sup>12+</sup> | "HwMnoteWindSnapshotMode" | **Read/Write capability**: read-only<br>Motion snapshot mode.| 8456 8457## FragmentMapPropertyKey<sup>13+</sup> 8458 8459Enumerates the fragment map information. 8460 8461**System capability**: SystemCapability.Multimedia.Image.Core 8462 8463| Name | Value | Description | 8464| ------------- | --------------------- | ----------------------------------- | 8465| X_IN_ORIGINAL | "XInOriginal" | X coordinate of the upper left corner of the fragment map in the original image.| 8466| Y_IN_ORIGINAL | "YInOriginal" | Y coordinate of the upper left corner of the fragment map in the original image.| 8467| WIDTH | "FragmentImageWidth" | Width of the fragment map. | 8468| HEIGHT | "FragmentImageHeight" | Height of the fragment map. | 8469 8470## ImageFormat<sup>9+</sup> 8471 8472Enumerates the image formats. 8473 8474**System capability**: SystemCapability.Multimedia.Image.Core 8475 8476| Name | Value | Description | 8477| ------------ | ------ | -------------------- | 8478| YCBCR_422_SP | 1000 | YCBCR422 semi-planar format.| 8479| JPEG | 2000 | JPEG encoding format. | 8480 8481## ComponentType<sup>9+</sup> 8482 8483Enumerates the color component types of images. 8484 8485**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 8486 8487| Name | Value | Description | 8488| ----- | ------ | ----------- | 8489| YUV_Y | 1 | Luminance component. | 8490| YUV_U | 2 | Chrominance component. | 8491| YUV_V | 3 | Chrominance component. | 8492| JPEG | 4 | JPEG type.| 8493 8494## Component<sup>9+</sup> 8495 8496Describes the color components of an image. 8497 8498**System capability**: SystemCapability.Multimedia.Image.Core 8499 8500| Name | Type | Read Only| Optional| Description | 8501| ------------- | -------------------------------- | ---- | ---- | ------------ | 8502| componentType | [ComponentType](#componenttype9) | Yes | No | Color component type. | 8503| rowStride | number | Yes | No | Row stride. The camera preview stream data needs to be read by stride. For details, see [Dual-Channel Preview (ArkTS)](../../media/camera/camera-dual-channel-preview.md). | 8504| pixelStride | number | Yes | No | Pixel stride. | 8505| byteBuffer | ArrayBuffer | Yes | No | Component buffer.| 8506 8507## DecodingDynamicRange<sup>12+</sup> 8508 8509Describes the desired dynamic range of an image during decoding. 8510 8511**System capability**: SystemCapability.Multimedia.Image.Core 8512 8513| Name | Value | Description | 8514| ------------- | ----------| ------------ | 8515| 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. | 8516| SDR | 1 | The image is decoded according to the standard dynamic range. | 8517| 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. | 8518 8519## PackingDynamicRange<sup>12+</sup> 8520 8521Describes the desired dynamic range of an image during encoding. 8522 8523**System capability**: SystemCapability.Multimedia.Image.Core 8524 8525| Name | Value | Description | 8526| ------------- | ----------| ------------ | 8527| AUTO | 0 | Adaptive. The [pixelmap](#pixelmap7) is encoded based on the format. If the PixelMap is in HDR format, it is encoded based on the HDR content; otherwise, it is encoded based on the SDR content. | 8528| SDR | 1 | The image is decoded according to the standard dynamic range. | 8529 8530## HdrMetadataKey<sup>12+</sup> 8531 8532Enumerates the keys of HDR metadata used by [pixelmap](#pixelmap7). 8533 8534**System capability**: SystemCapability.Multimedia.Image.Core 8535 8536| Name | Value | Description | 8537| ------------- | ----------| ------------ | 8538| HDR_METADATA_TYPE | 0 | Metadata type used by [pixelmap](#pixelmap7). | 8539| HDR_STATIC_METADATA | 1 | Static metadata. | 8540| HDR_DYNAMIC_METADATA | 2 | Dynamic metadata. | 8541| HDR_GAINMAP_METADATA | 3 | Metadata used by gain maps. | 8542 8543## HdrMetadataType<sup>12+</sup> 8544 8545Enumerates the values available for **HDR_METADATA_TYPE** in [HdrMetadataKey](#hdrmetadatakey12). 8546 8547**System capability**: SystemCapability.Multimedia.Image.Core 8548 8549| Name | Value | Description | 8550| ------------- | ----------| ------------ | 8551| NONE | 0 | No metadata. | 8552| BASE | 1 | Metadata used for base graphics. | 8553| GAINMAP | 2 | Metadata used for gain maps. | 8554| ALTERNATE| 3 | Metadata used for synthesized HDR graphics. | 8555 8556## HdrStaticMetadata<sup>12+</sup> 8557 8558Describes the static metadata keys, that is, the values available for **HDR_STATIC_METADATA** in [HdrMetadataKey](#hdrmetadatakey12). 8559 8560**System capability**: SystemCapability.Multimedia.Image.Core 8561 8562| Name | Type | Read Only| Optional| Description | 8563| ------------- | ----------| -- | -- | ------------ | 8564| displayPrimariesX | Array\<number> | No| No| 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]. | 8565| displayPrimariesY | Array\<number> | No| No| 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]. | 8566| whitePointX | number | No| No| X coordinate of the white point after normalization. The unit is 0.00002. The value range is [0.0, 1.0]. | 8567| whitePointY | number | No| No| X coordinate of the white point after normalization. The unit is 0.00002. The value range is [0.0, 1.0]. | 8568| maxLuminance | number | No| No| Maximum luminance of the main monitor. The unit is 1, and the maximum value is 65535. | 8569| minLuminance | number | No| No| Minimum luminance of the main monitor. The unit is 0.0001, and the maximum value is 6.55535. | 8570| maxContentLightLevel | number | No| No| Maximum luminance of the displayed content. The unit is 1, and the maximum value is 65535. | 8571| maxFrameAverageLightLevel | number | No| No| Maximum average luminance of the displayed content. The unit is 1, and the maximum value is 65535.| 8572 8573## GainmapChannel<sup>12+</sup> 8574 8575Describes the data content of a single channel of the gain map. For details, see ISO 21496-1. 8576 8577**System capability**: SystemCapability.Multimedia.Image.Core 8578 8579| Name | Type | Read Only| Optional| Description | 8580| ------------- | ----------| -- | -- | ------------ | 8581| gainmapMax | number | No| No| Maximum value of the gain map. For details, see ISO 21496-1. | 8582| gainmapMin | number | No| No| Minimum value of the gain map. For details, see ISO 21496-1. | 8583| gamma | number | No| No| Gamma. For details, see ISO 21496-1. | 8584| baseOffset | number | No| No| Offset of the base graphic. For details, see ISO 21496-1. | 8585| alternateOffset | number | No| No| Offset of the alternative graphic that can be extracted. For details, see ISO 21496-1. | 8586 8587## HdrGainmapMetadata<sup>12+</sup> 8588 8589Describes 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. 8590 8591**System capability**: SystemCapability.Multimedia.Image.Core 8592 8593| Name | Type | Read Only| Optional| Description | 8594| ------------- | ----------| -- | -- | ------------ | 8595| writerVersion | number | No| No| Version used by the metadata editor. | 8596| miniVersion | number | No| No| Minimum version that needs to be understood for metadata parsing. | 8597| gainmapChannelCount | number | No| No| 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. | 8598| useBaseColorFlag | boolean | No| No| Whether to use the color space of the base graphic. For details, see ISO 21496-1. | 8599| baseHeadroom | number | No| No| Headroom of the base graphic, which means the additional brightness that can be added to the base graphic. For details, see ISO 21496-1. | 8600| alternateHeadroom | number | No| No| Headroom of the alternate graphic. For details, see ISO 21496-1. | 8601| channels | Array<[GainmapChannel](#gainmapchannel12)> | No| No| Number of channels. The length is 3. For details, see ISO 21496-1.| 8602 8603## HdrMetadataValue<sup>12+</sup> 8604 8605type HdrMetadataValue = HdrMetadataType | HdrStaticMetadata | ArrayBuffer | HdrGainmapMetadata 8606 8607Describes the HDR metadata values used by a PixelMap, which corresponds to the values available for [HdrMetadataKey](#hdrmetadatakey12). 8608 8609**System capability**: SystemCapability.Multimedia.Image.Core 8610 8611| Type | Description | 8612| ------------------- | ----------------------------------------------- | 8613| [HdrMetadataType](#hdrmetadatatype12) | Metadata value corresponding to the **HDR_GAINMAP_METADATA** key in [HdrMetadataKey](#hdrmetadatakey12).| 8614| [HdrStaticMetadata](#hdrstaticmetadata12) | Metadata value corresponding to the **HDR_STATIC_METADATA** key in [HdrMetadataKey](#hdrmetadatakey12).| 8615| ArrayBuffer | Metadata value corresponding to the **HDR_DYNAMIC_METADATA** key in [HdrMetadataKey](#hdrmetadatakey12).| 8616| [HdrGainmapMetadata](#hdrgainmapmetadata12) | Metadata value corresponding to the **HDR_GAINMAP_METADATA** key in [HdrMetadataKey](#hdrmetadatakey12).| 8617 8618## AntiAliasingLevel<sup>12+</sup> 8619 8620Enumerates the anti-aliasing levels. 8621 8622**Atomic service API**: This API can be used in atomic services since API version 14. 8623 8624**System capability**: SystemCapability.Multimedia.Image.Core 8625 8626| Name | Value | Description | 8627| ---------------------- | ------ | ----------------- | 8628| NONE | 0 | Nearest neighbor interpolation. | 8629| LOW | 1 | Bilinear interpolation. | 8630| MEDIUM | 2 | Bilinear interpolation with mipmap enabled. You are advised to use this value when zooming out an image. | 8631| HIGH | 3 | Cubic interpolation. | 8632 8633## AllocatorType<sup>15+</sup> 8634 8635Enumerates the types of the memory used for image decoding. 8636 8637**System capability**: SystemCapability.Multimedia.Image.Core 8638 8639| Name | Value | Description | 8640| ------------ | ---- | ---------------------------------- | 8641| AUTO | 0 | The system determines whether DMA memory or shared memory is used. | 8642| DMA | 1 | DMA memory is used. | 8643| SHARE_MEMORY | 2 | Shared memory is used.| 8644 8645## Supplementary Information 8646 8647### SVG Tags 8648 8649The 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: 8650- a 8651- circla 8652- clipPath 8653- defs 8654- ellipse 8655- feBlend 8656- feColorMatrix 8657- feComposite 8658- feDiffuseLighting 8659- feDisplacementMap 8660- feDistantLight 8661- feFlood 8662- feGaussianBlur 8663- feImage 8664- feMorphology 8665- feOffset 8666- fePointLight 8667- feSpecularLighting 8668- feSpotLight 8669- feTurbulence 8670- filter 8671- g 8672- image 8673- line 8674- linearGradient 8675- mask 8676- path 8677- pattern 8678- polygon 8679- polyline 8680- radialGradient 8681- rect 8682- stop 8683- svg 8684- text 8685- textPath 8686- tspan 8687- use 8688