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. 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. 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 [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 [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 pixels of an image are editable.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12.| 1271| isStrideAlignment<sup>11+</sup> | boolean | Yes | No | Whether the image memory is the DMA memory.| 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### translate<sup>9+</sup> 2568 2569translate(x: number, y: number, callback: AsyncCallback\<void>): void 2570 2571Translates this image based on given coordinates. This API uses an asynchronous callback to return the result. 2572 2573The 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. 2574 2575**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2576 2577**Atomic service API**: This API can be used in atomic services since API version 11. 2578 2579**System capability**: SystemCapability.Multimedia.Image.Core 2580 2581**Parameters** 2582 2583| Name | Type | Mandatory| Description | 2584| -------- | -------------------- | ---- | ----------------------------- | 2585| x | number | Yes | X coordinate to translate, in pixels.| 2586| y | number | Yes | Y coordinate to translate, in pixels.| 2587| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 2588 2589**Example** 2590 2591```ts 2592import { BusinessError } from '@kit.BasicServicesKit'; 2593 2594async function Translate() { 2595 let translateX: number = 50.0; 2596 let translateY: number = 10.0; 2597 if (pixelMap != undefined) { 2598 pixelMap.translate(translateX, translateY, (err: BusinessError) => { 2599 if (err) { 2600 console.error(`Failed to translate pixelmap. code is ${err.code}, message is ${err.message}`); 2601 return; 2602 } else { 2603 console.info("Succeeded in translating pixelmap."); 2604 } 2605 }) 2606 } 2607} 2608``` 2609 2610### translate<sup>9+</sup> 2611 2612translate(x: number, y: number): Promise\<void> 2613 2614Translates this image based on given coordinates. This API uses a promise to return the result. 2615 2616The 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. 2617 2618**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2619 2620**Atomic service API**: This API can be used in atomic services since API version 11. 2621 2622**System capability**: SystemCapability.Multimedia.Image.Core 2623 2624**Parameters** 2625 2626| Name| Type | Mandatory| Description | 2627| ------ | ------ | ---- | ----------- | 2628| x | number | Yes | X coordinate to translate, in pixels.| 2629| y | number | Yes | Y coordinate to translate, in pixels.| 2630 2631**Return value** 2632 2633| Type | Description | 2634| -------------- | --------------------------- | 2635| Promise\<void> | Promise that returns no value.| 2636 2637**Example** 2638 2639```ts 2640import { BusinessError } from '@kit.BasicServicesKit'; 2641 2642async function Translate() { 2643 let translateX: number = 50.0; 2644 let translateY: number = 10.0; 2645 if (pixelMap != undefined) { 2646 pixelMap.translate(translateX, translateY).then(() => { 2647 console.info('Succeeded in translating pixelmap.'); 2648 }).catch((err: BusinessError) => { 2649 console.error(`Failed to translate pixelmap. code is ${err.code}, message is ${err.message}`); 2650 }) 2651 } 2652} 2653``` 2654 2655### translateSync<sup>12+</sup> 2656 2657translateSync(x: number, y: number): void 2658 2659Translates this image based on given coordinates. This API returns the result synchronously. 2660 2661The 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. 2662 2663**Atomic service API**: This API can be used in atomic services since API version 12. 2664 2665**System capability**: SystemCapability.Multimedia.Image.Core 2666 2667**Parameters** 2668 2669| Name | Type | Mandatory| Description | 2670| -------- | -------------------- | ---- | ------------------------------- | 2671| x | number | Yes | X coordinate to translate, in pixels.| 2672| y | number | Yes | Y coordinate to translate, in pixels.| 2673 2674**Error codes** 2675 2676For details about the error codes, see [Image Error Codes](errorcode-image.md). 2677 2678| ID| Error Message| 2679| ------- | --------------------------------------------| 2680| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2681| 501 | Resource Unavailable | 2682 2683**Example** 2684 2685```ts 2686import { BusinessError } from '@kit.BasicServicesKit'; 2687 2688async function TranslateSync() { 2689 let translateX : number = 50.0; 2690 let translateY : number = 10.0; 2691 if (pixelMap != undefined) { 2692 pixelMap.translateSync(translateX, translateY); 2693 } 2694} 2695``` 2696 2697### rotate<sup>9+</sup> 2698 2699rotate(angle: number, callback: AsyncCallback\<void>): void 2700 2701Rotates this image based on a given angle. This API uses an asynchronous callback to return the result. 2702 2703> **NOTE** 2704> 2705> 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. 2706> 2707> If the rotation angle is not an integer multiple of 90 degrees, the image size will change after rotation. 2708 2709**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2710 2711**Atomic service API**: This API can be used in atomic services since API version 11. 2712 2713**System capability**: SystemCapability.Multimedia.Image.Core 2714 2715**Parameters** 2716 2717| Name | Type | Mandatory| Description | 2718| -------- | -------------------- | ---- | ----------------------------- | 2719| angle | number | Yes | Angle to rotate.| 2720| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 2721 2722**Example** 2723 2724```ts 2725import { BusinessError } from '@kit.BasicServicesKit'; 2726 2727async function Rotate() { 2728 let angle: number = 90.0; 2729 if (pixelMap != undefined) { 2730 pixelMap.rotate(angle, (err: BusinessError) => { 2731 if (err) { 2732 console.error(`Failed to rotate pixelmap. code is ${err.code}, message is ${err.message}`); 2733 return; 2734 } else { 2735 console.info("Succeeded in rotating pixelmap."); 2736 } 2737 }) 2738 } 2739} 2740``` 2741 2742### rotate<sup>9+</sup> 2743 2744rotate(angle: number): Promise\<void> 2745 2746Rotates this image based on a given angle. This API uses a promise to return the result. 2747 2748> **NOTE** 2749> 2750> 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. 2751> 2752> If the rotation angle is not an integer multiple of 90 degrees, the image size will change after rotation. 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| angle | number | Yes | Angle to rotate.| 2765 2766**Return value** 2767 2768| Type | Description | 2769| -------------- | --------------------------- | 2770| Promise\<void> | Promise that returns no value.| 2771 2772**Example** 2773 2774```ts 2775import { BusinessError } from '@kit.BasicServicesKit'; 2776 2777async function Rotate() { 2778 let angle: number = 90.0; 2779 if (pixelMap != undefined) { 2780 pixelMap.rotate(angle).then(() => { 2781 console.info('Succeeded in rotating pixelmap.'); 2782 }).catch((err: BusinessError) => { 2783 console.error(`Failed to rotate pixelmap. code is ${err.code}, message is ${err.message}`); 2784 }) 2785 } 2786} 2787``` 2788 2789### rotateSync<sup>12+</sup> 2790 2791rotateSync(angle: number): void 2792 2793Rotates this image based on a given angle. This API returns the result synchronously. 2794 2795> **NOTE** 2796> 2797> 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. 2798> 2799> If the rotation angle is not an integer multiple of 90 degrees, the image size will change after rotation. 2800 2801**Atomic service API**: This API can be used in atomic services since API version 12. 2802 2803**System capability**: SystemCapability.Multimedia.Image.Core 2804 2805**Parameters** 2806 2807| Name | Type | Mandatory| Description | 2808| -------- | -------------------- | ---- | ----------------------------- | 2809| angle | number | Yes | Angle to rotate.| 2810 2811**Error codes** 2812 2813For details about the error codes, see [Image Error Codes](errorcode-image.md). 2814 2815| ID| Error Message| 2816| ------- | --------------------------------------------| 2817| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2818| 501 | Resource Unavailable | 2819 2820**Example** 2821 2822```ts 2823import { BusinessError } from '@kit.BasicServicesKit'; 2824 2825async function RotateSync() { 2826 let angle : number = 90.0; 2827 if (pixelMap != undefined) { 2828 pixelMap.rotateSync(angle); 2829 } 2830} 2831``` 2832 2833### flip<sup>9+</sup> 2834 2835flip(horizontal: boolean, vertical: boolean, callback: AsyncCallback\<void>): void 2836 2837Flips this image horizontally or vertically, or both. This API uses an asynchronous callback to return the result. 2838 2839**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2840 2841**Atomic service API**: This API can be used in atomic services since API version 11. 2842 2843**System capability**: SystemCapability.Multimedia.Image.Core 2844 2845**Parameters** 2846 2847| Name | Type | Mandatory| Description | 2848| ---------- | -------------------- | ---- | ----------------------------- | 2849| horizontal | boolean | Yes | Whether to flip the image horizontally. | 2850| vertical | boolean | Yes | Whether to flip the image vertically. | 2851| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 2852 2853**Example** 2854 2855```ts 2856import { BusinessError } from '@kit.BasicServicesKit'; 2857 2858async function Flip() { 2859 let horizontal: boolean = true; 2860 let vertical: boolean = false; 2861 if (pixelMap != undefined) { 2862 pixelMap.flip(horizontal, vertical, (err: BusinessError) => { 2863 if (err) { 2864 console.error(`Failed to flip pixelmap. code is ${err.code}, message is ${err.message}`); 2865 return; 2866 } else { 2867 console.info("Succeeded in flipping pixelmap."); 2868 } 2869 }) 2870 } 2871} 2872``` 2873 2874### flip<sup>9+</sup> 2875 2876flip(horizontal: boolean, vertical: boolean): Promise\<void> 2877 2878Flips this image horizontally or vertically, or both. This API uses a promise to return the result. 2879 2880**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2881 2882**Atomic service API**: This API can be used in atomic services since API version 11. 2883 2884**System capability**: SystemCapability.Multimedia.Image.Core 2885 2886**Parameters** 2887 2888| Name | Type | Mandatory| Description | 2889| ---------- | ------- | ---- | --------- | 2890| horizontal | boolean | Yes | Whether to flip the image horizontally.| 2891| vertical | boolean | Yes | Whether to flip the image vertically.| 2892 2893**Return value** 2894 2895| Type | Description | 2896| -------------- | --------------------------- | 2897| Promise\<void> | Promise that returns no value.| 2898 2899**Example** 2900 2901```ts 2902import { BusinessError } from '@kit.BasicServicesKit'; 2903 2904async function Flip() { 2905 let horizontal: boolean = true; 2906 let vertical: boolean = false; 2907 if (pixelMap != undefined) { 2908 pixelMap.flip(horizontal, vertical).then(() => { 2909 console.info('Succeeded in flipping pixelmap.'); 2910 }).catch((err: BusinessError) => { 2911 console.error(`Failed to flip pixelmap. code is ${err.code}, message is ${err.message}`); 2912 }) 2913 } 2914} 2915``` 2916 2917### flipSync<sup>12+</sup> 2918 2919flipSync(horizontal: boolean, vertical: boolean): void 2920 2921Flips this image horizontally or vertically, or both. This API returns the result synchronously. 2922 2923**Atomic service API**: This API can be used in atomic services since API version 12. 2924 2925**System capability**: SystemCapability.Multimedia.Image.Core 2926 2927**Parameters** 2928 2929| Name | Type | Mandatory| Description | 2930| ---------- | -------------------- | ---- | ----------------------------- | 2931| horizontal | boolean | Yes | Whether to flip the image horizontally. | 2932| vertical | boolean | Yes | Whether to flip the image vertically. | 2933 2934**Error codes** 2935 2936For details about the error codes, see [Image Error Codes](errorcode-image.md). 2937 2938| ID| Error Message| 2939| ------- | --------------------------------------------| 2940| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2941| 501 | Resource Unavailable | 2942 2943**Example** 2944 2945```ts 2946import { BusinessError } from '@kit.BasicServicesKit'; 2947 2948async function FlipSync() { 2949 let horizontal : boolean = true; 2950 let vertical : boolean = false; 2951 if (pixelMap != undefined) { 2952 pixelMap.flipSync(horizontal, vertical); 2953 } 2954} 2955``` 2956 2957### crop<sup>9+</sup> 2958 2959crop(region: Region, callback: AsyncCallback\<void>): void 2960 2961Crops this image based on a given size. This API uses an asynchronous callback to return the result. 2962 2963**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2964 2965**Atomic service API**: This API can be used in atomic services since API version 11. 2966 2967**System capability**: SystemCapability.Multimedia.Image.Core 2968 2969**Parameters** 2970 2971| Name | Type | Mandatory| Description | 2972| -------- | -------------------- | ---- | ----------------------------- | 2973| region | [Region](#region8) | Yes | Size of the image after cropping. | 2974| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 2975 2976**Example** 2977 2978```ts 2979import { BusinessError } from '@kit.BasicServicesKit'; 2980 2981async function Crop() { 2982 let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 2983 if (pixelMap != undefined) { 2984 pixelMap.crop(region, (err: BusinessError) => { 2985 if (err) { 2986 console.error(`Failed to crop pixelmap. code is ${err.code}, message is ${err.message}`); 2987 return; 2988 } else { 2989 console.info("Succeeded in cropping pixelmap."); 2990 } 2991 }) 2992 } 2993} 2994``` 2995 2996### crop<sup>9+</sup> 2997 2998crop(region: Region): Promise\<void> 2999 3000Crops this image based on a given size. This API uses a promise to return the result. 3001 3002**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3003 3004**Atomic service API**: This API can be used in atomic services since API version 11. 3005 3006**System capability**: SystemCapability.Multimedia.Image.Core 3007 3008**Parameters** 3009 3010| Name| Type | Mandatory| Description | 3011| ------ | ------------------ | ---- | ----------- | 3012| region | [Region](#region8) | Yes | Size of the image after cropping. | 3013 3014**Return value** 3015 3016| Type | Description | 3017| -------------- | --------------------------- | 3018| Promise\<void> | Promise that returns no value.| 3019 3020**Example** 3021 3022```ts 3023import { BusinessError } from '@kit.BasicServicesKit'; 3024 3025async function Crop() { 3026 let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 3027 if (pixelMap != undefined) { 3028 pixelMap.crop(region).then(() => { 3029 console.info('Succeeded in cropping pixelmap.'); 3030 }).catch((err: BusinessError) => { 3031 console.error(`Failed to crop pixelmap. code is ${err.code}, message is ${err.message}`); 3032 3033 }); 3034 } 3035} 3036``` 3037 3038### cropSync<sup>12+</sup> 3039 3040cropSync(region: Region): void 3041 3042Crops this image based on a given size. This API returns the result synchronously. 3043 3044**Atomic service API**: This API can be used in atomic services since API version 12. 3045 3046**System capability**: SystemCapability.Multimedia.Image.Core 3047 3048**Parameters** 3049 3050| Name | Type | Mandatory| Description | 3051| -------- | -------------------- | ---- | ----------------------------- | 3052| region | [Region](#region8) | Yes | Size of the image after cropping. | 3053 3054**Error codes** 3055 3056For details about the error codes, see [Image Error Codes](errorcode-image.md). 3057 3058| ID| Error Message| 3059| ------- | --------------------------------------------| 3060| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 3061| 501 | Resource Unavailable | 3062 3063**Example** 3064 3065```ts 3066import { BusinessError } from '@kit.BasicServicesKit'; 3067 3068async function CropSync() { 3069 let region : image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 3070 if (pixelMap != undefined) { 3071 pixelMap.cropSync(region); 3072 } 3073} 3074``` 3075 3076### getColorSpace<sup>10+</sup> 3077 3078getColorSpace(): colorSpaceManager.ColorSpaceManager 3079 3080Obtains the color space of this image. 3081 3082**System capability**: SystemCapability.Multimedia.Image.Core 3083 3084**Return value** 3085 3086| Type | Description | 3087| ----------------------------------- | ---------------- | 3088| [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | Color space obtained.| 3089 3090**Error codes** 3091 3092For details about the error codes, see [Image Error Codes](errorcode-image.md). 3093 3094| ID| Error Message| 3095| ------- | --------------------------------------------| 3096| 62980101| If the image data abnormal. | 3097| 62980103| If the image data unsupport. | 3098| 62980115| If the image parameter invalid. | 3099 3100**Example** 3101 3102```ts 3103async function GetColorSpace() { 3104 if (pixelMap != undefined) { 3105 let csm = pixelMap.getColorSpace(); 3106 } 3107} 3108``` 3109 3110### setColorSpace<sup>10+</sup> 3111 3112setColorSpace(colorSpace: colorSpaceManager.ColorSpaceManager): void 3113 3114Sets the color space for this image. 3115 3116**System capability**: SystemCapability.Multimedia.Image.Core 3117 3118**Parameters** 3119 3120| Name | Type | Mandatory| Description | 3121| ---------- | ----------------------------------- | ---- | --------------- | 3122| colorSpace | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | Yes | Color space to set.| 3123 3124**Error codes** 3125 3126For details about the error codes, see [Image Error Codes](errorcode-image.md). 3127 3128| ID| Error Message| 3129| ------- | --------------------------------------------| 3130| 62980111| The image source data is incomplete. | 3131| 62980115| If the image parameter invalid. | 3132 3133**Example** 3134 3135```ts 3136import { colorSpaceManager } from '@kit.ArkGraphics2D'; 3137async function SetColorSpace() { 3138 let colorSpaceName = colorSpaceManager.ColorSpace.SRGB; 3139 let csm: colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName); 3140 if (pixelMap != undefined) { 3141 pixelMap.setColorSpace(csm); 3142 } 3143} 3144``` 3145 3146### applyColorSpace<sup>11+</sup> 3147 3148applyColorSpace(targetColorSpace: colorSpaceManager.ColorSpaceManager, callback: AsyncCallback\<void>): void 3149 3150Performs 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. 3151 3152**System capability**: SystemCapability.Multimedia.Image.Core 3153 3154**Parameters** 3155 3156| Name | Type | Mandatory| Description | 3157| -------- | -------------------- | ---- | ----------------------------- | 3158| 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.| 3159| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 3160 3161**Error codes** 3162 3163For details about the error codes, see [Image Error Codes](errorcode-image.md). 3164 3165| ID| Error Message| 3166| ------- | ------------------------------------------| 3167| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 3168| 62980104| Failed to initialize the internal object. | 3169| 62980108| Failed to convert the color space. | 3170| 62980115| Invalid image parameter. | 3171 3172**Example** 3173 3174```ts 3175import { colorSpaceManager } from '@kit.ArkGraphics2D'; 3176import { BusinessError } from '@kit.BasicServicesKit'; 3177 3178async function ApplyColorSpace() { 3179 let colorSpaceName = colorSpaceManager.ColorSpace.SRGB; 3180 let targetColorSpace: colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName); 3181 if (pixelMap != undefined) { 3182 pixelMap.applyColorSpace(targetColorSpace, (err: BusinessError) => { 3183 if (err) { 3184 console.error(`Failed to apply color space for pixelmap object. code is ${err.code}, message is ${err.message}`); 3185 return; 3186 } else { 3187 console.info('Succeeded in applying color space for pixelmap object.'); 3188 } 3189 }) 3190 } 3191} 3192``` 3193 3194### applyColorSpace<sup>11+</sup> 3195 3196applyColorSpace(targetColorSpace: colorSpaceManager.ColorSpaceManager): Promise\<void> 3197 3198Performs CSC on the image pixel color based on a given color space. This API uses a promise to return the result. 3199 3200**System capability**: SystemCapability.Multimedia.Image.Core 3201 3202**Parameters** 3203 3204| Name| Type | Mandatory| Description | 3205| ------ | ------------------ | ---- | ----------- | 3206| 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.| 3207 3208**Return value** 3209 3210| Type | Description | 3211| -------------- | --------------------------- | 3212| Promise\<void> | Promise that returns no value.| 3213 3214**Error codes** 3215 3216For details about the error codes, see [Image Error Codes](errorcode-image.md). 3217 3218| ID| Error Message| 3219| ------- | ------------------------------------------| 3220| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 3221| 62980104| Failed to initialize the internal object. | 3222| 62980108| Failed to convert the color space. | 3223| 62980115| Invalid image parameter. | 3224 3225**Example** 3226 3227```ts 3228import { colorSpaceManager } from '@kit.ArkGraphics2D'; 3229import { BusinessError } from '@kit.BasicServicesKit'; 3230 3231async function ApplyColorSpace() { 3232 let colorSpaceName = colorSpaceManager.ColorSpace.SRGB; 3233 let targetColorSpace: colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName); 3234 if (pixelMap != undefined) { 3235 pixelMap.applyColorSpace(targetColorSpace).then(() => { 3236 console.info('Succeeded in applying color space for pixelmap object.'); 3237 }).catch((error: BusinessError) => { 3238 console.error(`Failed to apply color space for pixelmap object. code is ${error.code}, message is ${error.message}`); 3239 }) 3240 } 3241} 3242``` 3243 3244### toSdr<sup>12+<sup> 3245 3246toSdr(): Promise\<void> 3247 3248Converts an HDR image into an SDR image. This API uses a promise to return the result. 3249 3250**System capability**: SystemCapability.Multimedia.Image.Core 3251 3252**Return value** 3253 3254| Type | Description | 3255| -------------- | --------------------------- | 3256| Promise\<void> | Promise that returns no value.| 3257 3258**Error codes** 3259 3260For details about the error codes, see [Image Error Codes](errorcode-image.md). 3261 3262| ID| Error Message| 3263| ------- | --------------------------------------------| 3264| 62980137 | Invalid image operation. | 3265 3266**Example** 3267 3268```ts 3269import image from '@ohos.multimedia.image' 3270import resourceManager from '@ohos.resourceManager' 3271import { BusinessError } from '@kit.BasicServicesKit'; 3272 3273// '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. 3274let img = getContext().resourceManager.getMediaContentSync($r('app.media.hdr')); 3275let imageSource = image.createImageSource(img.buffer.slice(0)); 3276let decodingOptions: image.DecodingOptions = { 3277 desiredDynamicRange: image.DecodingDynamicRange.AUTO 3278}; 3279let pixelmap = imageSource.createPixelMapSync(decodingOptions); 3280if (pixelmap != undefined) { 3281 console.info('Succeeded in creating pixelMap object.'); 3282 pixelmap.toSdr().then(() => { 3283 let imageInfo = pixelmap.getImageInfoSync(); 3284 console.info("after toSdr ,imageInfo isHdr:" + imageInfo.isHdr); 3285 }).catch((err: BusinessError) => { 3286 console.error(`Failed to set sdr. code is ${err.code}, message is ${err.message}`); 3287 }); 3288} else { 3289 console.info('Failed to create pixelMap.'); 3290} 3291``` 3292 3293### createPixelMapUsingAllocator<sup>15+</sup> 3294 3295createPixelMapUsingAllocator(option?: DecodingOptions, allocatorType?: AllocatorType): Promise\<PixelMap\> 3296 3297Creates a **PixelMap** object based on decoding options and memory type. This API uses a Promise to return the result. 3298 3299**System capability**: SystemCapability.Multimedia.Image.ImageSource 3300 3301**Parameters** 3302 3303| Name | Type | Mandatory| Description | 3304| ------------- | ------------------------------------ | ---- | ------------------------ | 3305| option | [DecodingOptions](#decodingoptions7) | No | Decoding options. | 3306| allocatorType | [AllocatorType](#allocatortype15) | No | Type of the memory. The default value is **AllocatorType.AUTO**.| 3307 3308**Return value** 3309 3310| Type | Description | 3311| -------------------------------- | --------------------------- | 3312| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.| 3313 3314**Error codes** 3315 3316For details about the error codes, see [Image Error Codes](errorcode-image.md). 3317 3318| ID| Error Message | 3319| -------- | ------------------------------------------------------------ | 3320| 401 | Parameter error.Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types;3.Parameter verification failed. | 3321| 7700101 | Bad source. | 3322| 7700102 | Unsupported mimetype. | 3323| 7700103 | Image too large. | 3324| 7700201 | Unsupported allocator type, e.g., use share memory to decode a HDR image as only DMA supported hdr metadata. | 3325| 7700203 | Unsupported options, e.g., cannot convert image into desired pixel format. | 3326| 7700301 | Decode failed. | 3327| 7700302 | Memory allocation failed. | 3328 3329**Example** 3330 3331```ts 3332import image from '@ohos.multimedia.image'; 3333 3334const context: Context = getContext(this); 3335// '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. 3336let filePath: string = context.filesDir + "/test.jpg"; 3337let imageSource = image.createImageSource(filePath); 3338let decodingOptions: image.DecodingOptions = { 3339 editable: true, 3340 desiredSize: { width: 3072, height: 4096 }, 3341 rotate: 10, 3342 desiredPixelFormat: image.PixelMapFormat.RGBA_8888, 3343 desiredRegion: { size: { height: 3072, width: 4096 }, x: 0, y: 0 }, 3344 index: 0 3345}; 3346let pixelmap = await imageSource.createPixelMapUsingAllocator(decodingOptions, image.AllocatorType.AUTO); 3347if (pixelmap != undefined) { 3348 console.info('Succeeded in creating pixelMap object.'); 3349} else { 3350 console.info('Failed to create pixelMap.'); 3351} 3352``` 3353 3354### createPixelMapUsingAllocatorSync<sup>15+</sup> 3355 3356createPixelMapUsingAllocatorSync(option?: DecodingOptions, allocatorType?: AllocatorType): PixelMap 3357 3358Creates a **PixelMap** object based on decoding options and memory type. This API returns the result synchronously. 3359 3360**System capability**: SystemCapability.Multimedia.Image.ImageSource 3361 3362**Parameters** 3363 3364| Name | Type | Mandatory| Description | 3365| ------------- | ------------------------------------ | ---- | ------------------------ | 3366| option | [DecodingOptions](#decodingoptions7) | No | Decoding options. | 3367| allocatorType | [AllocatorType](#allocatortype15) | No | Type of the memory. The default value is **AllocatorType.AUTO**.| 3368 3369**Return value** 3370 3371| Type | Description | 3372| ---------------------- | ---------------------- | 3373| [PixelMap](#pixelmap7) | **PixelMap** object.| 3374 3375**Error codes** 3376 3377For details about the error codes, see [Image Error Codes](errorcode-image.md). 3378 3379| ID| Error Message | 3380| -------- | ------------------------------------------------------------ | 3381| 401 | Parameter error.Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types;3.Parameter verification failed. | 3382| 7700101 | Bad source. | 3383| 7700102 | Unsupported mimetype. | 3384| 7700103 | Image too large. | 3385| 7700201 | Unsupported allocator type, e.g., use share memory to decode a HDR image as only DMA supported hdr metadata. | 3386| 7700203 | Unsupported options, e.g., cannot convert image into desired pixel format. | 3387| 7700301 | Decode failed. | 3388| 7700302 | Memory allocation failed. | 3389 3390**Example** 3391 3392```ts 3393import image from '@ohos.multimedia.image'; 3394 3395const context: Context = getContext(this); 3396// '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. 3397let filePath: string = context.filesDir + "/test.jpg"; 3398let imageSource = image.createImageSource(filePath); 3399let decodingOptions: image.DecodingOptions = { 3400 editable: true, 3401 desiredSize: { width: 3072, height: 4096 }, 3402 rotate: 10, 3403 desiredPixelFormat: image.PixelMapFormat.RGBA_8888, 3404 desiredRegion: { size: { height: 3072, width: 4096 }, x: 0, y: 0 }, 3405 index: 0 3406}; 3407let pixelmap = imageSource.createPixelMapUsingAllocatorSync(decodingOptions, image.AllocatorType.AUTO); 3408if (pixelmap != undefined) { 3409 console.info('Succeeded in creating pixelMap object.'); 3410} else { 3411 console.info('Failed to create pixelMap.'); 3412} 3413``` 3414 3415### getMetadata<sup>12+</sup> 3416 3417getMetadata(key: HdrMetadataKey): HdrMetadataValue 3418 3419Obtains the value of the metadata with a given key in this PixelMap. 3420 3421**System capability**: SystemCapability.Multimedia.Image.Core 3422 3423**Parameters** 3424 3425| Name | Type | Mandatory| Description | 3426| ------------- | -------------------------------- | ---- | ---------------- | 3427| key | [HdrMetadataKey](#hdrmetadatakey12) | Yes | Key of the HDR metadata.| 3428 3429**Return value** 3430 3431| Type | Description | 3432| --------------------------------- | --------------------------------- | 3433| [HdrMetadataValue](#hdrmetadatavalue12) | Value of the metadata with the given key.| 3434 3435**Error codes** 3436 3437For details about the error codes, see [Image Error Codes](errorcode-image.md). 3438 3439| ID| Error Message| 3440| ------- | --------------------------------------------| 3441| 401| Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 3442| 501 | Resource unavailable. | 3443| 62980173 | The DMA memory does not exist. | 3444| 62980302 | Memory copy failed. | 3445 3446**Example** 3447 3448```ts 3449import { BusinessError } from '@kit.BasicServicesKit'; 3450import image from '@ohos.multimedia.image' 3451 3452// Replace 'app.media.test' with a local HDR image. 3453let img = getContext().resourceManager.getMediaContentSync($r('app.media.test')); 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 try { 3462 let staticMetadata = pixelmap.getMetadata(image.HdrMetadataKey.HDR_STATIC_METADATA); 3463 console.info("getmetadata:" + JSON.stringify(staticMetadata)); 3464 } catch (e) { 3465 console.info('pixelmap create failed' + e); 3466 } 3467} else { 3468 console.info('Failed to create pixelMap.'); 3469} 3470``` 3471 3472### setMetadata<sup>12+</sup> 3473 3474setMetadata(key: HdrMetadataKey, value: HdrMetadataValue): Promise\<void> 3475 3476Sets the value for 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| value | [HdrMetadataValue](#hdrmetadatavalue12) | Yes | Value of the metadata.| 3486 3487**Return value** 3488 3489| Type | Description | 3490| -------------- | --------------------- | 3491| Promise\<void> | Promise that returns no value.| 3492 3493**Error codes** 3494 3495For details about the error codes, see [Image Error Codes](errorcode-image.md). 3496 3497| ID| Error Message| 3498| ------- | --------------------------------------------| 3499| 401| Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 3500| 501 | Resource unavailable. | 3501| 62980173 | The DMA memory does not exist. | 3502| 62980302 | Memory copy failed. | 3503 3504**Example** 3505 3506```ts 3507import image from '@ohos.multimedia.image' 3508import { BusinessError } from '@kit.BasicServicesKit'; 3509 3510let staticMetadata: image.HdrStaticMetadata = { 3511 displayPrimariesX: [1.1, 1.1, 1.1], 3512 displayPrimariesY: [1.2, 1.2, 1.2], 3513 whitePointX: 1.1, 3514 whitePointY: 1.2, 3515 maxLuminance: 2.1, 3516 minLuminance: 1.0, 3517 maxContentLightLevel: 2.1, 3518 maxFrameAverageLightLevel: 2.1, 3519} 3520const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 3521let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 3522image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => { 3523 pixelMap.setMetadata(image.HdrMetadataKey.HDR_STATIC_METADATA, staticMetadata).then(() => { 3524 console.info('Succeeded in setting pixelMap metadata.'); 3525 }).catch((error: BusinessError) => { 3526 console.error(`Failed to set the metadata.code ${error.code},message is ${error.message}`); 3527 }) 3528}).catch((error: BusinessError) => { 3529 console.error(`Failed to create the PixelMap.code ${error.code},message is ${error.message}`); 3530}) 3531 3532``` 3533 3534### setTransferDetached<sup>12+<sup> 3535 3536setTransferDetached(detached: boolean): void 3537 3538Sets 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. 3539 3540**System capability**: SystemCapability.Multimedia.Image.Core 3541 3542**Parameters** 3543 3544| Name | Type | Mandatory| Description | 3545| ------- | ------------------ | ---- | ----------------------------- | 3546| detached | boolean | Yes | Whether to detach from the original thread. | 3547 3548**Error codes** 3549 3550For details about the error codes, see [Image Error Codes](errorcode-image.md). 3551 3552| ID| Error Message| 3553| ------- | --------------------------------------------| 3554| 501 | Resource Unavailable | 3555 3556**Example** 3557 3558```ts 3559import { BusinessError } from '@kit.BasicServicesKit'; 3560import image from '@ohos.multimedia.image'; 3561import taskpool from '@ohos.taskpool'; 3562 3563@Concurrent 3564// Child thread method. 3565async function loadPixelMap(rawFileDescriptor: number): Promise<PixelMap> { 3566 // Create an ImageSource instance. 3567 const imageSource = image.createImageSource(rawFileDescriptor); 3568 // Create a pixelMap. 3569 const pixelMap = imageSource.createPixelMapSync(); 3570 // Release the ImageSource instance. 3571 imageSource.release(); 3572 // Disconnect the reference of the original thread after the cross-thread transfer of the pixelMap is complete. 3573 pixelMap.setTransferDetached(true); 3574 // Return the pixelMap to the main thread. 3575 return pixelMap; 3576} 3577 3578struct Demo { 3579 @State pixelMap: PixelMap | undefined = undefined; 3580 // Main thread method. 3581 private loadImageFromThread(): void { 3582 const resourceMgr = getContext(this).resourceManager; 3583 // '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. 3584 resourceMgr.getRawFd('example.jpg').then(rawFileDescriptor => { 3585 taskpool.execute(loadPixelMap, rawFileDescriptor).then(pixelMap => { 3586 if (pixelMap) { 3587 this.pixelMap = pixelMap as PixelMap; 3588 console.log('Succeeded in creating pixelMap.'); 3589 // The main thread releases the pixelMap. Because setTransferDetached has been called when the child thread returns pixelMap, the pixelMap can be released immediately. 3590 this.pixelMap.release(); 3591 } else { 3592 console.error('Failed to create pixelMap.'); 3593 } 3594 }); 3595 }); 3596 } 3597} 3598``` 3599 3600### marshalling<sup>10+</sup> 3601 3602marshalling(sequence: rpc.MessageSequence): void 3603 3604Marshals this **PixelMap** object and writes it to a **MessageSequence** object. 3605 3606**System capability**: SystemCapability.Multimedia.Image.Core 3607 3608**Parameters** 3609 3610| Name | Type | Mandatory| Description | 3611| ---------------------- | ------------------------------------------------------ | ---- | ---------------------------------------- | 3612| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | Yes | **MessageSequence** object. | 3613 3614**Error codes** 3615 3616For details about the error codes, see [Image Error Codes](errorcode-image.md). 3617 3618| ID| Error Message| 3619| ------- | --------------------------------------------| 3620| 62980115 | Invalid image parameter. | 3621| 62980097 | IPC error. | 3622 3623**Example** 3624 3625```ts 3626import { image } from '@kit.ImageKit'; 3627import { rpc } from '@kit.IPCKit'; 3628 3629class MySequence implements rpc.Parcelable { 3630 pixel_map: image.PixelMap; 3631 constructor(conPixelMap : image.PixelMap) { 3632 this.pixel_map = conPixelMap; 3633 } 3634 marshalling(messageSequence : rpc.MessageSequence) { 3635 this.pixel_map.marshalling(messageSequence); 3636 console.info('marshalling'); 3637 return true; 3638 } 3639 unmarshalling(messageSequence : rpc.MessageSequence) { 3640 image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}}).then((pixelParcel: image.PixelMap) => { 3641 pixelParcel.unmarshalling(messageSequence).then(async (pixelMap: image.PixelMap) => { 3642 this.pixel_map = pixelMap; 3643 pixelMap.getImageInfo().then((imageInfo: image.ImageInfo) => { 3644 console.info("unmarshalling information h:" + imageInfo.size.height + "w:" + imageInfo.size.width); 3645 }) 3646 }) 3647 }); 3648 return true; 3649 } 3650} 3651async function Marshalling() { 3652 const color: ArrayBuffer = new ArrayBuffer(96); 3653 let bufferArr: Uint8Array = new Uint8Array(color); 3654 for (let i = 0; i < bufferArr.length; i++) { 3655 bufferArr[i] = 0x80; 3656 } 3657 let opts: image.InitializationOptions = { 3658 editable: true, 3659 pixelFormat: image.PixelMapFormat.BGRA_8888, 3660 size: { height: 4, width: 6 }, 3661 alphaType: image.AlphaType.UNPREMUL 3662 } 3663 let pixelMap: image.PixelMap | undefined = undefined; 3664 image.createPixelMap(color, opts).then((srcPixelMap: image.PixelMap) => { 3665 pixelMap = srcPixelMap; 3666 }) 3667 if (pixelMap != undefined) { 3668 // Implement serialization. 3669 let parcelable: MySequence = new MySequence(pixelMap); 3670 let data: rpc.MessageSequence = rpc.MessageSequence.create(); 3671 data.writeParcelable(parcelable); 3672 3673 // Implement deserialization to obtain data through the RPC. 3674 let ret: MySequence = new MySequence(pixelMap); 3675 data.readParcelable(ret); 3676 } 3677} 3678``` 3679 3680### unmarshalling<sup>10+</sup> 3681 3682unmarshalling(sequence: rpc.MessageSequence): Promise\<PixelMap> 3683 3684Unmarshals a **MessageSequence** object to obtain a **PixelMap** object. 3685To create a **PixelMap** object in synchronous mode, use [createPixelMapFromParcel](#imagecreatepixelmapfromparcel11). 3686 3687**System capability**: SystemCapability.Multimedia.Image.Core 3688 3689**Parameters** 3690 3691| Name | Type | Mandatory| Description | 3692| ---------------------- | ----------------------------------------------------- | ---- | ---------------------------------------- | 3693| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | Yes | **MessageSequence** object that stores the **PixelMap** information. | 3694 3695**Return value** 3696 3697| Type | Description | 3698| -------------------------------- | --------------------- | 3699| Promise\<[PixelMap](#pixelmap7)> |Promise used to return the **PixelMap** object.| 3700 3701**Error codes** 3702 3703For details about the error codes, see [Image Error Codes](errorcode-image.md). 3704 3705| ID| Error Message| 3706| ------- | --------------------------------------------| 3707| 62980115 | Invalid image parameter. | 3708| 62980097 | IPC error. | 3709| 62980096 | The operation failed. | 3710 3711**Example** 3712 3713```ts 3714import { image } from '@kit.ImageKit'; 3715import { rpc } from '@kit.IPCKit'; 3716 3717class MySequence implements rpc.Parcelable { 3718 pixel_map: image.PixelMap; 3719 constructor(conPixelMap: image.PixelMap) { 3720 this.pixel_map = conPixelMap; 3721 } 3722 marshalling(messageSequence: rpc.MessageSequence) { 3723 this.pixel_map.marshalling(messageSequence); 3724 console.info('marshalling'); 3725 return true; 3726 } 3727 unmarshalling(messageSequence: rpc.MessageSequence) { 3728 image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}}).then((pixelParcel : image.PixelMap) => { 3729 pixelParcel.unmarshalling(messageSequence).then(async (pixelMap : image.PixelMap) => { 3730 this.pixel_map = pixelMap; 3731 pixelMap.getImageInfo().then((imageInfo : image.ImageInfo) => { 3732 console.info("unmarshalling information h:" + imageInfo.size.height + "w:" + imageInfo.size.width); 3733 }) 3734 }) 3735 }); 3736 return true; 3737 } 3738} 3739async function Unmarshalling() { 3740 const color: ArrayBuffer = new ArrayBuffer(96); 3741 let bufferArr: Uint8Array = new Uint8Array(color); 3742 for (let i = 0; i < bufferArr.length; i++) { 3743 bufferArr[i] = 0x80; 3744 } 3745 let opts: image.InitializationOptions = { 3746 editable: true, 3747 pixelFormat: image.PixelMapFormat.BGRA_8888, 3748 size: { height: 4, width: 6 }, 3749 alphaType: image.AlphaType.UNPREMUL 3750 } 3751 let pixelMap: image.PixelMap | undefined = undefined; 3752 image.createPixelMap(color, opts).then((srcPixelMap : image.PixelMap) => { 3753 pixelMap = srcPixelMap; 3754 }) 3755 if (pixelMap != undefined) { 3756 // Implement serialization. 3757 let parcelable: MySequence = new MySequence(pixelMap); 3758 let data : rpc.MessageSequence = rpc.MessageSequence.create(); 3759 data.writeParcelable(parcelable); 3760 3761 // Implement deserialization to obtain data through the RPC. 3762 let ret : MySequence = new MySequence(pixelMap); 3763 data.readParcelable(ret); 3764 } 3765} 3766``` 3767 3768### release<sup>7+</sup> 3769 3770release():Promise\<void> 3771 3772Releases this **PixelMap** object. This API uses a promise to return the result. 3773 3774ArkTS 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. 3775 3776**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3777 3778**Atomic service API**: This API can be used in atomic services since API version 11. 3779 3780**System capability**: SystemCapability.Multimedia.Image.Core 3781 3782**Return value** 3783 3784| Type | Description | 3785| -------------- | ------------------------------- | 3786| Promise\<void> | Promise that returns no value.| 3787 3788**Example** 3789 3790```ts 3791import { BusinessError } from '@kit.BasicServicesKit'; 3792 3793async function Release() { 3794 if (pixelMap != undefined) { 3795 pixelMap.release().then(() => { 3796 console.info('Succeeded in releasing pixelmap object.'); 3797 }).catch((error: BusinessError) => { 3798 console.error(`Failed to release pixelmap object. code is ${error.code}, message is ${error.message}`); 3799 }) 3800 } 3801} 3802``` 3803 3804### release<sup>7+</sup> 3805 3806release(callback: AsyncCallback\<void>): void 3807 3808Releases this **PixelMap** object. This API uses an asynchronous callback to return the result. 3809 3810ArkTS 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. 3811 3812**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3813 3814**Atomic service API**: This API can be used in atomic services since API version 11. 3815 3816**System capability**: SystemCapability.Multimedia.Image.Core 3817 3818**Parameters** 3819 3820| Name | Type | Mandatory| Description | 3821| -------- | -------------------- | ---- | ------------------ | 3822| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 3823 3824**Example** 3825 3826```ts 3827import { BusinessError } from '@kit.BasicServicesKit'; 3828 3829async function Release() { 3830 if (pixelMap != undefined) { 3831 pixelMap.release((err: BusinessError) => { 3832 if (err) { 3833 console.error(`Failed to release pixelmap object. code is ${err.code}, message is ${err.message}`); 3834 return; 3835 } else { 3836 console.info('Succeeded in releasing pixelmap object.'); 3837 } 3838 }) 3839 } 3840} 3841``` 3842 3843### convertPixelFormat<sup>12+</sup> 3844 3845convertPixelFormat(targetPixelFormat: PixelMapFormat): Promise\<void> 3846 3847Performs 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. 3848 3849**System capability**: SystemCapability.Multimedia.Image.Core 3850 3851**Parameters** 3852 3853| Name | Type | Mandatory| Description | 3854| -------- | -------------------- | ---- | ------------------ | 3855| targetPixelFormat | [PixelMapFormat](#pixelmapformat7) | Yes | Target pixel format. Currently, only conversion between NV12/NV21 and RGB888/RGBA8888/RGB565/BGRA8888/RGBAF16 and conversion between YCRCB_P010/YCBCR_P010 and RGBA1010102 are supported.| 3856 3857**Return value** 3858 3859| Type | Description | 3860| -------------- | ------------------------------- | 3861| Promise\<void> | Promise that returns no value.| 3862 3863**Error codes** 3864 3865For details about the error codes, see [Image Error Codes](errorcode-image.md). 3866 3867| ID| Error Message| 3868| ------- | --------------------------------------------| 3869| 62980111 | The image source data is incomplete. | 3870| 62980115 | Invalid input parameter. | 3871| 62980178 | Failed to create the pixelmap. | 3872| 62980274 | The conversion failed | 3873| 62980276 | The type to be converted is an unsupported target pixel format| 3874 3875**Example** 3876 3877```ts 3878import { BusinessError } from '@kit.BasicServicesKit'; 3879 3880if (pixelMap != undefined) { 3881 // Set the target pixel format to NV12. 3882 let targetPixelFormat = image.PixelMapFormat.NV12; 3883 pixelMap.convertPixelFormat(targetPixelFormat).then(() => { 3884 // The pixelMap is converted to the NV12 format. 3885 console.info('PixelMapFormat convert Succeeded'); 3886 }).catch((error: BusinessError) => { 3887 // The pixelMap fails to be converted to the NV12 format. 3888 console.error(`PixelMapFormat convert Failed. code is ${error.code}, message is ${error.message}`); 3889 }) 3890} 3891``` 3892 3893### setMemoryNameSync<sup>13+</sup> 3894 3895setMemoryNameSync(name: string): void 3896 3897Sets a memory name for this PixelMap. 3898 3899**System capability**: SystemCapability.Multimedia.Image.Core 3900 3901**Parameters** 3902 3903| Name | Type | Mandatory| Description | 3904| ------------- | -------------------------------- | ---- | ---------------- | 3905| 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.| 3906 3907**Error codes** 3908 3909For details about the error codes, see [Image Error Codes](errorcode-image.md). 3910 3911| ID| Error Message| 3912| ------- | --------------------------------------------| 3913| 401 | Parameter error. Possible causes: 1.The length of the input parameter is too long. 2.Parameter verification failed. | 3914| 501 | Resource unavailable. | 3915| 62980286 | Memory format not supported. | 3916 3917**Example** 3918 3919```ts 3920import { BusinessError } from '@ohos.base'; 3921 3922async function SetMemoryNameSync() { 3923 if (pixelMap != undefined) { 3924 try { 3925 pixelMap.setMemoryNameSync("PixelMapName Test"); 3926 } catch(e) { 3927 let error = e as BusinessError; 3928 console.error(`setMemoryNameSync error. code is ${error.code}, message is ${error.message}`); 3929 } 3930 } 3931} 3932``` 3933 3934## image.createImageSource 3935 3936createImageSource(uri: string): ImageSource 3937 3938Creates an **ImageSource** instance based on a given URI. 3939 3940 3941**Atomic service API**: This API can be used in atomic services since API version 11. 3942 3943**System capability**: SystemCapability.Multimedia.Image.ImageSource 3944 3945**Parameters** 3946 3947| Name| Type | Mandatory| Description | 3948| ------ | ------ | ---- | ---------------------------------- | 3949| 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>.| 3950 3951**Return value** 3952 3953| Type | Description | 3954| --------------------------- | -------------------------------------------- | 3955| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 3956 3957**Example** 3958 3959```ts 3960const context: Context = getContext(this); 3961// '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. 3962const path: string = context.filesDir + "/test.jpg"; 3963const imageSourceApi: image.ImageSource = image.createImageSource(path); 3964``` 3965 3966## image.createImageSource<sup>9+</sup> 3967 3968createImageSource(uri: string, options: SourceOptions): ImageSource 3969 3970Creates an **ImageSource** instance based on a given URI. 3971 3972**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3973 3974**Atomic service API**: This API can be used in atomic services since API version 11. 3975 3976**System capability**: SystemCapability.Multimedia.Image.ImageSource 3977 3978**Parameters** 3979 3980| Name | Type | Mandatory| Description | 3981| ------- | ------------------------------- | ---- | ----------------------------------- | 3982| 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>.| 3983| options | [SourceOptions](#sourceoptions9) | Yes | Image properties, including the image pixel density, pixel format, and image size.| 3984 3985**Return value** 3986 3987| Type | Description | 3988| --------------------------- | -------------------------------------------- | 3989| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 3990 3991**Example** 3992 3993```ts 3994let sourceOptions: image.SourceOptions = { sourceDensity: 120 }; 3995const context: Context = getContext(this); 3996// '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. 3997const path: string = context.filesDir + "/test.png"; 3998let imageSourceApi: image.ImageSource = image.createImageSource(path, sourceOptions); 3999``` 4000 4001## image.createImageSource<sup>7+</sup> 4002 4003createImageSource(fd: number): ImageSource 4004 4005Creates an **ImageSource** instance based on a given file descriptor. 4006 4007**Atomic service API**: This API can be used in atomic services since API version 11. 4008 4009**System capability**: SystemCapability.Multimedia.Image.ImageSource 4010 4011**Parameters** 4012 4013| Name| Type | Mandatory| Description | 4014| ------ | ------ | ---- | ------------- | 4015| fd | number | Yes | File descriptor.| 4016 4017**Return value** 4018 4019| Type | Description | 4020| --------------------------- | -------------------------------------------- | 4021| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 4022 4023**Example** 4024 4025```ts 4026import { fileIo as fs } from '@kit.CoreFileKit'; 4027 4028const context: Context = getContext(this); 4029// '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. 4030let filePath: string = context.filesDir + "/test.jpg"; 4031let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 4032const imageSourceApi: image.ImageSource = image.createImageSource(file.fd); 4033``` 4034 4035## image.createImageSource<sup>9+</sup> 4036 4037createImageSource(fd: number, options: SourceOptions): ImageSource 4038 4039Creates an **ImageSource** instance based on a given file descriptor. 4040 4041**Widget capability**: This API can be used in ArkTS widgets since API version 12. 4042 4043**Atomic service API**: This API can be used in atomic services since API version 11. 4044 4045**System capability**: SystemCapability.Multimedia.Image.ImageSource 4046 4047**Parameters** 4048 4049| Name | Type | Mandatory| Description | 4050| ------- | ------------------------------- | ---- | ----------------------------------- | 4051| fd | number | Yes | File descriptor. | 4052| options | [SourceOptions](#sourceoptions9) | Yes | Image properties, including the image pixel density, pixel format, and image size.| 4053 4054**Return value** 4055 4056| Type | Description | 4057| --------------------------- | -------------------------------------------- | 4058| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 4059 4060**Example** 4061 4062```ts 4063import { fileIo as fs } from '@kit.CoreFileKit'; 4064 4065let sourceOptions: image.SourceOptions = { sourceDensity: 120 }; 4066const context: Context = getContext(); 4067// '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. 4068const filePath: string = context.filesDir + "/test.jpg"; 4069let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 4070const imageSourceApi: image.ImageSource = image.createImageSource(file.fd, sourceOptions); 4071``` 4072 4073## image.createImageSource<sup>9+</sup> 4074 4075createImageSource(buf: ArrayBuffer): ImageSource 4076 4077Creates 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). 4078 4079**Widget capability**: This API can be used in ArkTS widgets since API version 12. 4080 4081**Atomic service API**: This API can be used in atomic services since API version 11. 4082 4083**System capability**: SystemCapability.Multimedia.Image.ImageSource 4084 4085**Parameters** 4086 4087| Name| Type | Mandatory| Description | 4088| ------ | ----------- | ---- | ---------------- | 4089| buf | ArrayBuffer | Yes | Array of image buffers.| 4090 4091**Return value** 4092 4093| Type | Description | 4094| --------------------------- | -------------------------------------------- | 4095| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 4096 4097 4098**Example** 4099 4100```ts 4101const buf: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 4102const imageSourceApi: image.ImageSource = image.createImageSource(buf); 4103``` 4104 4105## image.createImageSource<sup>9+</sup> 4106 4107createImageSource(buf: ArrayBuffer, options: SourceOptions): ImageSource 4108 4109Creates 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). 4110 4111**Widget capability**: This API can be used in ArkTS widgets since API version 12. 4112 4113**Atomic service API**: This API can be used in atomic services since API version 11. 4114 4115**System capability**: SystemCapability.Multimedia.Image.ImageSource 4116 4117**Parameters** 4118 4119| Name| Type | Mandatory| Description | 4120| ------ | -------------------------------- | ---- | ------------------------------------ | 4121| buf | ArrayBuffer | Yes | Array of image buffers. | 4122| options | [SourceOptions](#sourceoptions9) | Yes | Image properties, including the image pixel density, pixel format, and image size.| 4123 4124**Return value** 4125 4126| Type | Description | 4127| --------------------------- | -------------------------------------------- | 4128| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 4129 4130**Example** 4131 4132```ts 4133const data: ArrayBuffer = new ArrayBuffer(112); 4134let sourceOptions: image.SourceOptions = { sourceDensity: 120 }; 4135const imageSourceApi: image.ImageSource = image.createImageSource(data, sourceOptions); 4136``` 4137 4138## image.createImageSource<sup>11+</sup> 4139 4140createImageSource(rawfile: resourceManager.RawFileDescriptor, options?: SourceOptions): ImageSource 4141 4142Creates an **ImageSource** instance based on the raw file descriptor of an image resource file. 4143 4144**Atomic service API**: This API can be used in atomic services since API version 11. 4145 4146**System capability**: SystemCapability.Multimedia.Image.ImageSource 4147 4148**Parameters** 4149 4150| Name| Type | Mandatory| Description | 4151| ------ | -------------------------------- | ---- | ------------------------------------ | 4152| rawfile | [resourceManager.RawFileDescriptor](../apis-localization-kit/js-apis-resource-manager.md#rawfiledescriptor9) | Yes| Raw file descriptor of the image resource file.| 4153| options | [SourceOptions](#sourceoptions9) | No| Image properties, including the image pixel density, pixel format, and image size.| 4154 4155**Return value** 4156 4157| Type | Description | 4158| --------------------------- | -------------------------------------------- | 4159| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 4160 4161**Example** 4162 4163```ts 4164import { resourceManager } from '@kit.LocalizationKit'; 4165 4166const context: Context = getContext(this); 4167// Obtain a resource manager. 4168const resourceMgr: resourceManager.ResourceManager = context.resourceManager; 4169// '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. 4170resourceMgr.getRawFd('test.jpg').then((rawFileDescriptor: resourceManager.RawFileDescriptor) => { 4171 const imageSourceApi: image.ImageSource = image.createImageSource(rawFileDescriptor); 4172}).catch((error: BusinessError) => { 4173 console.error(`Failed to get RawFileDescriptor.code is ${error.code}, message is ${error.message}`); 4174}) 4175``` 4176 4177## image.CreateIncrementalSource<sup>9+</sup> 4178 4179CreateIncrementalSource(buf: ArrayBuffer): ImageSource 4180 4181Creates an **ImageSource** instance in incremental mode based on buffers. Such an instance does not support reading or writing of EXIF information. 4182 4183The **ImageSource** instance created in incremental mode supports the following capabilities (applicable to synchronous, callback, and promise modes): 4184- Obtaining image information: Call [getImageInfo](#getimageinfo) to obtain image information by index, or call [getImageInfo](#getimageinfo-1) to directly obtain image information. 4185- Obtaining an image property: Call [getImageProperty](#getimageproperty11) to obtain the value of a property with the specified index in an image. 4186- Obtaining image properties: Call [getImageProperties](#getimageproperties12) to obtain the values of properties with the given names in an image. 4187- Updating incremental data: Call [updateData](#updatedata9) to update data. 4188- 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. 4189- Releasing an **ImageSource** instance: Call [release](#release) to release an image source. 4190 4191**System capability**: SystemCapability.Multimedia.Image.ImageSource 4192 4193**Parameters** 4194 4195| Name | Type | Mandatory| Description | 4196| ------- | ------------| ---- | ----------| 4197| buf | ArrayBuffer | Yes | Incremental data.| 4198 4199**Return value** 4200 4201| Type | Description | 4202| --------------------------- | --------------------------------- | 4203| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns undefined otherwise.| 4204 4205**Example** 4206 4207```ts 4208const context: Context = getContext(this) 4209let imageArray = context.resourceManager.getMediaContentSync($r('app.media.startIcon')) // Obtain the image resource. 4210// '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. 4211let splitBuff1 = imageArray.slice(0, imageArray.byteLength / 2) // Image slice. 4212let splitBuff2 = imageArray.slice(imageArray.byteLength / 2) 4213const imageSourceIncrementalSApi: image.ImageSource = image.CreateIncrementalSource(new ArrayBuffer(imageArray.byteLength)); 4214imageSourceIncrementalSApi.updateData(splitBuff1, false, 0, splitBuff1.byteLength).then(() => { 4215 imageSourceIncrementalSApi.updateData(splitBuff2, true, 0, splitBuff2.byteLength).then(() => { 4216 let pixelMap = imageSourceIncrementalSApi.createPixelMapSync() 4217 let imageInfo = pixelMap.getImageInfoSync() 4218 console.info('Succeeded in creating pixelMap') 4219 }).catch((error : BusinessError) => { 4220 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`) 4221 }) 4222}).catch((error : BusinessError) => { 4223 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`) 4224}) 4225``` 4226 4227## image.CreateIncrementalSource<sup>9+</sup> 4228 4229CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource 4230 4231Creates an **ImageSource** instance in incremental mode based on buffers. Such an instance does not support reading or writing of EXIF information. 4232 4233The 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). 4234 4235**System capability**: SystemCapability.Multimedia.Image.ImageSource 4236 4237**Parameters** 4238 4239| Name | Type | Mandatory| Description | 4240| ------- | ------------------------------- | ---- | ------------------------------------ | 4241| buf | ArrayBuffer | Yes | Incremental data. | 4242| options | [SourceOptions](#sourceoptions9) | No | Image properties, including the image pixel density, pixel format, and image size.| 4243 4244**Return value** 4245 4246| Type | Description | 4247| --------------------------- | --------------------------------- | 4248| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns undefined otherwise.| 4249 4250**Example** 4251 4252```ts 4253const context: Context = getContext(this) 4254let imageArray = context.resourceManager.getMediaContentSync($r('app.media.startIcon')) // Obtain the image resource. 4255// '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. 4256let splitBuff1 = imageArray.slice(0, imageArray.byteLength / 2) // Image slice. 4257let splitBuff2 = imageArray.slice(imageArray.byteLength / 2) 4258let sourceOptions: image.SourceOptions = { sourceDensity: 120}; 4259 4260const imageSourceIncrementalSApi: image.ImageSource = image.CreateIncrementalSource(new ArrayBuffer(imageArray.byteLength), sourceOptions); 4261imageSourceIncrementalSApi.updateData(splitBuff1, false, 0, splitBuff1.byteLength).then(() => { 4262 imageSourceIncrementalSApi.updateData(splitBuff2, true, 0, splitBuff2.byteLength).then(() => { 4263 let pixelMap = imageSourceIncrementalSApi.createPixelMapSync() 4264 let imageInfo = pixelMap.getImageInfoSync() 4265 console.info('Succeeded in creating pixelMap') 4266 }).catch((error : BusinessError) => { 4267 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`) 4268 }) 4269}).catch((error : BusinessError) => { 4270 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`) 4271}) 4272``` 4273 4274## ImageSource 4275 4276Provides APIs to obtain image information. Before calling any API in **ImageSource**, you must use [createImageSource](#imagecreateimagesource) to create an **ImageSource** instance. 4277 4278### Properties 4279 4280**System capability**: SystemCapability.Multimedia.Image.ImageSource 4281 4282| Name | Type | Readable| Writable| Description | 4283| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | 4284| supportedFormats | Array\<string> | Yes | No | Supported formats, including .png, .jpeg, .bmp, .gif, .webp, .dng. and .heic<sup>12+</sup> (depending on the hardware).| 4285 4286### getImageInfo 4287 4288getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void 4289 4290Obtains information about an image with the specified index. This API uses an asynchronous callback to return the result. 4291 4292**Widget capability**: This API can be used in ArkTS widgets since API version 12. 4293 4294**Atomic service API**: This API can be used in atomic services since API version 11. 4295 4296**System capability**: SystemCapability.Multimedia.Image.ImageSource 4297 4298**Parameters** 4299 4300| Name | Type | Mandatory| Description | 4301| -------- | -------------------------------------- | ---- | ---------------------------------------- | 4302| index | number | Yes | Index of the image. | 4303| 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.| 4304 4305**Example** 4306 4307```ts 4308import { BusinessError } from '@kit.BasicServicesKit'; 4309 4310imageSourceApi.getImageInfo(0, (error: BusinessError, imageInfo: image.ImageInfo) => { 4311 if (error) { 4312 console.error(`Failed to obtain the image information.code is ${error.code}, message is ${error.message}`); 4313 } else { 4314 console.info('Succeeded in obtaining the image information.'); 4315 } 4316}) 4317``` 4318 4319### getImageInfo 4320 4321getImageInfo(callback: AsyncCallback\<ImageInfo>): void 4322 4323Obtains information about this image. This API uses an asynchronous callback to return the result. 4324 4325**Widget capability**: This API can be used in ArkTS widgets since API version 12. 4326 4327**Atomic service API**: This API can be used in atomic services since API version 11. 4328 4329**System capability**: SystemCapability.Multimedia.Image.ImageSource 4330 4331**Parameters** 4332 4333| Name | Type | Mandatory| Description | 4334| -------- | -------------------------------------- | ---- | ---------------------------------------- | 4335| 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.| 4336 4337**Example** 4338 4339```ts 4340import { BusinessError } from '@kit.BasicServicesKit'; 4341 4342imageSourceApi.getImageInfo((err: BusinessError, imageInfo: image.ImageInfo) => { 4343 if (err) { 4344 console.error(`Failed to obtain the image information.code is ${err.code}, message is ${err.message}`); 4345 } else { 4346 console.info('Succeeded in obtaining the image information.'); 4347 } 4348}) 4349``` 4350 4351### getImageInfo 4352 4353getImageInfo(index?: number): Promise\<ImageInfo> 4354 4355Obtains information about an image with the specified index. This API uses a promise to return the result. 4356 4357**Widget capability**: This API can be used in ArkTS widgets since API version 12. 4358 4359**Atomic service API**: This API can be used in atomic services since API version 11. 4360 4361**System capability**: SystemCapability.Multimedia.Image.ImageSource 4362 4363**Parameters** 4364 4365| Name| Type | Mandatory| Description | 4366| ----- | ------ | ---- | ------------------------------------- | 4367| index | number | No | Index of the image. If this parameter is not set, the default value **0** is used.| 4368 4369**Return value** 4370 4371| Type | Description | 4372| -------------------------------- | ---------------------- | 4373| Promise<[ImageInfo](#imageinfo)> | Promise used to return the image information.| 4374 4375**Example** 4376 4377```ts 4378import { BusinessError } from '@kit.BasicServicesKit'; 4379 4380imageSourceApi.getImageInfo(0) 4381 .then((imageInfo: image.ImageInfo) => { 4382 console.info('Succeeded in obtaining the image information.'); 4383 }).catch((error: BusinessError) => { 4384 console.error(`Failed to obtain the image information.code is ${error.code}, message is ${error.message}`); 4385 }) 4386``` 4387 4388### getImageInfoSync<sup>12+</sup> 4389 4390getImageInfoSync(index?: number): ImageInfo 4391 4392Obtains information about an image with the specified index. This API returns the result synchronously. 4393 4394**System capability**: SystemCapability.Multimedia.Image.ImageSource 4395 4396**Parameters** 4397 4398| Name| Type | Mandatory| Description | 4399| ----- | ------ | ---- | ------------------------------------- | 4400| index | number | No | Index of the image. If this parameter is not set, the default value **0** is used.| 4401 4402**Return value** 4403 4404| Type | Description | 4405| -------------------------------- | ---------------------- | 4406| [ImageInfo](#imageinfo) | Image information.| 4407 4408**Example** 4409 4410```ts 4411import { image } from '@kit.ImageKit'; 4412 4413const context: Context = getContext(); 4414// '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. 4415let filePath: string = context.filesDir + "/test.jpg"; 4416let imageSource = image.createImageSource(filePath); 4417let imageInfo = imageSource.getImageInfoSync(0); 4418if (imageInfo == undefined) { 4419 console.error('Failed to obtain the image information.'); 4420} else { 4421 console.info('Succeeded in obtaining the image information.'); 4422 console.info('imageInfo.size.height:' + imageInfo.size.height); 4423 console.info('imageInfo.size.width:' + imageInfo.size.width); 4424} 4425``` 4426 4427### getImageProperty<sup>11+</sup> 4428 4429getImageProperty(key:PropertyKey, options?: ImagePropertyOptions): Promise\<string> 4430 4431Obtains 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. 4432 4433**System capability**: SystemCapability.Multimedia.Image.ImageSource 4434 4435**Parameters** 4436 4437| Name | Type | Mandatory| Description | 4438| ------- | ---------------------------------------------------- | ---- | ------------------------------------ | 4439| key | [PropertyKey](#propertykey7) | Yes | Name of the property. | 4440| options | [ImagePropertyOptions](#imagepropertyoptions11) | No | Image properties, including the image index and default property value.| 4441 4442**Return value** 4443 4444| Type | Description | 4445| ---------------- | ----------------------------------------------------------------- | 4446| Promise\<string> | Promise used to return the property value. If the operation fails, the default value is returned.| 4447 4448**Error codes** 4449 4450For details about the error codes, see [Image Error Codes](errorcode-image.md). 4451 4452| ID| Error Message| 4453| ------- | --------------------------------------------| 4454| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 4455| 62980096 | The operation failed. | 4456| 62980103 | The image data is not supported. | 4457| 62980110 | The image source data is incorrect. | 4458| 62980111 | The image source data is incomplete. | 4459| 62980112 | The image format does not match. | 4460| 62980113 | Unknown image format. | 4461| 62980115 | Invalid image parameter. | 4462| 62980116| Failed to decode the image. | 4463| 62980118 | Failed to create the image plugin. | 4464| 62980122 | Failed to decode the image header. | 4465| 62980123| Images in EXIF format are not supported. | 4466| 62980135| The EXIF value is invalid. | 4467 4468**Example** 4469 4470```ts 4471import { BusinessError } from '@kit.BasicServicesKit'; 4472 4473let options: image.ImagePropertyOptions = { index: 0, defaultValue: '9999' } 4474imageSourceApi.getImageProperty(image.PropertyKey.BITS_PER_SAMPLE, options) 4475.then((data: string) => { 4476 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 4477}).catch((error: BusinessError) => { 4478 console.error('Failed to get the value of the specified attribute key of the image.'); 4479}) 4480``` 4481 4482### getImageProperty<sup>(deprecated)</sup> 4483 4484getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\<string> 4485 4486Obtains 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. 4487 4488> **NOTE** 4489> 4490> This API is deprecated since API version 11. You are advised to use [getImageProperty](#getimageproperty11). 4491 4492**System capability**: SystemCapability.Multimedia.Image.ImageSource 4493 4494**Parameters** 4495 4496| Name | Type | Mandatory| Description | 4497| ------- | ---------------------------------------------------- | ---- | ------------------------------------ | 4498| key | string | Yes | Name of the property. | 4499| options | [GetImagePropertyOptions](#getimagepropertyoptionsdeprecated) | No | Image properties, including the image index and default property value.| 4500 4501**Return value** 4502 4503| Type | Description | 4504| ---------------- | ----------------------------------------------------------------- | 4505| Promise\<string> | Promise used to return the property value. If the operation fails, the default value is returned.| 4506 4507**Example** 4508 4509```ts 4510import { BusinessError } from '@kit.BasicServicesKit'; 4511 4512imageSourceApi.getImageProperty("BitsPerSample") 4513 .then((data: string) => { 4514 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 4515 }).catch((error: BusinessError) => { 4516 console.error('Failed to get the value of the specified attribute key of the image.'); 4517 }) 4518``` 4519 4520### getImageProperty<sup>(deprecated)</sup> 4521 4522getImageProperty(key:string, callback: AsyncCallback\<string>): void 4523 4524Obtains 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. 4525 4526> **NOTE** 4527> 4528> This API is deprecated since API version 11. You are advised to use [getImageProperty](#getimageproperty11). 4529 4530**System capability**: SystemCapability.Multimedia.Image.ImageSource 4531 4532**Parameters** 4533 4534| Name | Type | Mandatory| Description | 4535| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 4536| key | string | Yes | Name of the property. | 4537| 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.| 4538 4539**Example** 4540 4541```ts 4542import { BusinessError } from '@kit.BasicServicesKit'; 4543 4544imageSourceApi.getImageProperty("BitsPerSample", (error: BusinessError, data: string) => { 4545 if (error) { 4546 console.error('Failed to get the value of the specified attribute key of the image.'); 4547 } else { 4548 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 4549 } 4550}) 4551``` 4552 4553### getImageProperty<sup>(deprecated)</sup> 4554 4555getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCallback\<string>): void 4556 4557Obtains 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. 4558 4559> **NOTE** 4560> 4561> This API is deprecated since API version 11. You are advised to use [getImageProperty](#getimageproperty11). 4562 4563**System capability**: SystemCapability.Multimedia.Image.ImageSource 4564 4565**Parameters** 4566 4567| Name | Type | Mandatory| Description | 4568| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------- | 4569| key | string | Yes | Name of the property. | 4570| options | [GetImagePropertyOptions](#getimagepropertyoptionsdeprecated) | Yes | Image properties, including the image index and default property value. | 4571| 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.| 4572 4573**Example** 4574 4575```ts 4576import { BusinessError } from '@kit.BasicServicesKit'; 4577 4578let property: image.GetImagePropertyOptions = { index: 0, defaultValue: '9999' } 4579imageSourceApi.getImageProperty("BitsPerSample", property, (error: BusinessError, data: string) => { 4580 if (error) { 4581 console.error('Failed to get the value of the specified attribute key of the image.'); 4582 } else { 4583 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 4584 } 4585}) 4586``` 4587 4588### getImageProperties<sup>12+</sup> 4589 4590getImageProperties(key: Array<PropertyKey>): Promise<Record<PropertyKey, string|null>> 4591 4592Obtains 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. 4593 4594**System capability**: SystemCapability.Multimedia.Image.ImageSource 4595 4596**Parameters** 4597 4598| Name | Type | Mandatory| Description | 4599| ------- | ---------------------------------------------------- | ---- | ------------------------------------ | 4600| key | Array\<[PropertyKey](#propertykey7)> | Yes | Array of properties names. | 4601 4602**Return value** 4603 4604| Type | Description | 4605| ---------------- | ----------------------------------------------------------------- | 4606| Promise\<Record<[PropertyKey](#propertykey7), string \| null>> | Promise used to return the property values. If the operation fails, **null** is returned.| 4607 4608**Error codes** 4609 4610For details about the error codes, see [Image Error Codes](errorcode-image.md). 4611 4612| ID| Error Message| 4613| ------- | --------------------------------------------| 4614| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 4615| 62980096| The operation failed. | 4616| 62980110| The image source data is incorrect. | 4617| 62980113| Unknown image format. | 4618| 62980116| Failed to decode the image. | 4619 4620**Example** 4621 4622```ts 4623import { image } from '@kit.ImageKit'; 4624import { BusinessError } from '@kit.BasicServicesKit'; 4625 4626let key = [image.PropertyKey.IMAGE_WIDTH, image.PropertyKey.IMAGE_LENGTH]; 4627imageSourceApi.getImageProperties(key).then((data) => { 4628 console.info(JSON.stringify(data)); 4629}).catch((err: BusinessError) => { 4630 console.error(JSON.stringify(err)); 4631}); 4632``` 4633 4634### modifyImageProperty<sup>11+</sup> 4635 4636modifyImageProperty(key: PropertyKey, value: string): Promise\<void> 4637 4638Modifies 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. 4639 4640> **NOTE** 4641> 4642> 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. 4643 4644**System capability**: SystemCapability.Multimedia.Image.ImageSource 4645 4646**Parameters** 4647 4648| Name | Type | Mandatory| Description | 4649| ------- | ------ | ---- | ------------ | 4650| key | [PropertyKey](#propertykey7) | Yes | Name of the property.| 4651| value | string | Yes | New value of the property. | 4652 4653**Return value** 4654 4655| Type | Description | 4656| -------------- | --------------------------- | 4657| Promise\<void> | Promise that returns no value.| 4658 4659**Error codes** 4660 4661For details about the error codes, see [Image Error Codes](errorcode-image.md). 4662 4663| ID| Error Message| 4664| ------- | --------------------------------------------| 4665| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; | 4666| 62980123| The image does not support EXIF decoding. | 4667| 62980133| The EXIF data is out of range. | 4668| 62980135| The EXIF value is invalid. | 4669| 62980146| The EXIF data failed to be written to the file. | 4670 4671**Example** 4672 4673```ts 4674import { BusinessError } from '@kit.BasicServicesKit'; 4675 4676imageSourceApi.modifyImageProperty(image.PropertyKey.IMAGE_WIDTH, "120").then(() => { 4677 imageSourceApi.getImageProperty(image.PropertyKey.IMAGE_WIDTH).then((width: string) => { 4678 console.info(`ImageWidth is :${width}`); 4679 }).catch((error: BusinessError) => { 4680 console.error('Failed to get the Image Width.'); 4681 }) 4682}).catch((error: BusinessError) => { 4683 console.error('Failed to modify the Image Width'); 4684}) 4685``` 4686 4687### modifyImageProperty<sup>(deprecated)</sup> 4688 4689modifyImageProperty(key: string, value: string): Promise\<void> 4690 4691Modifies 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. 4692 4693> **NOTE** 4694> 4695> 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. 4696> 4697> This API is deprecated since API version 11. You are advised to use [modifyImageProperty](#modifyimageproperty11). 4698 4699**System capability**: SystemCapability.Multimedia.Image.ImageSource 4700 4701**Parameters** 4702 4703| Name | Type | Mandatory| Description | 4704| ------- | ------ | ---- | ------------ | 4705| key | string | Yes | Name of the property.| 4706| value | string | Yes | New value of the property. | 4707 4708**Return value** 4709 4710| Type | Description | 4711| -------------- | --------------------------- | 4712| Promise\<void> | Promise that returns no value.| 4713 4714**Example** 4715 4716```ts 4717import { BusinessError } from '@kit.BasicServicesKit'; 4718 4719imageSourceApi.modifyImageProperty("ImageWidth", "120").then(() => { 4720 imageSourceApi.getImageProperty("ImageWidth").then((width: string) => { 4721 console.info(`ImageWidth is :${width}`); 4722 }).catch((error: BusinessError) => { 4723 console.error('Failed to get the Image Width.'); 4724 }) 4725}).catch((error: BusinessError) => { 4726 console.error('Failed to modify the Image Width'); 4727}) 4728``` 4729 4730### modifyImageProperty<sup>(deprecated)</sup> 4731 4732modifyImageProperty(key: string, value: string, callback: AsyncCallback\<void>): void 4733 4734Modifies 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. 4735 4736> **NOTE** 4737> 4738> 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. 4739> 4740>This API is deprecated since API version 11. You are advised to use [modifyImageProperty](#modifyimageproperty11). 4741 4742**System capability**: SystemCapability.Multimedia.Image.ImageSource 4743 4744**Parameters** 4745 4746| Name | Type | Mandatory| Description | 4747| -------- | ------------------- | ---- | ------------------------------ | 4748| key | string | Yes | Name of the property. | 4749| value | string | Yes | New value of the property. | 4750| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 4751 4752**Example** 4753 4754```ts 4755import { BusinessError } from '@kit.BasicServicesKit'; 4756 4757imageSourceApi.modifyImageProperty("ImageWidth", "120", (err: BusinessError) => { 4758 if (err) { 4759 console.error(`Failed to modify the Image Width.code is ${err.code}, message is ${err.message}`); 4760 } else { 4761 console.info('Succeeded in modifying the Image Width.'); 4762 } 4763}) 4764``` 4765 4766### modifyImageProperties<sup>12+</sup> 4767 4768modifyImageProperties(records: Record<PropertyKey, string|null>): Promise\<void> 4769 4770Modifies 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. 4771 4772> **NOTE** 4773> 4774> 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. 4775> 4776 4777**System capability**: SystemCapability.Multimedia.Image.ImageSource 4778 4779**Parameters** 4780 4781| Name | Type | Mandatory| Description | 4782| ------- | ------ | ---- | ------------ | 4783| records | Record<[PropertyKey](#propertykey7), string \| null> | Yes | Array of property names and property values.| 4784 4785**Return value** 4786 4787| Type | Description | 4788| -------------- | --------------------------- | 4789| Promise\<void> | Promise that returns no value.| 4790 4791**Error codes** 4792 4793For details about the error codes, see [Image Error Codes](errorcode-image.md). 4794 4795| ID| Error Message| 4796| ------- | --------------------------------------------| 4797| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 4798| 62980123| The image does not support EXIF decoding. | 4799| 62980133| The EXIF data is out of range. | 4800| 62980135| The EXIF value is invalid. | 4801| 62980146| The EXIF data failed to be written to the file. | 4802 4803**Example** 4804 4805```ts 4806import { image } from '@kit.ImageKit'; 4807import { BusinessError } from '@kit.BasicServicesKit'; 4808 4809let keyValues: Record<PropertyKey, string|null> = { 4810 [image.PropertyKey.IMAGE_WIDTH] : "1024", 4811 [image.PropertyKey.IMAGE_LENGTH] : "1024" 4812}; 4813let checkKey = [image.PropertyKey.IMAGE_WIDTH, image.PropertyKey.IMAGE_LENGTH]; 4814imageSourceApi.modifyImageProperties(keyValues).then(() => { 4815 imageSourceApi.getImageProperties(checkKey).then((data) => { 4816 console.info(JSON.stringify(data)); 4817 }).catch((err: BusinessError) => { 4818 console.error(JSON.stringify(err)); 4819 }); 4820}).catch((err: BusinessError) => { 4821 console.error(JSON.stringify(err)); 4822}); 4823``` 4824 4825### updateData<sup>9+</sup> 4826 4827updateData(buf: ArrayBuffer, isFinished: boolean, offset: number, length: number): Promise\<void> 4828 4829Updates incremental data. This API uses a promise to return the result. 4830 4831**System capability**: SystemCapability.Multimedia.Image.ImageSource 4832 4833**Parameters** 4834 4835| Name | Type | Mandatory| Description | 4836| ---------- | ----------- | ---- | ------------ | 4837| buf | ArrayBuffer | Yes | Incremental data. | 4838| isFinished | boolean | Yes | Whether the update is complete.| 4839| offset | number | Yes | Offset for data reading. | 4840| length | number | Yes | Array length. | 4841 4842**Return value** 4843 4844| Type | Description | 4845| -------------- | -------------------------- | 4846| Promise\<void> | Promise that returns no value.| 4847 4848**Example** 4849 4850```ts 4851import { BusinessError } from '@kit.BasicServicesKit'; 4852 4853const array: ArrayBuffer = new ArrayBuffer(100); 4854imageSourceApi.updateData(array, false, 0, 10).then(() => { 4855 console.info('Succeeded in updating data.'); 4856}).catch((err: BusinessError) => { 4857 console.error(`Failed to update data.code is ${err.code},message is ${err.message}`); 4858}) 4859``` 4860 4861 4862### updateData<sup>9+</sup> 4863 4864updateData(buf: ArrayBuffer, isFinished: boolean, offset: number, length: number, callback: AsyncCallback\<void>): void 4865 4866Updates incremental data. This API uses an asynchronous callback to return the result. 4867 4868**System capability**: SystemCapability.Multimedia.Image.ImageSource 4869 4870**Parameters** 4871 4872| Name | Type | Mandatory| Description | 4873| ---------- | ------------------- | ---- | -------------------- | 4874| buf | ArrayBuffer | Yes | Incremental data. | 4875| isFinished | boolean | Yes | Whether the update is complete. | 4876| offset | number | Yes | Offset for data reading. | 4877| length | number | Yes | Array length. | 4878| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 4879 4880**Example** 4881 4882```ts 4883import { BusinessError } from '@kit.BasicServicesKit'; 4884 4885const array: ArrayBuffer = new ArrayBuffer(100); 4886imageSourceApi.updateData(array, false, 0, 10, (err: BusinessError) => { 4887 if (err) { 4888 console.error(`Failed to update data.code is ${err.code},message is ${err.message}`); 4889 } else { 4890 console.info('Succeeded in updating data.'); 4891 } 4892}) 4893``` 4894 4895### createPicture<sup>13+</sup> 4896 4897createPicture(options?: DecodingOptionsForPicture): Promise\<Picture> 4898 4899Creates a **Picture** object based on decoding options. This API uses a promise to return the result. 4900 4901**System capability**: SystemCapability.Multimedia.Image.ImageSource 4902 4903**Parameters** 4904 4905| Name | Type | Mandatory| Description | 4906| ------- | ------------------------------------------------------ | ---- | ---------- | 4907| options | [DecodingOptionsForPicture](#decodingoptionsforpicture13) | No | Decoding options.| 4908 4909**Return value** 4910 4911| Type | Description | 4912| ---------------------------- | -------------------------- | 4913| Promise\<[Picture](#picture13)> | Promise used to return the **Picture** object.| 4914 4915**Error codes** 4916 4917For details about the error codes, see [Image Error Codes](errorcode-image.md). 4918 4919| ID| Error Message | 4920| -------- | ------------------------------------------------------------ | 4921| 401 | Parameter error.Possible causes: 1.Mandatory parameters are left unspecified.2.Incorrect parameter types; 3.Parameter verification failed. | 4922| 7700301 | Decode failed. | 4923 4924**Example** 4925 4926```ts 4927import { image } from '@kit.ImageKit'; 4928 4929async function CreatePicture() { 4930 let options: image.DecodingOptionsForPicture = { 4931 desiredAuxiliaryPictures: [image.AuxiliaryPictureType.GAINMAP] // GAINMAP indicates the type of the auxiliary picture to be decoded. 4932 }; 4933 let pictureObj: image.Picture = await imageSourceApi.createPicture(options); 4934 if (pictureObj != null) { 4935 console.info('Create picture succeeded'); 4936 } else { 4937 console.info('Create picture failed'); 4938 } 4939} 4940``` 4941 4942### createPixelMap<sup>7+</sup> 4943 4944createPixelMap(options?: DecodingOptions): Promise\<PixelMap> 4945 4946Creates a **PixelMap** object based on decoding options. This API uses a promise to return the result. 4947 4948**Widget capability**: This API can be used in ArkTS widgets since API version 12. 4949 4950**Atomic service API**: This API can be used in atomic services since API version 11. 4951 4952**System capability**: SystemCapability.Multimedia.Image.ImageSource 4953 4954**Parameters** 4955 4956| Name | Type | Mandatory| Description | 4957| ------- | ------------------------------------ | ---- | ---------- | 4958| options | [DecodingOptions](#decodingoptions7) | No | Decoding options.| 4959 4960**Return value** 4961 4962| Type | Description | 4963| -------------------------------- | --------------------- | 4964| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.| 4965 4966**Example** 4967 4968```ts 4969import { BusinessError } from '@kit.BasicServicesKit'; 4970 4971imageSourceApi.createPixelMap().then((pixelMap: image.PixelMap) => { 4972 console.info('Succeeded in creating pixelMap object through image decoding parameters.'); 4973}).catch((error: BusinessError) => { 4974 console.error('Failed to create pixelMap object through image decoding parameters.'); 4975}) 4976``` 4977 4978### createPixelMap<sup>7+</sup> 4979 4980createPixelMap(callback: AsyncCallback\<PixelMap>): void 4981 4982Creates a **PixelMap** object based on the default parameters. This API uses an asynchronous callback to return the result. 4983 4984**Widget capability**: This API can be used in ArkTS widgets since API version 12. 4985 4986**Atomic service API**: This API can be used in atomic services since API version 11. 4987 4988**System capability**: SystemCapability.Multimedia.Image.ImageSource 4989 4990**Parameters** 4991 4992| Name | Type | Mandatory| Description | 4993| -------- | ------------------------------------- | ---- | -------------------------- | 4994| 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.| 4995 4996**Example** 4997 4998```ts 4999import { BusinessError } from '@kit.BasicServicesKit'; 5000 5001imageSourceApi.createPixelMap((err: BusinessError, pixelMap: image.PixelMap) => { 5002 if (err) { 5003 console.error(`Failed to create pixelMap.code is ${err.code},message is ${err.message}`); 5004 } else { 5005 console.info('Succeeded in creating pixelMap object.'); 5006 } 5007}) 5008``` 5009 5010### createPixelMap<sup>7+</sup> 5011 5012createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): void 5013 5014Creates a **PixelMap** object based on decoding options. This API uses an asynchronous callback to return the result. 5015 5016**Widget capability**: This API can be used in ArkTS widgets since API version 12. 5017 5018**Atomic service API**: This API can be used in atomic services since API version 11. 5019 5020**System capability**: SystemCapability.Multimedia.Image.ImageSource 5021 5022**Parameters** 5023 5024| Name | Type | Mandatory| Description | 5025| -------- | ------------------------------------- | ---- | -------------------------- | 5026| options | [DecodingOptions](#decodingoptions7) | Yes | Decoding options. | 5027| 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.| 5028 5029**Example** 5030 5031```ts 5032import { BusinessError } from '@kit.BasicServicesKit'; 5033 5034let decodingOptions: image.DecodingOptions = { 5035 sampleSize: 1, 5036 editable: true, 5037 desiredSize: { width: 1, height: 2 }, 5038 rotate: 10, 5039 desiredPixelFormat: image.PixelMapFormat.RGBA_8888, 5040 desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 }, 5041 index: 0 5042}; 5043imageSourceApi.createPixelMap(decodingOptions, (err: BusinessError, pixelMap: image.PixelMap) => { 5044 if (err) { 5045 console.error(`Failed to create pixelMap.code is ${err.code},message is ${err.message}`); 5046 } else { 5047 console.info('Succeeded in creating pixelMap object.'); 5048 } 5049}) 5050``` 5051 5052### createPixelMapSync<sup>12+</sup> 5053 5054createPixelMapSync(options?: DecodingOptions): PixelMap 5055 5056Creates a **PixelMap** object based on decoding options. This API returns the result synchronously. 5057 5058**System capability**: SystemCapability.Multimedia.Image.ImageSource 5059 5060**Parameters** 5061 5062| Name | Type | Mandatory| Description | 5063| -------- | ------------------------------------- | ---- | -------------------------- | 5064| options | [DecodingOptions](#decodingoptions7) | No | Decoding options. | 5065 5066**Return value** 5067 5068| Type | Description | 5069| -------------------------------- | --------------------- | 5070| [PixelMap](#pixelmap7) | **PixelMap** object.| 5071 5072**Example** 5073 5074```ts 5075import { image } from '@kit.ImageKit'; 5076 5077const context: Context = getContext(); 5078// '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. 5079let filePath: string = context.filesDir + "/test.jpg"; 5080let imageSource = image.createImageSource(filePath); 5081let decodingOptions: image.DecodingOptions = { 5082 sampleSize: 1, 5083 editable: true, 5084 desiredSize: { width: 1, height: 2 }, 5085 rotate: 10, 5086 desiredPixelFormat: image.PixelMapFormat.RGBA_8888, 5087 desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 }, 5088 index: 0 5089}; 5090let pixelmap = imageSource.createPixelMapSync(decodingOptions); 5091if (pixelmap != undefined) { 5092 console.info('Succeeded in creating pixelMap object.'); 5093} else { 5094 console.info('Failed to create pixelMap.'); 5095} 5096``` 5097 5098 5099### createPixelMapList<sup>10+</sup> 5100 5101createPixelMapList(options?: DecodingOptions): Promise<Array\<PixelMap>> 5102 5103Creates 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. 5104 5105> **NOTE** 5106> 5107> 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. 5108 5109**System capability**: SystemCapability.Multimedia.Image.ImageSource 5110 5111**Parameters** 5112 5113| Name | Type | Mandatory| Description | 5114| -------- | ------------------------------------- | ---- | -------------------------- | 5115| options | [DecodingOptions](#decodingoptions7) | No | Decoding options. | 5116 5117**Return value** 5118 5119| Type | Description | 5120| -------------------------------- | --------------------- | 5121| Promise<Array<[PixelMap](#pixelmap7)>> | Promise used to return an array of **PixelMap** objects.| 5122 5123**Error codes** 5124 5125For details about the error codes, see [Image Error Codes](errorcode-image.md). 5126 5127| ID| Error Message| 5128| ------- | --------------------------------------------| 5129| 62980096| The operation failed. | 5130| 62980099 | The shared memory data is abnormal. | 5131| 62980101 | The image data is abnormal. | 5132| 62980103| The image data is not supported. | 5133| 62980106 | The image is too large. | 5134| 62980109 | Failed to crop the image. | 5135| 62980110| The image source data is incorrect. | 5136| 62980111| The image source data is incomplete. | 5137| 62980112 | The image format does not match. | 5138| 62980113 | Unknown image format. | 5139| 62980115 | Invalid image parameter. | 5140| 62980116 | Failed to decode the image. | 5141| 62980118| Failed to create the image plugin. | 5142| 62980122 | Failed to decode the image header. | 5143| 62980137 | Invalid media operation. | 5144| 62980173 | The DMA memory does not exist. | 5145| 62980174 | The DMA memory data is abnormal. | 5146 5147**Example** 5148 5149```ts 5150import { BusinessError } from '@kit.BasicServicesKit'; 5151 5152let decodeOpts: image.DecodingOptions = { 5153 sampleSize: 1, 5154 editable: true, 5155 desiredSize: { width: 198, height: 202 }, 5156 rotate: 0, 5157 desiredPixelFormat: image.PixelMapFormat.RGBA_8888, 5158 index: 0, 5159}; 5160imageSourceApi.createPixelMapList(decodeOpts).then((pixelMapList: Array<image.PixelMap>) => { 5161 console.info('Succeeded in creating pixelMapList object.'); 5162}).catch((err: BusinessError) => { 5163 console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`); 5164}) 5165``` 5166 5167### createPixelMapList<sup>10+</sup> 5168 5169createPixelMapList(callback: AsyncCallback<Array\<PixelMap>>): void 5170 5171Creates 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. 5172 5173> **NOTE** 5174> 5175> 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. 5176 5177**System capability**: SystemCapability.Multimedia.Image.ImageSource 5178 5179**Parameters** 5180 5181| Name | Type | Mandatory| Description | 5182| -------- | ------------------------------------- | ---- | -------------------------- | 5183| 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. | 5184 5185**Error codes** 5186 5187For details about the error codes, see [Image Error Codes](errorcode-image.md). 5188 5189| ID| Error Message| 5190| ------- | --------------------------------------------| 5191| 62980096 | The operation failed. | 5192| 62980099 | The shared memory data is abnormal. | 5193| 62980101 | The image data is abnormal. | 5194| 62980103 | The image data is not supported. | 5195| 62980106 | The image is too large. | 5196| 62980109 | Failed to crop the image. | 5197| 62980110 | The image source data is incorrect. | 5198| 62980111 | The image source data is incomplete. | 5199| 62980112 | The image format does not match. | 5200| 62980113 | Unknown image format. | 5201| 62980115 | Invalid image parameter. | 5202| 62980116 | Failed to decode the image. | 5203| 62980118 | Failed to create the image plugin. | 5204| 62980122 | Failed to decode the image header. | 5205| 62980137 | Invalid media operation. | 5206| 62980173 | The DMA memory does not exist. | 5207| 62980174 | The DMA memory data is abnormal. | 5208 5209**Example** 5210 5211```ts 5212import { BusinessError } from '@kit.BasicServicesKit'; 5213 5214imageSourceApi.createPixelMapList((err: BusinessError, pixelMapList: Array<image.PixelMap>) => { 5215 if (err) { 5216 console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`); 5217 } else { 5218 console.info('Succeeded in creating pixelMapList object.'); 5219 } 5220}) 5221``` 5222 5223### createPixelMapList<sup>10+</sup> 5224 5225createPixelMapList(options: DecodingOptions, callback: AsyncCallback<Array\<PixelMap>>): void 5226 5227Creates 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. 5228 5229> **NOTE** 5230> 5231> 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. 5232 5233**System capability**: SystemCapability.Multimedia.Image.ImageSource 5234 5235**Parameters** 5236 5237| Name | Type | Mandatory| Description | 5238| -------- | -------------------- | ---- | ---------------------------------- | 5239| options | [DecodingOptions](#decodingoptions7) | Yes| Decoding options.| 5240| 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. | 5241 5242**Error codes** 5243 5244For details about the error codes, see [Image Error Codes](errorcode-image.md). 5245 5246| ID| Error Message| 5247| ------- | --------------------------------------------| 5248| 62980096 | The operation failed. | 5249| 62980099 | The shared memory data is abnormal. | 5250| 62980101 | The image data is abnormal. | 5251| 62980103 | The image data is not supported. | 5252| 62980106 | The image is too large. | 5253| 62980109 | Failed to crop the image. | 5254| 62980110 | The image source data is incorrect. | 5255| 62980111 | The image source data is incomplete. | 5256| 62980112 | The image format does not match. | 5257| 62980113 | Unknown image format. | 5258| 62980115 | Invalid image parameter. | 5259| 62980116 | Failed to decode the image. | 5260| 62980118 | Failed to create the image plugin. | 5261| 62980122 | Failed to decode the image header. | 5262| 62980137 | Invalid media operation. | 5263| 62980173 | The DMA memory does not exist. | 5264| 62980174 | The DMA memory data is abnormal. | 5265 5266**Example** 5267 5268```ts 5269import { BusinessError } from '@kit.BasicServicesKit'; 5270 5271let decodeOpts: image.DecodingOptions = { 5272 sampleSize: 1, 5273 editable: true, 5274 desiredSize: { width: 198, height: 202 }, 5275 rotate: 0, 5276 desiredPixelFormat: image.PixelMapFormat.RGBA_8888, 5277 index: 0, 5278}; 5279imageSourceApi.createPixelMapList(decodeOpts, (err: BusinessError, pixelMapList: Array<image.PixelMap>) => { 5280 if (err) { 5281 console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`); 5282 } else { 5283 console.info('Succeeded in creating pixelMapList object.'); 5284 } 5285}) 5286``` 5287 5288### getDelayTimeList<sup>10+</sup> 5289 5290getDelayTimeList(callback: AsyncCallback<Array\<number>>): void 5291 5292Obtains 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. 5293 5294**System capability**: SystemCapability.Multimedia.Image.ImageSource 5295 5296**Parameters** 5297 5298| Name | Type | Mandatory| Description | 5299| -------- | -------------------- | ---- | ---------------------------------- | 5300| 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.| 5301 5302**Error codes** 5303 5304For details about the error codes, see [Image Error Codes](errorcode-image.md). 5305 5306| ID| Error Message| 5307| ------- | --------------------------------------------| 5308| 62980096| The operation failed. | 5309| 62980110| The image source data is incorrect. | 5310| 62980111| The image source data is incomplete. | 5311| 62980112 | The image format does not match. | 5312| 62980113| Unknown image format. | 5313| 62980115 | Invalid image parameter. | 5314| 62980116| Failed to decode the image. | 5315| 62980118| Failed to create the image plugin. | 5316| 62980122| Failed to decode the image header. | 5317| 62980137 | Invalid media operation. | 5318| 62980149 | Invalid MIME type for the image source. | 5319 5320**Example** 5321 5322```ts 5323import { BusinessError } from '@kit.BasicServicesKit'; 5324 5325imageSourceApi.getDelayTimeList((err: BusinessError, delayTimes: Array<number>) => { 5326 if (err) { 5327 console.error(`Failed to get delayTimes object.code is ${err.code},message is ${err.message}`); 5328 } else { 5329 console.info('Succeeded in getting delayTimes object.'); 5330 } 5331}) 5332``` 5333 5334### getDelayTimeList<sup>10+</sup> 5335 5336getDelayTimeList(): Promise<Array\<number>> 5337 5338Obtains 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. 5339 5340**System capability**: SystemCapability.Multimedia.Image.ImageSource 5341 5342**Return value** 5343 5344| Type | Description | 5345| -------------- | --------------------------- | 5346| Promise<Array\<number>> | Promise used to return an array of delay times.| 5347 5348**Error codes** 5349 5350For details about the error codes, see [Image Error Codes](errorcode-image.md). 5351 5352| ID| Error Message| 5353| ------- | --------------------------------------------| 5354| 62980096 | The operation failed. | 5355| 62980110 | The image source data is incorrect. | 5356| 62980111 | The image source data is incomplete. | 5357| 62980112 | The image format does not match. | 5358| 62980113 | Unknown image format. | 5359| 62980115 | Invalid image parameter. | 5360| 62980116 | Failed to decode the image. | 5361| 62980118 | Failed to create the image plugin. | 5362| 62980122 | Failed to decode the image header. | 5363| 62980137 | Invalid media operation. | 5364| 62980149 | Invalid MIME type for the image source. | 5365 5366**Example** 5367 5368```ts 5369import { BusinessError } from '@kit.BasicServicesKit'; 5370 5371imageSourceApi.getDelayTimeList().then((delayTimes: Array<number>) => { 5372 console.info('Succeeded in getting delayTimes object.'); 5373}).catch((err: BusinessError) => { 5374 console.error(`Failed to get delayTimes object.code is ${err.code},message is ${err.message}`); 5375}) 5376``` 5377 5378### getFrameCount<sup>10+</sup> 5379 5380getFrameCount(callback: AsyncCallback\<number>): void 5381 5382Obtains the number of frames. This API uses an asynchronous callback to return the result. 5383 5384**System capability**: SystemCapability.Multimedia.Image.ImageSource 5385 5386**Parameters** 5387 5388| Name | Type | Mandatory| Description | 5389| -------- | -------------------- | ---- | ---------------------------------- | 5390| 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.| 5391 5392**Error codes** 5393 5394For details about the error codes, see [Image Error Codes](errorcode-image.md). 5395 5396| ID| Error Message| 5397| ------- | --------------------------------------------| 5398| 62980096| The operation failed. | 5399| 62980110| The image source data is incorrect. | 5400| 62980111| The image source data is incomplete. | 5401| 62980112| The image format does not match. | 5402| 62980113| Unknown image format. | 5403| 62980115| Invalid image parameter. | 5404| 62980116| Failed to decode the image. | 5405| 62980118| Failed to create the image plugin. | 5406| 62980122| Failed to decode the image header. | 5407| 62980137| Invalid media operation. | 5408 5409**Example** 5410 5411```ts 5412import { BusinessError } from '@kit.BasicServicesKit'; 5413 5414imageSourceApi.getFrameCount((err: BusinessError, frameCount: number) => { 5415 if (err) { 5416 console.error(`Failed to get frame count.code is ${err.code},message is ${err.message}`); 5417 } else { 5418 console.info('Succeeded in getting frame count.'); 5419 } 5420}) 5421``` 5422 5423### getFrameCount<sup>10+</sup> 5424 5425getFrameCount(): Promise\<number> 5426 5427Obtains the number of frames. This API uses a promise to return the result. 5428 5429**System capability**: SystemCapability.Multimedia.Image.ImageSource 5430 5431**Return value** 5432 5433| Type | Description | 5434| -------------- | --------------------------- | 5435| Promise\<number> | Promise used to return the number of frames.| 5436 5437**Error codes** 5438 5439For details about the error codes, see [Image Error Codes](errorcode-image.md). 5440 5441| ID| Error Message| 5442| ------- | --------------------------------------------| 5443| 62980096 | The operation failed. | 5444| 62980110 | The image source data is incorrect. | 5445| 62980111 | The image source data is incomplete. | 5446| 62980112 | The image format does not match. | 5447| 62980113 | Unknown image format. | 5448| 62980115 | Invalid image parameter. | 5449| 62980116 | Failed to decode the image. | 5450| 62980118 | Failed to create the image plugin. | 5451| 62980122 | Failed to decode the image header. | 5452| 62980137 | Invalid media operation. | 5453 5454**Example** 5455 5456```ts 5457import { BusinessError } from '@kit.BasicServicesKit'; 5458 5459imageSourceApi.getFrameCount().then((frameCount: number) => { 5460 console.info('Succeeded in getting frame count.'); 5461}).catch((err: BusinessError) => { 5462 console.error(`Failed to get frame count.code is ${err.code},message is ${err.message}`); 5463}) 5464``` 5465 5466### getDisposalTypeList<sup>12+</sup> 5467 5468getDisposalTypeList(): Promise\<Array\<number>> 5469 5470Obtains the list of disposal types. This API uses a promise to return the result. It is used only for GIF images. 5471 5472**System capability**: SystemCapability.Multimedia.Image.ImageSource 5473 5474**Return value** 5475 5476| Type | Description | 5477| -------------- | --------------------------- | 5478| Promise\<Array\<number>> | Promise used to return an array of disposal types.| 5479 5480**Error codes** 5481 5482For details about the error codes, see [Image Error Codes](errorcode-image.md). 5483 5484| ID| Error Message| 5485| ------- | --------------------------------------------| 5486| 62980096 | The operation failed. | 5487| 62980101 | The image data is abnormal. | 5488| 62980137 | Invalid media operation. | 5489| 62980149 | Invalid MIME type for the image source. | 5490 5491**Example** 5492 5493```ts 5494import { BusinessError } from '@kit.BasicServicesKit'; 5495imageSourceApi.getDisposalTypeList().then((disposalTypes: Array<number>) => { 5496 console.info('Succeeded in getting disposalTypes object.'); 5497}).catch((err: BusinessError) => { 5498 console.error(`Failed to get disposalTypes object.code ${err.code},message is ${err.message}`); 5499}) 5500``` 5501 5502### release 5503 5504release(callback: AsyncCallback\<void>): void 5505 5506Releases this **ImageSource** instance. This API uses an asynchronous callback to return the result. 5507 5508ArkTS 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. 5509 5510**System capability**: SystemCapability.Multimedia.Image.ImageSource 5511 5512**Parameters** 5513 5514| Name | Type | Mandatory| Description | 5515| -------- | -------------------- | ---- | ---------------------------------- | 5516| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 5517 5518**Example** 5519 5520```ts 5521import { BusinessError } from '@kit.BasicServicesKit'; 5522 5523imageSourceApi.release((err: BusinessError) => { 5524 if (err) { 5525 console.error(`Failed to release the image source instance.code ${err.code},message is ${err.message}`); 5526 } else { 5527 console.info('Succeeded in releasing the image source instance.'); 5528 } 5529}) 5530``` 5531 5532### release 5533 5534release(): Promise\<void> 5535 5536Releases this **ImageSource** instance. This API uses a promise to return the result. 5537 5538ArkTS 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. 5539 5540**System capability**: SystemCapability.Multimedia.Image.ImageSource 5541 5542**Return value** 5543 5544| Type | Description | 5545| -------------- | --------------------------- | 5546| Promise\<void> | Promise that returns no value.| 5547 5548**Example** 5549 5550```ts 5551import { BusinessError } from '@kit.BasicServicesKit'; 5552 5553imageSourceApi.release().then(() => { 5554 console.info('Succeeded in releasing the image source instance.'); 5555}).catch((error: BusinessError) => { 5556 console.error(`Failed to release the image source instance.code ${error.code},message is ${error.message}`); 5557}) 5558``` 5559 5560## image.createImagePacker 5561 5562createImagePacker(): ImagePacker 5563 5564Creates an **ImagePacker** instance. 5565 5566**Atomic service API**: This API can be used in atomic services since API version 11. 5567 5568**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5569 5570**Return value** 5571 5572| Type | Description | 5573| --------------------------- | --------------------- | 5574| [ImagePacker](#imagepacker) | **ImagePacker** instance created.| 5575 5576**Example** 5577 5578```ts 5579const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5580``` 5581 5582## ImagePacker 5583 5584Provides 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). 5585 5586### Properties 5587 5588**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5589 5590| Name | Type | Readable| Writable| Description | 5591| ---------------- | -------------- | ---- | ---- | -------------------------- | 5592| supportedFormats | Array\<string> | Yes | No | Supported formats, including .jpeg, .webp, .png, and heic<sup>12+</sup> (depending on the hardware).| 5593 5594### packToData<sup>13+</sup> 5595 5596packToData(source: ImageSource, options: PackingOption): Promise\<ArrayBuffer> 5597 5598Packs an image. This API uses a promise to return the result. 5599 5600**Atomic service API**: This API can be used in atomic services since API version 13. 5601 5602**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5603 5604**Parameters** 5605 5606| Name| Type | Mandatory| Description | 5607| ------ | ------------------------------- | ---- | -------------- | 5608| source | [ImageSource](#imagesource) | Yes | Image to pack.| 5609| options | [PackingOption](#packingoption) | Yes | Option for image packing.| 5610 5611**Error codes** 5612 5613For details about the error codes, see [Image Error Codes](errorcode-image.md). 5614 5615| ID| Error Message| 5616| ------- | --------------------------------------------| 5617| 401 | If the parameter is invalid. | 5618| 62980096| The Operation failed. | 5619| 62980101 | The image data is abnormal. | 5620| 62980106 | The image is too large. | 5621| 62980113 | Unknown image format. | 5622| 62980119 | If encoder occur error during encoding. | 5623| 62980120 | Add pixelmap out of range. | 5624| 62980172 | Failed to encode icc. | 5625| 62980252 | Failed to create surface. | 5626 5627**Return value** 5628 5629| Type | Description | 5630| ---------------------------- | --------------------------------------------- | 5631| Promise\<ArrayBuffer> | Promise used to return the packed image data.| 5632 5633**Example** 5634 5635```ts 5636import { BusinessError } from '@kit.BasicServicesKit'; 5637 5638const context: Context = getContext(); 5639// '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. 5640let filePath: string = context.filesDir + "/test.jpg"; 5641const imageSourceApi: image.ImageSource = image.createImageSource(filePath); 5642let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 5643const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5644imagePackerApi.packToData(imageSourceApi, packOpts) 5645 .then((data: ArrayBuffer) => { 5646 console.info('Succeeded in packing the image.'); 5647 }).catch((error: BusinessError) => { 5648 console.error(`Failed to pack the image.code ${error.code},message is ${error.message}`); 5649 }) 5650``` 5651 5652### packToData<sup>13+</sup> 5653 5654packToData(source: PixelMap, options: PackingOption): Promise\<ArrayBuffer> 5655 5656Packs an image. This API uses a promise to return the result. 5657 5658> **NOTE** 5659> 5660> 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. 5661 5662**Atomic service API**: This API can be used in atomic services since API version 13. 5663 5664**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5665 5666**Parameters** 5667 5668| Name| Type | Mandatory| Description | 5669| ------ | ------------------------------- | ---- | ------------------ | 5670| source | [PixelMap](#pixelmap7) | Yes | **PixelMap** object to pack.| 5671| options | [PackingOption](#packingoption) | Yes | Option for image packing. | 5672 5673**Return value** 5674 5675| Type | Description | 5676| --------------------- | -------------------------------------------- | 5677| Promise\<ArrayBuffer> | Promise used to return the packed image data.| 5678 5679**Error codes** 5680 5681For details about the error codes, see [Image Error Codes](errorcode-image.md). 5682 5683| ID| Error Message| 5684| ------- | --------------------------------------------| 5685| 401 | If the parameter is invalid. | 5686| 62980096| The Operation failed. | 5687| 62980101 | The image data is abnormal. | 5688| 62980106 | The image is too large. | 5689| 62980113 | Unknown image format. | 5690| 62980119 | If encoder occur error during encoding. | 5691| 62980120 | Add pixelmap out of range. | 5692| 62980172 | Failed to encode icc. | 5693| 62980252 | Failed to create surface. | 5694 5695**Example** 5696 5697```ts 5698import { BusinessError } from '@kit.BasicServicesKit'; 5699 5700const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 5701let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } 5702image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => { 5703 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 5704 const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5705 imagePackerApi.packToData(pixelMap, packOpts) 5706 .then((data: ArrayBuffer) => { 5707 console.info('Succeeded in packing the image.'); 5708 }).catch((error: BusinessError) => { 5709 console.error(`Failed to pack the image.code ${error.code},message is ${error.message}`); 5710 }) 5711}).catch((error: BusinessError) => { 5712 console.error(`Failed to create PixelMap.code ${error.code},message is ${error.message}`); 5713}) 5714``` 5715 5716### packing<sup>13+</sup> 5717 5718packing(picture: Picture, options: PackingOption): Promise\<ArrayBuffer> 5719 5720Packs a picture. This API uses a promise to return the result. 5721 5722**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5723 5724**Parameters** 5725 5726| Name | Type | Mandatory| Description | 5727| ---------------- | ---------------------------------------------------- | ---- | -------------------- | 5728| picture | [Picture](#picture13) | Yes | **Picture** object to pack.| 5729| options | [PackingOption](#packingoption) | Yes | Option for image packing. | 5730 5731**Return value** 5732 5733| Type | Description | 5734| --------------------- | ------------------------------------- | 5735| Promise\<ArrayBuffer> | Promise used to return the packed image data.| 5736 5737**Error codes** 5738 5739For details about the error codes, see [Image Error Codes](errorcode-image.md). 5740 5741| ID| Error Message | 5742| -------- | ------------------------------------------------------------ | 5743| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 5744| 7800301 | Encode failed. | 5745 5746**Example** 5747 5748```ts 5749import { BusinessError } from '@kit.BasicServicesKit'; 5750import { image } from '@kit.ImageKit'; 5751 5752async function Packing() { 5753 const context = getContext(); 5754 const resourceMgr = context.resourceManager; 5755 const rawFile = await resourceMgr.getRawFileContent("test.jpg"); 5756 let ops: image.SourceOptions = { 5757 sourceDensity: 98, 5758 } 5759 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 5760 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 5761 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 5762 const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5763 let funcName = "Packing"; 5764 if (imagePackerApi != null) { 5765 let opts: image.PackingOption = { 5766 format: "image/jpeg", 5767 quality: 98, 5768 bufferSize: 10, 5769 desiredDynamicRange: image.PackingDynamicRange.AUTO, 5770 needsPackProperties: true}; 5771 await imagePackerApi.packing(pictureObj, opts).then((data: ArrayBuffer) => { 5772 console.info(funcName, 'Succeeded in packing the image.'+ data); 5773 }).catch((error: BusinessError) => { 5774 console.error(funcName, 'Failed to pack the image.code ${error.code},message is ${error.message}'); 5775 }); 5776 } 5777} 5778``` 5779 5780### packing<sup>(deprecated)</sup> 5781 5782packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void 5783 5784Packs an image. This API uses an asynchronous callback to return the result. 5785 5786> **NOTE** 5787> 5788> This API is supported since API version 6 and deprecated since API version 13. Use [packToData](#packtodata13) instead. 5789 5790**Atomic service API**: This API can be used in atomic services since API version 11. 5791 5792**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5793 5794**Parameters** 5795 5796| Name | Type | Mandatory| Description | 5797| -------- | ---------------------------------- | ---- | ---------------------------------- | 5798| source | [ImageSource](#imagesource) | Yes | Image to pack. | 5799| option | [PackingOption](#packingoption) | Yes | Option for image packing. | 5800| 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. | 5801 5802**Example** 5803 5804```ts 5805import { BusinessError } from '@kit.BasicServicesKit'; 5806 5807const context: Context = getContext(); 5808// '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. 5809let filePath: string = context.filesDir + "/test.jpg"; 5810const imageSourceApi: image.ImageSource = image.createImageSource(filePath); 5811let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }; 5812const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5813imagePackerApi.packing(imageSourceApi, packOpts, (err: BusinessError, data: ArrayBuffer) => { 5814 if (err) { 5815 console.error(`Failed to pack the image.code ${err.code},message is ${err.message}`); 5816 } else { 5817 console.info('Succeeded in packing the image.'); 5818 } 5819}) 5820``` 5821 5822### packing<sup>(deprecated)</sup> 5823 5824packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer> 5825 5826Packs an image. This API uses a promise to return the result. 5827 5828> **NOTE** 5829> 5830> This API is supported since API version 6 and deprecated since API version 13. Use [packToData](#packtodata13) instead. 5831 5832**Atomic service API**: This API can be used in atomic services since API version 11. 5833 5834**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5835 5836**Parameters** 5837 5838| Name| Type | Mandatory| Description | 5839| ------ | ------------------------------- | ---- | -------------- | 5840| source | [ImageSource](#imagesource) | Yes | Image to pack.| 5841| option | [PackingOption](#packingoption) | Yes | Option for image packing.| 5842 5843**Return value** 5844 5845| Type | Description | 5846| ---------------------------- | --------------------------------------------- | 5847| Promise\<ArrayBuffer> | Promise used to return the packed image data.| 5848 5849**Example** 5850 5851```ts 5852import { BusinessError } from '@kit.BasicServicesKit'; 5853 5854const context: Context = getContext(); 5855// '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. 5856let filePath: string = context.filesDir + "/test.jpg"; 5857const imageSourceApi: image.ImageSource = image.createImageSource(filePath); 5858let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 5859const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5860imagePackerApi.packing(imageSourceApi, packOpts) 5861 .then((data: ArrayBuffer) => { 5862 console.info('Succeeded in packing the image.'); 5863 }).catch((error: BusinessError) => { 5864 console.error(`Failed to pack the image.code ${error.code},message is ${error.message}`); 5865 }) 5866``` 5867 5868### packing<sup>(deprecated)</sup> 5869 5870packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void 5871 5872Packs an image. This API uses an asynchronous callback to return the result. 5873 5874> **NOTE** 5875> 5876> This API is supported since API version 8 and deprecated since API version 13. Use [packToData](#packtodata13) instead. 5877 5878> **NOTE** 5879> 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. 5880 5881**Atomic service API**: This API can be used in atomic services since API version 11. 5882 5883**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5884 5885**Parameters** 5886 5887| Name | Type | Mandatory| Description | 5888| -------- | ------------------------------- | ---- | ---------------------------------- | 5889| source | [PixelMap](#pixelmap7) | Yes | **PixelMap** object to pack. | 5890| option | [PackingOption](#packingoption) | Yes | Option for image packing. | 5891| 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. | 5892 5893**Example** 5894 5895```ts 5896import { BusinessError } from '@kit.BasicServicesKit'; 5897 5898const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 5899let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 5900image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => { 5901 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 5902 const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5903 imagePackerApi.packing(pixelMap, packOpts, (err: BusinessError, data: ArrayBuffer) => { 5904 if (err) { 5905 console.error(`Failed to pack the image.code ${err.code},message is ${err.message}`); 5906 } else { 5907 console.info('Succeeded in packing the image.'); 5908 } 5909 }) 5910}).catch((error: BusinessError) => { 5911 console.error(`Failed to create the PixelMap.code ${error.code},message is ${error.message}`); 5912}) 5913``` 5914 5915### packing<sup>(deprecated)</sup> 5916 5917packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer> 5918 5919Packs an image. This API uses a promise to return the result. 5920 5921> **NOTE** 5922> 5923> This API is supported since API version 8 and deprecated since API version 13. Use [packToData](#packtodata13) instead. 5924> 5925> 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. 5926 5927**Atomic service API**: This API can be used in atomic services since API version 11. 5928 5929**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5930 5931**Parameters** 5932 5933| Name| Type | Mandatory| Description | 5934| ------ | ------------------------------- | ---- | ------------------ | 5935| source | [PixelMap](#pixelmap7) | Yes | **PixelMap** object to pack.| 5936| option | [PackingOption](#packingoption) | Yes | Option for image packing. | 5937 5938**Return value** 5939 5940| Type | Description | 5941| --------------------- | -------------------------------------------- | 5942| Promise\<ArrayBuffer> | Promise used to return the packed image data.| 5943 5944**Example** 5945 5946```ts 5947import { BusinessError } from '@kit.BasicServicesKit'; 5948 5949const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 5950let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 5951image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => { 5952 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 5953 const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5954 imagePackerApi.packing(pixelMap, packOpts) 5955 .then((data: ArrayBuffer) => { 5956 console.info('Succeeded in packing the image.'); 5957 }).catch((error: BusinessError) => { 5958 console.error(`Failed to pack the image.code ${error.code},message is ${error.message}`); 5959 }) 5960}).catch((error: BusinessError) => { 5961 console.error(`Failed to create PixelMap.code ${error.code},message is ${error.message}`); 5962}) 5963``` 5964 5965### release 5966 5967release(callback: AsyncCallback\<void>): void 5968 5969Releases this **ImagePacker** instance. This API uses an asynchronous callback to return the result. 5970 5971ArkTS 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. 5972 5973**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5974 5975**Parameters** 5976 5977| Name | Type | Mandatory| Description | 5978| -------- | -------------------- | ---- | ------------------------------ | 5979| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 5980 5981**Example** 5982 5983```ts 5984import { BusinessError } from '@kit.BasicServicesKit'; 5985 5986const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5987imagePackerApi.release((err: BusinessError)=>{ 5988 if (err) { 5989 console.error(`Failed to release image packaging.code ${err.code},message is ${err.message}`); 5990 } else { 5991 console.info('Succeeded in releasing image packaging.'); 5992 } 5993}) 5994``` 5995 5996### release 5997 5998release(): Promise\<void> 5999 6000Releases this **ImagePacker** instance. This API uses a promise to return the result. 6001 6002ArkTS 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. 6003 6004**System capability**: SystemCapability.Multimedia.Image.ImagePacker 6005 6006**Return value** 6007 6008| Type | Description | 6009| -------------- | ------------------------------------------------------ | 6010| Promise\<void> | Promise that returns no value.| 6011 6012**Example** 6013 6014```ts 6015import { BusinessError } from '@kit.BasicServicesKit'; 6016 6017const imagePackerApi: image.ImagePacker = image.createImagePacker(); 6018imagePackerApi.release().then(() => { 6019 console.info('Succeeded in releasing image packaging.'); 6020}).catch((error: BusinessError) => { 6021 console.error(`Failed to release image packaging.code ${error.code},message is ${error.message}`); 6022}) 6023``` 6024 6025### packToFile<sup>11+</sup> 6026 6027packToFile(source: ImageSource, fd: number, options: PackingOption, callback: AsyncCallback\<void>): void 6028 6029Encodes an **ImageSource** object and packs it into a file. This API uses an asynchronous callback to return the result. 6030 6031**System capability**: SystemCapability.Multimedia.Image.ImagePacker 6032 6033**Parameters** 6034 6035| Name | Type | Mandatory| Description | 6036| -------- | ------------------------------- | ---- | ------------------------------ | 6037| source | [ImageSource](#imagesource) | Yes | Image to pack. | 6038| fd | number | Yes | File descriptor. | 6039| options | [PackingOption](#packingoption) | Yes | Option for image packing. | 6040| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 6041 6042**Error codes** 6043 6044For details about the error codes, see [Image Error Codes](errorcode-image.md). 6045 6046| ID| Error Message| 6047| ------- | --------------------------------------------| 6048| 62980096| The Operation failed. | 6049| 62980101 | The image data is abnormal. | 6050| 62980106 | The image is too large. | 6051| 62980113 | Unknown image format. | 6052| 62980115 | If the parameter is invalid. | 6053| 62980119 | If encoder occur error during encoding. | 6054| 62980120 | Add pixelmap out of range. | 6055| 62980172 | Failed to encode icc. | 6056| 62980252 | Failed to create surface. | 6057 6058**Example** 6059 6060```ts 6061import { BusinessError } from '@kit.BasicServicesKit'; 6062import { fileIo as fs } from '@kit.CoreFileKit'; 6063 6064const context: Context = getContext(this); 6065// '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. 6066const path: string = context.filesDir + "/test.png"; 6067const imageSourceApi: image.ImageSource = image.createImageSource(path); 6068let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }; 6069const filePath: string = context.filesDir + "/image_source.jpg"; 6070let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 6071const imagePackerApi: image.ImagePacker = image.createImagePacker(); 6072imagePackerApi.packToFile(imageSourceApi, file.fd, packOpts, (err: BusinessError) => { 6073 if (err) { 6074 console.error(`Failed to pack the image to file.code ${err.code},message is ${err.message}`); 6075 } else { 6076 console.info('Succeeded in packing the image to file.'); 6077 } 6078}) 6079``` 6080 6081### packToFile<sup>11+</sup> 6082 6083packToFile (source: ImageSource, fd: number, options: PackingOption): Promise\<void> 6084 6085Encodes an **ImageSource** object and packs it into a file. This API uses a promise to return the result. 6086 6087**System capability**: SystemCapability.Multimedia.Image.ImagePacker 6088 6089**Parameters** 6090 6091| Name| Type | Mandatory| Description | 6092| ------ | ------------------------------- | ---- | -------------- | 6093| source | [ImageSource](#imagesource) | Yes | Image to pack.| 6094| fd | number | Yes | File descriptor. | 6095| options | [PackingOption](#packingoption) | Yes | Option for image packing.| 6096 6097**Return value** 6098 6099| Type | Description | 6100| -------------- | --------------------------------- | 6101| Promise\<void> | Promise that returns no value.| 6102 6103**Error codes** 6104 6105For details about the error codes, see [Image Error Codes](errorcode-image.md). 6106 6107| ID| Error Message| 6108| ------- | --------------------------------------------| 6109| 62980096| The Operation failed. | 6110| 62980101 | The image data is abnormal. | 6111| 62980106 | The image is too large. | 6112| 62980113 | Unknown image format. | 6113| 62980115 | If the parameter is invalid. | 6114| 62980119 | If encoder occur error during encoding. | 6115| 62980120 | Add pixelmap out of range. | 6116| 62980172 | Failed to encode icc. | 6117| 62980252 | Failed to create surface. | 6118 6119**Example** 6120 6121```ts 6122import { BusinessError } from '@kit.BasicServicesKit'; 6123import { fileIo as fs } from '@kit.CoreFileKit'; 6124 6125const context: Context = getContext(this); 6126// '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. 6127const path: string = context.filesDir + "/test.png"; 6128const imageSourceApi: image.ImageSource = image.createImageSource(path); 6129let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }; 6130const filePath: string = context.filesDir + "/image_source.jpg"; 6131let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 6132const imagePackerApi: image.ImagePacker = image.createImagePacker(); 6133imagePackerApi.packToFile(imageSourceApi, file.fd, packOpts).then(() => { 6134 console.info('Succeeded in packing the image to file.'); 6135}).catch((error: BusinessError) => { 6136 console.error(`Failed to pack the image to file.code ${error.code},message is ${error.message}`); 6137}) 6138``` 6139 6140### packToFile<sup>11+</sup> 6141 6142packToFile (source: PixelMap, fd: number, options: PackingOption, callback: AsyncCallback\<void>): void; 6143 6144Encodes a **PixelMap** object and packs it into a file. This API uses an asynchronous callback to return the result. 6145 6146> **NOTE** 6147> 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. 6148 6149**System capability**: SystemCapability.Multimedia.Image.ImagePacker 6150 6151**Parameters** 6152 6153| Name | Type | Mandatory| Description | 6154| -------- | ------------------------------- | ---- | ------------------------------ | 6155| source | [PixelMap](#pixelmap7) | Yes | **PixelMap** object to pack. | 6156| fd | number | Yes | File descriptor. | 6157| options | [PackingOption](#packingoption) | Yes | Option for image packing. | 6158| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 6159 6160**Error codes** 6161 6162For details about the error codes, see [Image Error Codes](errorcode-image.md). 6163 6164| ID| Error Message| 6165| ------- | --------------------------------------------| 6166| 62980096| The Operation failed. | 6167| 62980101 | The image data is abnormal. | 6168| 62980106 | The image is too large. | 6169| 62980113 | Unknown image format. | 6170| 62980115 | If the parameter is invalid. | 6171| 62980119 | If encoder occur error during encoding. | 6172| 62980120 | Add pixelmap out of range. | 6173| 62980172 | Failed to encode icc. | 6174| 62980252 | Failed to create surface. | 6175 6176**Example** 6177 6178```ts 6179import { BusinessError } from '@kit.BasicServicesKit'; 6180import { fileIo as fs } from '@kit.CoreFileKit'; 6181 6182const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 6183let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 6184const context: Context = getContext(this); 6185const path: string = context.filesDir + "/pixel_map.jpg"; 6186image.createPixelMap(color, opts).then((pixelmap: image.PixelMap) => { 6187 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 6188 let file = fs.openSync(path, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 6189 const imagePackerApi: image.ImagePacker = image.createImagePacker(); 6190 imagePackerApi.packToFile(pixelmap, file.fd, packOpts, (err: BusinessError) => { 6191 if (err) { 6192 console.error(`Failed to pack the image to file.code ${err.code},message is ${err.message}`); 6193 } else { 6194 console.info('Succeeded in packing the image to file.'); 6195 } 6196 }) 6197}) 6198``` 6199 6200### packToFile<sup>11+</sup> 6201 6202packToFile (source: PixelMap, fd: number, options: PackingOption): Promise\<void> 6203 6204Encodes a **PixelMap** object and packs it into a file. This API uses a promise to return the result. 6205 6206> **NOTE** 6207> 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. 6208 6209**System capability**: SystemCapability.Multimedia.Image.ImagePacker 6210 6211**Parameters** 6212 6213| Name| Type | Mandatory| Description | 6214| ------ | ------------------------------- | ---- | -------------------- | 6215| source | [PixelMap](#pixelmap7) | Yes | **PixelMap** object to pack.| 6216| fd | number | Yes | File descriptor. | 6217| options | [PackingOption](#packingoption) | Yes | Option for image packing. | 6218 6219**Return value** 6220 6221| Type | Description | 6222| -------------- | --------------------------------- | 6223| Promise\<void> | Promise that returns no value.| 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 color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 6248let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 6249const context: Context = getContext(this); 6250const path: string = context.filesDir + "/pixel_map.jpg"; 6251image.createPixelMap(color, opts).then((pixelmap: image.PixelMap) => { 6252 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 6253 let file = fs.openSync(path, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 6254 const imagePackerApi: image.ImagePacker = image.createImagePacker(); 6255 imagePackerApi.packToFile(pixelmap, file.fd, packOpts) 6256 .then(() => { 6257 console.info('Succeeded in packing the image to file.'); 6258 }).catch((error: BusinessError) => { 6259 console.error(`Failed to pack the image to file.code ${error.code},message is ${error.message}`); 6260 }) 6261}) 6262``` 6263 6264### packToFile<sup>13+</sup> 6265 6266packToFile(picture: Picture, fd: number, options: PackingOption): Promise\<void> 6267 6268Encodes a **Picture** 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| picture | [Picture](#picture13) | Yes | **Picture** object 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> | 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| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6293| 7800301 | Encode failed. | 6294 6295**Example** 6296 6297```ts 6298import { BusinessError } from '@kit.BasicServicesKit'; 6299import { image } from '@kit.ImageKit'; 6300import { fileIo as fs } from '@kit.CoreFileKit'; 6301 6302async function PackToFile() { 6303 const context = getContext(); 6304 const resourceMgr = context.resourceManager; 6305 const rawFile = await resourceMgr.getRawFileContent("test.jpg"); 6306 let ops: image.SourceOptions = { 6307 sourceDensity: 98, 6308 } 6309 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6310 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6311 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6312 6313 let funcName = "PackToFile"; 6314 const imagePackerApi: image.ImagePacker = image.createImagePacker(); 6315 if (imagePackerApi != null) { 6316 const context: Context = getContext(); 6317 const filePath: string = context.filesDir + "/test.jpg"; 6318 let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 6319 let packOpts: image.PackingOption = { 6320 format: "image/jpeg", 6321 quality: 98, 6322 bufferSize: 10, 6323 desiredDynamicRange: image.PackingDynamicRange.AUTO, 6324 needsPackProperties: true}; 6325 await imagePackerApi.packToFile(pictureObj, file.fd, packOpts).then(() => { 6326 console.info(funcName, 'Succeeded in packing the image to file.'); 6327 }).catch((error: BusinessError) => { 6328 console.error(funcName, 'Failed to pack the image to file.code ${error.code},message is ${error.message}'); 6329 }); 6330 } 6331} 6332``` 6333 6334## image.createAuxiliaryPicture<sup>13+</sup> 6335 6336createAuxiliaryPicture(buffer: ArrayBuffer, size: Size, type: AuxiliaryPictureType): AuxiliaryPicture 6337 6338Creates an **AuxiliaryPicture** instance based on the ArrayBuffer image data, auxiliary picture size, and auxiliary picture type. 6339 6340**System capability**: SystemCapability.Multimedia.Image.Core 6341 6342**Parameters** 6343 6344| Name| Type | Mandatory| Description | 6345| ------ | ----------------------------------------------- | ---- | ---------------------------- | 6346| buffer | ArrayBuffer | Yes | Image data stored in the buffer.| 6347| size | [Size](#size) | Yes | Size of the auxiliary picture. | 6348| type | [AuxiliaryPictureType](#auxiliarypicturetype13) | Yes | Type of the auxiliary picture. | 6349 6350**Return value** 6351 6352| Type | Description | 6353| --------------------------------------- | ------------------------------------------ | 6354| [AuxiliaryPicture](#auxiliarypicture13) | **AuxiliaryPicture** instance if the operation is successful.| 6355 6356**Error codes** 6357 6358For details about the error codes, see [Image Error Codes](errorcode-image.md). 6359 6360| ID| Error Message | 6361| -------- | ------------------------------------------------------------ | 6362| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6363 6364**Example** 6365 6366```ts 6367import { image } from '@kit.ImageKit'; 6368 6369async function CreateAuxiliaryPicture() { 6370 let funcName = "CreateAuxiliaryPicture"; 6371 const context = getContext(); 6372 const resourceMgr = context.resourceManager; 6373 const rawFile = await resourceMgr.getRawFileContent("hdr.jpg"); // Support for HDR images is required. 6374 let auxBuffer: ArrayBuffer = rawFile.buffer as ArrayBuffer; 6375 let auxSize: Size = { 6376 height: 180, 6377 width: 240 6378 }; 6379 let auxType: image.AuxiliaryPictureType = image.AuxiliaryPictureType.GAINMAP; 6380 let auxPictureObj: image.AuxiliaryPicture | null = image.createAuxiliaryPicture(auxBuffer, auxSize, auxType); 6381 if(auxPictureObj != null) { 6382 let type: image.AuxiliaryPictureType = auxPictureObj.getType(); 6383 console.info(funcName, 'CreateAuxiliaryPicture succeeded this.Aux_picture.type.' + JSON.stringify(type)); 6384 } else { 6385 console.error(funcName, 'CreateAuxiliaryPicture failed'); 6386 } 6387} 6388``` 6389 6390## AuxiliaryPicture<sup>13+</sup> 6391 6392The 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. 6393 6394### Properties 6395 6396**System capability**: SystemCapability.Multimedia.Image.Core 6397 6398### writePixelsFromBuffer<sup>13+</sup> 6399 6400writePixelsFromBuffer(data: ArrayBuffer): Promise\<void> 6401 6402Reads pixels from an ArrayBuffer and writes the data to this **AuxiliaryPicture** object. This API uses a promise to return the result. 6403 6404**System capability**: SystemCapability.Multimedia.Image.Core 6405 6406**Parameters** 6407 6408| Name| Type | Mandatory| Description | 6409| ------ | ----------- | ---- | ---------------- | 6410| data | ArrayBuffer | Yes | Pixels of the auxiliary picture.| 6411 6412**Return value** 6413 6414| Type | Description | 6415| -------------- | -------------------------------------- | 6416| Promise\<void> | Promise that returns no value.| 6417 6418**Error codes** 6419 6420For details about the error codes, see [Image Error Codes](errorcode-image.md). 6421 6422| ID| Error Message | 6423| -------- | ------------------------------------------------------------ | 6424| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6425| 7600301 | Memory alloc failed. | 6426| 7600302 | Memory copy failed. | 6427 6428**Example** 6429 6430```ts 6431import { image } from '@kit.ImageKit'; 6432 6433async function WritePixelsFromBuffer() { 6434 const context = getContext(); 6435 const resourceMgr = context.resourceManager; 6436 const rawFile = await resourceMgr.getRawFileContent("hdr.jpg"); // Support for HDR images is required. 6437 let ops: image.SourceOptions = { 6438 sourceDensity: 98, 6439 } 6440 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6441 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6442 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6443 let auxPictureObj: image.AuxiliaryPicture | null = pictureObj.getAuxiliaryPicture(image.AuxiliaryPictureType.GAINMAP); 6444 if(auxPictureObj != null) { 6445 let auxBuffer: ArrayBuffer = await auxPictureObj.readPixelsToBuffer(); 6446 await auxPictureObj.writePixelsFromBuffer(auxBuffer); 6447 console.info('Write pixels from buffer success.'); 6448 } else { 6449 console.error('AuxPictureObj is null.'); 6450 } 6451} 6452``` 6453 6454### readPixelsToBuffer<sup>13+</sup> 6455 6456readPixelsToBuffer(): Promise\<ArrayBuffer> 6457 6458Reads pixels of this auxiliary picture and writes the data to an ArrayBuffer. This API uses a promise to return the result. 6459 6460**System capability**: SystemCapability.Multimedia.Image.Core 6461 6462**Return value** 6463 6464| Type | Description | 6465| --------------------- | --------------------------------- | 6466| Promise\<ArrayBuffer> | Promise used to return the pixels of the auxiliary picture.| 6467 6468**Error codes** 6469 6470For details about the error codes, see [Image Error Codes](errorcode-image.md). 6471 6472| ID| Error Message | 6473| -------- | -------------------- | 6474| 7600301 | Memory alloc failed. | 6475| 7600302 | Memory copy failed. | 6476 6477**Example** 6478 6479```ts 6480import { BusinessError } from '@kit.BasicServicesKit'; 6481import { image } from '@kit.ImageKit'; 6482 6483async function ReadPixelsToBuffer() { 6484 const context = getContext(); 6485 const resourceMgr = context.resourceManager; 6486 const rawFile = await resourceMgr.getRawFileContent("hdr.jpg"); // Support for HDR images is required. 6487 let ops: image.SourceOptions = { 6488 sourceDensity: 98, 6489 } 6490 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6491 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6492 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6493 let auxPictureObj: image.AuxiliaryPicture | null = pictureObj.getAuxiliaryPicture(image.AuxiliaryPictureType.GAINMAP); 6494 if(auxPictureObj != null) { 6495 await auxPictureObj.readPixelsToBuffer().then((pixelsBuffer: ArrayBuffer) => { 6496 console.info('Read pixels to buffer success.' ); 6497 }).catch((error: BusinessError) => { 6498 console.error('Read pixels to buffer failed error.code: ' + JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message)); 6499 }); 6500 } else { 6501 console.error('AuxPictureObj is null.'); 6502 } 6503} 6504``` 6505 6506### getType<sup>13+</sup> 6507 6508getType(): AuxiliaryPictureType 6509 6510Obtains the type of this auxiliary picture. 6511 6512**System capability**: SystemCapability.Multimedia.Image.Core 6513 6514**Return value** 6515 6516| Type | Description | 6517| ----------------------------------------------- | ---------------------------- | 6518| [AuxiliaryPictureType](#auxiliarypicturetype13) | Type of the auxiliary picture.| 6519 6520**Example** 6521 6522```ts 6523import { image } from '@kit.ImageKit'; 6524 6525async function GetAuxiliaryPictureType() { 6526 if (auxPictureObj != null) { 6527 let type: image.AuxiliaryPictureType = auxPictureObj.getType(); 6528 console.info('Success get auxiliary picture type ' + JSON.stringify(type)); 6529 } else { 6530 console.info('Failed get auxiliary picture type '); 6531 } 6532} 6533``` 6534 6535### setMetadata<sup>13+</sup> 6536 6537setMetadata(metadataType: MetadataType, metadata: Metadata): Promise\<void> 6538 6539Sets the metadata for this auxiliary picture. 6540 6541**System capability**: SystemCapability.Multimedia.Image.Core 6542 6543**Parameters** 6544 6545| Name | Type | Mandatory| Description | 6546| ------------ | ------------------------------- | ---- | ------------------------------------ | 6547| metadataType | [MetadataType](#metadatatype13) | Yes | Metadata type, which is used to set the corresponding metadata.| 6548| metadata | [Metadata](#metadata13) | Yes | **Metadata** object. | 6549 6550**Return value** 6551 6552| Type | Description | 6553| -------------- | -------------------------------------- | 6554| Promise\<void> | Promise that returns no value.| 6555 6556**Error codes** 6557 6558For details about the error codes, see [Image Error Codes](errorcode-image.md). 6559 6560| ID| Error Message | 6561| -------- | ------------------------------------------------------------ | 6562| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6563| 7600202 | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. | 6564 6565**Example** 6566 6567```ts 6568import { BusinessError } from '@kit.BasicServicesKit'; 6569import { image } from '@kit.ImageKit'; 6570 6571async function SetAuxPictureObjMetadata() { 6572 const exifContext = getContext(); 6573 const exifResourceMgr = exifContext.resourceManager; 6574 const exifRawFile = await exifResourceMgr.getRawFileContent("exif.jpg");// The image contains EXIF metadata. 6575 let exifOps: image.SourceOptions = { 6576 sourceDensity: 98, 6577 } 6578 let exifImageSource: image.ImageSource = image.createImageSource(exifRawFile.buffer as ArrayBuffer, exifOps); 6579 let exifCommodityPixelMap: image.PixelMap = await exifImageSource.createPixelMap(); 6580 let exifPictureObj: image.Picture = image.createPicture(exifCommodityPixelMap); 6581 if (exifPictureObj != null) { 6582 console.info('Create picture succeeded'); 6583 } else { 6584 console.info('Create picture failed'); 6585 } 6586 6587 if (auxPictureObj != null) { 6588 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 6589 let exifMetaData: image.Metadata = await exifPictureObj.getMetadata(metadataType); 6590 auxPictureObj.setMetadata(metadataType, exifMetaData).then(() => { 6591 console.info('Set metadata success'); 6592 }).catch((error: BusinessError) => { 6593 console.error('Set metadata failed.error.code: ${error.code}, error.message: ${error.message}'); 6594 }); 6595 } else { 6596 console.info('AuxPictureObjMetaData is null'); 6597 } 6598} 6599``` 6600 6601### getMetadata<sup>13+</sup> 6602 6603getMetadata(metadataType: MetadataType): Promise\<Metadata> 6604 6605Obtains the metadata of this auxiliary picture. 6606 6607**System capability**: SystemCapability.Multimedia.Image.Core 6608 6609**Parameters** 6610 6611| Name | Type | Mandatory| Description | 6612| ------------ | ------------------------------- | ---- | -------------------------------------- | 6613| metadataType | [MetadataType](#metadatatype13) | Yes | Metadata type, which is used to obtain metadata of the corresponding type.| 6614 6615**Return value** 6616 6617| Type | Description | 6618| -------------------------------- | ---------------- | 6619| Promise<[Metadata](#metadata13)> | Metadata object.| 6620 6621**Error codes** 6622 6623For details about the error codes, see [Image Error Codes](errorcode-image.md). 6624 6625| ID| Error Message | 6626| -------- | ------------------------------------------------------------ | 6627| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6628| 7600202 | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. | 6629 6630**Example** 6631 6632```ts 6633import { image } from '@kit.ImageKit'; 6634 6635async function GetAuxPictureObjMetadata() { 6636 if (auxPictureObj != null) { 6637 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 6638 let auxPictureObjMetaData: image.Metadata | null = await auxPictureObj.getMetadata(metadataType); 6639 if (auxPictureObjMetaData != null) { 6640 console.info('Get auxpictureobj Metadata success' ); 6641 } else { 6642 console.info('Get auxpictureobj Metadata failed'); 6643 } 6644 } else { 6645 console.info('Get auxpictureobj is null.'); 6646 } 6647} 6648``` 6649 6650### getAuxiliaryPictureinfo<sup>13+</sup> 6651 6652getAuxiliaryPictureInfo(): AuxiliaryPictureInfo 6653 6654Obtains the auxiliary picture information. 6655 6656**System capability**: SystemCapability.Multimedia.Image.Core 6657 6658**Return value** 6659 6660| Type | Description | 6661| ----------------------------------------------- | --------------------------------- | 6662| [AuxiliaryPictureInfo](#auxiliarypictureinfo13) | Promise used to return the auxiliary picture information.| 6663 6664**Example** 6665 6666```ts 6667import { image } from '@kit.ImageKit'; 6668 6669async function GetAuxiliaryPictureInfo() { 6670 if(auxPictureObj != null) { 6671 let auxinfo: image.AuxiliaryPictureInfo = auxPictureObj.getAuxiliaryPictureInfo(); 6672 console.info('GetAuxiliaryPictureInfo Type: ' + auxinfo.auxiliaryPictureType + 6673 ' height: ' + auxinfo.size.height + ' width: ' + auxinfo.size.width + 6674 ' rowStride: ' + auxinfo.rowStride + ' pixelFormat: ' + auxinfo.pixelFormat + 6675 ' colorSpace: ' + auxinfo.colorSpace); 6676 } else { 6677 console.info('Get auxiliary picture information failed'); 6678 } 6679} 6680``` 6681 6682### setAuxiliaryPictureinfo<sup>13+</sup> 6683 6684setAuxiliaryPictureInfo(info: AuxiliaryPictureInfo): void 6685 6686Sets the auxiliary picture information. 6687 6688**System capability**: SystemCapability.Multimedia.Image.Core 6689 6690**Parameters** 6691 6692| Name| Type | Mandatory| Description | 6693| ------ | ----------------------------------------------- | ---- | ------------------ | 6694| info | [AuxiliaryPictureInfo](#auxiliarypictureinfo13) | Yes | Auxiliary picture information.| 6695 6696**Error codes** 6697 6698For details about the error codes, see [Image Error Codes](errorcode-image.md). 6699 6700| ID| Error Message | 6701| -------- | :----------------------------------------------------------- | 6702| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6703 6704**Example** 6705 6706```ts 6707import { colorSpaceManager } from '@kit.ArkGraphics2D'; 6708import { image } from '@kit.ImageKit'; 6709 6710async function SetAuxiliaryPictureInfo() { 6711 if(auxPictureObj != null) { 6712 let colorSpaceName = colorSpaceManager.ColorSpace.SRGB; 6713 let info: image.AuxiliaryPictureInfo = { 6714 auxiliaryPictureType: image.AuxiliaryPictureType.GAINMAP, 6715 size: {height: 100, width: 200}, 6716 pixelFormat: image.PixelMapFormat.RGBA_8888, 6717 rowStride: 0, 6718 colorSpace: colorSpaceManager.create(colorSpaceName), 6719 }; 6720 auxPictureObj.setAuxiliaryPictureInfo(info); 6721 } 6722} 6723``` 6724 6725### release<sup>13+</sup> 6726 6727release():void 6728 6729Releases this AuxiliaryPicture object. No value is returned. 6730 6731**System capability**: SystemCapability.Multimedia.Image.Core 6732 6733**Example** 6734 6735```ts 6736import { image } from '@kit.ImageKit'; 6737 6738async function Release() { 6739 let funcName = "Release"; 6740 if (auxPictureObj != null) { 6741 auxPictureObj.release(); 6742 if (auxPictureObj.getType() == null) { 6743 console.info(funcName, 'Success !'); 6744 } else { 6745 console.info(funcName, 'Failed !'); 6746 } 6747 } else { 6748 console.info('PictureObj is null'); 6749 } 6750} 6751``` 6752 6753## Metadata<sup>13+</sup> 6754 6755A class used to store image metadata. For details about the supported metadata types, see [MetadataType](#metadatatype13). 6756 6757### Properties 6758 6759**System capability**: SystemCapability.Multimedia.Image.Core 6760 6761### getProperties<sup>13+</sup> 6762 6763getProperties(key: Array\<string>): Promise\<Record\<string, string | null>> 6764 6765Obtains 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). 6766 6767**System capability**: SystemCapability.Multimedia.Image.Core 6768 6769**Parameters** 6770 6771| Name| Type | Mandatory| Description | 6772| ------ | -------------- | ---- | ------------------------ | 6773| key | Array\<string> | Yes | Names of the properties.| 6774 6775**Return value** 6776 6777| Type | Description | 6778| ---------------------------------------- | ------------------------------------------------------------ | 6779| Promise\<Record<string, string \| null>> | Promise used to return the property values. If the retrieval operation fails, an error code is returned.| 6780 6781**Error codes** 6782 6783For details about the error codes, see [Image Error Codes](errorcode-image.md). 6784 6785| ID| Error Message | 6786| -------- | ------------------------------------------------------------ | 6787| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 6788| 7600202 | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. | 6789 6790**Example** 6791 6792```ts 6793import { BusinessError } from '@kit.BasicServicesKit'; 6794import { image } from '@kit.ImageKit'; 6795 6796async function GetProperties() { 6797 const context = getContext(); 6798 const resourceMgr = context.resourceManager; 6799 const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); // The image contains EXIF metadata. 6800 let ops: image.SourceOptions = { 6801 sourceDensity: 98, 6802 } 6803 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6804 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6805 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6806 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 6807 let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType); 6808 if (metaData != null) { 6809 await metaData.getProperties(["ImageWidth", "ImageLength"]).then((data2) => { 6810 console.info('Get properties ',JSON.stringify(data2)); 6811 }).catch((error: BusinessError) => { 6812 console.info('Get properties failed error.code: ' +JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message)); 6813 }); 6814 } else { 6815 console.info('Metadata is null.'); 6816 } 6817} 6818``` 6819 6820### setProperties<sup>13+</sup> 6821 6822setProperties(records: Record\<string, string | null>): Promise\<void> 6823 6824Sets 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). 6825 6826**System capability**: SystemCapability.Multimedia.Image.Core 6827 6828**Parameters** 6829 6830| Name | Type | Mandatory| Description | 6831| ------- | ------------------------------ | ---- | ------------------------ | 6832| records | Record<string, string \| null> | Yes | Array of properties and their values.| 6833 6834**Return value** 6835 6836| Type | Description | 6837| -------------- | ------------------------------------- | 6838| Promise\<void> | Promise that returns no value. If the operation fails, an error code is returned.| 6839 6840**Error codes** 6841 6842For details about the error codes, see [Image Error Codes](errorcode-image.md). 6843 6844| ID| Error Message | 6845| -------- | ------------------------------------------------------------ | 6846| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 6847| 7600202 | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. | 6848 6849**Example** 6850 6851```ts 6852import { BusinessError } from '@kit.BasicServicesKit'; 6853import { image } from '@kit.ImageKit'; 6854 6855async function SetProperties() { 6856 const context = getContext(); 6857 const resourceMgr = context.resourceManager; 6858 const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); // The image contains EXIF metadata. 6859 let ops: image.SourceOptions = { 6860 sourceDensity: 98, 6861 } 6862 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6863 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6864 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6865 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 6866 let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType); 6867 if (metaData != null) { 6868 let setkey: Record<string, string | null> = { 6869 "ImageWidth": "200", 6870 "ImageLength": "300" 6871 }; 6872 await metaData.setProperties(setkey).then(async () => { 6873 console.info('Set auxpictureobj properties success.'); 6874 }).catch((error: BusinessError) => { 6875 console.error('Failed to set metadata Properties. code is ${error.code}, message is ${error.message}'); 6876 }) 6877 } else { 6878 console.info('AuxPictureObj metadata is null. '); 6879 } 6880} 6881``` 6882 6883### getAllProperties<sup>13+</sup> 6884 6885getAllProperties(): Promise\<Record<string, string | null>> 6886 6887Obtains 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). 6888 6889**System capability**: SystemCapability.Multimedia.Image.Core 6890 6891**Return value** 6892 6893| Type | Description | 6894| ---------------------------------------- | ------------------------------------------- | 6895| Promise\<Record<string, string \| null>> | Promise used to return the values of all properties.| 6896 6897**Example** 6898 6899```ts 6900import { BusinessError } from '@kit.BasicServicesKit'; 6901import { image } from '@kit.ImageKit'; 6902 6903async function GetAllProperties() { 6904 const context = getContext(); 6905 const resourceMgr = context.resourceManager; 6906 const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); // The image contains EXIF metadata. 6907 let ops: image.SourceOptions = { 6908 sourceDensity: 98, 6909 } 6910 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6911 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6912 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6913 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 6914 let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType); 6915 if (metaData != null) { 6916 await metaData.getAllProperties().then((data2) => { 6917 const count = Object.keys(data2).length; 6918 console.info('Metadata have ', count, ' properties'); 6919 console.info('Get metadata all properties: ', JSON.stringify(data2)); 6920 }).catch((error: BusinessError) => { 6921 console.error('Get metadata all properties failed error.code: ' +JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message)); 6922 }); 6923 } else { 6924 console.info('Metadata is null.'); 6925 } 6926} 6927``` 6928 6929### clone<sup>13+</sup> 6930 6931clone(): Promise\<Metadata> 6932 6933Clones the metadata. This API uses a promise to return the result. 6934 6935**System capability**: SystemCapability.Multimedia.Image.Core 6936 6937**Return value** 6938 6939| Type | Description | 6940| --------------------------------- | --------------------------------- | 6941| Promise\<[Metadata](#metadata13)> | Promise used to return the metadata instance.| 6942 6943**Error codes** 6944 6945For details about the error codes, see [Image Error Codes](errorcode-image.md). 6946 6947| ID| Error Message | 6948| -------- | -------------------- | 6949| 7600301 | Memory alloc failed. | 6950| 7600302 | Memory copy failed. | 6951 6952**Example** 6953 6954```ts 6955import { BusinessError } from '@kit.BasicServicesKit'; 6956import { image } from '@kit.ImageKit'; 6957 6958async function clone() { 6959 const context = getContext(); 6960 const resourceMgr = context.resourceManager; 6961 const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); // The image contains EXIF metadata. 6962 let ops: image.SourceOptions = { 6963 sourceDensity: 98, 6964 } 6965 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6966 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6967 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6968 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 6969 let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType); 6970 if (metaData != null) { 6971 let new_metadata: image.Metadata = await metaData.clone(); 6972 new_metadata.getProperties(["ImageWidth"]).then((data1) => { 6973 console.info('Clone new_metadata and get Properties.', JSON.stringify(data1)); 6974 }).catch((err: BusinessError) => { 6975 console.error('Clone new_metadata failed.', JSON.stringify(err)); 6976 }); 6977 } else { 6978 console.info('Metadata is null.'); 6979 } 6980} 6981``` 6982 6983## image.createImageReceiver<sup>11+</sup> 6984 6985createImageReceiver(size: Size, format: ImageFormat, capacity: number): ImageReceiver 6986 6987Creates an **ImageReceiver** instance by specifying the image size, format, and capacity. 6988 6989**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 6990 6991**Parameters** 6992 6993| Name | Type | Mandatory| Description | 6994| -------- | ------ | ---- | ---------------------- | 6995| size | [Size](#size) | Yes | Default size of the image. | 6996| 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.) | 6997| capacity | number | Yes | Maximum number of images that can be accessed at the same time.| 6998 6999**Return value** 7000 7001| Type | Description | 7002| -------------------------------- | --------------------------------------- | 7003| [ImageReceiver](#imagereceiver9) | Returns an **ImageReceiver** instance if the operation is successful.| 7004 7005**Error codes** 7006 7007For details about the error codes, see [Image Error Codes](errorcode-image.md). 7008 7009| ID| Error Message| 7010| ------- | --------------------------------------------| 7011| 401| Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; | 7012 7013**Example** 7014 7015```ts 7016let size: image.Size = { 7017 height: 8192, 7018 width: 8 7019} 7020let receiver: image.ImageReceiver = image.createImageReceiver(size, image.ImageFormat.JPEG, 8); 7021``` 7022 7023## image.createImageReceiver<sup>(deprecated)</sup> 7024 7025createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver 7026 7027Creates an **ImageReceiver** instance by specifying the image width, height, format, and capacity. 7028 7029> **NOTE** 7030> 7031> This API is deprecated since API version 11. You are advised to use [createImageReceiver](#imagecreateimagereceiver11). 7032 7033**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7034 7035**Parameters** 7036 7037| Name | Type | Mandatory| Description | 7038| -------- | ------ | ---- | ---------------------- | 7039| width | number | Yes | Default image width. | 7040| height | number | Yes | Default image height. | 7041| 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.) | 7042| capacity | number | Yes | Maximum number of images that can be accessed at the same time.| 7043 7044**Return value** 7045 7046| Type | Description | 7047| -------------------------------- | --------------------------------------- | 7048| [ImageReceiver](#imagereceiver9) | Returns an **ImageReceiver** instance if the operation is successful.| 7049 7050**Example** 7051 7052```ts 7053let receiver: image.ImageReceiver = image.createImageReceiver(8192, 8, image.ImageFormat.JPEG, 8); 7054``` 7055 7056## ImageReceiver<sup>9+</sup> 7057 7058Provides APIs to obtain the surface ID of a component, read the latest image, read the next image, and release the **ImageReceiver** instance. 7059 7060Before calling any APIs in **ImageReceiver**, you must create an **ImageReceiver** instance. 7061 7062### Properties 7063 7064**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7065 7066| Name | Type | Readable| Writable| Description | 7067| -------- | ---------------------------- | ---- | ---- | ------------------ | 7068| size | [Size](#size) | Yes | No | Image size. | 7069| capacity | number | Yes | No | Maximum number of images that can be accessed at the same time.| 7070| format | [ImageFormat](#imageformat9) | Yes | No | Image format. | 7071 7072### getReceivingSurfaceId<sup>9+</sup> 7073 7074getReceivingSurfaceId(callback: AsyncCallback\<string>): void 7075 7076Obtains a surface ID for the camera or other components. This API uses an asynchronous callback to return the result. 7077 7078**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7079 7080**Parameters** 7081 7082| Name | Type | Mandatory| Description | 7083| -------- | ---------------------- | ---- | -------------------------- | 7084| 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.| 7085 7086**Example** 7087 7088```ts 7089import { BusinessError } from '@kit.BasicServicesKit'; 7090 7091receiver.getReceivingSurfaceId((err: BusinessError, id: string) => { 7092 if (err) { 7093 console.error(`Failed to get the ReceivingSurfaceId.code ${err.code},message is ${err.message}`); 7094 } else { 7095 console.info('Succeeded in getting the ReceivingSurfaceId.'); 7096 } 7097}); 7098``` 7099 7100### getReceivingSurfaceId<sup>9+</sup> 7101 7102getReceivingSurfaceId(): Promise\<string> 7103 7104Obtains a surface ID for the camera or other components. This API uses a promise to return the result. 7105 7106**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7107 7108**Return value** 7109 7110| Type | Description | 7111| ---------------- | -------------------- | 7112| Promise\<string> | Promise used to return the surface ID.| 7113 7114**Example** 7115 7116```ts 7117import { BusinessError } from '@kit.BasicServicesKit'; 7118 7119receiver.getReceivingSurfaceId().then((id: string) => { 7120 console.info('Succeeded in getting the ReceivingSurfaceId.'); 7121}).catch((error: BusinessError) => { 7122 console.error(`Failed to get the ReceivingSurfaceId.code ${error.code},message is ${error.message}`); 7123}) 7124``` 7125 7126### readLatestImage<sup>9+</sup> 7127 7128readLatestImage(callback: AsyncCallback\<Image>): void 7129 7130Reads the latest image from the **ImageReceiver** instance. This API uses an asynchronous callback to return the result. 7131 7132**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. 7133 7134**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7135 7136**Parameters** 7137 7138| Name | Type | Mandatory| Description | 7139| -------- | ------------------------------- | ---- | ------------------------ | 7140| 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. | 7141 7142**Example** 7143 7144```ts 7145import { BusinessError } from '@kit.BasicServicesKit'; 7146 7147receiver.readLatestImage((err: BusinessError, img: image.Image) => { 7148 if (err) { 7149 console.error(`Failed to read the latest Image.code ${err.code},message is ${err.message}`); 7150 } else { 7151 console.info('Succeeded in reading the latest Image.'); 7152 } 7153}); 7154``` 7155 7156### readLatestImage<sup>9+</sup> 7157 7158readLatestImage(): Promise\<Image> 7159 7160Reads the latest image from the **ImageReceiver** instance. This API uses a promise to return the result. 7161 7162**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. 7163 7164**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7165 7166**Return value** 7167 7168| Type | Description | 7169| ------------------------- | ------------------ | 7170| Promise<[Image](#image9)> | Promise used to return the latest image.| 7171 7172**Example** 7173 7174```ts 7175import { BusinessError } from '@kit.BasicServicesKit'; 7176 7177receiver.readLatestImage().then((img: image.Image) => { 7178 console.info('Succeeded in reading the latest Image.'); 7179}).catch((error: BusinessError) => { 7180 console.error(`Failed to read the latest Image.code ${error.code},message is ${error.message}`); 7181}) 7182``` 7183 7184### readNextImage<sup>9+</sup> 7185 7186readNextImage(callback: AsyncCallback\<Image>): void 7187 7188Reads the next image from the **ImageReceiver** instance. This API uses an asynchronous callback to return the result. 7189 7190**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. 7191 7192**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7193 7194**Parameters** 7195 7196| Name | Type | Mandatory| Description | 7197| -------- | ------------------------------- | ---- | -------------------------- | 7198| 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. | 7199 7200**Example** 7201 7202```ts 7203import { BusinessError } from '@kit.BasicServicesKit'; 7204 7205receiver.readNextImage((err: BusinessError, img: image.Image) => { 7206 if (err) { 7207 console.error(`Failed to read the next Image.code ${err.code},message is ${err.message}`); 7208 } else { 7209 console.info('Succeeded in reading the next Image.'); 7210 } 7211}); 7212``` 7213 7214### readNextImage<sup>9+</sup> 7215 7216readNextImage(): Promise\<Image> 7217 7218Reads the next image from the **ImageReceiver** instance. This API uses a promise to return the result. 7219 7220**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. 7221 7222**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7223 7224**Return value** 7225 7226| Type | Description | 7227| ------------------------- | -------------------- | 7228| Promise<[Image](#image9)> | Promise used to return the next image.| 7229 7230**Example** 7231 7232```ts 7233import { BusinessError } from '@kit.BasicServicesKit'; 7234 7235receiver.readNextImage().then((img: image.Image) => { 7236 console.info('Succeeded in reading the next Image.'); 7237}).catch((error: BusinessError) => { 7238 console.error(`Failed to read the next Image.code ${error.code},message is ${error.message}`); 7239}) 7240``` 7241 7242### on<sup>9+</sup> 7243 7244on(type: 'imageArrival', callback: AsyncCallback\<void>): void 7245 7246Listens for image arrival events. 7247 7248**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7249 7250**Parameters** 7251 7252| Name | Type | Mandatory| Description | 7253| -------- | -------------------- | ---- | ------------------------------------------------------ | 7254| type | string | Yes | Type of event to listen for. The value is fixed at **'imageArrival'**, which is triggered when an image is received.| 7255| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 7256 7257**Example** 7258 7259```ts 7260receiver.on('imageArrival', () => { 7261 // image arrival, do something. 7262}) 7263``` 7264 7265### off<sup>13+</sup> 7266 7267off(type: 'imageArrival', callback?: AsyncCallback\<void>): void 7268 7269Unregisters the callback function that is triggered when the buffer is released. 7270 7271**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7272 7273**Parameters** 7274 7275| Name | Type | Mandatory| Description | 7276| -------- | -------------------- |----|----------------------------------------| 7277| type | string | Yes | Type of event, which is **'imageArrival'**.| 7278| callback | AsyncCallback\<void> | No | Callback to unregister. | 7279 7280**Example** 7281 7282```ts 7283let callbackFunc = ()=>{ 7284 // do something. 7285} 7286receiver.on('imageArrival', callbackFunc) 7287receiver.off('imageArrival', callbackFunc) 7288``` 7289 7290### release<sup>9+</sup> 7291 7292release(callback: AsyncCallback\<void>): void 7293 7294Releases this **ImageReceiver** instance. This API uses an asynchronous callback to return the result. 7295 7296ArkTS 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. 7297 7298**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7299 7300**Parameters** 7301 7302| Name | Type | Mandatory| Description | 7303| -------- | -------------------- | ---- | ------------------------ | 7304| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 7305 7306**Example** 7307 7308```ts 7309import { BusinessError } from '@kit.BasicServicesKit'; 7310 7311receiver.release((err: BusinessError) => { 7312 if (err) { 7313 console.error(`Failed to release the receiver.code ${err.code},message is ${err.message}`); 7314 } else { 7315 console.info('Succeeded in releasing the receiver.'); 7316 } 7317}) 7318``` 7319 7320### release<sup>9+</sup> 7321 7322release(): Promise\<void> 7323 7324Releases this **ImageReceiver** instance. This API uses a promise to return the result. 7325 7326ArkTS 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. 7327 7328**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7329 7330**Return value** 7331 7332| Type | Description | 7333| -------------- | ------------------ | 7334| Promise\<void> | Promise that returns no value.| 7335 7336**Example** 7337 7338```ts 7339import { BusinessError } from '@kit.BasicServicesKit'; 7340 7341receiver.release().then(() => { 7342 console.info('Succeeded in releasing the receiver.'); 7343}).catch((error: BusinessError) => { 7344 console.error(`Failed to release the receiver.code ${error.code},message is ${error.message}`); 7345}) 7346``` 7347 7348## image.createImageCreator<sup>11+</sup> 7349 7350createImageCreator(size: Size, format: ImageFormat, capacity: number): ImageCreator 7351 7352Creates an **ImageCreator** instance by specifying the image size, format, and capacity. 7353 7354**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7355 7356**Parameters** 7357 7358| Name | Type | Mandatory| Description | 7359| -------- | ------ | ---- | ---------------------- | 7360| size | [Size](#size) | Yes | Default size of the image. | 7361| format | [ImageFormat](#imageformat9) | Yes | Image format, for example, YCBCR_422_SP or JPEG. | 7362| capacity | number | Yes | Maximum number of images that can be accessed at the same time.| 7363 7364**Return value** 7365 7366| Type | Description | 7367| ------------------------------ | --------------------------------------- | 7368| [ImageCreator](#imagecreator9) | Returns an **ImageCreator** instance if the operation is successful.| 7369 7370 7371**Error codes** 7372 7373For details about the error codes, see [Image Error Codes](errorcode-image.md). 7374 7375| ID| Error Message| 7376| ------- | --------------------------------------------| 7377| 401| Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; | 7378 7379**Example** 7380 7381```ts 7382let size: image.Size = { 7383 height: 8192, 7384 width: 8 7385} 7386let creator: image.ImageCreator = image.createImageCreator(size, image.ImageFormat.JPEG, 8); 7387``` 7388 7389## image.createImageCreator<sup>(deprecated)</sup> 7390 7391createImageCreator(width: number, height: number, format: number, capacity: number): ImageCreator 7392 7393Creates an **ImageCreator** instance by specifying the image width, height, format, and capacity. 7394 7395> **NOTE** 7396> 7397> This API is deprecated since API version 11. You are advised to use [createImageCreator](#imagecreateimagecreator11). 7398 7399**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7400 7401**Parameters** 7402 7403| Name | Type | Mandatory| Description | 7404| -------- | ------ | ---- | ---------------------- | 7405| width | number | Yes | Default image width. | 7406| height | number | Yes | Default image height. | 7407| format | number | Yes | Image format, for example, YCBCR_422_SP or JPEG. | 7408| capacity | number | Yes | Maximum number of images that can be accessed at the same time.| 7409 7410**Return value** 7411 7412| Type | Description | 7413| ------------------------------ | --------------------------------------- | 7414| [ImageCreator](#imagecreator9) | Returns an **ImageCreator** instance if the operation is successful.| 7415 7416**Example** 7417 7418```ts 7419let creator: image.ImageCreator = image.createImageCreator(8192, 8, image.ImageFormat.JPEG, 8); 7420``` 7421 7422## ImageCreator<sup>9+</sup> 7423 7424Provides APIs for applications to request an image native data area and compile native image data. 7425Before calling any APIs in **ImageCreator**, you must create an [ImageCreator](#imagecreator9) instance. **ImageCreator** does not support multiple threads. 7426 7427### Properties 7428 7429**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7430 7431| Name | Type | Readable| Writable| Description | 7432| -------- | ---------------------------- | ---- | ---- | ------------------ | 7433| capacity | number | Yes | No | Maximum number of images that can be accessed at the same time.| 7434| format | [ImageFormat](#imageformat9) | Yes | No | Image format. | 7435 7436### dequeueImage<sup>9+</sup> 7437 7438dequeueImage(callback: AsyncCallback\<Image>): void 7439 7440Obtains an image buffer from the idle queue and writes image data into it. This API uses an asynchronous callback to return the result. 7441 7442**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7443 7444**Parameters** 7445 7446| Name | Type | Mandatory| Description | 7447| ------------- | ---------------------------------------| ---- | -------------------- | 7448| 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. | 7449 7450**Example** 7451 7452```ts 7453import { BusinessError } from '@kit.BasicServicesKit'; 7454 7455creator.dequeueImage((err: BusinessError, img: image.Image) => { 7456 if (err) { 7457 console.error(`Failed to dequeue the Image.code ${err.code},message is ${err.message}`); 7458 } else { 7459 console.info('Succeeded in dequeuing the Image.'); 7460 } 7461}); 7462``` 7463 7464### dequeueImage<sup>9+</sup> 7465 7466dequeueImage(): Promise\<Image> 7467 7468Obtains an image buffer from the idle queue and writes image data into it. This API uses a promise to return the result. 7469 7470**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7471 7472**Return value** 7473 7474| Type | Description | 7475| --------------- | ------------- | 7476| Promise\<[Image](#image9)> | Promise used to return the latest image.| 7477 7478**Example** 7479 7480```ts 7481import { BusinessError } from '@kit.BasicServicesKit'; 7482 7483creator.dequeueImage().then((img: image.Image) => { 7484 console.info('Succeeded in dequeuing the Image.'); 7485}).catch((error: BusinessError) => { 7486 console.error(`Failed to dequeue the Image.code ${error.code},message is ${error.message}`); 7487}) 7488``` 7489 7490### queueImage<sup>9+</sup> 7491 7492queueImage(interface: Image, callback: AsyncCallback\<void>): void 7493 7494Places the drawn image in the dirty queue. This API uses an asynchronous callback to return the result. 7495 7496**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7497 7498**Parameters** 7499 7500| Name | Type | Mandatory| Description | 7501| ------------- | -------------------------| ---- | -------------------- | 7502| interface | [Image](#image9) | Yes | Drawn image.| 7503| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 7504 7505**Example** 7506 7507```ts 7508import { BusinessError } from '@kit.BasicServicesKit'; 7509 7510creator.dequeueImage().then((img: image.Image) => { 7511 // Draw the image. 7512 img.getComponent(4).then((component : image.Component) => { 7513 let bufferArr: Uint8Array = new Uint8Array(component.byteBuffer); 7514 for (let i = 0; i < bufferArr.length; i += 4) { 7515 bufferArr[i] = 0; //B 7516 bufferArr[i + 1] = 0; //G 7517 bufferArr[i + 2] = 255; //R 7518 bufferArr[i + 3] = 255; //A 7519 } 7520 }) 7521 creator.queueImage(img, (err: BusinessError) => { 7522 if (err) { 7523 console.error(`Failed to queue the Image.code ${err.code},message is ${err.message}`); 7524 } else { 7525 console.info('Succeeded in queuing the Image.'); 7526 } 7527 }) 7528}) 7529 7530``` 7531 7532### queueImage<sup>9+</sup> 7533 7534queueImage(interface: Image): Promise\<void> 7535 7536Places the drawn image in the dirty queue. This API uses a promise to return the result. 7537 7538**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7539 7540**Parameters** 7541 7542| Name | Type | Mandatory| Description | 7543| ------------- | --------| ---- | ------------------- | 7544| interface | [Image](#image9) | Yes | Drawn image.| 7545 7546**Return value** 7547 7548| Type | Description | 7549| -------------- | ------------- | 7550| Promise\<void> | Promise that returns no value.| 7551 7552**Example** 7553 7554```ts 7555import { BusinessError } from '@kit.BasicServicesKit'; 7556 7557creator.dequeueImage().then((img: image.Image) => { 7558 // Draw the image. 7559 img.getComponent(4).then((component: image.Component) => { 7560 let bufferArr: Uint8Array = new Uint8Array(component.byteBuffer); 7561 for (let i = 0; i < bufferArr.length; i += 4) { 7562 bufferArr[i] = 0; //B 7563 bufferArr[i + 1] = 0; //G 7564 bufferArr[i + 2] = 255; //R 7565 bufferArr[i + 3] = 255; //A 7566 } 7567 }) 7568 creator.queueImage(img).then(() => { 7569 console.info('Succeeded in queuing the Image.'); 7570 }).catch((error: BusinessError) => { 7571 console.error(`Failed to queue the Image.code ${error.code},message is ${error.message}`); 7572 }) 7573}) 7574 7575``` 7576 7577### on<sup>9+</sup> 7578 7579on(type: 'imageRelease', callback: AsyncCallback\<void>): void 7580 7581Listens for image release events. This API uses an asynchronous callback to return the result. 7582 7583**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7584 7585**Parameters** 7586 7587| Name | Type | Mandatory| Description | 7588| ------------- | -------------------------| ---- | -------------------- | 7589| type | string | Yes | Type of event, which is **'imageRelease'**.| 7590| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 7591 7592**Example** 7593 7594```ts 7595import { BusinessError } from '@kit.BasicServicesKit'; 7596 7597creator.on('imageRelease', (err: BusinessError) => { 7598 if (err) { 7599 console.error(`Failed to get the imageRelease callback.code ${err.code},message is ${err.message}`); 7600 } else { 7601 console.info('Succeeded in getting imageRelease callback.'); 7602 } 7603}) 7604``` 7605 7606### off<sup>13+</sup> 7607 7608off(type: 'imageRelease', callback?: AsyncCallback\<void>): void 7609 7610Unregisters the callback function that is triggered when the buffer is released. 7611 7612**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7613 7614**Parameters** 7615 7616| Name | Type | Mandatory| Description | 7617| ------------- | -------------------------|----|--------------------------------------------| 7618| type | string | Yes | Type of event, which is **'imageRelease'**. | 7619| callback | AsyncCallback\<void> | No | Callback to unregister.| 7620 7621**Example** 7622 7623```ts 7624let callbackFunc = ()=>{ 7625 // do something. 7626} 7627creator.on('imageRelease', callbackFunc) 7628creator.off('imageRelease', callbackFunc) 7629``` 7630 7631### release<sup>9+</sup> 7632 7633release(callback: AsyncCallback\<void>): void 7634 7635Releases this **ImageCreator** instance. This API uses an asynchronous callback to return the result. 7636 7637ArkTS 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. 7638 7639**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7640 7641**Parameters** 7642 7643| Name | Type | Mandatory| Description | 7644| ------------- | -------------------------| ---- | -------------------- | 7645| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 7646 7647**Example** 7648 7649```ts 7650import { BusinessError } from '@kit.BasicServicesKit'; 7651 7652creator.release((err: BusinessError) => { 7653 if (err) { 7654 console.error(`Failed to release the creator.code ${err.code},message is ${err.message}`); 7655 } else { 7656 console.info('Succeeded in releasing creator.'); 7657 } 7658}); 7659``` 7660### release<sup>9+</sup> 7661 7662release(): Promise\<void> 7663 7664Releases this **ImageCreator** instance. This API uses a promise to return the result. 7665 7666ArkTS 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. 7667 7668**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7669 7670**Return value** 7671 7672| Type | Description | 7673| -------------- | ------------- | 7674| Promise\<void> | Promise that returns no value.| 7675 7676**Example** 7677 7678```ts 7679import { BusinessError } from '@kit.BasicServicesKit'; 7680 7681creator.release().then(() => { 7682 console.info('Succeeded in releasing creator.'); 7683}).catch((error: BusinessError) => { 7684 console.error(`Failed to release the creator.code ${error.code},message is ${error.message}`); 7685}) 7686``` 7687 7688## Image<sup>9+</sup> 7689 7690Provides 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. 7691 7692### Properties 7693 7694**System capability**: SystemCapability.Multimedia.Image.Core 7695 7696| Name | Type | Readable| Writable| Description | 7697| -------- | ------------------ | ---- | ---- | -------------------------------------------------- | 7698| clipRect | [Region](#region8) | Yes | Yes | Image area to be cropped. | 7699| 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). | 7700| format | number | Yes | No | Image format. For details, see [OH_NativeBuffer_Format](../apis-arkgraphics2d/_o_h___native_buffer.md#oh_nativebuffer_format).| 7701| 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.| 7702 7703### getComponent<sup>9+</sup> 7704 7705getComponent(componentType: ComponentType, callback: AsyncCallback\<Component>): void 7706 7707Obtains the component buffer from the **Image** instance based on the color component type. This API uses an asynchronous callback to return the result. 7708 7709**System capability**: SystemCapability.Multimedia.Image.Core 7710 7711**Parameters** 7712 7713| Name | Type | Mandatory| Description | 7714| ------------- | --------------------------------------- | ---- | -------------------- | 7715| 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.) | 7716| 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. | 7717 7718**Example** 7719 7720```ts 7721import { BusinessError } from '@kit.BasicServicesKit'; 7722 7723img.getComponent(4, (err: BusinessError, component: image.Component) => { 7724 if (err) { 7725 console.error(`Failed to get the component.code ${err.code},message is ${err.message}`); 7726 } else { 7727 console.info('Succeeded in getting component.'); 7728 } 7729}) 7730``` 7731 7732### getComponent<sup>9+</sup> 7733 7734getComponent(componentType: ComponentType): Promise\<Component> 7735 7736Obtains the component buffer from the **Image** instance based on the color component type. This API uses a promise to return the result. 7737 7738**System capability**: SystemCapability.Multimedia.Image.Core 7739 7740**Parameters** 7741 7742| Name | Type | Mandatory| Description | 7743| ------------- | -------------------------------- | ---- | ---------------- | 7744| 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.)| 7745 7746**Return value** 7747 7748| Type | Description | 7749| --------------------------------- | --------------------------------- | 7750| Promise<[Component](#component9)> | Promise used to return the component buffer.| 7751 7752**Example** 7753 7754```ts 7755import { BusinessError } from '@kit.BasicServicesKit'; 7756 7757img.getComponent(4).then((component: image.Component) => { 7758 console.info('Succeeded in getting component.'); 7759}).catch((error: BusinessError) => { 7760 console.error(`Failed to get the component.code ${error.code},message is ${error.message}`); 7761}) 7762``` 7763 7764### release<sup>9+</sup> 7765 7766release(callback: AsyncCallback\<void>): void 7767 7768Releases this **Image** instance. This API uses an asynchronous callback to return the result. 7769 7770The corresponding resources must be released before another image arrives. 7771 7772ArkTS 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. 7773 7774**System capability**: SystemCapability.Multimedia.Image.Core 7775 7776**Parameters** 7777 7778| Name | Type | Mandatory| Description | 7779| -------- | -------------------- | ---- | -------------- | 7780| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 7781 7782**Example** 7783 7784```ts 7785import { BusinessError } from '@kit.BasicServicesKit'; 7786 7787img.release((err: BusinessError) => { 7788 if (err) { 7789 console.error(`Failed to release the image instance.code ${err.code},message is ${err.message}`); 7790 } else { 7791 console.info('Succeeded in releasing the image instance.'); 7792 } 7793}) 7794``` 7795 7796### release<sup>9+</sup> 7797 7798release(): Promise\<void> 7799 7800Releases this **Image** instance. This API uses a promise to return the result. 7801 7802The corresponding resources must be released before another image arrives. 7803 7804ArkTS 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. 7805 7806**System capability**: SystemCapability.Multimedia.Image.Core 7807 7808**Return value** 7809 7810| Type | Description | 7811| -------------- | --------------------- | 7812| Promise\<void> | Promise that returns no value.| 7813 7814**Example** 7815 7816```ts 7817import { BusinessError } from '@kit.BasicServicesKit'; 7818 7819img.release().then(() => { 7820 console.info('Succeeded in releasing the image instance.'); 7821}).catch((error: BusinessError) => { 7822 console.error(`Failed to release the image instance.code ${error.code},message is ${error.message}`); 7823}) 7824``` 7825 7826## PositionArea<sup>7+</sup> 7827 7828Describes area information in an image. 7829 7830**Widget capability**: This API can be used in ArkTS widgets since API version 12. 7831 7832**Atomic service API**: This API can be used in atomic services since API version 11. 7833 7834**System capability**: SystemCapability.Multimedia.Image.Core 7835 7836| Name | Type | Read Only| Optional| Description | 7837| ------ | ------------------ | ---| -----|------------------------------------------------------- | 7838| pixels | ArrayBuffer | No| No | Pixels of the image. Only pixel data in BGRA_8888 format is supported.| 7839| offset | number | No| No | Offset for data reading. | 7840| 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. | 7841| 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.| 7842 7843## ImageInfo 7844 7845Describes image information. 7846 7847**System capability**: SystemCapability.Multimedia.Image.Core 7848 7849| Name| Type | Read Only| Optional| Description | 7850| ---- | ------------- | --- |-----|---------- | 7851| 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.| 7852| 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.| 7853| 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.| 7854| 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.| 7855| 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.| 7856| mimeType<sup>12+</sup> | string | No | No |Actual image format (MIME type). | 7857| 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.| 7858 7859## Size 7860 7861Describes the size of an image. 7862 7863**Widget capability**: This API can be used in ArkTS widgets since API version 12. 7864 7865**Atomic service API**: This API can be used in atomic services since API version 11. 7866 7867**System capability**: SystemCapability.Multimedia.Image.Core 7868 7869| Name | Type | Read Only| Optional |Description | 7870| ------ | ------ | -- |-----| -------------- | 7871| height | number | No | No |Image height, in px.| 7872| width | number | No | No| Image width, in px.| 7873 7874## PixelMapFormat<sup>7+</sup> 7875 7876Enumerates the pixel formats of images. 7877 7878**System capability**: SystemCapability.Multimedia.Image.Core 7879 7880| Name | Value | Description | 7881| ---------------------- | ------ | ----------------- | 7882| 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. | 7883| ARGB_8888<sup>16+</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.| 7884| 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. | 7885| 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.| 7886| 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.| 7887| 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. | 7888| 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. | 7889| 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. | 7890| 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. | 7891| 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. | 7892| 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.| 7893| 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. 7894| 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. | 7895 7896## AlphaType<sup>9+</sup> 7897 7898Enumerates the alpha types of images. 7899 7900**Widget capability**: This API can be used in ArkTS widgets since API version 12. 7901 7902**Atomic service API**: This API can be used in atomic services since API version 11. 7903 7904**System capability**: SystemCapability.Multimedia.Image.Core 7905 7906| Name | Value | Description | 7907| -------- | ------ | ----------------------- | 7908| UNKNOWN | 0 | Unknown alpha type. | 7909| OPAQUE | 1 | There is no alpha or the image is opaque.| 7910| PREMUL | 2 | Premultiplied alpha. | 7911| UNPREMUL | 3 | RGB non-premultiplied alpha. | 7912 7913## AuxiliaryPictureType<sup>13+</sup> 7914 7915Enumerates the auxiliary pictures types. 7916 7917**System capability**: SystemCapability.Multimedia.Image.Core 7918 7919| Name | Value | Description | 7920| ------------- | ---- | ------------ | 7921| 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. | 7922| 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. | 7923| 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. | 7924| 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. | 7925| 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.| 7926 7927## AuxiliaryPictureInfo<sup>13+</sup> 7928 7929Describes the auxiliary picture information. 7930 7931**System capability**: SystemCapability.Multimedia.Image.Core 7932 7933| Name | Type | Read Only| Optional| Description | 7934| ------------------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ | 7935| auxiliaryPictureType | [AuxiliaryPictureType](#auxiliarypicturetype13) | No | No | Auxiliary picture type. | 7936| size | [Size](#size) | No | No | Image size.| 7937| rowStride | number | No | No | Row stride. | 7938| pixelFormat | [PixelMapFormat](#pixelmapformat7) | No | No | Pixel format.| 7939| colorSpace | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | No | No | Color space. | 7940 7941## MetadataType<sup>13+</sup> 7942 7943Enumerates image metadata types. 7944 7945**System capability**: SystemCapability.Multimedia.Image.Core 7946 7947| Name | Value | Description | 7948| ----------------- | ---- | ------------------ | 7949| EXIF_METADATA | 1 | EXIF data. | 7950| FRAGMENT_METADATA | 2 | Fragment map metadata.| 7951 7952## ScaleMode<sup>9+</sup> 7953 7954Enumerates the scale modes of images. 7955 7956**Widget capability**: This API can be used in ArkTS widgets since API version 12. 7957 7958**Atomic service API**: This API can be used in atomic services since API version 11. 7959 7960**System capability**: SystemCapability.Multimedia.Image.Core 7961 7962| Name | Value | Description | 7963| --------------- | ------ | -------------------------------------------------- | 7964| CENTER_CROP | 1 | Scales the image so that it fills the requested bounds of the target and crops the extra.| 7965| FIT_TARGET_SIZE | 0 | Reduces the image size to the dimensions of the target. | 7966 7967## SourceOptions<sup>9+</sup> 7968 7969Defines image source initialization options. 7970 7971**Widget capability**: This API can be used in ArkTS widgets since API version 12. 7972 7973**Atomic service API**: This API can be used in atomic services since API version 11. 7974 7975**System capability**: SystemCapability.Multimedia.Image.Core 7976 7977| Name | Type | Read Only| Optional| Description | 7978| ----------------- | ---------------------------------- | ---- | ---- | ------------------ | 7979| 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.| 7980| sourcePixelFormat | [PixelMapFormat](#pixelmapformat7) | No | Yes | Image pixel format. The default value is **UNKNOWN**. | 7981| sourceSize | [Size](#size) | No | Yes | Image pixel size. The default value is null. | 7982 7983 7984## InitializationOptions<sup>8+</sup> 7985 7986Defines PixelMap initialization options. 7987 7988**System capability**: SystemCapability.Multimedia.Image.Core 7989 7990| Name | Type | Read Only|Optional| Description | 7991| ------------------------ | ---------------------------------- | ----| -----| -------------- | 7992| 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. | 7993| 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.| 7994| srcPixelFormat<sup>12+</sup> | [PixelMapFormat](#pixelmapformat7) | No| Yes| Pixel format of the passed-in buffer data. The default value is **BGRA_8888**.| 7995| 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. | 7996| 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. | 7997| 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.| 7998 7999## DecodingOptions<sup>7+</sup> 8000 8001Describes the image decoding options. 8002 8003**System capability**: SystemCapability.Multimedia.Image.ImageSource 8004 8005| Name | Type | Read Only| Optional| Description | 8006| ------------------ | ---------------------------------- | ---- | ---- | ---------------- | 8007| 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.| 8008| 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. | 8009| 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. | 8010| 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. | 8011| 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. | 8012| 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.| 8013| 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. | 8014| 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. | 8015| desiredColorSpace<sup>11+</sup> | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | No | Yes | Target color space. The default value is **UNKNOWN**.| 8016| 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.| 8017 8018## DecodingOptionsForPicture<sup>13+</sup> 8019 8020Describes the image decoding options. 8021 8022**System capability**: SystemCapability.Multimedia.Image.ImageSource 8023 8024| Name | Type | Read Only| Optional| Description | 8025| ------------------------ | ------------------------------------------------------- | ---- | ---- | ------------------------------------------------------------ | 8026| desiredAuxiliaryPictures | Array\<[AuxiliaryPictureType](#auxiliarypicturetype13)> | No | No | Auxiliary picture type. By default, all auxiliary picture types are decoded.| 8027 8028## Region<sup>8+</sup> 8029 8030Describes the region information. 8031 8032**Widget capability**: This API can be used in ArkTS widgets since API version 12. 8033 8034**Atomic service API**: This API can be used in atomic services since API version 11. 8035 8036**System capability**: SystemCapability.Multimedia.Image.Core 8037 8038| Name| Type | Read Only| Optional| Description | 8039| ---- | ------------- | ---- | ---- | ------------ | 8040| size<sup>7+</sup> | [Size](#size) | No | No | Region size. | 8041| x<sup>7+</sup> | number | No | No | X coordinate of the upper left corner of the region.| 8042| y<sup>7+</sup> | number | No | No | Y coordinate of the upper left corner of the region.| 8043 8044## PackingOption 8045 8046Describes the options for image packing. 8047 8048**System capability**: SystemCapability.Multimedia.Image.ImagePacker 8049 8050| Name | Type | Read Only| Optional| Description | 8051| ------- | ------ | ---- | ---- | --------------------------------------------------- | 8052| 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.| 8053| 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.| 8054| 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.| 8055| desiredDynamicRange<sup>12+</sup> | [PackingDynamicRange](#packingdynamicrange12) | No | Yes | Desired dynamic range. The default value is **SDR**.| 8056| needsPackProperties<sup>12+</sup> | boolean | No | Yes | Whether to encode image property information, for example, EXIF. The default value is **false**.| 8057 8058## ImagePropertyOptions<sup>11+</sup> 8059 8060Describes the image properties. 8061 8062**System capability**: SystemCapability.Multimedia.Image.ImageSource 8063 8064| Name | Type | Read Only| Optional| Description | 8065| ------------ | ------ | ---- | ---- | ------------ | 8066| index | number | Yes | Yes | Index of the image. The default value is **0**. | 8067| defaultValue | string | Yes | Yes | Default property value. The default value is null.| 8068 8069## GetImagePropertyOptions<sup>(deprecated)</sup> 8070 8071Describes the image properties. 8072 8073> **NOTE** 8074> 8075> This API is deprecated since API version 11. You are advised to use [ImagePropertyOptions](#imagepropertyoptions11). 8076 8077**System capability**: SystemCapability.Multimedia.Image.ImageSource 8078 8079| Name | Type | Read Only| Optional| Description | 8080| ------------ | ------ | ---- | ---- | ------------ | 8081| index | number | No | Yes | Index of the image. The default value is **0**. | 8082| defaultValue | string | No | Yes | Default property value. The default value is null.| 8083 8084## PropertyKey<sup>7+</sup> 8085 8086Describes the exchangeable image file format (EXIF) data of an image. 8087 8088**System capability**: SystemCapability.Multimedia.Image.Core 8089 8090| Name | Value | Description | 8091| ----------------- | ----------------------- |---------------------------| 8092| 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.| 8093| 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.| 8094| IMAGE_WIDTH | "ImageWidth" | **Read/Write capability**: readable and writable<br> Image width.| 8095| IMAGE_LENGTH | "ImageLength" | **Read/Write capability**: readable and writable<br> Image length.| 8096| 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.| 8097| COMPRESSION <sup>12+</sup> | "Compression" | **Read/Write capability**: readable and writable<br> Compression scheme used on the image data.| 8098| PHOTOMETRIC_INTERPRETATION <sup>12+</sup> | "PhotometricInterpretation" | **Read/Write capability**: readable and writable<br> Color space of the image data, for example, RGB or YCbCr.| 8099| IMAGE_DESCRIPTION<sup>10+</sup> | "ImageDescription" | **Read/Write capability**: readable and writable<br> Image description.| 8100| MAKE<sup>10+</sup> | "Make" | **Read/Write capability**: readable and writable<br> Manufacturer.| 8101| MODEL<sup>10+</sup> | "Model" | **Read/Write capability**: readable and writable<br> Device model.| 8102| STRIP_OFFSETS <sup>12+</sup> | "StripOffsets" | **Read/Write capability**: readable and writable<br> Byte offset of each strip.| 8103| 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.| 8104| 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.| 8105| ROWS_PER_STRIP <sup>12+</sup> | "RowsPerStrip" | **Read/Write capability**: readable and writable<br> Number of rows per strip.| 8106| STRIP_BYTE_COUNTS <sup>12+</sup> | "StripByteCounts" | **Read/Write capability**: readable and writable<br> Number of bytes in each strip after compression.| 8107| X_RESOLUTION <sup>12+</sup> | "XResolution" | **Read/Write capability**: readable and writable<br> Number of pixels per ResolutionUnit in the image width (X) direction.| 8108| Y_RESOLUTION <sup>12+</sup> | "YResolution" | **Read/Write capability**: readable and writable<br> Number of pixels per ResolutionUnit in the image height (Y) direction.| 8109| 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.| 8110| RESOLUTION_UNIT <sup>12+</sup> | "ResolutionUnit" | **Read/Write capability**: readable and writable<br> Unit of measurement for XResolution and YResolution.| 8111| 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.| 8112| SOFTWARE <sup>12+</sup> | "Software" | **Read/Write capability**: readable and writable<br> Name and version number of the software used to create the image.| 8113| 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.| 8114| ARTIST <sup>12+</sup> | "Artist" | **Read/Write capability**: readable and writable<br> Person who created the image.| 8115| WHITE_POINT <sup>12+</sup> | "WhitePoint" | **Read/Write capability**: readable and writable<br> Chromaticity of the white point of the image.| 8116| PRIMARY_CHROMATICITIES <sup>12+</sup> | "PrimaryChromaticities" | **Read/Write capability**: readable and writable<br> Chromaticities of the primaries of the image.| 8117| PHOTO_MODE<sup>10+</sup> | "PhotoMode" | **Read/Write capability**: readable and writable<br> Photographing mode.| 8118| 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.| 8119| JPEG_INTERCHANGE_FORMAT_LENGTH <sup>12+</sup> | "JPEGInterchangeFormatLength" | **Read/Write capability**: readable and writable<br> Number of bytes of the JPEG stream.| 8120| YCBCR_COEFFICIENTS <sup>12+</sup> | "YCbCrCoefficients" | **Read/Write capability**: readable and writable<br> Transformation from RGB to YCbCr image data.| 8121| 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.| 8122| YCBCR_POSITIONING <sup>12+</sup> | "YCbCrPositioning" | **Read/Write capability**: readable and writable<br> Positioning of subsampled chrominance components relative to luminance samples.| 8123| 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.| 8124| COPYRIGHT <sup>12+</sup> | "Copyright" | **Read/Write capability**: readable and writable<br> Copyright notice of the image.| 8125| EXPOSURE_TIME<sup>9+</sup> | "ExposureTime" | **Read/Write capability**: readable and writable<br> Exposure time, for example, 1/33 seconds.| 8126| F_NUMBER<sup>9+</sup> | "FNumber" | **Read/Write capability**: readable and writable<br> F number, for example, f/1.8.| 8127| 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.| 8128| SPECTRAL_SENSITIVITY <sup>12+</sup> | "SpectralSensitivity" | **Read/Write capability**: readable and writable<br> Spectral sensitivity of each channel of the camera.| 8129| GPS_VERSION_ID <sup>12+</sup> | "GPSVersionID" | **Read/Write capability**: readable and writable<br> Version of GPSInfoIFD.| 8130| GPS_LATITUDE_REF | "GPSLatitudeRef" | **Read/Write capability**: readable and writable<br> Whether the latitude is north or south latitude.| 8131| 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.| 8132| GPS_LONGITUDE_REF | "GPSLongitudeRef" | **Read/Write capability**: readable and writable<br> Whether the longitude is east or west longitude.| 8133| 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.| 8134| GPS_ALTITUDE_REF <sup>12+</sup> | "GPSAltitudeRef" | **Read/Write capability**: readable and writable<br> Whether the latitude is north or south latitude.| 8135| GPS_ALTITUDE <sup>12+</sup> | "GPSAltitude" | **Read/Write capability**: readable and writable<br> Altitude based on the reference in GPSAltitudeRef.| 8136| GPS_TIME_STAMP<sup>10+</sup> | "GPSTimeStamp" | **Read/Write capability**: readable and writable<br> GPS timestamp.| 8137| GPS_SATELLITES <sup>12+</sup> | "GPSSatellites" | **Read/Write capability**: readable and writable<br> GPS satellites used for measurement.| 8138| GPS_STATUS <sup>12+</sup> | "GPSStatus" | **Read/Write capability**: readable and writable<br> Status of the GPS receiver when the image was recorded.| 8139| GPS_MEASURE_MODE <sup>12+</sup> | "GPSMeasureMode" | **Read/Write capability**: readable and writable<br> GPS measurement pmode.| 8140| GPS_DOP <sup>12+</sup> | "GPSDOP" | **Read/Write capability**: readable and writable<br> GPS DOP (data degree of precision)| 8141| 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.| 8142| GPS_SPEED <sup>12+</sup> | "GPSSpeed" | **Read/Write capability**: readable and writable<br> Movement speed of the GPS receiver.| 8143| GPS_TRACK_REF <sup>12+</sup> | "GPSTrackRef" | **Read/Write capability**: readable and writable<br> Reference of the movement direction of the GPS receiver.| 8144| GPS_TRACK <sup>12+</sup> | "GPSTrack" | **Read/Write capability**: readable and writable<br> Movement direction of the GPS receiver.| 8145| 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.| 8146| GPS_IMG_DIRECTION <sup>12+</sup> | "GPSImgDirection" | **Read/Write capability**: readable and writable<br> Direction of the image when it was captured.| 8147| GPS_MAP_DATUM <sup>12+</sup> | "GPSMapDatum" | **Read/Write capability**: readable and writable<br> Geodetic survey data used by the GPS receiver.| 8148| 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.| 8149| GPS_DEST_LATITUDE <sup>12+</sup> | "GPSDestLatitude" | **Read/Write capability**: readable and writable<br> Latitude of the destination point.| 8150| 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.| 8151| GPS_DEST_LONGITUDE <sup>12+</sup> | "GPSDestLongitude" | **Read/Write capability**: readable and writable<br> Longitude of the destination point.| 8152| GPS_DEST_BEARING_REF <sup>12+</sup> | "GPSDestBearingRef" | **Read/Write capability**: readable and writable<br> Reference of the bearing to the destination point.| 8153| GPS_DEST_BEARING <sup>12+</sup> | "GPSDestBearing" | **Read/Write capability**: readable and writable<br> Bearing to the destination point.| 8154| 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.| 8155| GPS_DEST_DISTANCE <sup>12+</sup> | "GPSDestDistance" | **Read/Write capability**: readable and writable<br> Distance to the destination point.| 8156| 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.| 8157| GPS_AREA_INFORMATION <sup>12+</sup> | "GPSAreaInformation" | **Read/Write capability**: readable and writable<br> String that records the name of the GPS area.| 8158| GPS_DATE_STAMP<sup>10+</sup> | "GPSDateStamp" | **Read/Write capability**: readable and writable<br> GPS date stamp.| 8159| 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.| 8160| GPS_H_POSITIONING_ERROR <sup>12+</sup> | "GPSHPositioningError" | **Read/Write capability**: readable and writable<br> Horizontal positioning error, in meters.| 8161| ISO_SPEED_RATINGS<sup>9+</sup> | "ISOSpeedRatings" | **Read/Write capability**: readable and writable<br> ISO sensitivity or ISO speed, for example, 400.| 8162| 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.| 8163| OECF <sup>12+</sup> | "OECF" | **Read/Write capability**: readable and writable<br> Opto-Electric Conversion Function (OECF) specified in ISO 14524.| 8164| SENSITIVITY_TYPE<sup>10+</sup> | "SensitivityType" | **Read/Write capability**: readable and writable<br> Sensitivity type.| 8165| STANDARD_OUTPUT_SENSITIVITY<sup>10+</sup> | "StandardOutputSensitivity" | **Read/Write capability**: readable and writable<br> Standard output sensitivity.| 8166| RECOMMENDED_EXPOSURE_INDEX<sup>10+</sup> | "RecommendedExposureIndex" | **Read/Write capability**: readable and writable<br> Recommended exposure index.| 8167| ISO_SPEED<sup>10+</sup> | "ISOSpeedRatings" | **Read/Write capability**: readable and writable<br> ISO speed.| 8168| 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.| 8169| 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.| 8170| EXIF_VERSION <sup>12+</sup> | "ExifVersion" | **Read/Write capability**: readable and writable<br> Version of the supported EXIF standard.| 8171| 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.| 8172| 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.| 8173| 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.| 8174| 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.| 8175| 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.| 8176| COMPONENTS_CONFIGURATION <sup>12+</sup> | "ComponentsConfiguration" | **Read/Write capability**: readable and writable<br> Specific information about compressed data.| 8177| 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.| 8178| SHUTTER_SPEED <sup>12+</sup> | "ShutterSpeedValue" | **Read/Write capability**: readable and writable<br> Shutter speed, expressed in Additive System of Photographic Exposure (APEX) values.| 8179| APERTURE_VALUE<sup>10+</sup> | "ApertureValue" | **Read/Write capability**: readable and writable<br> Lens aperture. An example in the correct format is 4/1.| 8180| BRIGHTNESS_VALUE <sup>12+</sup> | "BrightnessValue" | **Read/Write capability**: readable and writable<br> Value of brightness, expressed in APEX values.| 8181| EXPOSURE_BIAS_VALUE<sup>10+</sup> | "ExposureBiasValue" | **Read/Write capability**: readable and writable<br> Exposure bias.| 8182| MAX_APERTURE_VALUE <sup>12+</sup> | "MaxApertureValue" | **Read/Write capability**: readable and writable<br> Smallest F number of the lens.| 8183| SUBJECT_DISTANCE <sup>12+</sup> | "SubjectDistance" | **Read/Write capability**: readable and writable<br> Distance to the subject, in meters.| 8184| METERING_MODE<sup>10+</sup> | "MeteringMode" | **Read/Write capability**: readable and writable<br> Metering mode.| 8185| LIGHT_SOURCE<sup>10+</sup> | "LightSource" | **Read/Write capability**: readable and writable<br> Light source. An example value is **Fluorescent**.| 8186| FLASH <sup>10+</sup> | "Flash" | **Read/Write capability**: readable and writable<br> Flash status.| 8187| FOCAL_LENGTH <sup>10+</sup> | "FocalLength" | **Read/Write capability**: readable and writable<br> Focal length of the lens.| 8188| SUBJECT_AREA <sup>12+</sup> | "SubjectArea" | **Read/Write capability**: readable and writable<br> Location and area of the main subject in the entire scene.| 8189| MAKER_NOTE <sup>12+</sup> | "MakerNote" | **Read/Write capability**: read-only<br> Marker used by EXIF/DCF manufacturers to record any required information.| 8190| SCENE_POINTER <sup>12+</sup> | "HwMnoteScenePointer" | **Read/Write capability**: read-only<br> Pointer to the scene.| 8191| SCENE_VERSION <sup>12+</sup> | "HwMnoteSceneVersion" | **Read/Write capability**: read-only<br> Scene algorithm version.| 8192| SCENE_FOOD_CONF<sup>11+</sup> | "HwMnoteSceneFoodConf" | **Read/Write capability**: read-only<br> Photographing scene: food.| 8193| SCENE_STAGE_CONF<sup>11+</sup> | "HwMnoteSceneStageConf" | **Read/Write capability**: read-only<br> Photographing scene: stage.| 8194| SCENE_BLUE_SKY_CONF<sup>11+</sup> | "HwMnoteSceneBlueSkyConf" | **Read/Write capability**: read-only<br> Photographing scene: blue sky.| 8195| SCENE_GREEN_PLANT_CONF<sup>11+</sup> | "HwMnoteSceneGreenPlantConf" | **Read/Write capability**: read-only<br> Photographing scene: green plant.| 8196| SCENE_BEACH_CONF<sup>11+</sup> | "HwMnoteSceneBeachConf" | **Read/Write capability**: read-only<br> Photographing scene: beach.| 8197| SCENE_SNOW_CONF<sup>11+</sup> | "HwMnoteSceneSnowConf" | **Read/Write capability**: read-only<br> Photographing scene: snow.| 8198| SCENE_SUNSET_CONF<sup>11+</sup> | "HwMnoteSceneSunsetConf" | **Read/Write capability**: read-only<br> Photographing scene: sunset.| 8199| SCENE_FLOWERS_CONF<sup>11+</sup> | "HwMnoteSceneFlowersConf" | **Read/Write capability**: read-only<br> Photographing scene: flowers.| 8200| SCENE_NIGHT_CONF<sup>11+</sup> | "HwMnoteSceneNightConf" | **Read/Write capability**: read-only<br> Photographing scene: night.| 8201| SCENE_TEXT_CONF<sup>11+</sup> | "HwMnoteSceneTextConf" | **Read/Write capability**: read-only<br> Photographing scene: text.| 8202| FACE_POINTER <sup>12+</sup> | "HwMnoteFacePointer" | **Read/Write capability**: read-only<br> Face pointer.| 8203| FACE_VERSION <sup>12+</sup> | "HwMnoteFaceVersion" | **Read/Write capability**: read-only<br> Facial recognition algorithm version.| 8204| FACE_COUNT<sup>11+</sup> | "HwMnoteFaceCount" | **Read/Write capability**: read-only<br> Number of faces.| 8205| FACE_CONF <sup>12+</sup> | "HwMnoteFaceConf" | **Read/Write capability**: read-only<br> Face confidence.| 8206| FACE_SMILE_SCORE <sup>12+</sup> | "HwMnoteFaceSmileScore" | **Read/Write capability**: read-only<br> Smile score of for faces.| 8207| FACE_RECT <sup>12+</sup> | "HwMnoteFaceRect" | **Read/Write capability**: read-only<br> Face rectangle.| 8208| FACE_LEYE_CENTER <sup>12+</sup> | "HwMnoteFaceLeyeCenter" | **Read/Write capability**: read-only<br> Left eye centered.| 8209| FACE_REYE_CENTER <sup>12+</sup> | "HwMnoteFaceReyeCenter" | **Read/Write capability**: read-only<br> Right eye centered.| 8210| FACE_MOUTH_CENTER <sup>12+</sup> | "HwMnoteFaceMouthCenter" | **Read/Write capability**: read-only<br> Mouth centered.| 8211| CAPTURE_MODE <sup>10+</sup> | "HwMnoteCaptureMode" | **Read/Write capability**: readable and writable<br> Capture mode.| 8212| BURST_NUMBER <sup>12+</sup> | "HwMnoteBurstNumber" | **Read/Write capability**: read-only<br> Number of burst shooting times.| 8213| FRONT_CAMERA <sup>12+</sup> | "HwMnoteFrontCamera" | **Read/Write capability**: read-only<br> Whether the front camera is used to take a selfie.| 8214| ROLL_ANGLE <sup>11+</sup> | "HwMnoteRollAngle" | **Read/Write capability**: read-only<br> Roll angle.| 8215| PITCH_ANGLE<sup>11+</sup> | "HwMnotePitchAngle" | **Read/Write capability**: read-only<br> Pitch angle.| 8216| PHYSICAL_APERTURE <sup>10+</sup> | "HwMnotePhysicalAperture" | **Read/Write capability**: read-only<br> Physical aperture.| 8217| FOCUS_MODE<sup>11+</sup> | "HwMnoteFocusMode" | **Read/Write capability**: read-only<br> Focus mode.| 8218| USER_COMMENT <sup>10+</sup> | "UserComment" | **Read/Write capability**: readable and writable<br> User comments.| 8219| SUBSEC_TIME <sup>12+</sup> | "SubsecTime" | **Read/Write capability**: readable and writable<br> Tag used to record fractions of seconds for the **DateTime** tag.| 8220| 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.| 8221| 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.| 8222| 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.| 8223| 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.| 8224| PIXEL_X_DIMENSION <sup>10+</sup> | "PixelXDimension" | **Read/Write capability**: readable and writable<br> Pixel X dimension.| 8225| PIXEL_Y_DIMENSION<sup>10+</sup> | "PixelYDimension" | **Read/Write capability**: readable and writable<br> Pixel Y dimension.| 8226| RELATED_SOUND_FILE <sup>12+</sup> | "RelatedSoundFile" | **Read/Write capability**: readable and writable<br> Name of an audio file related to the image data.| 8227| 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).| 8228| SPATIAL_FREQUENCY_RESPONSE <sup>12+</sup> | "SpatialFrequencyResponse" | **Read/Write capability**: readable and writable<br> Spatial frequency table of the camera or input device.| 8229| 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.| 8230| 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.| 8231| FOCAL_PLANE_RESOLUTION_UNIT <sup>12+</sup> | "FocalPlaneResolutionUnit" | **Read/Write capability**: readable and writable<br> Unit for measuring FocalPlaneXResolution and FocalPlaneYResolution.| 8232| SUBJECT_LOCATION <sup>12+</sup> | "SubjectLocation" | **Read/Write capability**: readable and writable<br> Location of the main subject relative to the left edge.| 8233| EXPOSURE_INDEX <sup>12+</sup> | "ExposureIndex" | **Read/Write capability**: readable and writable<br> Exposure index selected at the time the image is captured.| 8234| SENSING_METHOD <sup>12+</sup> | "SensingMethod" | **Read/Write capability**: readable and writable<br> Type of the image sensor on the camera.| 8235| FILE_SOURCE <sup>12+</sup> | "FileSource" | **Read/Write capability**: readable and writable<br> Image source.| 8236| SCENE_TYPE<sup>9+</sup> | "SceneType" | **Read/Write capability**: readable and writable<br> Type of the scene, for example, portrait, scenery, motion, and night.| 8237| CFA_PATTERN <sup>12+</sup> | "CFAPattern" | **Read/Write capability**: readable and writable<br> Color Filter Array (CFA) geometric pattern of the image sensor.| 8238| CUSTOM_RENDERED <sup>12+</sup> | "CustomRendered" | **Read/Write capability**: readable and writable<br> Special processing on image data.| 8239| EXPOSURE_MODE <sup>12+</sup> | "ExposureMode" | **Read/Write capability**: readable and writable<br> Exposure mode set when the image was captured.| 8240| WHITE_BALANCE <sup>10+</sup> | "WhiteBalance" | **Read/Write capability**: readable and writable<br> White balance.| 8241| DIGITAL_ZOOM_RATIO <sup>12+</sup> | "DigitalZoomRatio" | **Read/Write capability**: readable and writable<br> Digital zoom ratio when the image was captured.| 8242| FOCAL_LENGTH_IN_35_MM_FILM <sup>10+</sup> | "FocalLengthIn35mmFilm" | **Read/Write capability**: readable and writable<br> Focal length in 35mm film.| 8243| SCENE_CAPTURE_TYPE <sup>12+</sup> | "SceneCaptureType" | **Read/Write capability**: readable and writable<br> Type of the scene that was captured.| 8244| GAIN_CONTROL <sup>12+</sup> | "GainControl" | **Read/Write capability**: readable and writable<br> Degree of overall image gain adjustment.| 8245| CONTRAST <sup>12+</sup> | "Contrast" | **Read/Write capability**: readable and writable<br> Direction of contrast processing used by the camera.| 8246| SATURATION <sup>12+</sup> | "Saturation" | **Read/Write capability**: readable and writable<br> Direction of saturation processing used by the camera.| 8247| SHARPNESS <sup>12+</sup> | "Sharpness" | **Read/Write capability**: readable and writable<br> Direction of sharpness processing used by the camera.| 8248| DEVICE_SETTING_DESCRIPTION <sup>12+</sup> | "DeviceSettingDescription" | **Read/Write capability**: readable and writable<br> Information about the photographing conditions of a specific camera model.| 8249| SUBJECT_DISTANCE_RANGE <sup>12+</sup> | "SubjectDistanceRange" | **Read/Write capability**: readable and writable<br> Distance to the subject.| 8250| IMAGE_UNIQUE_ID <sup>12+</sup> | "ImageUniqueID" | **Read/Write capability**: readable and writable<br> Unique identifier assigned to each image.| 8251| CAMERA_OWNER_NAME <sup>12+</sup> | "CameraOwnerName" | **Read/Write capability**: readable and writable<br> Name of the camera owner.| 8252| BODY_SERIAL_NUMBER <sup>12+</sup> | "BodySerialNumber" | **Read/Write capability**: readable and writable<br> Serial number of the camera body.| 8253| LENS_SPECIFICATION <sup>12+</sup> | "LensSpecification" | **Read/Write capability**: readable and writable<br> Specifications of the lens.| 8254| LENS_MAKE <sup>12+</sup> | "LensMake" | **Read/Write capability**: readable and writable<br> Manufacturer of the lens.| 8255| LENS_MODEL <sup>12+</sup> | "LensModel" | **Read/Write capability**: readable and writable<br> Model of the lens.| 8256| LENS_SERIAL_NUMBER <sup>12+</sup> | "LensSerialNumber" | **Read/Write capability**: readable and writable<br> Serial number of the lens.| 8257| COMPOSITE_IMAGE <sup>12+</sup> | "CompositeImage" | **Read/Write capability**: readable and writable<br> Whether the image is a composite image.| 8258| 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.| 8259| 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.| 8260| GAMMA <sup>12+</sup> | "Gamma" | **Read/Write capability**: readable and writable<br> Gamma value.| 8261| DNG_VERSION <sup>12+</sup> | "DNGVersion" | **Read/Write capability**: readable and writable<br> DNG version. It encodes the DNG 4-tier version number.| 8262| 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.| 8263| 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.| 8264| IS_XMAGE_SUPPORTED <sup>12+</sup> | "HwMnoteIsXmageSupported" | **Read/Write capability**: readable and writable<br>Whether XMAGE is supported.| 8265| XMAGE_MODE <sup>12+</sup> | "HwMnoteXmageMode" | **Read/Write capability**: readable and writable<br>XMAGE watermark mode.| 8266| XMAGE_LEFT <sup>12+</sup> | "HwMnoteXmageLeft" | **Read/Write capability**: readable and writable<br>X1 coordinate of the watermark region.| 8267| XMAGE_TOP <sup>12+</sup> | "HwMnoteXmageTop" | **Read/Write capability**: readable and writable<br>Y1 coordinate of the watermark region.| 8268| XMAGE_RIGHT <sup>12+</sup> | "HwMnoteXmageRight" | **Read/Write capability**: readable and writable<br>X2 coordinate of the watermark region.| 8269| XMAGE_BOTTOM <sup>12+</sup> | "HwMnoteXmageBottom" | **Read/Write capability**: readable and writable<br>Y2 coordinate of the watermark region.| 8270| CLOUD_ENHANCEMENT_MODE <sup>12+</sup> | "HwMnoteCloudEnhancementMode" | **Read/Write capability**: readable and writable<br>Cloud enhancement mode.| 8271| WIND_SNAPSHOT_MODE <sup>12+</sup> | "HwMnoteWindSnapshotMode" | **Read/Write capability**: read-only<br>Motion snapshot mode.| 8272 8273## FragmentMapPropertyKey<sup>13+</sup> 8274 8275Enumerates the fragment map information. 8276 8277**System capability**: SystemCapability.Multimedia.Image.Core 8278 8279| Name | Value | Description | 8280| ------------- | --------------------- | ----------------------------------- | 8281| X_IN_ORIGINAL | "XInOriginal" | X coordinate of the upper left corner of the fragment map in the original image.| 8282| Y_IN_ORIGINAL | "YInOriginal" | Y coordinate of the upper left corner of the fragment map in the original image.| 8283| WIDTH | "FragmentImageWidth" | Width of the fragment map. | 8284| HEIGHT | "FragmentImageHeight" | Height of the fragment map. | 8285 8286## ImageFormat<sup>9+</sup> 8287 8288Enumerates the image formats. 8289 8290**System capability**: SystemCapability.Multimedia.Image.Core 8291 8292| Name | Value | Description | 8293| ------------ | ------ | -------------------- | 8294| YCBCR_422_SP | 1000 | YCBCR422 semi-planar format.| 8295| JPEG | 2000 | JPEG encoding format. | 8296 8297## ComponentType<sup>9+</sup> 8298 8299Enumerates the color component types of images. 8300 8301**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 8302 8303| Name | Value | Description | 8304| ----- | ------ | ----------- | 8305| YUV_Y | 1 | Luminance component. | 8306| YUV_U | 2 | Chrominance component. | 8307| YUV_V | 3 | Chrominance component. | 8308| JPEG | 4 | JPEG type.| 8309 8310## Component<sup>9+</sup> 8311 8312Describes the color components of an image. 8313 8314**System capability**: SystemCapability.Multimedia.Image.Core 8315 8316| Name | Type | Read Only| Optional| Description | 8317| ------------- | -------------------------------- | ---- | ---- | ------------ | 8318| componentType | [ComponentType](#componenttype9) | Yes | No | Color component type. | 8319| 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). | 8320| pixelStride | number | Yes | No | Pixel stride. | 8321| byteBuffer | ArrayBuffer | Yes | No | Component buffer.| 8322 8323## DecodingDynamicRange<sup>12+</sup> 8324 8325Describes the desired dynamic range of an image during decoding. 8326 8327**System capability**: SystemCapability.Multimedia.Image.Core 8328 8329| Name | Value | Description | 8330| ------------- | ----------| ------------ | 8331| 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. | 8332| SDR | 1 | The image is decoded according to the standard dynamic range. | 8333| 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. | 8334 8335## PackingDynamicRange<sup>12+</sup> 8336 8337Describes the desired dynamic range of an image during encoding. 8338 8339**System capability**: SystemCapability.Multimedia.Image.Core 8340 8341| Name | Value | Description | 8342| ------------- | ----------| ------------ | 8343| 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. | 8344| SDR | 1 | The image is decoded according to the standard dynamic range. | 8345 8346## HdrMetadataKey<sup>12+</sup> 8347 8348Enumerates the keys of HDR metadata used by [pixelmap](#pixelmap7). 8349 8350**System capability**: SystemCapability.Multimedia.Image.Core 8351 8352| Name | Value | Description | 8353| ------------- | ----------| ------------ | 8354| HDR_METADATA_TYPE | 0 | Metadata type used by [pixelmap](#pixelmap7). | 8355| HDR_STATIC_METADATA | 1 | Static metadata. | 8356| HDR_DYNAMIC_METADATA | 2 | Dynamic metadata. | 8357| HDR_GAINMAP_METADATA | 3 | Metadata used by gain maps. | 8358 8359## HdrMetadataType<sup>12+</sup> 8360 8361Enumerates the values available for **HDR_METADATA_TYPE** in [HdrMetadataKey](#hdrmetadatakey12). 8362 8363**System capability**: SystemCapability.Multimedia.Image.Core 8364 8365| Name | Value | Description | 8366| ------------- | ----------| ------------ | 8367| NONE | 0 | No metadata. | 8368| BASE | 1 | Metadata used for base graphics. | 8369| GAINMAP | 2 | Metadata used for gain maps. | 8370| ALTERNATE| 3 | Metadata used for synthesized HDR graphics. | 8371 8372## HdrStaticMetadata<sup>12+</sup> 8373 8374Describes the static metadata keys, that is, the values available for **HDR_STATIC_METADATA** in [HdrMetadataKey](#hdrmetadatakey12). 8375 8376**System capability**: SystemCapability.Multimedia.Image.Core 8377 8378| Name | Type | Read Only| Optional| Description | 8379| ------------- | ----------| -- | -- | ------------ | 8380| 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]. | 8381| 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]. | 8382| 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]. | 8383| 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]. | 8384| maxLuminance | number | No| No| Maximum luminance of the main monitor. The unit is 1, and the maximum value is 65535. | 8385| minLuminance | number | No| No| Minimum luminance of the main monitor. The unit is 0.0001, and the maximum value is 6.55535. | 8386| maxContentLightLevel | number | No| No| Maximum luminance of the displayed content. The unit is 1, and the maximum value is 65535. | 8387| maxFrameAverageLightLevel | number | No| No| Maximum average luminance of the displayed content. The unit is 1, and the maximum value is 65535.| 8388 8389## GainmapChannel<sup>12+</sup> 8390 8391Describes the data content of a single channel of the gain map. For details, see ISO 21496-1. 8392 8393**System capability**: SystemCapability.Multimedia.Image.Core 8394 8395| Name | Type | Read Only| Optional| Description | 8396| ------------- | ----------| -- | -- | ------------ | 8397| gainmapMax | number | No| No| Maximum value of the gain map. For details, see ISO 21496-1. | 8398| gainmapMin | number | No| No| Minimum value of the gain map. For details, see ISO 21496-1. | 8399| gamma | number | No| No| Gamma. For details, see ISO 21496-1. | 8400| baseOffset | number | No| No| Offset of the base graphic. For details, see ISO 21496-1. | 8401| alternateOffset | number | No| No| Offset of the alternative graphic that can be extracted. For details, see ISO 21496-1. | 8402 8403## HdrGainmapMetadata<sup>12+</sup> 8404 8405Describes 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. 8406 8407**System capability**: SystemCapability.Multimedia.Image.Core 8408 8409| Name | Type | Read Only| Optional| Description | 8410| ------------- | ----------| -- | -- | ------------ | 8411| writerVersion | number | No| No| Version used by the metadata editor. | 8412| miniVersion | number | No| No| Minimum version that needs to be understood for metadata parsing. | 8413| 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. | 8414| useBaseColorFlag | boolean | No| No| Whether to use the color space of the base graphic. For details, see ISO 21496-1. | 8415| 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. | 8416| alternateHeadroom | number | No| No| Headroom of the alternate graphic. For details, see ISO 21496-1. | 8417| channels | Array<[GainmapChannel](#gainmapchannel12)> | No| No| Number of channels. The length is 3. For details, see ISO 21496-1.| 8418 8419## HdrMetadataValue<sup>12+</sup> 8420 8421type HdrMetadataValue = HdrMetadataType | HdrStaticMetadata | ArrayBuffer | HdrGainmapMetadata 8422 8423Describes the HDR metadata values used by a PixelMap, which corresponds to the values available for [HdrMetadataKey](#hdrmetadatakey12). 8424 8425**System capability**: SystemCapability.Multimedia.Image.Core 8426 8427| Type | Description | 8428| ------------------- | ----------------------------------------------- | 8429| [HdrMetadataType](#hdrmetadatatype12) | Metadata value corresponding to the **HDR_GAINMAP_METADATA** key in [HdrMetadataKey](#hdrmetadatakey12).| 8430| [HdrStaticMetadata](#hdrstaticmetadata12) | Metadata value corresponding to the **HDR_STATIC_METADATA** key in [HdrMetadataKey](#hdrmetadatakey12).| 8431| ArrayBuffer | Metadata value corresponding to the **HDR_DYNAMIC_METADATA** key in [HdrMetadataKey](#hdrmetadatakey12).| 8432| [HdrGainmapMetadata](#hdrgainmapmetadata12) | Metadata value corresponding to the **HDR_GAINMAP_METADATA** key in [HdrMetadataKey](#hdrmetadatakey12).| 8433 8434## AntiAliasingLevel<sup>12+</sup> 8435 8436Enumerates the anti-aliasing levels. 8437 8438**Atomic service API**: This API can be used in atomic services since API version 14. 8439 8440**System capability**: SystemCapability.Multimedia.Image.Core 8441 8442| Name | Value | Description | 8443| ---------------------- | ------ | ----------------- | 8444| NONE | 0 | Nearest neighbor interpolation. | 8445| LOW | 1 | Bilinear interpolation. | 8446| MEDIUM | 2 | Bilinear interpolation with mipmap enabled. You are advised to use this value when zooming out an image. | 8447| HIGH | 3 | Cubic interpolation. | 8448 8449## AllocatorType<sup>15+</sup> 8450 8451Enumerates the types of the memory used for image decoding. 8452 8453**Atomic service API**: This API can be used in atomic services since API version 15. 8454 8455**System capability**: SystemCapability.Multimedia.Image.Core 8456 8457| Name | Value | Description | 8458| ------------ | ---- | ---------------------------------- | 8459| AUTO | 0 | The system determines whether DMA memory or shared memory is used. | 8460| DMA | 1 | DMA memory is used. | 8461| SHARE_MEMORY | 2 | Shared memory is used.| 8462 8463## Supplementary Information 8464 8465### SVG Tags 8466 8467The 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: 8468- a 8469- circla 8470- clipPath 8471- defs 8472- ellipse 8473- feBlend 8474- feColorMatrix 8475- feComposite 8476- feDiffuseLighting 8477- feDisplacementMap 8478- feDistantLight 8479- feFlood 8480- feGaussianBlur 8481- feImage 8482- feMorphology 8483- feOffset 8484- fePointLight 8485- feSpecularLighting 8486- feSpotLight 8487- feTurbulence 8488- filter 8489- g 8490- image 8491- line 8492- linearGradient 8493- mask 8494- path 8495- pattern 8496- polygon 8497- polyline 8498- radialGradient 8499- rect 8500- stop 8501- svg 8502- text 8503- textPath 8504- tspan 8505- use 8506 8507<!--no_check-->