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.| 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 Demo() { 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: 3, 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.| 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 Demo() { 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: 3, 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 Demo() { 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: 4, 298 size: { height: 4, width: 6 }, 299 alphaType: 3 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> The width and height of [Region](#region8).size must be the same as those of the [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md). 329> You need to adjust the width and height of the [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md) when switching the folded state of a foldable device. 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 is obtained from [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md).| 338| region | [Region](#region8) | Yes | Region information.| 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 Demo(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> The width and height of [Region](#region8).size must be the same as those of the [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md). 378> You need to adjust the width and height of the [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md) when switching the folded state of a foldable device. 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 is obtained from [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md).| 387| region | [Region](#region8) | Yes | Region information.| 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.createPixelMapSync<sup>12+</sup> 417 418createPixelMapSync(colors: ArrayBuffer, options: InitializationOptions): PixelMap 419 420Creates a **PixelMap** object with the specified pixel properties. This API returns the result synchronously. 421 422**System capability**: SystemCapability.Multimedia.Image.Core 423 424**Parameters** 425 426| Name | Type | Mandatory| Description | 427| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 428| 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.| 429| options | [InitializationOptions](#initializationoptions8) | Yes | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.| 430 431**Return value** 432| Type | Description | 433| -------------------------------- | --------------------- | 434| [PixelMap](#pixelmap7) | Returns a **PixelMap** object if the operation is successful; throws an error otherwise.| 435 436**Error codes** 437 438For details about the error codes, see [Image Error Codes](errorcode-image.md). 439 440| ID| Error Message| 441| ------- | --------------------------------------------| 442| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 443 444**Example** 445 446```ts 447import { BusinessError } from '@kit.BasicServicesKit'; 448 449async function Demo() { 450 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. 451 let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } 452 let pixelMap : image.PixelMap = image.createPixelMapSync(color, opts); 453 return pixelMap; 454} 455``` 456 457## image.createPixelMapSync<sup>12+</sup> 458 459createPixelMapSync(options: InitializationOptions): PixelMap 460 461Creates a **PixelMap** object with the specified pixel properties. This API returns the result synchronously. 462 463**System capability**: SystemCapability.Multimedia.Image.Core 464 465**Parameters** 466 467| Name | Type | Mandatory| Description | 468| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 469| options | [InitializationOptions](#initializationoptions8) | Yes | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.| 470 471**Return value** 472| Type | Description | 473| -------------------------------- | --------------------- | 474| [PixelMap](#pixelmap7) | Returns a **PixelMap** object if the operation is successful; throws an error otherwise.| 475 476**Error codes** 477 478For details about the error codes, see [Image Error Codes](errorcode-image.md). 479 480| ID| Error Message| 481| ------- | --------------------------------------------| 482| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 483 484**Example** 485 486```ts 487import { BusinessError } from '@kit.BasicServicesKit'; 488 489async function Demo() { 490 let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } 491 let pixelMap : image.PixelMap = image.createPixelMapSync(opts); 492 return pixelMap; 493} 494``` 495 496## image.createPremultipliedPixelMap<sup>12+</sup> 497 498createPremultipliedPixelMap(src: PixelMap, dst: PixelMap, callback: AsyncCallback\<void>): void 499 500Converts 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. 501 502**System capability**: SystemCapability.Multimedia.Image.Core 503 504**Parameters** 505 506| Name | Type | Mandatory| Description | 507| -------- | ------------------------------------------------ | ---- | -------------------------- | 508| src | [PixelMap](#pixelmap7) | Yes | Source **PixelMap** object.| 509| dst | [PixelMap](#pixelmap7) | Yes | Target **PixelMap** object.| 510|callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 511 512**Error codes** 513 514For details about the error codes, see [Image Error Codes](errorcode-image.md). 515 516| ID| Error Message| 517| ------- | --------------------------------------------| 518| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 519| 62980103 | The image data is not supported | 520| 62980246 | Failed to read the pixelMap | 521| 62980248 | Pixelmap not allow modify | 522 523**Example** 524 525```ts 526import { BusinessError } from '@kit.BasicServicesKit'; 527 528async function Demo() { 529 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. 530 let bufferArr = new Uint8Array(color); 531 for (let i = 0; i < bufferArr.length; i += 4) { 532 bufferArr[i] = 255; 533 bufferArr[i+1] = 255; 534 bufferArr[i+2] = 122; 535 bufferArr[i+3] = 122; 536 } 537 let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 2, width: 2 } , alphaType: 3} 538 let srcPixelmap = image.createPixelMapSync(color, optsForUnpre); 539 let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 2, width: 2 } , alphaType: 2} 540 let dstPixelMap = image.createPixelMapSync(optsForPre); 541 image.createPremultipliedPixelMap(srcPixelmap, dstPixelMap, (error: BusinessError) => { 542 if(error) { 543 console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`); 544 return; 545 } else { 546 console.info('Succeeded in converting pixelmap.'); 547 } 548 }) 549} 550``` 551 552## image.createPremultipliedPixelMap<sup>12+</sup> 553 554createPremultipliedPixelMap(src: PixelMap, dst: PixelMap): Promise\<void> 555 556Converts 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. 557 558**System capability**: SystemCapability.Multimedia.Image.Core 559 560**Parameters** 561 562| Name | Type | Mandatory| Description | 563| -------- | ------------------------------------------------ | ---- | -------------------------- | 564| src | [PixelMap](#pixelmap7) | Yes | Source **PixelMap** object.| 565| dst | [PixelMap](#pixelmap7) | Yes | Target **PixelMap** object.| 566 567**Return value** 568 569| Type | Description | 570| -------------------------------- | ----------------------------------------------------------------------- | 571| Promise\<void> | Promise that returns no value.| 572 573**Error codes** 574 575For details about the error codes, see [Image Error Codes](errorcode-image.md). 576 577| ID| Error Message| 578| ------- | --------------------------------------------| 579| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 580| 62980103 | The image data is not supported | 581| 62980246 | Failed to read the pixelMap | 582| 62980248 | Pixelmap not allow modify | 583 584**Example** 585 586```ts 587import { BusinessError } from '@kit.BasicServicesKit'; 588 589async function Demo() { 590 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. 591 let bufferArr = new Uint8Array(color); 592 for (let i = 0; i < bufferArr.length; i += 4) { 593 bufferArr[i] = 255; 594 bufferArr[i+1] = 255; 595 bufferArr[i+2] = 122; 596 bufferArr[i+3] = 122; 597 } 598 let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 2, width: 2 } , alphaType: 3} 599 let srcPixelmap = image.createPixelMapSync(color, optsForUnpre); 600 let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 2, width: 2 } , alphaType: 2} 601 let dstPixelMap = image.createPixelMapSync(optsForPre); 602 image.createPremultipliedPixelMap(srcPixelmap, dstPixelMap).then(() => { 603 console.info('Succeeded in converting pixelmap.'); 604 }).catch((error: BusinessError) => { 605 console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`); 606 }) 607} 608``` 609 610## image.createUnpremultipliedPixelMap<sup>12+</sup> 611 612createUnpremultipliedPixelMap(src: PixelMap, dst: PixelMap, callback: AsyncCallback\<void>): void 613 614Converts 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. 615 616**System capability**: SystemCapability.Multimedia.Image.Core 617 618**Parameters** 619 620| Name | Type | Mandatory| Description | 621| -------- | ------------------------------------------------ | ---- | -------------------------- | 622| src | [PixelMap](#pixelmap7) | Yes | Source **PixelMap** object.| 623| dst | [PixelMap](#pixelmap7) | Yes | Target **PixelMap** object.| 624|callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 625 626**Error codes** 627 628For details about the error codes, see [Image Error Codes](errorcode-image.md). 629 630| ID| Error Message| 631| ------- | --------------------------------------------| 632| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 633| 62980103 | The image data is not supported | 634| 62980246 | Failed to read the pixelMap | 635| 62980248 | Pixelmap not allow modify | 636 637**Example** 638 639```ts 640import { BusinessError } from '@kit.BasicServicesKit'; 641 642async function Demo() { 643 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. 644 let bufferArr = new Uint8Array(color); 645 for (let i = 0; i < bufferArr.length; i += 4) { 646 bufferArr[i] = 255; 647 bufferArr[i+1] = 255; 648 bufferArr[i+2] = 122; 649 bufferArr[i+3] = 122; 650 } 651 let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 2, width: 2 } , alphaType: 2} 652 let srcPixelmap = image.createPixelMapSync(color, optsForPre); 653 let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 2, width: 2 } , alphaType: 3} 654 let dstPixelMap = image.createPixelMapSync(optsForUnpre); 655 image.createUnpremultipliedPixelMap(srcPixelmap, dstPixelMap, (error: BusinessError) => { 656 if(error) { 657 console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`); 658 return; 659 } else { 660 console.info('Succeeded in converting pixelmap.'); 661 } 662 }) 663} 664``` 665 666## image.createUnpremultipliedPixelMap<sup>12+</sup> 667 668createUnpremultipliedPixelMap(src: PixelMap, dst: PixelMap): Promise\<void> 669 670Converts 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. 671 672**System capability**: SystemCapability.Multimedia.Image.Core 673 674**Parameters** 675 676| Name | Type | Mandatory| Description | 677| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 678| src | [PixelMap](#pixelmap7) | Yes | Source **PixelMap** object.| 679| dst | [PixelMap](#pixelmap7) | Yes | Target **PixelMap** object.| 680 681**Return value** 682 683| Type | Description | 684| -------------------------------- | ----------------------------------------------------------------------- | 685| Promise\<void> | Promise that returns no value.| 686 687**Error codes** 688 689For details about the error codes, see [Image Error Codes](errorcode-image.md). 690 691| ID| Error Message| 692| ------- | --------------------------------------------| 693| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 694| 62980103 | The image data is not supported | 695| 62980246 | Failed to read the pixelMap. | 696| 62980248 | Pixelmap not allow modify. | 697 698**Example** 699 700```ts 701import { BusinessError } from '@kit.BasicServicesKit'; 702 703async function Demo() { 704 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. 705 let bufferArr = new Uint8Array(color); 706 for (let i = 0; i < bufferArr.length; i += 4) { 707 bufferArr[i] = 255; 708 bufferArr[i+1] = 255; 709 bufferArr[i+2] = 122; 710 bufferArr[i+3] = 122; 711 } 712 let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 2, width: 2 } , alphaType: 2} 713 let srcPixelmap = image.createPixelMapSync(color, optsForPre); 714 let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 2, width: 2 } , alphaType: 3} 715 let dstPixelMap = image.createPixelMapSync(optsForUnpre); 716 image.createUnpremultipliedPixelMap(srcPixelmap, dstPixelMap).then(() => { 717 console.info('Succeeded in converting pixelmap.'); 718 }).catch((error: BusinessError) => { 719 console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`); 720 }) 721} 722``` 723 724 725## Picture<sup>13+</sup> 726 727An 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. 728 729### Properties 730 731**System capability**: SystemCapability.Multimedia.Image.Core 732 733### getMainPixelmap<sup>13+</sup> 734 735getMainPixelmap(): PixelMap 736 737Obtains the **PixelMap** object of the main picture. This API returns the result synchronously. 738 739**System capability**: SystemCapability.Multimedia.Image.Core 740 741**Return value** 742 743| Type | Description | 744| ------------------- | ---------------------- | 745| [PixelMap](#pixelmap7) | **PixelMap** object.| 746 747**Example** 748 749```ts 750import { BusinessError } from '@kit.BasicServicesKit'; 751import { image } from '@kit.ImageKit'; 752 753async function GetMainPixelmap() { 754 let funcName = "getMainPixelmap"; 755 if (pictureObj != null) { 756 let mainPixelmap: image.PixelMap = pictureObj.getMainPixelmap(); 757 if (mainPixelmap != null) { 758 mainPixelmap.getImageInfo().then((imageInfo: image.ImageInfo) => { 759 if (imageInfo != null) { 760 console.info('GetMainPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width); 761 } 762 }).catch((error: BusinessError) => { 763 console.error(funcName, 'Failed error.code: ${error.code} ,error.message: ${error.message}'); 764 }); 765 } 766 } else { 767 console.info('PictureObj is null'); 768 } 769} 770``` 771 772### getHdrComposedPixelmap<sup>13+</sup> 773 774getHdrComposedPixelmap(): Promise\<PixelMap> 775 776Generates an HDR image and obtains its **PixelMap** object. This API uses a promise to return the result. 777 778**System capability**: SystemCapability.Multimedia.Image.Core 779 780**Return value** 781 782| Type | Description | 783| ----------------------------- | --------------------------- | 784| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.| 785 786**Error codes** 787 788For details about the error codes, see [Image Error Codes](errorcode-image.md). 789 790| ID| Error Message | 791| -------- | ---------------------- | 792| 7600901 | Unknown error. | 793| 7600201 | Unsupported operation. | 794 795**Example** 796 797```ts 798import { BusinessError } from '@kit.BasicServicesKit'; 799import { image } from '@kit.ImageKit'; 800 801async function GetHdrComposedPixelmap() { 802 let funcName = "getHdrComposedPixelmap"; 803 if (pictureObj != null) { // An HDR image is contained. 804 let hdrComposedPixelmap: image.PixelMap = await pictureObj.getHdrComposedPixelmap(); 805 if (hdrComposedPixelmap != null) { 806 hdrComposedPixelmap.getImageInfo().then((imageInfo: image.ImageInfo) => { 807 if (imageInfo != null) { 808 console.info('GetHdrComposedPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width); 809 } 810 }).catch((error: BusinessError) => { 811 console.error(funcName, 'Failed error.code: ${error.code} ,error.message: ${error.message}'); 812 }); 813 } 814 } else { 815 console.info('PictureObj is null'); 816 } 817} 818``` 819 820### getGainmapPixelmap<sup>13+</sup> 821 822getGainmapPixelmap(): PixelMap | null 823 824Obtains the **PixelMap** object of the gain map. 825 826**System capability**: SystemCapability.Multimedia.Image.Core 827 828**Return value** 829 830| Type | Description | 831| ------------------------- | -------------------------------------- | 832| [PixelMap](#pixelmap7) \| null | **PixelMap** object obtained. If there is no **PixelMap** object, null is returned.| 833 834**Example** 835 836```ts 837import { BusinessError } from '@kit.BasicServicesKit'; 838import { image } from '@kit.ImageKit'; 839 840async function GetGainmapPixelmap() { 841 let funcName = "getGainmapPixelmap"; 842 if (pictureObj != null) { // A gain map is contained. 843 let gainPixelmap: image.PixelMap | null = pictureObj.getGainmapPixelmap(); 844 if (gainPixelmap != null) { 845 gainPixelmap.getImageInfo().then((imageInfo: image.ImageInfo) => { 846 if (imageInfo != null) { 847 console.info('GetGainmapPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width); 848 } else { 849 console.info('GainPixelmap is null'); 850 } 851 }).catch((error: BusinessError) => { 852 console.error(funcName, 'Failed error.code: ${error.code} ,error.message: ${error.message}'); 853 }); 854 } else { 855 console.info('GainPixelmap is null'); 856 } 857 } else { 858 console.info('PictureObj is null'); 859 } 860} 861``` 862 863### setAuxiliaryPicture<sup>13+</sup> 864 865setAuxiliaryPicture(type: AuxiliaryPictureType, auxiliaryPicture: AuxiliaryPicture): void 866 867Sets an auxiliary picture. 868 869**System capability**: SystemCapability.Multimedia.Image.Core 870 871**Parameters** 872 873| Name | Type | Mandatory| Description | 874| ---------------- | -------------------- | ---- | ------------ | 875| type | [AuxiliaryPictureType](#auxiliarypicturetype13) | Yes | Type of the auxiliary picture.| 876| auxiliaryPicture | [AuxiliaryPicture](#auxiliarypicture13) | Yes | **AuxiliaryPicture** object.| 877 878**Error codes** 879 880For details about the error codes, see [Image Error Codes](errorcode-image.md). 881 882| ID| Error Message | 883| -------- | ------------------------------------------------------------ | 884| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 885 886**Example** 887 888```ts 889import { image } from '@kit.ImageKit'; 890 891async function SetAuxiliaryPicture() { 892 const context = getContext(); 893 const resourceMgr = context.resourceManager; 894 const rawFile = await resourceMgr.getRawFileContent("hdr.jpg"); // Support for HDR images is required. 895 let ops: image.SourceOptions = { 896 sourceDensity: 98, 897 } 898 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 899 let pixelMap: image.PixelMap = await imageSource.createPixelMap(); 900 let auxPicture: image.Picture = image.createPicture(pixelMap); 901 if (auxPicture != null) { 902 console.info('Create picture succeeded'); 903 } else { 904 console.info('Create picture failed'); 905 } 906 907 if (pictureObj != null) { 908 let type: image.AuxiliaryPictureType = image.AuxiliaryPictureType.GAINMAP; 909 let auxPictureObj: image.AuxiliaryPicture | null = await auxPicture.getAuxiliaryPicture(type); 910 if (auxPictureObj != null) { 911 pictureObj.setAuxiliaryPicture(type, auxPictureObj); 912 } 913 } 914} 915``` 916 917### getAuxiliaryPicture<sup>13+</sup> 918 919getAuxiliaryPicture(type: AuxiliaryPictureType): AuxiliaryPicture | null 920 921Obtains an auxiliary picture by type. 922 923**System capability**: SystemCapability.Multimedia.Image.Core 924 925**Parameters** 926 927| Name| Type | Mandatory| Description | 928| ------ | -------------------- | ---- | ------------ | 929| type | [AuxiliaryPictureType](#auxiliarypicturetype13) | Yes | Type of the auxiliary picture.| 930 931**Return value** 932 933| Type | Description | 934| ---------------------- | ---------------------------------------------- | 935| [AuxiliaryPicture](#auxiliarypicture13) \| null | **AuxiliaryPicture** object. If there is no **AuxiliaryPicture** object, null is returned.| 936 937**Error codes** 938 939For details about the error codes, see [Image Error Codes](errorcode-image.md). 940 941| ID| Error Message | 942| -------- | ------------------------------------------------------------ | 943| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 944 945**Example** 946 947```ts 948import { image } from '@kit.ImageKit'; 949 950async function GetAuxiliaryPicture() { 951 if (pictureObj != null) { 952 let type: image.AuxiliaryPictureType = image.AuxiliaryPictureType.GAINMAP; 953 let auxPictureObj: image.AuxiliaryPicture | null = pictureObj.getAuxiliaryPicture(type); 954 } 955} 956``` 957 958### setMetadata<sup>13+</sup> 959 960setMetadata(metadataType: MetadataType, metadata: Metadata): Promise\<void> 961 962Sets the metadata for this **Picture** object. 963 964**System capability**: SystemCapability.Multimedia.Image.Core 965 966**Parameters** 967 968| Name | Type | Mandatory| Description | 969| ------------ | ------------ | ---- | ------------ | 970| metadataType | [MetadataType](#metadatatype13) | Yes | Metadata type.| 971| metadata | [Metadata](#metadata13) | Yes | **Metadata** object.| 972 973**Return value** 974 975| Type | Description | 976| -------------- | -------------------------------------- | 977| Promise\<void> | Promise that returns no value.| 978 979**Error codes** 980 981For details about the error codes, see [Image Error Codes](errorcode-image.md). 982 983| ID| Error Message | 984| -------- | ------------------------------------------------------------ | 985| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 986| 7600202 | Unsupported metadata. Possible causes: Unsupported metadata type. | 987 988**Example** 989 990```ts 991import { BusinessError } from '@kit.BasicServicesKit'; 992import { image } from '@kit.ImageKit'; 993 994async function SetPictureObjMetadata() { 995 const exifContext = getContext(); 996 const exifResourceMgr = exifContext.resourceManager; 997 const exifRawFile = await exifResourceMgr.getRawFileContent("exif.jpg"); // The image contains EXIF metadata. 998 let exifOps: image.SourceOptions = { 999 sourceDensity: 98, 1000 } 1001 let exifImageSource: image.ImageSource = image.createImageSource(exifRawFile.buffer as ArrayBuffer, exifOps); 1002 let exifCommodityPixelMap: image.PixelMap = await exifImageSource.createPixelMap(); 1003 let exifPictureObj: image.Picture = image.createPicture(exifCommodityPixelMap); 1004 if (exifPictureObj != null) { 1005 console.info('Create picture succeeded'); 1006 } else { 1007 console.info('Create picture failed'); 1008 } 1009 1010 if (pictureObj != null) { 1011 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 1012 let exifMetaData: image.Metadata = await exifPictureObj.getMetadata(metadataType); 1013 pictureObj.setMetadata(metadataType, exifMetaData).then(() => { 1014 console.info('Set metadata success'); 1015 }).catch((error: BusinessError) => { 1016 console.error('Failed to set metadata. error.code: ' +JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message)); 1017 }); 1018 } else { 1019 console.info('PictureObj is null'); 1020 } 1021} 1022``` 1023 1024### getMetadata<sup>13+</sup> 1025 1026getMetadata(metadataType: MetadataType): Promise\<Metadata> 1027 1028Obtains the metadata of this **Picture** object. 1029 1030**System capability**: SystemCapability.Multimedia.Image.Core 1031 1032**Parameters** 1033 1034| Name | Type | Mandatory| Description | 1035| ------------ | ------------ | ---- | ------------ | 1036| metadataType | [MetadataType](#metadatatype13) | Yes | Metadata type.| 1037 1038**Return value** 1039 1040| Type | Description | 1041| ------------------ | ------------------------- | 1042| Promise\<[Metadata](#metadata13)> | Promise used to return the metadata.| 1043 1044**Error codes** 1045 1046For details about the error codes, see [Image Error Codes](errorcode-image.md). 1047 1048| ID| Error Message | 1049| -------- | ------------------------------------------------------------ | 1050| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 1051| 7600202 | Unsupported metadata. Possible causes: Unsupported metadata type. | 1052 1053**Example** 1054 1055```ts 1056import { image } from '@kit.ImageKit'; 1057 1058async function GetPictureObjMetadataProperties() { 1059 if (pictureObj != null) { 1060 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 1061 let pictureObjMetaData: image.Metadata = await pictureObj.getMetadata(metadataType); 1062 if (pictureObjMetaData != null) { 1063 console.info('get picture metadata success'); 1064 } else { 1065 console.info('get picture metadata is failed'); 1066 } 1067 } else { 1068 console.info(" pictureObj is null"); 1069 } 1070} 1071``` 1072 1073### marshalling<sup>13+</sup> 1074 1075marshalling(sequence: rpc.MessageSequence): void 1076 1077Marshals this **Picture** object and writes it to a **MessageSequence** object. 1078 1079**System capability**: SystemCapability.Multimedia.Image.Core 1080 1081**Parameters** 1082 1083| Name | Type | Mandatory| Description | 1084| -------- | ------------------------------------------------------------------- | ---- | ------------------------- | 1085| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | Yes | **MessageSequence** object.| 1086 1087**Error codes** 1088 1089For details about the error codes, see [Image Error Codes](errorcode-image.md). 1090 1091| ID| Error Message | 1092| -------- | ------------------------------------------------------------ | 1093| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 1094| 62980097 | IPC error. | 1095 1096**Example** 1097 1098```ts 1099import { BusinessError } from '@kit.BasicServicesKit'; 1100import { image } from '@kit.ImageKit'; 1101import { rpc } from '@kit.IPCKit'; 1102 1103class MySequence implements rpc.Parcelable { 1104 picture: image.Picture | null = null; 1105 constructor(conPicture: image.Picture) { 1106 this.picture = conPicture; 1107 } 1108 marshalling(messageSequence: rpc.MessageSequence) { 1109 if(this.picture != null) { 1110 this.picture.marshalling(messageSequence); 1111 console.info('Marshalling success !'); 1112 return true; 1113 } else { 1114 console.info('Marshalling failed !'); 1115 return false; 1116 } 1117 } 1118 unmarshalling(messageSequence : rpc.MessageSequence) { 1119 this.picture = image.createPictureFromParcel(messageSequence); 1120 this.picture.getMainPixelmap().getImageInfo().then((imageInfo : image.ImageInfo) => { 1121 console.info('Unmarshalling to get mainPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width); 1122 }).catch((error: BusinessError) => { 1123 console.error('Unmarshalling failed error.code: ${error.code} ,error.message: ${error.message}'); 1124 }); 1125 return true; 1126 } 1127} 1128 1129async function Marshalling_UnMarshalling() { 1130 if (pictureObj != null) { 1131 let parcelable: MySequence = new MySequence(pictureObj); 1132 let data: rpc.MessageSequence = rpc.MessageSequence.create(); 1133 // marshalling 1134 data.writeParcelable(parcelable); 1135 let ret: MySequence = new MySequence(pictureObj); 1136 // unmarshalling 1137 data.readParcelable(ret); 1138 } else { 1139 console.info('PictureObj is null'); 1140 } 1141} 1142``` 1143 1144### release<sup>13+</sup> 1145 1146release(): void 1147 1148Releases this **Picture** object. 1149 1150**System capability**: SystemCapability.Multimedia.Image.Core 1151 1152**Example** 1153 1154```ts 1155import { image } from '@kit.ImageKit'; 1156 1157async function Release() { 1158 let funcName = "Release"; 1159 if (pictureObj != null) { 1160 pictureObj.release(); 1161 if (pictureObj.getMainPixelmap() == null) { 1162 console.info(funcName, 'Success !'); 1163 } else { 1164 console.info(funcName, 'Failed !'); 1165 } 1166 } else { 1167 console.info('PictureObj is null'); 1168 } 1169} 1170``` 1171 1172## PixelMap<sup>7+</sup> 1173 1174Provides 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. 1175 1176Since 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. 1177 1178Before calling any API in **PixelMap**, you must use [image.createPixelMap](#imagecreatepixelmap8) to create a **PixelMap** object. 1179 1180### Properties 1181 1182**System capability**: SystemCapability.Multimedia.Image.Core 1183 1184| Name | Type | Readable| Writable| Description | 1185| -----------------| ------- | ---- | ---- | -------------------------- | 1186| 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.| 1187| isStrideAlignment<sup>11+</sup> | boolean | Yes | No | Whether the image memory is the DMA memory.| 1188 1189### readPixelsToBuffer<sup>7+</sup> 1190 1191readPixelsToBuffer(dst: ArrayBuffer): Promise\<void> 1192 1193Reads the pixels of this PixelMap and writes the data to the buffer based on the pixel format of the PixelMap. This API uses a promise to return the result. 1194 1195**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1196 1197**Atomic service API**: This API can be used in atomic services since API version 11. 1198 1199**System capability**: SystemCapability.Multimedia.Image.Core 1200 1201**Parameters** 1202 1203| Name| Type | Mandatory| Description | 1204| ------ | ----------- | ---- | ----------------------------------------------------------------------------------------------------- | 1205| dst | ArrayBuffer | Yes | Buffer to which the pixels will be written. The buffer size is obtained by calling [getPixelBytesNumber](#getpixelbytesnumber7).| 1206 1207**Return value** 1208 1209| Type | Description | 1210| -------------- | ----------------------------------------------- | 1211| Promise\<void> | Promise that returns no value. | 1212 1213**Example** 1214 1215```ts 1216import { BusinessError } from '@kit.BasicServicesKit'; 1217 1218async function Demo() { 1219 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. 1220 if (pixelMap != undefined) { 1221 pixelMap.readPixelsToBuffer(readBuffer).then(() => { 1222 console.info('Succeeded in reading image pixel data.'); // Called if the condition is met. 1223 }).catch((error: BusinessError) => { 1224 console.error(`Failed to read image pixel data. code is ${error.code}, message is ${error.message}`); // Called if no condition is met. 1225 }) 1226 } 1227} 1228``` 1229 1230### readPixelsToBuffer<sup>7+</sup> 1231 1232readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\<void>): void 1233 1234Reads the pixels of this PixelMap and writes the data to the buffer based on the pixel format of the PixelMap. This API uses an asynchronous callback to return the result. 1235 1236**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1237 1238**Atomic service API**: This API can be used in atomic services since API version 11. 1239 1240**System capability**: SystemCapability.Multimedia.Image.Core 1241 1242**Parameters** 1243 1244| Name | Type | Mandatory| Description | 1245| -------- | -------------------- | ---- | ----------------------------------------------------------------------------------------------------- | 1246| dst | ArrayBuffer | Yes | Buffer to which the pixels will be written. The buffer size is obtained by calling [getPixelBytesNumber](#getpixelbytesnumber7).| 1247| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 1248 1249**Example** 1250 1251```ts 1252import { BusinessError } from '@kit.BasicServicesKit'; 1253 1254async function Demo() { 1255 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. 1256 if (pixelMap != undefined) { 1257 pixelMap.readPixelsToBuffer(readBuffer, (error: BusinessError, res: void) => { 1258 if(error) { 1259 console.error(`Failed to read image pixel data. code is ${error.code}, message is ${error.message}`); // Called if no condition is met. 1260 return; 1261 } else { 1262 console.info('Succeeded in reading image pixel data.'); // Called if the condition is met. 1263 } 1264 }) 1265 } 1266} 1267``` 1268 1269### readPixelsToBufferSync<sup>12+</sup> 1270 1271readPixelsToBufferSync(dst: ArrayBuffer): void 1272 1273Reads the pixels of this PixelMap and writes the data to the buffer based on the pixel format of the PixelMap. This API returns the result synchronously. 1274 1275**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1276 1277**Atomic service API**: This API can be used in atomic services since API version 12. 1278 1279**System capability**: SystemCapability.Multimedia.Image.Core 1280 1281**Parameters** 1282 1283| Name | Type | Mandatory| Description | 1284| -------- | -------------------- | ---- | ----------------------------------------------------------------------------------------------------- | 1285| dst | ArrayBuffer | Yes | Buffer to which the pixels will be written. The buffer size is obtained by calling [getPixelBytesNumber](#getpixelbytesnumber7).| 1286 1287**Error codes** 1288 1289For details about the error codes, see [Image Error Codes](errorcode-image.md). 1290 1291| ID| Error Message| 1292| ------- | --------------------------------------------| 1293| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 1294| 501 | Resource Unavailable | 1295 1296**Example** 1297 1298```ts 1299import { BusinessError } from '@kit.BasicServicesKit'; 1300 1301async function Demo() { 1302 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. 1303 if (pixelMap != undefined) { 1304 pixelMap.readPixelsToBufferSync(readBuffer); 1305 } 1306} 1307``` 1308 1309### readPixels<sup>7+</sup> 1310 1311readPixels(area: PositionArea): Promise\<void> 1312 1313Reads the pixels in the area (specified by [PositionArea] (#positionarea7).region) of this PixelMap and writes the data to the [PositionArea](#positionarea7).pixels buffer. This API uses a promise to return the result. 1314 1315When the pixel format of the PixelMap is RGB, the data is read from the PixelMap in the BGRA_8888 format. 1316 1317You can use a formula to calculate the size of the memory to be applied for based on **PositionArea**. 1318 1319YUV region calculation formula: region to read (region.size{width * height}) * 1.5 (1 * Y component + 0.25 * U component + 0.25 * V component) 1320 1321RGBA region calculation formula: region to read (region.size{width * height}) * 4 (1 * R component + 1 * G component + 1 * B component + 1 * A component) 1322 1323**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1324 1325**Atomic service API**: This API can be used in atomic services since API version 11. 1326 1327**System capability**: SystemCapability.Multimedia.Image.Core 1328 1329**Parameters** 1330 1331| Name| Type | Mandatory| Description | 1332| ------ | ------------------------------ | ---- | ------------------------ | 1333| area | [PositionArea](#positionarea7) | Yes | Area from which the pixels will be read.| 1334 1335**Return value** 1336 1337| Type | Description | 1338| :------------- | :-------------------------------------------------- | 1339| Promise\<void> | Promise that returns no value. | 1340 1341**Example** 1342 1343```ts 1344import { BusinessError } from '@kit.BasicServicesKit'; 1345 1346async function Demo() { 1347 const area: image.PositionArea = { 1348 pixels: new ArrayBuffer(8), // 8 is the size of the PixelMap buffer to create. The value is calculated as follows: height * width * 4. 1349 offset: 0, 1350 stride: 8, 1351 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 1352 }; 1353 if (pixelMap != undefined) { 1354 pixelMap.readPixels(area).then(() => { 1355 console.info('Succeeded in reading the image data in the area.'); // Called if the condition is met. 1356 }).catch((error: BusinessError) => { 1357 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. 1358 }) 1359 } 1360} 1361 1362async function Demo() { 1363 const area: image.PositionArea = { 1364 pixels: new ArrayBuffer(6), // 6 is the size of the PixelMap buffer to create. The value is calculated as follows: height * width * 1.5. 1365 offset: 0, 1366 stride: 8, 1367 region: { size: { height: 2, width: 2 }, x: 0, y: 0 } 1368 }; 1369 if (pixelMap != undefined) { 1370 pixelMap.readPixels(area).then(() => { 1371 console.info('Succeeded in reading the image data in the area.'); // Called if the condition is met. 1372 }).catch((error: BusinessError) => { 1373 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. 1374 }) 1375 } 1376} 1377``` 1378 1379### readPixels<sup>7+</sup> 1380 1381readPixels(area: PositionArea, callback: AsyncCallback\<void>): void 1382 1383Reads the pixels in the area (specified by [PositionArea] (#positionarea7).region) of this PixelMap and writes the data to the [PositionArea](#positionarea7).pixels buffer. This API uses an asynchronous callback to return the result. 1384 1385When the pixel format of the PixelMap is RGB, the data is read from the PixelMap in the BGRA_8888 format. 1386 1387You can use a formula to calculate the size of the memory to be applied for based on **PositionArea**. 1388 1389YUV region calculation formula: region to read (region.size{width * height}) * 1.5 (1 * Y component + 0.25 * U component + 0.25 * V component) 1390 1391RGBA region calculation formula: region to read (region.size{width * height}) * 4 (1 * R component + 1 * G component + 1 * B component + 1 * A component) 1392 1393**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1394 1395**Atomic service API**: This API can be used in atomic services since API version 11. 1396 1397**System capability**: SystemCapability.Multimedia.Image.Core 1398 1399**Parameters** 1400 1401| Name | Type | Mandatory| Description | 1402| -------- | ------------------------------ | ---- | ------------------------------ | 1403| area | [PositionArea](#positionarea7) | Yes | Area from which the pixels will be read. | 1404| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 1405 1406**Example** 1407 1408```ts 1409import { BusinessError } from '@kit.BasicServicesKit'; 1410 1411async function Demo() { 1412 const area: image.PositionArea = { 1413 pixels: new ArrayBuffer(8), // 8 is the size of the PixelMap buffer to create. The value is calculated as follows: height * width * 4. 1414 offset: 0, 1415 stride: 8, 1416 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 1417 }; 1418 if (pixelMap != undefined) { 1419 pixelMap.readPixels(area, (error: BusinessError) => { 1420 if (error) { 1421 console.error(`Failed to read pixelmap from the specified area. code is ${error.code}, message is ${error.message}`); 1422 return; 1423 } else { 1424 console.info('Succeeded in reading pixelmap from the specified area.'); 1425 } 1426 }) 1427 } 1428} 1429 1430async function Demo() { 1431 const area: image.PositionArea = { 1432 pixels: new ArrayBuffer(6), // 6 is the size of the PixelMap buffer to create. The value is calculated as follows: height * width * 1.5. 1433 offset: 0, 1434 stride: 8, 1435 region: { size: { height: 2, width: 2 }, x: 0, y: 0 } 1436 }; 1437 if (pixelMap != undefined) { 1438 pixelMap.readPixels(area, (error: BusinessError) => { 1439 if (error) { 1440 console.error(`Failed to read pixelmap from the specified area. code is ${error.code}, message is ${error.message}`); 1441 return; 1442 } else { 1443 console.info('Succeeded in reading pixelmap from the specified area.'); 1444 } 1445 }) 1446 } 1447} 1448``` 1449 1450### readPixelsSync<sup>12+</sup> 1451 1452readPixelsSync(area: PositionArea): void 1453 1454Reads the pixels in the area (specified by [PositionArea] (#positionarea7).region) of this PixelMap and writes the data to the [PositionArea](#positionarea7).pixels buffer. This API returns the result synchronously. 1455 1456When the pixel format of the PixelMap is RGB, the data is read from the PixelMap in the BGRA_8888 format. 1457 1458**Atomic service API**: This API can be used in atomic services since API version 12. 1459 1460**System capability**: SystemCapability.Multimedia.Image.Core 1461 1462**Parameters** 1463 1464| Name| Type | Mandatory| Description | 1465| ------ | ------------------------------ | ---- | ------------------------ | 1466| area | [PositionArea](#positionarea7) | Yes | Area from which the pixels will be read.| 1467 1468**Error codes** 1469 1470For details about the error codes, see [Image Error Codes](errorcode-image.md). 1471 1472| ID| Error Message| 1473| ------- | --------------------------------------------| 1474| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 1475| 501 | Resource Unavailable | 1476 1477**Example** 1478 1479```ts 1480import { BusinessError } from '@kit.BasicServicesKit'; 1481 1482async function Demo() { 1483 const area : image.PositionArea = { 1484 pixels: new ArrayBuffer(8), 1485 offset: 0, 1486 stride: 8, 1487 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 1488 }; 1489 if (pixelMap != undefined) { 1490 pixelMap.readPixelsSync(area); 1491 } 1492} 1493``` 1494 1495### writePixels<sup>7+</sup> 1496 1497writePixels(area: PositionArea): Promise\<void> 1498 1499Reads the pixels from the [PositionArea] (#positionarea7).pixels buffer and writes the data to the area (specified by [PositionArea](#positionarea7).region) in the PixelMap. This API uses a promise to return the result. 1500 1501When the pixel format of the PixelMap is RGB, the data is written to the PixelMap in the BGRA_8888 format. 1502 1503You can use a formula to calculate the size of the memory to be applied for based on **PositionArea**. 1504 1505YUV region calculation formula: region to read (region.size{width * height}) * 1.5 (1 * Y component + 0.25 * U component + 0.25 * V component) 1506 1507RGBA region calculation formula: region to read (region.size{width * height}) * 4 (1 * R component + 1 * G component + 1 * B component + 1 * A component) 1508 1509**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1510 1511**Atomic service API**: This API can be used in atomic services since API version 11. 1512 1513**System capability**: SystemCapability.Multimedia.Image.Core 1514 1515**Parameters** 1516 1517| Name| Type | Mandatory| Description | 1518| ------ | ------------------------------ | ---- | -------------------- | 1519| area | [PositionArea](#positionarea7) | Yes | Area to which the pixels will be written.| 1520 1521**Return value** 1522 1523| Type | Description | 1524| :------------- | :-------------------------------------------------- | 1525| Promise\<void> | Promise that returns no value. | 1526 1527**Example** 1528 1529```ts 1530import { BusinessError } from '@kit.BasicServicesKit'; 1531 1532async function Demo() { 1533 const area: image.PositionArea = { 1534 pixels: new ArrayBuffer(8), // 8 is the size of the PixelMap buffer to create. The value is calculated as follows: height * width * 4. 1535 offset: 0, 1536 stride: 8, 1537 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 1538 }; 1539 let bufferArr: Uint8Array = new Uint8Array(area.pixels); 1540 for (let i = 0; i < bufferArr.length; i++) { 1541 bufferArr[i] = i + 1; 1542 } 1543 if (pixelMap != undefined) { 1544 pixelMap.writePixels(area).then(() => { 1545 console.info('Succeeded in writing pixelmap into the specified area.'); 1546 }).catch((error: BusinessError) => { 1547 console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`); 1548 }) 1549 } 1550} 1551 1552async function Demo() { 1553 const area: image.PositionArea = { 1554 pixels: new ArrayBuffer(6), // 6 is the size of the PixelMap buffer to create. The value is calculated as follows: height * width * 1.5. 1555 offset: 0, 1556 stride: 8, 1557 region: { size: { height: 2, width: 2 }, x: 0, y: 0 } 1558 }; 1559 let bufferArr: Uint8Array = new Uint8Array(area.pixels); 1560 for (let i = 0; i < bufferArr.length; i++) { 1561 bufferArr[i] = i + 1; 1562 } 1563 if (pixelMap != undefined) { 1564 pixelMap.writePixels(area).then(() => { 1565 console.info('Succeeded in writing pixelmap into the specified area.'); 1566 }).catch((error: BusinessError) => { 1567 console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`); 1568 }) 1569 } 1570} 1571``` 1572 1573### writePixels<sup>7+</sup> 1574 1575writePixels(area: PositionArea, callback: AsyncCallback\<void>): void 1576 1577Reads the pixels from the [PositionArea] (#positionarea7).pixels buffer and writes the data to the area (specified by [PositionArea](#positionarea7).region) in the PixelMap. This API uses an asynchronous callback to return the result. 1578 1579When the pixel format of the PixelMap is RGB, the data is written to the PixelMap in the BGRA_8888 format. 1580 1581You can use a formula to calculate the size of the memory to be applied for based on **PositionArea**. 1582 1583YUV region calculation formula: region to read (region.size{width * height}) * 1.5 (1 * Y component + 0.25 * U component + 0.25 * V component) 1584 1585RGBA region calculation formula: region to read (region.size{width * height}) * 4 (1 * R component + 1 * G component + 1 * B component + 1 * A component) 1586 1587**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1588 1589**Atomic service API**: This API can be used in atomic services since API version 11. 1590 1591**System capability**: SystemCapability.Multimedia.Image.Core 1592 1593**Parameters** 1594 1595| Name | Type | Mandatory| Description | 1596| --------- | ------------------------------ | ---- | ------------------------------ | 1597| area | [PositionArea](#positionarea7) | Yes | Area to which the pixels will be written. | 1598| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 1599 1600**Example** 1601 1602```ts 1603import { BusinessError } from '@kit.BasicServicesKit'; 1604 1605async function Demo() { 1606 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. 1607 offset: 0, 1608 stride: 8, 1609 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 1610 }; 1611 let bufferArr: Uint8Array = new Uint8Array(area.pixels); 1612 for (let i = 0; i < bufferArr.length; i++) { 1613 bufferArr[i] = i + 1; 1614 } 1615 if (pixelMap != undefined) { 1616 pixelMap.writePixels(area, (error : BusinessError) => { 1617 if (error) { 1618 console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`); 1619 return; 1620 } else { 1621 console.info('Succeeded in writing pixelmap into the specified area.'); 1622 } 1623 }) 1624 } 1625} 1626 1627async function Demo() { 1628 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. 1629 offset: 0, 1630 stride: 8, 1631 region: { size: { height: 2, width: 2 }, x: 0, y: 0 } 1632 }; 1633 let bufferArr: Uint8Array = new Uint8Array(area.pixels); 1634 for (let i = 0; i < bufferArr.length; i++) { 1635 bufferArr[i] = i + 1; 1636 } 1637 if (pixelMap != undefined) { 1638 pixelMap.writePixels(area, (error : BusinessError) => { 1639 if (error) { 1640 console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`); 1641 return; 1642 } else { 1643 console.info('Succeeded in writing pixelmap into the specified area.'); 1644 } 1645 }) 1646 } 1647} 1648``` 1649 1650### writePixelsSync<sup>12+</sup> 1651 1652writePixelsSync(area: PositionArea): void 1653 1654Reads the pixels from the [PositionArea] (#positionarea7).pixels buffer and writes the data to the area (specified by [PositionArea](#positionarea7).region) in the PixelMap. This API returns the result synchronously. 1655 1656When the pixel format of the PixelMap is RGB, the data is written to the PixelMap in the BGRA_8888 format. 1657 1658**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1659 1660**Atomic service API**: This API can be used in atomic services since API version 12. 1661 1662**System capability**: SystemCapability.Multimedia.Image.Core 1663 1664**Parameters** 1665 1666| Name| Type | Mandatory| Description | 1667| ------ | ------------------------------ | ---- | -------------------- | 1668| area | [PositionArea](#positionarea7) | Yes | Area to which the pixels will be written.| 1669 1670**Error codes** 1671 1672For details about the error codes, see [Image Error Codes](errorcode-image.md). 1673 1674| ID| Error Message| 1675| ------- | --------------------------------------------| 1676| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 1677| 501 | Resource Unavailable | 1678 1679**Example** 1680 1681```ts 1682import { BusinessError } from '@kit.BasicServicesKit'; 1683 1684async function Demo() { 1685 const area: image.PositionArea = { 1686 pixels: new ArrayBuffer(8), 1687 offset: 0, 1688 stride: 8, 1689 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 1690 }; 1691 let bufferArr: Uint8Array = new Uint8Array(area.pixels); 1692 for (let i = 0; i < bufferArr.length; i++) { 1693 bufferArr[i] = i + 1; 1694 } 1695 if (pixelMap != undefined) { 1696 pixelMap.writePixelsSync(area); 1697 } 1698} 1699``` 1700 1701### writeBufferToPixels<sup>7+</sup> 1702 1703writeBufferToPixels(src: ArrayBuffer): Promise\<void> 1704 1705Reads the pixels in the buffer and writes the data to the PixelMap based on the pixel format of the PixelMap. This API uses a promise to return the result. 1706 1707**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1708 1709**Atomic service API**: This API can be used in atomic services since API version 11. 1710 1711**System capability**: SystemCapability.Multimedia.Image.Core 1712 1713**Parameters** 1714 1715| Name| Type | Mandatory| Description | 1716| ------ | ----------- | ---- | -------------- | 1717| src | ArrayBuffer | Yes | Buffer from which the pixels are read. The buffer size is obtained by calling [getPixelBytesNumber](#getpixelbytesnumber7).| 1718 1719**Return value** 1720 1721| Type | Description | 1722| -------------- | ----------------------------------------------- | 1723| Promise\<void> | Promise that returns no value. | 1724 1725**Example** 1726 1727```ts 1728import { BusinessError } from '@kit.BasicServicesKit'; 1729 1730async function Demo() { 1731 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. 1732 let bufferArr: Uint8Array = new Uint8Array(color); 1733 for (let i = 0; i < bufferArr.length; i++) { 1734 bufferArr[i] = i + 1; 1735 } 1736 if (pixelMap != undefined) { 1737 pixelMap.writeBufferToPixels(color).then(() => { 1738 console.info("Succeeded in writing data from a buffer to a PixelMap."); 1739 }).catch((error: BusinessError) => { 1740 console.error(`Failed to write data from a buffer to a PixelMap. code is ${error.code}, message is ${error.message}`); 1741 }) 1742 } 1743} 1744``` 1745 1746### writeBufferToPixels<sup>7+</sup> 1747 1748writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\<void>): void 1749 1750Reads the pixels in the buffer and writes the data to the PixelMap based on the pixel format of the PixelMap. This API uses an asynchronous callback to return the result. 1751 1752**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1753 1754**Atomic service API**: This API can be used in atomic services since API version 11. 1755 1756**System capability**: SystemCapability.Multimedia.Image.Core 1757 1758**Parameters** 1759 1760| Name | Type | Mandatory| Description | 1761| -------- | -------------------- | ---- | ------------------------------ | 1762| src | ArrayBuffer | Yes | Buffer from which the pixels are read. The buffer size is obtained by calling [getPixelBytesNumber](#getpixelbytesnumber7).| 1763| 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.| 1764 1765**Example** 1766 1767```ts 1768import { BusinessError } from '@kit.BasicServicesKit'; 1769 1770async function Demo() { 1771 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. 1772 let bufferArr: Uint8Array = new Uint8Array(color); 1773 for (let i = 0; i < bufferArr.length; i++) { 1774 bufferArr[i] = i + 1; 1775 } 1776 if (pixelMap != undefined) { 1777 pixelMap.writeBufferToPixels(color, (error: BusinessError) => { 1778 if (error) { 1779 console.error(`Failed to write data from a buffer to a PixelMap. code is ${error.code}, message is ${error.message}`); 1780 return; 1781 } else { 1782 console.info("Succeeded in writing data from a buffer to a PixelMap."); 1783 } 1784 }) 1785 } 1786} 1787``` 1788 1789### writeBufferToPixelsSync<sup>12+</sup> 1790 1791writeBufferToPixelsSync(src: ArrayBuffer): void 1792 1793Reads the pixels in the buffer and writes the data to the PixelMap based on the pixel format of the PixelMap. This API returns the result synchronously. 1794 1795**Atomic service API**: This API can be used in atomic services since API version 12. 1796 1797**System capability**: SystemCapability.Multimedia.Image.Core 1798 1799**Parameters** 1800 1801| Name| Type | Mandatory| Description | 1802| ------ | ----------- | ---- | -------------- | 1803| src | ArrayBuffer | Yes | Buffer from which the pixels are read. The buffer size is obtained by calling [getPixelBytesNumber](#getpixelbytesnumber7).| 1804 1805**Error codes** 1806 1807For details about the error codes, see [Image Error Codes](errorcode-image.md). 1808 1809| ID| Error Message| 1810| ------- | --------------------------------------------| 1811| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 1812| 501 | Resource Unavailable | 1813 1814**Example** 1815 1816```ts 1817import { BusinessError } from '@kit.BasicServicesKit'; 1818 1819async function Demo() { 1820 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. 1821 let bufferArr : Uint8Array = new Uint8Array(color); 1822 for (let i = 0; i < bufferArr.length; i++) { 1823 bufferArr[i] = i + 1; 1824 } 1825 if (pixelMap != undefined) { 1826 pixelMap.writeBufferToPixelsSync(color); 1827 } 1828} 1829``` 1830 1831 1832### getImageInfo<sup>7+</sup> 1833 1834getImageInfo(): Promise\<ImageInfo> 1835 1836Obtains the image information. This API uses a promise to return the result. 1837 1838**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1839 1840**Atomic service API**: This API can be used in atomic services since API version 11. 1841 1842**System capability**: SystemCapability.Multimedia.Image.Core 1843 1844**Return value** 1845 1846| Type | Description | 1847| --------------------------------- | ----------------------------------------------------------- | 1848| Promise\<[ImageInfo](#imageinfo)> | Promise used to return the image information.| 1849 1850**Example** 1851 1852```ts 1853import { BusinessError } from '@kit.BasicServicesKit'; 1854 1855async function Demo() { 1856 if (pixelMap != undefined) { 1857 pixelMap.getImageInfo().then((imageInfo: image.ImageInfo) => { 1858 if (imageInfo != undefined) { 1859 console.info("Succeeded in obtaining the image pixel map information."+ imageInfo.size.height); 1860 } 1861 }).catch((error: BusinessError) => { 1862 console.error(`Failed to obtain the image pixel map information. code is ${error.code}, message is ${error.message}`); 1863 }) 1864 } 1865} 1866``` 1867 1868### getImageInfo<sup>7+</sup> 1869 1870getImageInfo(callback: AsyncCallback\<ImageInfo>): void 1871 1872Obtains the image information. This API uses an asynchronous callback to return the result. 1873 1874**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1875 1876**Atomic service API**: This API can be used in atomic services since API version 11. 1877 1878**System capability**: SystemCapability.Multimedia.Image.Core 1879 1880**Parameters** 1881 1882| Name | Type | Mandatory| Description | 1883| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | 1884| 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.| 1885 1886**Example** 1887 1888```ts 1889import { BusinessError } from '@kit.BasicServicesKit'; 1890 1891async function Demo() { 1892 if (pixelMap != undefined) { 1893 pixelMap.getImageInfo((error: BusinessError, imageInfo: image.ImageInfo) => { 1894 if (error) { 1895 console.error(`Failed to obtain the image pixel map information. code is ${error.code}, message is ${error.message}`); 1896 return; 1897 } else { 1898 console.info("Succeeded in obtaining the image pixel map information."+ imageInfo.size.height); 1899 } 1900 }) 1901 } 1902} 1903``` 1904 1905### getImageInfoSync<sup>12+</sup> 1906 1907getImageInfoSync(): ImageInfo 1908 1909Obtains the image information. This API returns the result synchronously. 1910 1911**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1912 1913**Atomic service API**: This API can be used in atomic services since API version 12. 1914 1915**System capability**: SystemCapability.Multimedia.Image.ImageSource 1916 1917**Return value** 1918 1919| Type | Description | 1920| --------------------------------- | ----------------------------------------------------------- | 1921| [ImageInfo](#imageinfo) | Image information. | 1922 1923**Error codes** 1924 1925For details about the error codes, see [Image Error Codes](errorcode-image.md). 1926 1927| ID| Error Message| 1928| ------- | --------------------------------------------| 1929| 501 | Resource Unavailable | 1930 1931**Example** 1932 1933```ts 1934import { BusinessError } from '@kit.BasicServicesKit'; 1935 1936async function Demo() { 1937 if (pixelMap != undefined) { 1938 let imageInfo : image.ImageInfo = pixelMap.getImageInfoSync(); 1939 return imageInfo; 1940 } 1941 return undefined; 1942} 1943``` 1944 1945### getBytesNumberPerRow<sup>7+</sup> 1946 1947getBytesNumberPerRow(): number 1948 1949Obtains the number of bytes per row of this image. 1950 1951**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1952 1953**Atomic service API**: This API can be used in atomic services since API version 11. 1954 1955**System capability**: SystemCapability.Multimedia.Image.Core 1956 1957**Return value** 1958 1959| Type | Description | 1960| ------ | -------------------- | 1961| number | Number of bytes per row.| 1962 1963**Example** 1964 1965```ts 1966let rowCount: number = pixelMap.getBytesNumberPerRow(); 1967``` 1968 1969### getPixelBytesNumber<sup>7+</sup> 1970 1971getPixelBytesNumber(): number 1972 1973Obtains the total number of bytes of this image. 1974 1975**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1976 1977**Atomic service API**: This API can be used in atomic services since API version 11. 1978 1979**System capability**: SystemCapability.Multimedia.Image.Core 1980 1981**Return value** 1982 1983| Type | Description | 1984| ------ | -------------------- | 1985| number | Total number of bytes.| 1986 1987**Example** 1988 1989```ts 1990let pixelBytesNumber: number = pixelMap.getPixelBytesNumber(); 1991``` 1992 1993### getDensity<sup>9+</sup> 1994 1995getDensity():number 1996 1997Obtains the density of this image. 1998 1999**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2000 2001**Atomic service API**: This API can be used in atomic services since API version 11. 2002 2003**System capability**: SystemCapability.Multimedia.Image.Core 2004 2005**Return value** 2006 2007| Type | Description | 2008| ------ | --------------- | 2009| number | Density of the image.| 2010 2011**Example** 2012 2013```ts 2014let getDensity: number = pixelMap.getDensity(); 2015``` 2016 2017### opacity<sup>9+</sup> 2018 2019opacity(rate: number, callback: AsyncCallback\<void>): void 2020 2021Sets an opacity rate for this image. This API uses an asynchronous callback to return the result. It is invalid for YUV images. 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**Parameters** 2030 2031| Name | Type | Mandatory| Description | 2032| -------- | -------------------- | ---- | ------------------------------ | 2033| rate | number | Yes | Opacity rate. | 2034| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 2035 2036**Example** 2037 2038```ts 2039import { BusinessError } from '@kit.BasicServicesKit'; 2040 2041async function Demo() { 2042 let rate: number = 0.5; 2043 if (pixelMap != undefined) { 2044 pixelMap.opacity(rate, (err: BusinessError) => { 2045 if (err) { 2046 console.error(`Failed to set opacity. code is ${err.code}, message is ${err.message}`); 2047 return; 2048 } else { 2049 console.info("Succeeded in setting opacity."); 2050 } 2051 }) 2052 } 2053} 2054``` 2055 2056### opacity<sup>9+</sup> 2057 2058opacity(rate: number): Promise\<void> 2059 2060Sets an opacity rate for this image. This API uses a promise to return the result. It is invalid for YUV images. 2061 2062**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2063 2064**Atomic service API**: This API can be used in atomic services since API version 11. 2065 2066**System capability**: SystemCapability.Multimedia.Image.Core 2067 2068**Parameters** 2069 2070| Name| Type | Mandatory| Description | 2071| ------ | ------ | ---- | --------------------------- | 2072| rate | number | Yes | Opacity rate.| 2073 2074**Return value** 2075 2076| Type | Description | 2077| -------------- | ----------------------------------------------- | 2078| Promise\<void> | Promise that returns no value. | 2079 2080**Example** 2081 2082```ts 2083import { BusinessError } from '@kit.BasicServicesKit'; 2084 2085async function Demo() { 2086 let rate: number = 0.5; 2087 if (pixelMap != undefined) { 2088 pixelMap.opacity(rate).then(() => { 2089 console.info('Succeeded in setting opacity.'); 2090 }).catch((err: BusinessError) => { 2091 console.error(`Failed to set opacity. code is ${err.code}, message is ${err.message}`); 2092 }) 2093 } 2094} 2095``` 2096 2097### opacitySync<sup>12+</sup> 2098 2099opacitySync(rate: number): void 2100 2101Sets an opacity rate for this image. This API returns the result synchronously. It is invalid for YUV images. 2102 2103**Atomic service API**: This API can be used in atomic services since API version 12. 2104 2105**System capability**: SystemCapability.Multimedia.Image.Core 2106 2107**Parameters** 2108 2109| Name | Type | Mandatory| Description | 2110| -------- | -------------------- | ---- | ------------------------------ | 2111| rate | number | Yes | Opacity rate. | 2112 2113**Error codes** 2114 2115For details about the error codes, see [Image Error Codes](errorcode-image.md). 2116 2117| ID| Error Message| 2118| ------- | --------------------------------------------| 2119| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2120| 501 | Resource Unavailable | 2121 2122**Example** 2123 2124```ts 2125import { BusinessError } from '@kit.BasicServicesKit'; 2126 2127async function Demo() { 2128 let rate : number = 0.5; 2129 if (pixelMap != undefined) { 2130 pixelMap.opacitySync(rate); 2131 } 2132} 2133``` 2134 2135### createAlphaPixelmap<sup>9+</sup> 2136 2137createAlphaPixelmap(): Promise\<PixelMap> 2138 2139Creates 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. 2140 2141**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2142 2143**Atomic service API**: This API can be used in atomic services since API version 11. 2144 2145**System capability**: SystemCapability.Multimedia.Image.Core 2146 2147**Return value** 2148 2149| Type | Description | 2150| -------------------------------- | --------------------------- | 2151| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.| 2152 2153**Example** 2154 2155```ts 2156import { BusinessError } from '@kit.BasicServicesKit'; 2157 2158async function Demo() { 2159 if (pixelMap != undefined) { 2160 pixelMap.createAlphaPixelmap().then((alphaPixelMap: image.PixelMap) => { 2161 console.info('Succeeded in creating alpha pixelmap.'); 2162 }).catch((error: BusinessError) => { 2163 console.error(`Failed to create alpha pixelmap. code is ${error.code}, message is ${error.message}`); 2164 }) 2165 } 2166} 2167``` 2168 2169### createAlphaPixelmap<sup>9+</sup> 2170 2171createAlphaPixelmap(callback: AsyncCallback\<PixelMap>): void 2172 2173Creates 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. 2174 2175**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2176 2177**Atomic service API**: This API can be used in atomic services since API version 11. 2178 2179**System capability**: SystemCapability.Multimedia.Image.Core 2180 2181**Parameters** 2182 2183| Name | Type | Mandatory| Description | 2184| -------- | ------------------------ | ---- | ------------------------ | 2185| 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.| 2186 2187**Example** 2188 2189```ts 2190import { BusinessError } from '@kit.BasicServicesKit'; 2191 2192async function Demo() { 2193 if (pixelMap != undefined) { 2194 pixelMap.createAlphaPixelmap((err: BusinessError, alphaPixelMap: image.PixelMap) => { 2195 if (alphaPixelMap == undefined) { 2196 console.error(`Failed to obtain new pixel map. code is ${err.code}, message is ${err.message}`); 2197 return; 2198 } else { 2199 console.info('Succeeded in obtaining new pixel map.'); 2200 } 2201 }) 2202 } 2203} 2204``` 2205 2206### createAlphaPixelmapSync<sup>12+</sup> 2207 2208createAlphaPixelmapSync(): PixelMap 2209 2210Creates 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. 2211 2212**Atomic service API**: This API can be used in atomic services since API version 12. 2213 2214**System capability**: SystemCapability.Multimedia.Image.Core 2215 2216**Return value** 2217 2218| Type | Description | 2219| -------------------------------- | --------------------- | 2220| [PixelMap](#pixelmap7) | Returns a **PixelMap** object if the operation is successful; throws an error otherwise.| 2221 2222**Error codes** 2223 2224For details about the error codes, see [Image Error Codes](errorcode-image.md). 2225 2226| ID| Error Message| 2227| ------- | --------------------------------------------| 2228| 401 | Parameter error. Possible causes: 1.Parameter verification failed | 2229| 501 | Resource Unavailable | 2230 2231**Example** 2232 2233```ts 2234import { BusinessError } from '@kit.BasicServicesKit'; 2235 2236async function Demo() { 2237 if (pixelMap != undefined) { 2238 let pixelmap : image.PixelMap = pixelMap.createAlphaPixelmapSync(); 2239 return pixelmap; 2240 } 2241 return undefined; 2242} 2243``` 2244 2245### scale<sup>9+</sup> 2246 2247scale(x: number, y: number, callback: AsyncCallback\<void>): void 2248 2249Scales this image based on a given scaling multiple of the width and height. This API uses an asynchronous callback to return the result. 2250 2251**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2252 2253**Atomic service API**: This API can be used in atomic services since API version 11. 2254 2255**System capability**: SystemCapability.Multimedia.Image.Core 2256 2257**Parameters** 2258 2259| Name | Type | Mandatory| Description | 2260| -------- | -------------------- | ---- | ------------------------------- | 2261| x | number | Yes | Scaling multiple of the width.| 2262| y | number | Yes | Scaling multiple of the height.| 2263| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 2264 2265**Example** 2266 2267```ts 2268import { BusinessError } from '@kit.BasicServicesKit'; 2269 2270async function Demo() { 2271 let scaleX: number = 2.0; 2272 let scaleY: number = 1.0; 2273 if (pixelMap != undefined) { 2274 pixelMap.scale(scaleX, scaleY, (err: BusinessError) => { 2275 if (err) { 2276 console.error(`Failed to scale pixelmap. code is ${err.code}, message is ${err.message}`); 2277 return; 2278 } else { 2279 console.info("Succeeded in scaling pixelmap."); 2280 } 2281 }) 2282 } 2283} 2284``` 2285 2286### scale<sup>9+</sup> 2287 2288scale(x: number, y: number): Promise\<void> 2289 2290Scales this image based on a given scaling multiple of the width and height. This API uses a promise to return the result. 2291 2292**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2293 2294**Atomic service API**: This API can be used in atomic services since API version 11. 2295 2296**System capability**: SystemCapability.Multimedia.Image.Core 2297 2298**Parameters** 2299 2300| Name| Type | Mandatory| Description | 2301| ------ | ------ | ---- | ------------------------------- | 2302| x | number | Yes | Scaling multiple of the width.| 2303| y | number | Yes | Scaling multiple of the height.| 2304 2305**Return value** 2306 2307| Type | Description | 2308| -------------- | --------------------------- | 2309| Promise\<void> | Promise that returns no value.| 2310 2311**Example** 2312 2313```ts 2314import { BusinessError } from '@kit.BasicServicesKit'; 2315 2316async function Demo() { 2317 let scaleX: number = 2.0; 2318 let scaleY: number = 1.0; 2319 if (pixelMap != undefined) { 2320 pixelMap.scale(scaleX, scaleY).then(() => { 2321 console.info('Succeeded in scaling pixelmap.'); 2322 }).catch((err: BusinessError) => { 2323 console.error(`Failed to scale pixelmap. code is ${err.code}, message is ${err.message}`); 2324 2325 }) 2326 } 2327} 2328``` 2329 2330### scaleSync<sup>12+</sup> 2331 2332scaleSync(x: number, y: number): void 2333 2334Scales this image based on a given width and height. This API returns the result synchronously. 2335 2336**Atomic service API**: This API can be used in atomic services since API version 12. 2337 2338**System capability**: SystemCapability.Multimedia.Image.Core 2339 2340**Parameters** 2341 2342| Name| Type | Mandatory| Description | 2343| ------ | ------ | ---- | ------------------------------- | 2344| x | number | Yes | Scaling multiple of the width.| 2345| y | number | Yes | Scaling multiple of the height.| 2346 2347**Error codes** 2348 2349For details about the error codes, see [Image Error Codes](errorcode-image.md). 2350 2351| ID| Error Message| 2352| ------- | --------------------------------------------| 2353| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2354| 501 | Resource Unavailable | 2355 2356**Example** 2357 2358```ts 2359import { BusinessError } from '@kit.BasicServicesKit'; 2360 2361async function Demo() { 2362 let scaleX: number = 2.0; 2363 let scaleY: number = 1.0; 2364 if (pixelMap != undefined) { 2365 pixelMap.scaleSync(scaleX, scaleY); 2366 } 2367} 2368``` 2369 2370### scale<sup>12+</sup> 2371 2372scale(x: number, y: number, level: AntiAliasingLevel): Promise\<void> 2373 2374Scales this image based on a given scaling multiple of the width and height. This API uses a promise to return the result. 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 12. 2379 2380**System capability**: SystemCapability.Multimedia.Image.Core 2381 2382**Parameters** 2383 2384| Name| Type | Mandatory| Description | 2385| ------ | ------ | ---- | ------------------------------- | 2386| x | number | Yes | Scaling multiple of the width.| 2387| y | number | Yes | Scaling multiple of the height.| 2388| level | [AntiAliasingLevel](#antialiasinglevel12) | Yes | Anti-aliasing level.| 2389 2390**Return value** 2391 2392| Type | Description | 2393| -------------- | --------------------------- | 2394| Promise\<void> | Promise that returns no value.| 2395 2396**Error codes** 2397 2398For details about the error codes, see [Image Error Codes](errorcode-image.md). 2399 2400| ID| Error Message| 2401| ------- | --------------------------------------------| 2402| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2403| 501 | Resource Unavailable | 2404 2405**Example** 2406 2407```ts 2408import { BusinessError } from '@kit.BasicServicesKit'; 2409 2410async function Demo() { 2411 let scaleX: number = 2.0; 2412 let scaleY: number = 1.0; 2413 if (pixelMap != undefined) { 2414 pixelMap.scale(scaleX, scaleY, image.AntiAliasingLevel.LOW).then(() => { 2415 console.info('Succeeded in scaling pixelmap.'); 2416 }).catch((err: BusinessError) => { 2417 console.error(`Failed to scale pixelmap. code is ${err.code}, message is ${err.message}`); 2418 2419 }) 2420 } 2421} 2422``` 2423 2424### scaleSync<sup>12+</sup> 2425 2426scaleSync(x: number, y: number, level: AntiAliasingLevel): void 2427 2428Scales this image based on a given width and height. This API returns the result synchronously. 2429 2430**Atomic service API**: This API can be used in atomic services since API version 12. 2431 2432**System capability**: SystemCapability.Multimedia.Image.Core 2433 2434**Parameters** 2435 2436| Name| Type | Mandatory| Description | 2437| ------ | ------ | ---- | ------------------------------- | 2438| x | number | Yes | Scaling multiple of the width.| 2439| y | number | Yes | Scaling multiple of the height.| 2440| level | [AntiAliasingLevel](#antialiasinglevel12) | Yes | Anti-aliasing level.| 2441 2442**Error codes** 2443 2444For details about the error codes, see [Image Error Codes](errorcode-image.md). 2445 2446| ID| Error Message| 2447| ------- | --------------------------------------------| 2448| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2449| 501 | Resource Unavailable | 2450 2451**Example** 2452 2453```ts 2454import { BusinessError } from '@kit.BasicServicesKit'; 2455 2456async function Demo() { 2457 let scaleX: number = 2.0; 2458 let scaleY: number = 1.0; 2459 if (pixelMap != undefined) { 2460 pixelMap.scaleSync(scaleX, scaleY, image.AntiAliasingLevel.LOW); 2461 } 2462} 2463``` 2464 2465### translate<sup>9+</sup> 2466 2467translate(x: number, y: number, callback: AsyncCallback\<void>): void 2468 2469Translates this image based on given coordinates, with the new dimensions being width+X and height+Y. This API uses an asynchronous callback to return the result. 2470 2471**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2472 2473**Atomic service API**: This API can be used in atomic services since API version 11. 2474 2475**System capability**: SystemCapability.Multimedia.Image.Core 2476 2477**Parameters** 2478 2479| Name | Type | Mandatory| Description | 2480| -------- | -------------------- | ---- | ----------------------------- | 2481| x | number | Yes | X coordinate to translate. | 2482| y | number | Yes | Y coordinate to translate. | 2483| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 2484 2485**Example** 2486 2487```ts 2488import { BusinessError } from '@kit.BasicServicesKit'; 2489 2490async function Demo() { 2491 let translateX: number = 50.0; 2492 let translateY: number = 10.0; 2493 if (pixelMap != undefined) { 2494 pixelMap.translate(translateX, translateY, (err: BusinessError) => { 2495 if (err) { 2496 console.error(`Failed to translate pixelmap. code is ${err.code}, message is ${err.message}`); 2497 return; 2498 } else { 2499 console.info("Succeeded in translating pixelmap."); 2500 } 2501 }) 2502 } 2503} 2504``` 2505 2506### translate<sup>9+</sup> 2507 2508translate(x: number, y: number): Promise\<void> 2509 2510Translates this image based on given coordinates, with the new dimensions being width+X and height+Y. This API uses a promise to return the result. 2511 2512**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2513 2514**Atomic service API**: This API can be used in atomic services since API version 11. 2515 2516**System capability**: SystemCapability.Multimedia.Image.Core 2517 2518**Parameters** 2519 2520| Name| Type | Mandatory| Description | 2521| ------ | ------ | ---- | ----------- | 2522| x | number | Yes | X coordinate to translate.| 2523| y | number | Yes | Y coordinate to translate.| 2524 2525**Return value** 2526 2527| Type | Description | 2528| -------------- | --------------------------- | 2529| Promise\<void> | Promise that returns no value.| 2530 2531**Example** 2532 2533```ts 2534import { BusinessError } from '@kit.BasicServicesKit'; 2535 2536async function Demo() { 2537 let translateX: number = 50.0; 2538 let translateY: number = 10.0; 2539 if (pixelMap != undefined) { 2540 pixelMap.translate(translateX, translateY).then(() => { 2541 console.info('Succeeded in translating pixelmap.'); 2542 }).catch((err: BusinessError) => { 2543 console.error(`Failed to translate pixelmap. code is ${err.code}, message is ${err.message}`); 2544 }) 2545 } 2546} 2547``` 2548 2549### translateSync<sup>12+</sup> 2550 2551translateSync(x: number, y: number): void 2552 2553Translates this image based on given coordinates. This API returns the result synchronously. 2554 2555**Atomic service API**: This API can be used in atomic services since API version 12. 2556 2557**System capability**: SystemCapability.Multimedia.Image.Core 2558 2559**Parameters** 2560 2561| Name | Type | Mandatory| Description | 2562| -------- | -------------------- | ---- | ------------------------------- | 2563| x | number | Yes | X coordinate to translate.| 2564| y | number | Yes | Y coordinate to translate.| 2565 2566**Error codes** 2567 2568For details about the error codes, see [Image Error Codes](errorcode-image.md). 2569 2570| ID| Error Message| 2571| ------- | --------------------------------------------| 2572| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2573| 501 | Resource Unavailable | 2574 2575**Example** 2576 2577```ts 2578import { BusinessError } from '@kit.BasicServicesKit'; 2579 2580async function Demo() { 2581 let translateX : number = 50.0; 2582 let translateY : number = 10.0; 2583 if (pixelMap != undefined) { 2584 pixelMap.translateSync(translateX, translateY); 2585 } 2586} 2587``` 2588 2589### rotate<sup>9+</sup> 2590 2591rotate(angle: number, callback: AsyncCallback\<void>): void 2592 2593Rotates this image based on a given angle. This API uses an asynchronous callback to return the result. 2594 2595**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2596 2597**Atomic service API**: This API can be used in atomic services since API version 11. 2598 2599**System capability**: SystemCapability.Multimedia.Image.Core 2600 2601**Parameters** 2602 2603| Name | Type | Mandatory| Description | 2604| -------- | -------------------- | ---- | ----------------------------- | 2605| angle | number | Yes | Angle to rotate. | 2606| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 2607 2608**Example** 2609 2610```ts 2611import { BusinessError } from '@kit.BasicServicesKit'; 2612 2613async function Demo() { 2614 let angle: number = 90.0; 2615 if (pixelMap != undefined) { 2616 pixelMap.rotate(angle, (err: BusinessError) => { 2617 if (err) { 2618 console.error(`Failed to rotate pixelmap. code is ${err.code}, message is ${err.message}`); 2619 return; 2620 } else { 2621 console.info("Succeeded in rotating pixelmap."); 2622 } 2623 }) 2624 } 2625} 2626``` 2627 2628### rotate<sup>9+</sup> 2629 2630rotate(angle: number): Promise\<void> 2631 2632Rotates this image based on a given angle. This API uses a promise to return the result. 2633 2634**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2635 2636**Atomic service API**: This API can be used in atomic services since API version 11. 2637 2638**System capability**: SystemCapability.Multimedia.Image.Core 2639 2640**Parameters** 2641 2642| Name| Type | Mandatory| Description | 2643| ------ | ------ | ---- | ----------------------------- | 2644| angle | number | Yes | Angle to rotate. | 2645 2646**Return value** 2647 2648| Type | Description | 2649| -------------- | --------------------------- | 2650| Promise\<void> | Promise that returns no value.| 2651 2652**Example** 2653 2654```ts 2655import { BusinessError } from '@kit.BasicServicesKit'; 2656 2657async function Demo() { 2658 let angle: number = 90.0; 2659 if (pixelMap != undefined) { 2660 pixelMap.rotate(angle).then(() => { 2661 console.info('Succeeded in rotating pixelmap.'); 2662 }).catch((err: BusinessError) => { 2663 console.error(`Failed to rotate pixelmap. code is ${err.code}, message is ${err.message}`); 2664 }) 2665 } 2666} 2667``` 2668 2669### rotateSync<sup>12+</sup> 2670 2671rotateSync(angle: number): void 2672 2673Rotates this image based on a given angle. This API returns the result synchronously. 2674 2675**Atomic service API**: This API can be used in atomic services since API version 12. 2676 2677**System capability**: SystemCapability.Multimedia.Image.Core 2678 2679**Parameters** 2680 2681| Name | Type | Mandatory| Description | 2682| -------- | -------------------- | ---- | ----------------------------- | 2683| angle | number | Yes | Angle to rotate. | 2684 2685**Error codes** 2686 2687For details about the error codes, see [Image Error Codes](errorcode-image.md). 2688 2689| ID| Error Message| 2690| ------- | --------------------------------------------| 2691| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2692| 501 | Resource Unavailable | 2693 2694**Example** 2695 2696```ts 2697import { BusinessError } from '@kit.BasicServicesKit'; 2698 2699async function Demo() { 2700 let angle : number = 90.0; 2701 if (pixelMap != undefined) { 2702 pixelMap.rotateSync(angle); 2703 } 2704} 2705``` 2706 2707### flip<sup>9+</sup> 2708 2709flip(horizontal: boolean, vertical: boolean, callback: AsyncCallback\<void>): void 2710 2711Flips this image horizontally or vertically, or both. This API uses an asynchronous callback to return the result. 2712 2713**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2714 2715**Atomic service API**: This API can be used in atomic services since API version 11. 2716 2717**System capability**: SystemCapability.Multimedia.Image.Core 2718 2719**Parameters** 2720 2721| Name | Type | Mandatory| Description | 2722| ---------- | -------------------- | ---- | ----------------------------- | 2723| horizontal | boolean | Yes | Whether to flip the image horizontally. | 2724| vertical | boolean | Yes | Whether to flip the image vertically. | 2725| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 2726 2727**Example** 2728 2729```ts 2730import { BusinessError } from '@kit.BasicServicesKit'; 2731 2732async function Demo() { 2733 let horizontal: boolean = true; 2734 let vertical: boolean = false; 2735 if (pixelMap != undefined) { 2736 pixelMap.flip(horizontal, vertical, (err: BusinessError) => { 2737 if (err) { 2738 console.error(`Failed to flip pixelmap. code is ${err.code}, message is ${err.message}`); 2739 return; 2740 } else { 2741 console.info("Succeeded in flipping pixelmap."); 2742 } 2743 }) 2744 } 2745} 2746``` 2747 2748### flip<sup>9+</sup> 2749 2750flip(horizontal: boolean, vertical: boolean): Promise\<void> 2751 2752Flips this image horizontally or vertically, or both. This API uses a promise to return the result. 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| horizontal | boolean | Yes | Whether to flip the image horizontally.| 2765| vertical | boolean | Yes | Whether to flip the image vertically.| 2766 2767**Return value** 2768 2769| Type | Description | 2770| -------------- | --------------------------- | 2771| Promise\<void> | Promise that returns no value.| 2772 2773**Example** 2774 2775```ts 2776import { BusinessError } from '@kit.BasicServicesKit'; 2777 2778async function Demo() { 2779 let horizontal: boolean = true; 2780 let vertical: boolean = false; 2781 if (pixelMap != undefined) { 2782 pixelMap.flip(horizontal, vertical).then(() => { 2783 console.info('Succeeded in flipping pixelmap.'); 2784 }).catch((err: BusinessError) => { 2785 console.error(`Failed to flip pixelmap. code is ${err.code}, message is ${err.message}`); 2786 }) 2787 } 2788} 2789``` 2790 2791### flipSync<sup>12+</sup> 2792 2793flipSync(horizontal: boolean, vertical: boolean): void 2794 2795Flips this image horizontally or vertically, or both. This API returns the result synchronously. 2796 2797**Atomic service API**: This API can be used in atomic services since API version 12. 2798 2799**System capability**: SystemCapability.Multimedia.Image.Core 2800 2801**Parameters** 2802 2803| Name | Type | Mandatory| Description | 2804| ---------- | -------------------- | ---- | ----------------------------- | 2805| horizontal | boolean | Yes | Whether to flip the image horizontally. | 2806| vertical | boolean | Yes | Whether to flip the image vertically. | 2807 2808**Error codes** 2809 2810For details about the error codes, see [Image Error Codes](errorcode-image.md). 2811 2812| ID| Error Message| 2813| ------- | --------------------------------------------| 2814| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2815| 501 | Resource Unavailable | 2816 2817**Example** 2818 2819```ts 2820import { BusinessError } from '@kit.BasicServicesKit'; 2821 2822async function Demo() { 2823 let horizontal : boolean = true; 2824 let vertical : boolean = false; 2825 if (pixelMap != undefined) { 2826 pixelMap.flipSync(horizontal, vertical); 2827 } 2828} 2829``` 2830 2831### crop<sup>9+</sup> 2832 2833crop(region: Region, callback: AsyncCallback\<void>): void 2834 2835Crops this image based on a given size. This API uses an asynchronous callback to return the result. 2836 2837**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2838 2839**Atomic service API**: This API can be used in atomic services since API version 11. 2840 2841**System capability**: SystemCapability.Multimedia.Image.Core 2842 2843**Parameters** 2844 2845| Name | Type | Mandatory| Description | 2846| -------- | -------------------- | ---- | ----------------------------- | 2847| region | [Region](#region8) | Yes | Size of the image after cropping. | 2848| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 2849 2850**Example** 2851 2852```ts 2853import { BusinessError } from '@kit.BasicServicesKit'; 2854 2855async function Demo() { 2856 let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 2857 if (pixelMap != undefined) { 2858 pixelMap.crop(region, (err: BusinessError) => { 2859 if (err) { 2860 console.error(`Failed to crop pixelmap. code is ${err.code}, message is ${err.message}`); 2861 return; 2862 } else { 2863 console.info("Succeeded in cropping pixelmap."); 2864 } 2865 }) 2866 } 2867} 2868``` 2869 2870### crop<sup>9+</sup> 2871 2872crop(region: Region): Promise\<void> 2873 2874Crops this image based on a given size. This API uses a promise to return the result. 2875 2876**Widget capability**: This API can be used in ArkTS widgets since API version 12. 2877 2878**Atomic service API**: This API can be used in atomic services since API version 11. 2879 2880**System capability**: SystemCapability.Multimedia.Image.Core 2881 2882**Parameters** 2883 2884| Name| Type | Mandatory| Description | 2885| ------ | ------------------ | ---- | ----------- | 2886| region | [Region](#region8) | Yes | Size of the image after cropping.| 2887 2888**Return value** 2889 2890| Type | Description | 2891| -------------- | --------------------------- | 2892| Promise\<void> | Promise that returns no value.| 2893 2894**Example** 2895 2896```ts 2897import { BusinessError } from '@kit.BasicServicesKit'; 2898 2899async function Demo() { 2900 let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 2901 if (pixelMap != undefined) { 2902 pixelMap.crop(region).then(() => { 2903 console.info('Succeeded in cropping pixelmap.'); 2904 }).catch((err: BusinessError) => { 2905 console.error(`Failed to crop pixelmap. code is ${err.code}, message is ${err.message}`); 2906 2907 }); 2908 } 2909} 2910``` 2911 2912### cropSync<sup>12+</sup> 2913 2914cropSync(region: Region): void 2915 2916Crops this image based on a given size. This API returns the result synchronously. 2917 2918**Atomic service API**: This API can be used in atomic services since API version 12. 2919 2920**System capability**: SystemCapability.Multimedia.Image.Core 2921 2922**Parameters** 2923 2924| Name | Type | Mandatory| Description | 2925| -------- | -------------------- | ---- | ----------------------------- | 2926| region | [Region](#region8) | Yes | Size of the image after cropping. | 2927 2928**Error codes** 2929 2930For details about the error codes, see [Image Error Codes](errorcode-image.md). 2931 2932| ID| Error Message| 2933| ------- | --------------------------------------------| 2934| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2935| 501 | Resource Unavailable | 2936 2937**Example** 2938 2939```ts 2940import { BusinessError } from '@kit.BasicServicesKit'; 2941 2942async function Demo() { 2943 let region : image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 2944 if (pixelMap != undefined) { 2945 pixelMap.cropSync(region); 2946 } 2947} 2948``` 2949 2950### getColorSpace<sup>10+</sup> 2951 2952getColorSpace(): colorSpaceManager.ColorSpaceManager 2953 2954Obtains the color space of this image. 2955 2956**System capability**: SystemCapability.Multimedia.Image.Core 2957 2958**Return value** 2959 2960| Type | Description | 2961| ----------------------------------- | ---------------- | 2962| [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | Color space obtained.| 2963 2964**Error codes** 2965 2966For details about the error codes, see [Image Error Codes](errorcode-image.md). 2967 2968| ID| Error Message| 2969| ------- | --------------------------------------------| 2970| 62980101| If the image data abnormal. | 2971| 62980103| If the image data unsupport. | 2972| 62980115| If the image parameter invalid. | 2973 2974**Example** 2975 2976```ts 2977async function Demo() { 2978 if (pixelMap != undefined) { 2979 let csm = pixelMap.getColorSpace(); 2980 } 2981} 2982``` 2983 2984### setColorSpace<sup>10+</sup> 2985 2986setColorSpace(colorSpace: colorSpaceManager.ColorSpaceManager): void 2987 2988Sets the color space for this image. 2989 2990**System capability**: SystemCapability.Multimedia.Image.Core 2991 2992**Parameters** 2993 2994| Name | Type | Mandatory| Description | 2995| ---------- | ----------------------------------- | ---- | --------------- | 2996| colorSpace | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | Yes | Color space to set.| 2997 2998**Error codes** 2999 3000For details about the error codes, see [Image Error Codes](errorcode-image.md). 3001 3002| ID| Error Message| 3003| ------- | --------------------------------------------| 3004| 62980111| The image source data is incomplete. | 3005| 62980115| If the image parameter invalid. | 3006 3007**Example** 3008 3009```ts 3010import { colorSpaceManager } from '@kit.ArkGraphics2D'; 3011async function Demo() { 3012 let colorSpaceName = colorSpaceManager.ColorSpace.SRGB; 3013 let csm: colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName); 3014 if (pixelMap != undefined) { 3015 pixelMap.setColorSpace(csm); 3016 } 3017} 3018``` 3019 3020### applyColorSpace<sup>11+</sup> 3021 3022applyColorSpace(targetColorSpace: colorSpaceManager.ColorSpaceManager, callback: AsyncCallback\<void>): void 3023 3024Performs 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. 3025 3026**System capability**: SystemCapability.Multimedia.Image.Core 3027 3028**Parameters** 3029 3030| Name | Type | Mandatory| Description | 3031| -------- | -------------------- | ---- | ----------------------------- | 3032| 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.| 3033| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 3034 3035**Error codes** 3036 3037For details about the error codes, see [Image Error Codes](errorcode-image.md). 3038 3039| ID| Error Message| 3040| ------- | ------------------------------------------| 3041| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 3042| 62980104| Failed to initialize the internal object. | 3043| 62980108| Failed to convert the color space. | 3044| 62980115| Invalid image parameter. | 3045 3046**Example** 3047 3048```ts 3049import { colorSpaceManager } from '@kit.ArkGraphics2D'; 3050import { BusinessError } from '@kit.BasicServicesKit'; 3051 3052async function Demo() { 3053 let colorSpaceName = colorSpaceManager.ColorSpace.SRGB; 3054 let targetColorSpace: colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName); 3055 if (pixelMap != undefined) { 3056 pixelMap.applyColorSpace(targetColorSpace, (err: BusinessError) => { 3057 if (err) { 3058 console.error(`Failed to apply color space for pixelmap object. code is ${err.code}, message is ${err.message}`); 3059 return; 3060 } else { 3061 console.info('Succeeded in applying color space for pixelmap object.'); 3062 } 3063 }) 3064 } 3065} 3066``` 3067 3068### applyColorSpace<sup>11+</sup> 3069 3070applyColorSpace(targetColorSpace: colorSpaceManager.ColorSpaceManager): Promise\<void> 3071 3072Performs CSC on the image pixel color based on a given color space. This API uses a promise to return the result. 3073 3074**System capability**: SystemCapability.Multimedia.Image.Core 3075 3076**Parameters** 3077 3078| Name| Type | Mandatory| Description | 3079| ------ | ------------------ | ---- | ----------- | 3080| 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.| 3081 3082**Return value** 3083 3084| Type | Description | 3085| -------------- | --------------------------- | 3086| Promise\<void> | Promise that returns no value.| 3087 3088**Error codes** 3089 3090For details about the error codes, see [Image Error Codes](errorcode-image.md). 3091 3092| ID| Error Message| 3093| ------- | ------------------------------------------| 3094| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 3095| 62980104| Failed to initialize the internal object. | 3096| 62980108| Failed to convert the color space. | 3097| 62980115| Invalid image parameter. | 3098 3099**Example** 3100 3101```ts 3102import { colorSpaceManager } from '@kit.ArkGraphics2D'; 3103import { BusinessError } from '@kit.BasicServicesKit'; 3104 3105async function Demo() { 3106 let colorSpaceName = colorSpaceManager.ColorSpace.SRGB; 3107 let targetColorSpace: colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName); 3108 if (pixelMap != undefined) { 3109 pixelMap.applyColorSpace(targetColorSpace).then(() => { 3110 console.info('Succeeded in applying color space for pixelmap object.'); 3111 }).catch((error: BusinessError) => { 3112 console.error(`Failed to apply color space for pixelmap object. code is ${error.code}, message is ${error.message}`); 3113 }) 3114 } 3115} 3116``` 3117 3118### toSdr<sup>12+<sup> 3119 3120toSdr(): Promise\<void> 3121 3122Converts an HDR image into an SDR image. This API uses a promise to return the result. 3123 3124**System capability**: SystemCapability.Multimedia.Image.Core 3125 3126**Return value** 3127 3128| Type | Description | 3129| -------------- | --------------------------- | 3130| Promise\<void> | Promise that returns no value.| 3131 3132**Error codes** 3133 3134For details about the error codes, see [Image Error Codes](errorcode-image.md). 3135 3136| ID| Error Message| 3137| ------- | --------------------------------------------| 3138| 62980137 | Invalid image operation. | 3139 3140**Example** 3141 3142```ts 3143import image from '@ohos.multimedia.image' 3144import resourceManager from '@ohos.resourceManager' 3145import { BusinessError } from '@kit.BasicServicesKit'; 3146 3147// '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. 3148let img = getContext().resourceManager.getMediaContentSync($r('app.media.hdr')); 3149let imageSource = image.createImageSource(img.buffer.slice(0)); 3150let decodingOptions: image.DecodingOptions = { 3151 desiredDynamicRange: image.DecodingDynamicRange.AUTO 3152}; 3153let pixelmap = imageSource.createPixelMapSync(decodingOptions); 3154if (pixelmap != undefined) { 3155 console.info('Succeeded in creating pixelMap object.'); 3156 pixelmap.toSdr().then(() => { 3157 let imageInfo = pixelmap.getImageInfoSync(); 3158 console.info("after toSdr ,imageInfo isHdr:" + imageInfo.isHdr); 3159 }).catch((err: BusinessError) => { 3160 console.error(`Failed to set sdr. code is ${err.code}, message is ${err.message}`); 3161 }); 3162} else { 3163 console.info('Failed to create pixelMap.'); 3164} 3165``` 3166 3167### getMetadata<sup>12+</sup> 3168 3169getMetadata(key: HdrMetadataKey): HdrMetadataValue 3170 3171Obtains the value of the metadata with a given key in this PixelMap. 3172 3173**System capability**: SystemCapability.Multimedia.Image.Core 3174 3175**Parameters** 3176 3177| Name | Type | Mandatory| Description | 3178| ------------- | -------------------------------- | ---- | ---------------- | 3179| key | [HdrMetadataKey](#hdrmetadatakey12) | Yes | Key of the HDR metadata.| 3180 3181**Return value** 3182 3183| Type | Description | 3184| --------------------------------- | --------------------------------- | 3185| [HdrMetadataValue](#hdrmetadatavalue12) | Value of the metadata with the given key.| 3186 3187**Error codes** 3188 3189For details about the error codes, see [Image Error Codes](errorcode-image.md). 3190 3191| ID| Error Message| 3192| ------- | --------------------------------------------| 3193| 401| Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 3194| 501 | Resource unavailable. | 3195| 62980173 | The DMA memory does not exist. | 3196| 62980302 | Memory copy failed. | 3197 3198**Example** 3199 3200```ts 3201import { BusinessError } from '@kit.BasicServicesKit'; 3202import image from '@ohos.multimedia.image' 3203 3204// Replace 'app.media.test' with a local HDR image. 3205let img = getContext().resourceManager.getMediaContentSync($r('app.media.test')); 3206let imageSource = image.createImageSource(img.buffer.slice(0)); 3207let decodingOptions: image.DecodingOptions = { 3208 desiredDynamicRange: image.DecodingDynamicRange.AUTO 3209}; 3210let pixelmap = imageSource.createPixelMapSync(decodingOptions); 3211if (pixelmap != undefined) { 3212 console.info('Succeeded in creating pixelMap object.'); 3213 try { 3214 let staticMetadata = pixelmap.getMetadata(image.HdrMetadataKey.HDR_STATIC_METADATA); 3215 console.info("getmetadata:" + JSON.stringify(staticMetadata)); 3216 } catch (e) { 3217 console.info('pixelmap create failed' + e); 3218 } 3219} else { 3220 console.info('Failed to create pixelMap.'); 3221} 3222``` 3223 3224### setMetadata<sup>12+</sup> 3225 3226setMetadata(key: HdrMetadataKey, value: HdrMetadataValue): Promise\<void> 3227 3228Sets the value for the metadata with a given key in this PixelMap. 3229 3230**System capability**: SystemCapability.Multimedia.Image.Core 3231 3232**Parameters** 3233 3234| Name | Type | Mandatory| Description | 3235| ------------- | -------------------------------- | ---- | ---------------- | 3236| key | [HdrMetadataKey](#hdrmetadatakey12) | Yes | Key of the HDR metadata.| 3237| value | [HdrMetadataValue](#hdrmetadatavalue12) | Yes | Value of the metadata.| 3238 3239**Return value** 3240 3241| Type | Description | 3242| -------------- | --------------------- | 3243| Promise\<void> | Promise that returns no value.| 3244 3245**Error codes** 3246 3247For details about the error codes, see [Image Error Codes](errorcode-image.md). 3248 3249| ID| Error Message| 3250| ------- | --------------------------------------------| 3251| 401| Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 3252| 501 | Resource unavailable. | 3253| 62980173 | The DMA memory does not exist. | 3254| 62980302 | Memory copy failed. | 3255 3256**Example** 3257 3258```ts 3259import image from '@ohos.multimedia.image' 3260import { BusinessError } from '@kit.BasicServicesKit'; 3261 3262let staticMetadata: image.HdrStaticMetadata = { 3263 displayPrimariesX: [1.1, 1.1, 1.1], 3264 displayPrimariesY: [1.2, 1.2, 1.2], 3265 whitePointX: 1.1, 3266 whitePointY: 1.2, 3267 maxLuminance: 2.1, 3268 minLuminance: 1.0, 3269 maxContentLightLevel: 2.1, 3270 maxFrameAverageLightLevel: 2.1, 3271} 3272const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 3273let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } 3274image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => { 3275 pixelMap.setMetadata(image.HdrMetadataKey.HDR_STATIC_METADATA, staticMetadata).then((pixelMap: image.PixelMap) => { 3276 console.info('Succeeded in setting pixelMap metadata.'); 3277 }).catch((error: BusinessError) => { 3278 console.error(`Failed to set the metadata.code ${error.code},message is ${error.message}`); 3279 }) 3280}).catch((error: BusinessError) => { 3281 console.error(`Failed to create the PixelMap.code ${error.code},message is ${error.message}`); 3282}) 3283 3284``` 3285 3286### setTransferDetached<sup>12+<sup> 3287 3288setTransferDetached(detached: boolean): void 3289 3290Sets 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. 3291 3292**System capability**: SystemCapability.Multimedia.Image.Core 3293 3294**Parameters** 3295 3296| Name | Type | Mandatory| Description | 3297| ------- | ------------------ | ---- | ----------------------------- | 3298| detached | boolean | Yes | Whether to detach from the original thread. | 3299 3300**Error codes** 3301 3302For details about the error codes, see [Image Error Codes](errorcode-image.md). 3303 3304| ID| Error Message| 3305| ------- | --------------------------------------------| 3306| 501 | Resource Unavailable | 3307 3308**Example** 3309 3310```ts 3311import { BusinessError } from '@kit.BasicServicesKit'; 3312import image from '@ohos.multimedia.image'; 3313import taskpool from '@ohos.taskpool'; 3314 3315@Concurrent 3316// Child thread method 3317async function loadPixelMap(rawFileDescriptor: number): Promise<PixelMap> { 3318 // Create an ImageSource instance. 3319 const imageSource = image.createImageSource(rawFileDescriptor); 3320 // Create a pixelMap. 3321 const pixelMap = imageSource.createPixelMapSync(); 3322 // Release the ImageSource instance. 3323 imageSource.release(); 3324 // Disconnect the reference of the original thread after the cross-thread transfer of the pixelMap is complete. 3325 pixelMap.setTransferDetached(true); 3326 // Return the pixelMap to the main thread. 3327 return pixelMap; 3328} 3329 3330@Entry 3331@Component 3332struct Demo { 3333 @State pixelMap: PixelMap | undefined = undefined; 3334 // Main thread method 3335 private loadImageFromThread(): void { 3336 const resourceMgr = getContext(this).resourceManager; 3337 // '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. 3338 resourceMgr.getRawFd('example.jpg').then(rawFileDescriptor => { 3339 taskpool.execute(loadPixelMap, rawFileDescriptor).then(pixelMap => { 3340 if (pixelMap) { 3341 this.pixelMap = pixelMap as PixelMap; 3342 console.log('Succeeded in creating pixelMap.'); 3343 // The main thread releases the pixelMap. Because setTransferDetached has been called when the child thread returns pixelMap, the pixelMap can be released immediately. 3344 this.pixelMap.release(); 3345 } else { 3346 console.error('Failed to create pixelMap.'); 3347 } 3348 }); 3349 }); 3350 } 3351} 3352``` 3353 3354### marshalling<sup>10+</sup> 3355 3356marshalling(sequence: rpc.MessageSequence): void 3357 3358Marshals this **PixelMap** object and writes it to a **MessageSequence** object. 3359 3360**System capability**: SystemCapability.Multimedia.Image.Core 3361 3362**Parameters** 3363 3364| Name | Type | Mandatory| Description | 3365| ---------------------- | ------------------------------------------------------ | ---- | ---------------------------------------- | 3366| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | Yes | **MessageSequence** object. | 3367 3368**Error codes** 3369 3370For details about the error codes, see [Image Error Codes](errorcode-image.md). 3371 3372| ID| Error Message| 3373| ------- | --------------------------------------------| 3374| 62980115 | Invalid image parameter. | 3375| 62980097 | IPC error. | 3376 3377**Example** 3378 3379```ts 3380import { image } from '@kit.ImageKit'; 3381import { rpc } from '@kit.IPCKit'; 3382 3383class MySequence implements rpc.Parcelable { 3384 pixel_map: image.PixelMap; 3385 constructor(conPixelMap : image.PixelMap) { 3386 this.pixel_map = conPixelMap; 3387 } 3388 marshalling(messageSequence : rpc.MessageSequence) { 3389 this.pixel_map.marshalling(messageSequence); 3390 console.info('marshalling'); 3391 return true; 3392 } 3393 unmarshalling(messageSequence : rpc.MessageSequence) { 3394 image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}}).then((pixelParcel: image.PixelMap) => { 3395 pixelParcel.unmarshalling(messageSequence).then(async (pixelMap: image.PixelMap) => { 3396 this.pixel_map = pixelMap; 3397 pixelMap.getImageInfo().then((imageInfo: image.ImageInfo) => { 3398 console.info("unmarshalling information h:" + imageInfo.size.height + "w:" + imageInfo.size.width); 3399 }) 3400 }) 3401 }); 3402 return true; 3403 } 3404} 3405async function Demo() { 3406 const color: ArrayBuffer = new ArrayBuffer(96); 3407 let bufferArr: Uint8Array = new Uint8Array(color); 3408 for (let i = 0; i < bufferArr.length; i++) { 3409 bufferArr[i] = 0x80; 3410 } 3411 let opts: image.InitializationOptions = { 3412 editable: true, 3413 pixelFormat: 4, 3414 size: { height: 4, width: 6 }, 3415 alphaType: 3 3416 } 3417 let pixelMap: image.PixelMap | undefined = undefined; 3418 image.createPixelMap(color, opts).then((srcPixelMap: image.PixelMap) => { 3419 pixelMap = srcPixelMap; 3420 }) 3421 if (pixelMap != undefined) { 3422 // Implement serialization. 3423 let parcelable: MySequence = new MySequence(pixelMap); 3424 let data: rpc.MessageSequence = rpc.MessageSequence.create(); 3425 data.writeParcelable(parcelable); 3426 3427 // Implement deserialization to obtain data through the RPC. 3428 let ret: MySequence = new MySequence(pixelMap); 3429 data.readParcelable(ret); 3430 } 3431} 3432``` 3433 3434### unmarshalling<sup>10+</sup> 3435 3436unmarshalling(sequence: rpc.MessageSequence): Promise\<PixelMap> 3437 3438Unmarshals a **MessageSequence** object to obtain a **PixelMap** object. 3439To create a **PixelMap** object in synchronous mode, use [createPixelMapFromParcel](#imagecreatepixelmapfromparcel11). 3440 3441**System capability**: SystemCapability.Multimedia.Image.Core 3442 3443**Parameters** 3444 3445| Name | Type | Mandatory| Description | 3446| ---------------------- | ----------------------------------------------------- | ---- | ---------------------------------------- | 3447| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | Yes | **MessageSequence** object that stores the **PixelMap** information. | 3448 3449**Return value** 3450 3451| Type | Description | 3452| -------------------------------- | --------------------- | 3453| Promise\<[PixelMap](#pixelmap7)> |Promise used to return the **PixelMap** object.| 3454 3455**Error codes** 3456 3457For details about the error codes, see [Image Error Codes](errorcode-image.md). 3458 3459| ID| Error Message| 3460| ------- | --------------------------------------------| 3461| 62980115 | Invalid image parameter. | 3462| 62980097 | IPC error. | 3463| 62980096 | The operation failed. | 3464 3465**Example** 3466 3467```ts 3468import { image } from '@kit.ImageKit'; 3469import { rpc } from '@kit.IPCKit'; 3470 3471class MySequence implements rpc.Parcelable { 3472 pixel_map: image.PixelMap; 3473 constructor(conPixelMap: image.PixelMap) { 3474 this.pixel_map = conPixelMap; 3475 } 3476 marshalling(messageSequence: rpc.MessageSequence) { 3477 this.pixel_map.marshalling(messageSequence); 3478 console.info('marshalling'); 3479 return true; 3480 } 3481 unmarshalling(messageSequence: rpc.MessageSequence) { 3482 image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}}).then((pixelParcel : image.PixelMap) => { 3483 pixelParcel.unmarshalling(messageSequence).then(async (pixelMap : image.PixelMap) => { 3484 this.pixel_map = pixelMap; 3485 pixelMap.getImageInfo().then((imageInfo : image.ImageInfo) => { 3486 console.info("unmarshalling information h:" + imageInfo.size.height + "w:" + imageInfo.size.width); 3487 }) 3488 }) 3489 }); 3490 return true; 3491 } 3492} 3493async function Demo() { 3494 const color: ArrayBuffer = new ArrayBuffer(96); 3495 let bufferArr: Uint8Array = new Uint8Array(color); 3496 for (let i = 0; i < bufferArr.length; i++) { 3497 bufferArr[i] = 0x80; 3498 } 3499 let opts: image.InitializationOptions = { 3500 editable: true, 3501 pixelFormat: 4, 3502 size: { height: 4, width: 6 }, 3503 alphaType: 3 3504 } 3505 let pixelMap: image.PixelMap | undefined = undefined; 3506 image.createPixelMap(color, opts).then((srcPixelMap : image.PixelMap) => { 3507 pixelMap = srcPixelMap; 3508 }) 3509 if (pixelMap != undefined) { 3510 // Implement serialization. 3511 let parcelable: MySequence = new MySequence(pixelMap); 3512 let data : rpc.MessageSequence = rpc.MessageSequence.create(); 3513 data.writeParcelable(parcelable); 3514 3515 // Implement deserialization to obtain data through the RPC. 3516 let ret : MySequence = new MySequence(pixelMap); 3517 data.readParcelable(ret); 3518 } 3519} 3520``` 3521 3522### release<sup>7+</sup> 3523 3524release():Promise\<void> 3525 3526Releases this **PixelMap** object. This API uses a promise to return the result. 3527 3528ArkTS 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. 3529 3530**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3531 3532**Atomic service API**: This API can be used in atomic services since API version 11. 3533 3534**System capability**: SystemCapability.Multimedia.Image.Core 3535 3536**Return value** 3537 3538| Type | Description | 3539| -------------- | ------------------------------- | 3540| Promise\<void> | Promise that returns no value.| 3541 3542**Example** 3543 3544```ts 3545import { BusinessError } from '@kit.BasicServicesKit'; 3546 3547async function Demo() { 3548 if (pixelMap != undefined) { 3549 pixelMap.release().then(() => { 3550 console.info('Succeeded in releasing pixelmap object.'); 3551 }).catch((error: BusinessError) => { 3552 console.error(`Failed to release pixelmap object. code is ${error.code}, message is ${error.message}`); 3553 }) 3554 } 3555} 3556``` 3557 3558### release<sup>7+</sup> 3559 3560release(callback: AsyncCallback\<void>): void 3561 3562Releases this **PixelMap** object. This API uses an asynchronous callback to return the result. 3563 3564ArkTS 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. 3565 3566**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3567 3568**Atomic service API**: This API can be used in atomic services since API version 11. 3569 3570**System capability**: SystemCapability.Multimedia.Image.Core 3571 3572**Parameters** 3573 3574| Name | Type | Mandatory| Description | 3575| -------- | -------------------- | ---- | ------------------ | 3576| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 3577 3578**Example** 3579 3580```ts 3581import { BusinessError } from '@kit.BasicServicesKit'; 3582 3583async function Demo() { 3584 if (pixelMap != undefined) { 3585 pixelMap.release((err: BusinessError) => { 3586 if (err) { 3587 console.error(`Failed to release pixelmap object. code is ${err.code}, message is ${err.message}`); 3588 return; 3589 } else { 3590 console.info('Succeeded in releasing pixelmap object.'); 3591 } 3592 }) 3593 } 3594} 3595``` 3596 3597### convertPixelFormat<sup>12+</sup> 3598 3599convertPixelFormat(targetPixelFormat: PixelMapFormat): Promise\<void> 3600 3601Performs 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. 3602 3603**System capability**: SystemCapability.Multimedia.Image.Core 3604 3605**Parameters** 3606 3607| Name | Type | Mandatory| Description | 3608| -------- | -------------------- | ---- | ------------------ | 3609| 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.| 3610 3611**Return value** 3612 3613| Type | Description | 3614| -------------- | ------------------------------- | 3615| Promise\<void> | Promise that returns no value.| 3616 3617**Error codes** 3618 3619For details about the error codes, see [Image Error Codes](errorcode-image.md). 3620 3621| ID| Error Message| 3622| ------- | --------------------------------------------| 3623| 62980111 | The image source data is incomplete. | 3624| 62980115 | Invalid input parameter. | 3625| 62980178 | Failed to create the pixelmap. | 3626| 62980274 | The conversion failed | 3627| 62980276 | The type to be converted is an unsupported target pixel format| 3628 3629**Example** 3630 3631```ts 3632import { BusinessError } from '@kit.BasicServicesKit'; 3633 3634if (pixelMap != undefined) { 3635 // Set the target pixel format to NV12. 3636 let targetPixelFormat = image.PixelMapFormat.NV12; 3637 pixelMap.convertPixelFormat(targetPixelFormat).then(() => { 3638 // The pixelMap is converted to the NV12 format. 3639 console.info('PixelMapFormat convert Succeeded'); 3640 }).catch((error: BusinessError) => { 3641 // The pixelMap fails to be converted to the NV12 format. 3642 console.error(`PixelMapFormat convert Failed. code is ${error.code}, message is ${error.message}`); 3643 }) 3644} 3645``` 3646 3647### setMemoryNameSync<sup>13+</sup> 3648 3649setMemoryNameSync(name: string): void 3650 3651Sets a memory name for this PixelMap. 3652 3653**System capability**: SystemCapability.Multimedia.Image.Core 3654 3655**Parameters** 3656 3657| Name | Type | Mandatory| Description | 3658| ------------- | -------------------------------- | ---- | ---------------- | 3659| 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.| 3660 3661**Error codes** 3662 3663For details about the error codes, see [Image Error Codes](errorcode-image.md). 3664 3665| ID| Error Message| 3666| ------- | --------------------------------------------| 3667| 401 | Parameter error. Possible causes: 1.The length of the input parameter is too long. 2.Parameter verification failed. | 3668| 501 | Resource unavailable. | 3669| 62980286 | Memory format not supported. | 3670 3671**Example** 3672 3673```ts 3674import { BusinessError } from '@ohos.base'; 3675 3676async Demo() { 3677 if (pixelMap != undefined) { 3678 try { 3679 pixelMap.setMemoryNameSync("PixelMapName Test"); 3680 } catch(e) { 3681 let error = e as BusinessError; 3682 console.error(`setMemoryNameSync error. code is ${error.code}, message is ${error.message}`); 3683 } 3684 } 3685} 3686``` 3687 3688## image.createImageSource 3689 3690createImageSource(uri: string): ImageSource 3691 3692Creates an **ImageSource** instance based on a given URI. 3693 3694 3695**Atomic service API**: This API can be used in atomic services since API version 11. 3696 3697**System capability**: SystemCapability.Multimedia.Image.ImageSource 3698 3699**Parameters** 3700 3701| Name| Type | Mandatory| Description | 3702| ------ | ------ | ---- | ---------------------------------- | 3703| 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>.| 3704 3705**Return value** 3706 3707| Type | Description | 3708| --------------------------- | -------------------------------------------- | 3709| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 3710 3711**Example** 3712 3713```ts 3714const context: Context = getContext(this); 3715// '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. 3716const path: string = context.filesDir + "/test.jpg"; 3717const imageSourceApi: image.ImageSource = image.createImageSource(path); 3718``` 3719 3720## image.createImageSource<sup>9+</sup> 3721 3722createImageSource(uri: string, options: SourceOptions): ImageSource 3723 3724Creates an **ImageSource** instance based on a given URI. 3725 3726**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3727 3728**Atomic service API**: This API can be used in atomic services since API version 11. 3729 3730**System capability**: SystemCapability.Multimedia.Image.ImageSource 3731 3732**Parameters** 3733 3734| Name | Type | Mandatory| Description | 3735| ------- | ------------------------------- | ---- | ----------------------------------- | 3736| 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>.| 3737| options | [SourceOptions](#sourceoptions9) | Yes | Image properties, including the image pixel density, pixel format, and image size.| 3738 3739**Return value** 3740 3741| Type | Description | 3742| --------------------------- | -------------------------------------------- | 3743| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 3744 3745**Example** 3746 3747```ts 3748let sourceOptions: image.SourceOptions = { sourceDensity: 120 }; 3749const context: Context = getContext(this); 3750// '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. 3751const path: string = context.filesDir + "/test.png"; 3752let imageSourceApi: image.ImageSource = image.createImageSource(path, sourceOptions); 3753``` 3754 3755## image.createImageSource<sup>7+</sup> 3756 3757createImageSource(fd: number): ImageSource 3758 3759Creates an **ImageSource** instance based on a given file descriptor. 3760 3761**Atomic service API**: This API can be used in atomic services since API version 11. 3762 3763**System capability**: SystemCapability.Multimedia.Image.ImageSource 3764 3765**Parameters** 3766 3767| Name| Type | Mandatory| Description | 3768| ------ | ------ | ---- | ------------- | 3769| fd | number | Yes | File descriptor.| 3770 3771**Return value** 3772 3773| Type | Description | 3774| --------------------------- | -------------------------------------------- | 3775| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 3776 3777**Example** 3778 3779```ts 3780import { fileIo as fs } from '@kit.CoreFileKit'; 3781 3782const context: Context = getContext(this); 3783// '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. 3784let filePath: string = context.filesDir + "/test.jpg"; 3785let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 3786const imageSourceApi: image.ImageSource = image.createImageSource(file.fd); 3787``` 3788 3789## image.createImageSource<sup>9+</sup> 3790 3791createImageSource(fd: number, options: SourceOptions): ImageSource 3792 3793Creates an **ImageSource** instance based on a given file descriptor. 3794 3795**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3796 3797**Atomic service API**: This API can be used in atomic services since API version 11. 3798 3799**System capability**: SystemCapability.Multimedia.Image.ImageSource 3800 3801**Parameters** 3802 3803| Name | Type | Mandatory| Description | 3804| ------- | ------------------------------- | ---- | ----------------------------------- | 3805| fd | number | Yes | File descriptor. | 3806| options | [SourceOptions](#sourceoptions9) | Yes | Image properties, including the image pixel density, pixel format, and image size.| 3807 3808**Return value** 3809 3810| Type | Description | 3811| --------------------------- | -------------------------------------------- | 3812| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 3813 3814**Example** 3815 3816```ts 3817import { fileIo as fs } from '@kit.CoreFileKit'; 3818 3819let sourceOptions: image.SourceOptions = { sourceDensity: 120 }; 3820const context: Context = getContext(); 3821// '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. 3822const filePath: string = context.filesDir + "/test.jpg"; 3823let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 3824const imageSourceApi: image.ImageSource = image.createImageSource(file.fd, sourceOptions); 3825``` 3826 3827## image.createImageSource<sup>9+</sup> 3828 3829createImageSource(buf: ArrayBuffer): ImageSource 3830 3831Creates 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). 3832 3833**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3834 3835**Atomic service API**: This API can be used in atomic services since API version 11. 3836 3837**System capability**: SystemCapability.Multimedia.Image.ImageSource 3838 3839**Parameters** 3840 3841| Name| Type | Mandatory| Description | 3842| ------ | ----------- | ---- | ---------------- | 3843| buf | ArrayBuffer | Yes | Array of image buffers.| 3844 3845**Return value** 3846 3847| Type | Description | 3848| --------------------------- | -------------------------------------------- | 3849| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 3850 3851 3852**Example** 3853 3854```ts 3855const buf: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 3856const imageSourceApi: image.ImageSource = image.createImageSource(buf); 3857``` 3858 3859## image.createImageSource<sup>9+</sup> 3860 3861createImageSource(buf: ArrayBuffer, options: SourceOptions): ImageSource 3862 3863Creates 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). 3864 3865**Widget capability**: This API can be used in ArkTS widgets since API version 12. 3866 3867**Atomic service API**: This API can be used in atomic services since API version 11. 3868 3869**System capability**: SystemCapability.Multimedia.Image.ImageSource 3870 3871**Parameters** 3872 3873| Name| Type | Mandatory| Description | 3874| ------ | -------------------------------- | ---- | ------------------------------------ | 3875| buf | ArrayBuffer | Yes | Array of image buffers. | 3876| options | [SourceOptions](#sourceoptions9) | Yes | Image properties, including the image pixel density, pixel format, and image size.| 3877 3878**Return value** 3879 3880| Type | Description | 3881| --------------------------- | -------------------------------------------- | 3882| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 3883 3884**Example** 3885 3886```ts 3887const data: ArrayBuffer = new ArrayBuffer(112); 3888let sourceOptions: image.SourceOptions = { sourceDensity: 120 }; 3889const imageSourceApi: image.ImageSource = image.createImageSource(data, sourceOptions); 3890``` 3891 3892## image.createImageSource<sup>11+</sup> 3893 3894createImageSource(rawfile: resourceManager.RawFileDescriptor, options?: SourceOptions): ImageSource 3895 3896Creates an **ImageSource** instance based on the raw file descriptor of an image resource file. 3897 3898**Atomic service API**: This API can be used in atomic services since API version 11. 3899 3900**System capability**: SystemCapability.Multimedia.Image.ImageSource 3901 3902**Parameters** 3903 3904| Name| Type | Mandatory| Description | 3905| ------ | -------------------------------- | ---- | ------------------------------------ | 3906| rawfile | [resourceManager.RawFileDescriptor](../apis-localization-kit/js-apis-resource-manager.md#rawfiledescriptor8) | Yes| Raw file descriptor of the image resource file.| 3907| options | [SourceOptions](#sourceoptions9) | No| Image properties, including the image pixel density, pixel format, and image size.| 3908 3909**Return value** 3910 3911| Type | Description | 3912| --------------------------- | -------------------------------------------- | 3913| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.| 3914 3915**Example** 3916 3917```ts 3918import { resourceManager } from '@kit.LocalizationKit'; 3919 3920const context: Context = getContext(this); 3921// Obtain a resource manager. 3922const resourceMgr: resourceManager.ResourceManager = context.resourceManager; 3923// '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. 3924resourceMgr.getRawFd('test.jpg').then((rawFileDescriptor: resourceManager.RawFileDescriptor) => { 3925 const imageSourceApi: image.ImageSource = image.createImageSource(rawFileDescriptor); 3926}).catch((error: BusinessError) => { 3927 console.error(`Failed to get RawFileDescriptor.code is ${error.code}, message is ${error.message}`); 3928}) 3929``` 3930 3931## image.CreateIncrementalSource<sup>9+</sup> 3932 3933CreateIncrementalSource(buf: ArrayBuffer): ImageSource 3934 3935Creates an **ImageSource** instance in incremental mode based on buffers. Such an instance does not support reading or writing of EXIF information. 3936 3937The **ImageSource** instance created in incremental mode supports the following capabilities (applicable to synchronous, callback, and promise modes): 3938- Obtaining image information: Call [getImageInfo](#getimageinfo) to obtain image information by index, or call [getImageInfo](#getimageinfo-1) to directly obtain image information. 3939- Obtaining an image property: Call [getImageProperty](#getimageproperty11) to obtain the value of a property with the specified index in an image. 3940- Obtaining image properties: Call [getImageProperties](#getimageproperties12) to obtain the values of properties with the given names in an image. 3941- Updating incremental data: Call [updateData](#updatedata9) to update data. 3942- Creating a **PixelMap** object: Call [createPixelMap](#createpixelmap7) or [createPixelMap](#createpixelmap7-2) to create a PixelMap based on image decoding parameters, or call [createPixelMap](#createpixelmap7-1) to create a PixelMap based on default parameters. 3943- Releasing an **ImageSource** instance: Call [release](#release) to release an image source. 3944 3945**System capability**: SystemCapability.Multimedia.Image.ImageSource 3946 3947**Parameters** 3948 3949| Name | Type | Mandatory| Description | 3950| ------- | ------------| ---- | ----------| 3951| buf | ArrayBuffer | Yes | Incremental data.| 3952 3953**Return value** 3954 3955| Type | Description | 3956| --------------------------- | --------------------------------- | 3957| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns undefined otherwise.| 3958 3959**Example** 3960 3961```ts 3962const context: Context = getContext(this) 3963let imageArray = context.resourceManager.getMediaContentSync($r('app.media.startIcon')) // Obtain the image resource. 3964// '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. 3965let splitBuff1 = imageArray.slice(0, imageArray.byteLength / 2) // Image slice. 3966let splitBuff2 = imageArray.slice(imageArray.byteLength / 2) 3967const imageSourceIncrementalSApi: image.ImageSource = image.CreateIncrementalSource(new ArrayBuffer(imageArray.byteLength)); 3968imageSourceIncrementalSApi.updateData(splitBuff1, false, 0, splitBuff1.byteLength).then(() => { 3969 imageSourceIncrementalSApi.updateData(splitBuff2, true, 0, splitBuff2.byteLength).then(() => { 3970 let pixelMap = imageSourceIncrementalSApi.createPixelMapSync() 3971 let imageInfo = pixelMap.getImageInfoSync() 3972 console.info('Succeeded in creating pixelMap') 3973 }).catch((error : BusinessError) => { 3974 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`) 3975 }) 3976}).catch((error : BusinessError) => { 3977 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`) 3978}) 3979``` 3980 3981## image.CreateIncrementalSource<sup>9+</sup> 3982 3983CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource 3984 3985Creates an **ImageSource** instance in incremental mode based on buffers. Such an instance does not support reading or writing of EXIF information. 3986 3987The 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). 3988 3989**System capability**: SystemCapability.Multimedia.Image.ImageSource 3990 3991**Parameters** 3992 3993| Name | Type | Mandatory| Description | 3994| ------- | ------------------------------- | ---- | ------------------------------------ | 3995| buf | ArrayBuffer | Yes | Incremental data. | 3996| options | [SourceOptions](#sourceoptions9) | No | Image properties, including the image pixel density, pixel format, and image size.| 3997 3998**Return value** 3999 4000| Type | Description | 4001| --------------------------- | --------------------------------- | 4002| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns undefined otherwise.| 4003 4004**Example** 4005 4006```ts 4007const context: Context = getContext(this) 4008let imageArray = context.resourceManager.getMediaContentSync($r('app.media.startIcon')) // Obtain the image resource. 4009// '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. 4010let splitBuff1 = imageArray.slice(0, imageArray.byteLength / 2) // Image slice. 4011let splitBuff2 = imageArray.slice(imageArray.byteLength / 2) 4012let sourceOptions: image.SourceOptions = { sourceDensity: 120}; 4013 4014const imageSourceIncrementalSApi: image.ImageSource = image.CreateIncrementalSource(new ArrayBuffer(imageArray.byteLength), sourceOptions); 4015imageSourceIncrementalSApi.updateData(splitBuff1, false, 0, splitBuff1.byteLength).then(() => { 4016 imageSourceIncrementalSApi.updateData(splitBuff2, true, 0, splitBuff2.byteLength).then(() => { 4017 let pixelMap = imageSourceIncrementalSApi.createPixelMapSync() 4018 let imageInfo = pixelMap.getImageInfoSync() 4019 console.info('Succeeded in creating pixelMap') 4020 }).catch((error : BusinessError) => { 4021 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`) 4022 }) 4023}).catch((error : BusinessError) => { 4024 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`) 4025}) 4026``` 4027 4028## ImageSource 4029 4030Provides APIs to obtain image information. Before calling any API in **ImageSource**, you must use [createImageSource](#imagecreateimagesource) to create an **ImageSource** instance. 4031 4032### Properties 4033 4034**System capability**: SystemCapability.Multimedia.Image.ImageSource 4035 4036| Name | Type | Readable| Writable| Description | 4037| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | 4038| supportedFormats | Array\<string> | Yes | No | Supported formats, including .png, .jpeg, .bmp, .gif, .webp, .dng. and .heif<sup>12+</sup> (depending on the hardware).| 4039 4040### getImageInfo 4041 4042getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void 4043 4044Obtains information about an image with the specified index. This API uses an asynchronous callback to return the result. 4045 4046**Widget capability**: This API can be used in ArkTS widgets since API version 12. 4047 4048**Atomic service API**: This API can be used in atomic services since API version 11. 4049 4050**System capability**: SystemCapability.Multimedia.Image.ImageSource 4051 4052**Parameters** 4053 4054| Name | Type | Mandatory| Description | 4055| -------- | -------------------------------------- | ---- | ---------------------------------------- | 4056| index | number | Yes | Index of the image. | 4057| 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.| 4058 4059**Example** 4060 4061```ts 4062import { BusinessError } from '@kit.BasicServicesKit'; 4063 4064imageSourceApi.getImageInfo(0, (error: BusinessError, imageInfo: image.ImageInfo) => { 4065 if (error) { 4066 console.error(`Failed to obtain the image information.code is ${error.code}, message is ${error.message}`); 4067 } else { 4068 console.info('Succeeded in obtaining the image information.'); 4069 } 4070}) 4071``` 4072 4073### getImageInfo 4074 4075getImageInfo(callback: AsyncCallback\<ImageInfo>): void 4076 4077Obtains information about this image. This API uses an asynchronous callback to return the result. 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| 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.| 4090 4091**Example** 4092 4093```ts 4094import { BusinessError } from '@kit.BasicServicesKit'; 4095 4096imageSourceApi.getImageInfo((err: BusinessError, imageInfo: image.ImageInfo) => { 4097 if (err) { 4098 console.error(`Failed to obtain the image information.code is ${err.code}, message is ${err.message}`); 4099 } else { 4100 console.info('Succeeded in obtaining the image information.'); 4101 } 4102}) 4103``` 4104 4105### getImageInfo 4106 4107getImageInfo(index?: number): Promise\<ImageInfo> 4108 4109Obtains information about an image with the specified index. This API uses a promise to return the result. 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| index | number | No | Index of the image. If this parameter is not set, the default value **0** is used.| 4122 4123**Return value** 4124 4125| Type | Description | 4126| -------------------------------- | ---------------------- | 4127| Promise<[ImageInfo](#imageinfo)> | Promise used to return the image information.| 4128 4129**Example** 4130 4131```ts 4132import { BusinessError } from '@kit.BasicServicesKit'; 4133 4134imageSourceApi.getImageInfo(0) 4135 .then((imageInfo: image.ImageInfo) => { 4136 console.info('Succeeded in obtaining the image information.'); 4137 }).catch((error: BusinessError) => { 4138 console.error(`Failed to obtain the image information.code is ${error.code}, message is ${error.message}`); 4139 }) 4140``` 4141 4142### getImageInfoSync<sup>12+</sup> 4143 4144getImageInfoSync(index?: number): ImageInfo 4145 4146Obtains information about an image with the specified index. This API returns the result synchronously. 4147 4148**System capability**: SystemCapability.Multimedia.Image.ImageSource 4149 4150**Parameters** 4151 4152| Name| Type | Mandatory| Description | 4153| ----- | ------ | ---- | ------------------------------------- | 4154| index | number | No | Index of the image. If this parameter is not set, the default value **0** is used.| 4155 4156**Return value** 4157 4158| Type | Description | 4159| -------------------------------- | ---------------------- | 4160| [ImageInfo](#imageinfo) | Image information.| 4161 4162**Example** 4163 4164```ts 4165import { image } from '@kit.ImageKit'; 4166 4167const context: Context = getContext(); 4168// '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. 4169let filePath: string = context.filesDir + "/test.jpg"; 4170let imageSource = image.createImageSource(filePath); 4171let imageInfo = imageSource.getImageInfoSync(0); 4172if (imageInfo == undefined) { 4173 console.error('Failed to obtain the image information.'); 4174} else { 4175 console.info('Succeeded in obtaining the image information.'); 4176 console.info('imageInfo.size.height:' + imageInfo.size.height); 4177 console.info('imageInfo.size.width:' + imageInfo.size.width); 4178} 4179``` 4180 4181### getImageProperty<sup>11+</sup> 4182 4183getImageProperty(key:PropertyKey, options?: ImagePropertyOptions): Promise\<string> 4184 4185Obtains 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. 4186 4187**System capability**: SystemCapability.Multimedia.Image.ImageSource 4188 4189**Parameters** 4190 4191| Name | Type | Mandatory| Description | 4192| ------- | ---------------------------------------------------- | ---- | ------------------------------------ | 4193| key | [PropertyKey](#propertykey7) | Yes | Name of the property. | 4194| options | [ImagePropertyOptions](#imagepropertyoptions11) | No | Image properties, including the image index and default property value.| 4195 4196**Return value** 4197 4198| Type | Description | 4199| ---------------- | ----------------------------------------------------------------- | 4200| Promise\<string> | Promise used to return the property value. If the operation fails, the default value is returned.| 4201 4202**Error codes** 4203 4204For details about the error codes, see [Image Error Codes](errorcode-image.md). 4205 4206| ID| Error Message| 4207| ------- | --------------------------------------------| 4208| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 4209| 62980096 | The operation failed. | 4210| 62980103 | The image data is not supported. | 4211| 62980110 | The image source data is incorrect. | 4212| 62980111 | The image source data is incomplete. | 4213| 62980112 | The image format does not match. | 4214| 62980113 | Unknown image format. | 4215| 62980115 | Invalid image parameter. | 4216| 62980116| Failed to decode the image. | 4217| 62980118 | Failed to create the image plugin. | 4218| 62980122 | Failed to decode the image header. | 4219| 62980123| Images in EXIF format are not supported. | 4220| 62980135| The EXIF value is invalid. | 4221 4222**Example** 4223 4224```ts 4225import { BusinessError } from '@kit.BasicServicesKit'; 4226 4227let options: image.ImagePropertyOptions = { index: 0, defaultValue: '9999' } 4228imageSourceApi.getImageProperty(image.PropertyKey.BITS_PER_SAMPLE, options) 4229.then((data: string) => { 4230 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 4231}).catch((error: BusinessError) => { 4232 console.error('Failed to get the value of the specified attribute key of the image.'); 4233}) 4234``` 4235 4236### getImageProperty<sup>(deprecated)</sup> 4237 4238getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\<string> 4239 4240Obtains 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. 4241 4242> **NOTE** 4243> 4244> This API is deprecated since API version 11. You are advised to use [getImageProperty](#getimageproperty11). 4245 4246**System capability**: SystemCapability.Multimedia.Image.ImageSource 4247 4248**Parameters** 4249 4250| Name | Type | Mandatory| Description | 4251| ------- | ---------------------------------------------------- | ---- | ------------------------------------ | 4252| key | string | Yes | Name of the property. | 4253| options | [GetImagePropertyOptions](#getimagepropertyoptionsdeprecated) | No | Image properties, including the image index and default property value.| 4254 4255**Return value** 4256 4257| Type | Description | 4258| ---------------- | ----------------------------------------------------------------- | 4259| Promise\<string> | Promise used to return the property value. If the operation fails, the default value is returned.| 4260 4261**Example** 4262 4263```ts 4264import { BusinessError } from '@kit.BasicServicesKit'; 4265 4266imageSourceApi.getImageProperty("BitsPerSample") 4267 .then((data: string) => { 4268 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 4269 }).catch((error: BusinessError) => { 4270 console.error('Failed to get the value of the specified attribute key of the image.'); 4271 }) 4272``` 4273 4274### getImageProperty<sup>(deprecated)</sup> 4275 4276getImageProperty(key:string, callback: AsyncCallback\<string>): void 4277 4278Obtains 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. 4279 4280> **NOTE** 4281> 4282> This API is deprecated since API version 11. You are advised to use [getImageProperty](#getimageproperty11). 4283 4284**System capability**: SystemCapability.Multimedia.Image.ImageSource 4285 4286**Parameters** 4287 4288| Name | Type | Mandatory| Description | 4289| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 4290| key | string | Yes | Name of the property. | 4291| 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.| 4292 4293**Example** 4294 4295```ts 4296import { BusinessError } from '@kit.BasicServicesKit'; 4297 4298imageSourceApi.getImageProperty("BitsPerSample", (error: BusinessError, data: string) => { 4299 if (error) { 4300 console.error('Failed to get the value of the specified attribute key of the image.'); 4301 } else { 4302 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 4303 } 4304}) 4305``` 4306 4307### getImageProperty<sup>(deprecated)</sup> 4308 4309getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCallback\<string>): void 4310 4311Obtains 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. 4312 4313> **NOTE** 4314> 4315> This API is deprecated since API version 11. You are advised to use [getImageProperty](#getimageproperty11). 4316 4317**System capability**: SystemCapability.Multimedia.Image.ImageSource 4318 4319**Parameters** 4320 4321| Name | Type | Mandatory| Description | 4322| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------- | 4323| key | string | Yes | Name of the property. | 4324| options | [GetImagePropertyOptions](#getimagepropertyoptionsdeprecated) | Yes | Image properties, including the image index and default property value. | 4325| 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.| 4326 4327**Example** 4328 4329```ts 4330import { BusinessError } from '@kit.BasicServicesKit'; 4331 4332let property: image.GetImagePropertyOptions = { index: 0, defaultValue: '9999' } 4333imageSourceApi.getImageProperty("BitsPerSample", property, (error: BusinessError, data: string) => { 4334 if (error) { 4335 console.error('Failed to get the value of the specified attribute key of the image.'); 4336 } else { 4337 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 4338 } 4339}) 4340``` 4341 4342### getImageProperties<sup>12+</sup> 4343 4344getImageProperties(key: Array<PropertyKey>): Promise<Record<PropertyKey, string|null>> 4345 4346Obtains 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. 4347 4348**System capability**: SystemCapability.Multimedia.Image.ImageSource 4349 4350**Parameters** 4351 4352| Name | Type | Mandatory| Description | 4353| ------- | ---------------------------------------------------- | ---- | ------------------------------------ | 4354| key | Array\<[PropertyKey](#propertykey7)> | Yes | Array of properties names. | 4355 4356**Return value** 4357 4358| Type | Description | 4359| ---------------- | ----------------------------------------------------------------- | 4360| Promise\<Record<[PropertyKey](#propertykey7), string \| null>> | Promise used to return the property values. If the operation fails, **null** is returned.| 4361 4362**Error codes** 4363 4364For details about the error codes, see [Image Error Codes](errorcode-image.md). 4365 4366| ID| Error Message| 4367| ------- | --------------------------------------------| 4368| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 4369| 62980096| The operation failed. | 4370| 62980110| The image source data is incorrect. | 4371| 62980113| Unknown image format. | 4372| 62980116| Failed to decode the image. | 4373 4374**Example** 4375 4376```ts 4377import { image } from '@kit.ImageKit'; 4378import { BusinessError } from '@kit.BasicServicesKit'; 4379 4380let key = [image.PropertyKey.IMAGE_WIDTH, image.PropertyKey.IMAGE_LENGTH]; 4381imageSourceApi.getImageProperties(key).then((data) => { 4382 console.info(JSON.stringify(data)); 4383}).catch((err: BusinessError) => { 4384 console.error(JSON.stringify(err)); 4385}); 4386``` 4387 4388### modifyImageProperty<sup>11+</sup> 4389 4390modifyImageProperty(key: PropertyKey, value: string): Promise\<void> 4391 4392Modifies 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. 4393 4394> **NOTE** 4395> 4396> 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. 4397 4398**System capability**: SystemCapability.Multimedia.Image.ImageSource 4399 4400**Parameters** 4401 4402| Name | Type | Mandatory| Description | 4403| ------- | ------ | ---- | ------------ | 4404| key | [PropertyKey](#propertykey7) | Yes | Name of the property.| 4405| value | string | Yes | New value of the property. | 4406 4407**Return value** 4408 4409| Type | Description | 4410| -------------- | --------------------------- | 4411| Promise\<void> | Promise that returns no value.| 4412 4413**Error codes** 4414 4415For details about the error codes, see [Image Error Codes](errorcode-image.md). 4416 4417| ID| Error Message| 4418| ------- | --------------------------------------------| 4419| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; | 4420| 62980123| The image does not support EXIF decoding. | 4421| 62980133| The EXIF data is out of range. | 4422| 62980135| The EXIF value is invalid. | 4423| 62980146| The EXIF data failed to be written to the file. | 4424 4425**Example** 4426 4427```ts 4428import { BusinessError } from '@kit.BasicServicesKit'; 4429 4430imageSourceApi.modifyImageProperty(image.PropertyKey.IMAGE_WIDTH, "120").then(() => { 4431 imageSourceApi.getImageProperty(image.PropertyKey.IMAGE_WIDTH).then((width: string) => { 4432 console.info(`ImageWidth is :${width}`); 4433 }).catch((error: BusinessError) => { 4434 console.error('Failed to get the Image Width.'); 4435 }) 4436}).catch((error: BusinessError) => { 4437 console.error('Failed to modify the Image Width'); 4438}) 4439``` 4440 4441### modifyImageProperty<sup>(deprecated)</sup> 4442 4443modifyImageProperty(key: string, value: string): Promise\<void> 4444 4445Modifies 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. 4446 4447> **NOTE** 4448> 4449> 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. 4450> 4451> This API is deprecated since API version 11. You are advised to use [modifyImageProperty](#modifyimageproperty11). 4452 4453**System capability**: SystemCapability.Multimedia.Image.ImageSource 4454 4455**Parameters** 4456 4457| Name | Type | Mandatory| Description | 4458| ------- | ------ | ---- | ------------ | 4459| key | string | Yes | Name of the property.| 4460| value | string | Yes | New value of the property. | 4461 4462**Return value** 4463 4464| Type | Description | 4465| -------------- | --------------------------- | 4466| Promise\<void> | Promise that returns no value.| 4467 4468**Example** 4469 4470```ts 4471import { BusinessError } from '@kit.BasicServicesKit'; 4472 4473imageSourceApi.modifyImageProperty("ImageWidth", "120").then(() => { 4474 imageSourceApi.getImageProperty("ImageWidth").then((width: string) => { 4475 console.info(`ImageWidth is :${width}`); 4476 }).catch((error: BusinessError) => { 4477 console.error('Failed to get the Image Width.'); 4478 }) 4479}).catch((error: BusinessError) => { 4480 console.error('Failed to modify the Image Width'); 4481}) 4482``` 4483 4484### modifyImageProperty<sup>(deprecated)</sup> 4485 4486modifyImageProperty(key: string, value: string, callback: AsyncCallback\<void>): void 4487 4488Modifies 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. 4489 4490> **NOTE** 4491> 4492> 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. 4493> 4494>This API is deprecated since API version 11. You are advised to use [modifyImageProperty](#modifyimageproperty11). 4495 4496**System capability**: SystemCapability.Multimedia.Image.ImageSource 4497 4498**Parameters** 4499 4500| Name | Type | Mandatory| Description | 4501| -------- | ------------------- | ---- | ------------------------------ | 4502| key | string | Yes | Name of the property. | 4503| value | string | Yes | New value of the property. | 4504| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 4505 4506**Example** 4507 4508```ts 4509import { BusinessError } from '@kit.BasicServicesKit'; 4510 4511imageSourceApi.modifyImageProperty("ImageWidth", "120", (err: BusinessError) => { 4512 if (err) { 4513 console.error(`Failed to modify the Image Width.code is ${err.code}, message is ${err.message}`); 4514 } else { 4515 console.info('Succeeded in modifying the Image Width.'); 4516 } 4517}) 4518``` 4519 4520### modifyImageProperties<sup>12+</sup> 4521 4522modifyImageProperties(records: Record<PropertyKey, string|null>): Promise\<void> 4523 4524Modifies 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. 4525 4526> **NOTE** 4527> 4528> 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. 4529> 4530 4531**System capability**: SystemCapability.Multimedia.Image.ImageSource 4532 4533**Parameters** 4534 4535| Name | Type | Mandatory| Description | 4536| ------- | ------ | ---- | ------------ | 4537| records | Record<[PropertyKey](#propertykey7), string \| null> | Yes | Array of property names and property values.| 4538 4539**Return value** 4540 4541| Type | Description | 4542| -------------- | --------------------------- | 4543| Promise\<void> | Promise that returns no value.| 4544 4545**Error codes** 4546 4547For details about the error codes, see [Image Error Codes](errorcode-image.md). 4548 4549| ID| Error Message| 4550| ------- | --------------------------------------------| 4551| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 4552| 62980123| The image does not support EXIF decoding. | 4553| 62980133| The EXIF data is out of range. | 4554| 62980135| The EXIF value is invalid. | 4555| 62980146| The EXIF data failed to be written to the file. | 4556 4557**Example** 4558 4559```ts 4560import { image } from '@kit.ImageKit'; 4561import { BusinessError } from '@kit.BasicServicesKit'; 4562 4563let keyValues: Record<PropertyKey, string|null> = { 4564 [image.PropertyKey.IMAGE_WIDTH] : "1024", 4565 [image.PropertyKey.IMAGE_LENGTH] : "1024" 4566}; 4567let checkKey = [image.PropertyKey.IMAGE_WIDTH, image.PropertyKey.IMAGE_LENGTH]; 4568imageSourceApi.modifyImageProperties(keyValues).then(() => { 4569 imageSourceApi.getImageProperties(checkKey).then((data) => { 4570 console.info(JSON.stringify(data)); 4571 }).catch((err: BusinessError) => { 4572 console.error(JSON.stringify(err)); 4573 }); 4574}).catch((err: BusinessError) => { 4575 console.error(JSON.stringify(err)); 4576}); 4577``` 4578 4579### updateData<sup>9+</sup> 4580 4581updateData(buf: ArrayBuffer, isFinished: boolean, offset: number, length: number): Promise\<void> 4582 4583Updates incremental data. This API uses a promise to return the result. 4584 4585**System capability**: SystemCapability.Multimedia.Image.ImageSource 4586 4587**Parameters** 4588 4589| Name | Type | Mandatory| Description | 4590| ---------- | ----------- | ---- | ------------ | 4591| buf | ArrayBuffer | Yes | Incremental data. | 4592| isFinished | boolean | Yes | Whether the update is complete.| 4593| offset | number | Yes | Offset for data reading. | 4594| length | number | Yes | Array length. | 4595 4596**Return value** 4597 4598| Type | Description | 4599| -------------- | -------------------------- | 4600| Promise\<void> | Promise that returns no value.| 4601 4602**Example** 4603 4604```ts 4605import { BusinessError } from '@kit.BasicServicesKit'; 4606 4607const array: ArrayBuffer = new ArrayBuffer(100); 4608imageSourceApi.updateData(array, false, 0, 10).then(() => { 4609 console.info('Succeeded in updating data.'); 4610}).catch((err: BusinessError) => { 4611 console.error(`Failed to update data.code is ${err.code},message is ${err.message}`); 4612}) 4613``` 4614 4615 4616### updateData<sup>9+</sup> 4617 4618updateData(buf: ArrayBuffer, isFinished: boolean, offset: number, length: number, callback: AsyncCallback\<void>): void 4619 4620Updates incremental data. This API uses an asynchronous callback to return the result. 4621 4622**System capability**: SystemCapability.Multimedia.Image.ImageSource 4623 4624**Parameters** 4625 4626| Name | Type | Mandatory| Description | 4627| ---------- | ------------------- | ---- | -------------------- | 4628| buf | ArrayBuffer | Yes | Incremental data. | 4629| isFinished | boolean | Yes | Whether the update is complete. | 4630| offset | number | Yes | Offset for data reading. | 4631| length | number | Yes | Array length. | 4632| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 4633 4634**Example** 4635 4636```ts 4637import { BusinessError } from '@kit.BasicServicesKit'; 4638 4639const array: ArrayBuffer = new ArrayBuffer(100); 4640imageSourceApi.updateData(array, false, 0, 10, (err: BusinessError) => { 4641 if (err) { 4642 console.error(`Failed to update data.code is ${err.code},message is ${err.message}`); 4643 } else { 4644 console.info('Succeeded in updating data.'); 4645 } 4646}) 4647``` 4648 4649### createPicture<sup>13+</sup> 4650 4651createPicture(options?: DecodingOptionsForPicture): Promise\<Picture> 4652 4653Creates a **Picture** object based on image decoding parameters. This API uses a promise to return the result. 4654 4655**System capability**: SystemCapability.Multimedia.Image.ImageSource 4656 4657**Parameters** 4658 4659| Name | Type | Mandatory| Description | 4660| ------- | ------------------------------------------------------ | ---- | ---------- | 4661| options | [DecodingOptionsForPicture](#decodingoptionsforpicture13) | No | Image decoding parameters.| 4662 4663**Return value** 4664 4665| Type | Description | 4666| ---------------------------- | -------------------------- | 4667| Promise\<[Picture](#picture13)> | Promise used to return the **Picture** object.| 4668 4669**Error codes** 4670 4671For details about the error codes, see [Image Error Codes](errorcode-image.md). 4672 4673| ID| Error Message | 4674| -------- | ------------------------------------------------------------ | 4675| 401 | Parameter error.Possible causes: 1.Mandatory parameters are left unspecified.2.Incorrect parameter types; 3.Parameter verification failed. | 4676| 7700301 | Decode failed. | 4677 4678**Example** 4679 4680```ts 4681import { image } from '@kit.ImageKit'; 4682 4683async function CreatePicture() { 4684 let options: image.DecodingOptionsForPicture = { 4685 desiredAuxiliaryPictures: [image.AuxiliaryPictureType.GAINMAP] // GAINMAP indicates the type of the auxiliary picture to be decoded. 4686 }; 4687 let pictureObj: image.Picture = await imageSourceApi.createPicture(options); 4688 if (pictureObj != null) { 4689 console.info('Create picture succeeded'); 4690 } else { 4691 console.info('Create picture failed'); 4692 } 4693} 4694``` 4695 4696### createPixelMap<sup>7+</sup> 4697 4698createPixelMap(options?: DecodingOptions): Promise\<PixelMap> 4699 4700Creates a **PixelMap** object based on image decoding parameters. This API uses a promise to return the result. 4701 4702**Widget capability**: This API can be used in ArkTS widgets since API version 12. 4703 4704**Atomic service API**: This API can be used in atomic services since API version 11. 4705 4706**System capability**: SystemCapability.Multimedia.Image.ImageSource 4707 4708**Parameters** 4709 4710| Name | Type | Mandatory| Description | 4711| ------- | ------------------------------------ | ---- | ---------- | 4712| options | [DecodingOptions](#decodingoptions7) | No | Image decoding parameters.| 4713 4714**Return value** 4715 4716| Type | Description | 4717| -------------------------------- | --------------------- | 4718| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.| 4719 4720**Example** 4721 4722```ts 4723import { BusinessError } from '@kit.BasicServicesKit'; 4724 4725imageSourceApi.createPixelMap().then((pixelMap: image.PixelMap) => { 4726 console.info('Succeeded in creating pixelMap object through image decoding parameters.'); 4727}).catch((error: BusinessError) => { 4728 console.error('Failed to create pixelMap object through image decoding parameters.'); 4729}) 4730``` 4731 4732### createPixelMap<sup>7+</sup> 4733 4734createPixelMap(callback: AsyncCallback\<PixelMap>): void 4735 4736Creates a **PixelMap** object based on the default parameters. This API uses an asynchronous callback to return the result. 4737 4738**Widget capability**: This API can be used in ArkTS widgets since API version 12. 4739 4740**Atomic service API**: This API can be used in atomic services since API version 11. 4741 4742**System capability**: SystemCapability.Multimedia.Image.ImageSource 4743 4744**Parameters** 4745 4746| Name | Type | Mandatory| Description | 4747| -------- | ------------------------------------- | ---- | -------------------------- | 4748| 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.| 4749 4750**Example** 4751 4752```ts 4753import { BusinessError } from '@kit.BasicServicesKit'; 4754 4755imageSourceApi.createPixelMap((err: BusinessError, pixelMap: image.PixelMap) => { 4756 if (err) { 4757 console.error(`Failed to create pixelMap.code is ${err.code},message is ${err.message}`); 4758 } else { 4759 console.info('Succeeded in creating pixelMap object.'); 4760 } 4761}) 4762``` 4763 4764### createPixelMap<sup>7+</sup> 4765 4766createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): void 4767 4768Creates a **PixelMap** object based on image decoding parameters. This API uses an asynchronous callback to return the result. 4769 4770**Widget capability**: This API can be used in ArkTS widgets since API version 12. 4771 4772**Atomic service API**: This API can be used in atomic services since API version 11. 4773 4774**System capability**: SystemCapability.Multimedia.Image.ImageSource 4775 4776**Parameters** 4777 4778| Name | Type | Mandatory| Description | 4779| -------- | ------------------------------------- | ---- | -------------------------- | 4780| options | [DecodingOptions](#decodingoptions7) | Yes | Image decoding parameters. | 4781| 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.| 4782 4783**Example** 4784 4785```ts 4786import { BusinessError } from '@kit.BasicServicesKit'; 4787 4788let decodingOptions: image.DecodingOptions = { 4789 sampleSize: 1, 4790 editable: true, 4791 desiredSize: { width: 1, height: 2 }, 4792 rotate: 10, 4793 desiredPixelFormat: 3, 4794 desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 }, 4795 index: 0 4796}; 4797imageSourceApi.createPixelMap(decodingOptions, (err: BusinessError, pixelMap: image.PixelMap) => { 4798 if (err) { 4799 console.error(`Failed to create pixelMap.code is ${err.code},message is ${err.message}`); 4800 } else { 4801 console.info('Succeeded in creating pixelMap object.'); 4802 } 4803}) 4804``` 4805 4806### createPixelMapSync<sup>12+</sup> 4807 4808createPixelMapSync(options?: DecodingOptions): PixelMap 4809 4810Creates a **PixelMap** object based on image decoding parameters. This API returns the result synchronously. 4811 4812**System capability**: SystemCapability.Multimedia.Image.ImageSource 4813 4814**Parameters** 4815 4816| Name | Type | Mandatory| Description | 4817| -------- | ------------------------------------- | ---- | -------------------------- | 4818| options | [DecodingOptions](#decodingoptions7) | No | Image decoding parameters. | 4819 4820**Return value** 4821 4822| Type | Description | 4823| -------------------------------- | --------------------- | 4824| [PixelMap](#pixelmap7) | **PixelMap** object.| 4825 4826**Example** 4827 4828```ts 4829import { image } from '@kit.ImageKit'; 4830 4831const context: Context = getContext(); 4832// '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. 4833let filePath: string = context.filesDir + "/test.jpg"; 4834let imageSource = image.createImageSource(filePath); 4835let decodingOptions: image.DecodingOptions = { 4836 sampleSize: 1, 4837 editable: true, 4838 desiredSize: { width: 1, height: 2 }, 4839 rotate: 10, 4840 desiredPixelFormat: 3, 4841 desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 }, 4842 index: 0 4843}; 4844let pixelmap = imageSource.createPixelMapSync(decodingOptions); 4845if (pixelmap != undefined) { 4846 console.info('Succeeded in creating pixelMap object.'); 4847} else { 4848 console.info('Failed to create pixelMap.'); 4849} 4850``` 4851 4852### createPixelMapList<sup>10+</sup> 4853 4854createPixelMapList(options?: DecodingOptions): Promise<Array\<PixelMap>> 4855 4856Creates an array of **PixelMap** objects based on image decoding parameters. This API uses a promise to return the result. For dynamic images such as GIF and WebP images, this API returns the data of each frame of the image. For static images, this API returns the data of the unique frame of the image. 4857 4858**System capability**: SystemCapability.Multimedia.Image.ImageSource 4859 4860**Parameters** 4861 4862| Name | Type | Mandatory| Description | 4863| -------- | ------------------------------------- | ---- | -------------------------- | 4864| options | [DecodingOptions](#decodingoptions7) | No | Image decoding parameters. | 4865 4866**Return value** 4867 4868| Type | Description | 4869| -------------------------------- | --------------------- | 4870| Promise<Array<[PixelMap](#pixelmap7)>> | Promise used to return an array of **PixelMap** objects.| 4871 4872**Error codes** 4873 4874For details about the error codes, see [Image Error Codes](errorcode-image.md). 4875 4876| ID| Error Message| 4877| ------- | --------------------------------------------| 4878| 62980096| The operation failed. | 4879| 62980099 | The shared memory data is abnormal. | 4880| 62980101 | The image data is abnormal. | 4881| 62980103| The image data is not supported. | 4882| 62980106 | The image is too large. | 4883| 62980109 | Failed to crop the image. | 4884| 62980110| The image source data is incorrect. | 4885| 62980111| The image source data is incomplete. | 4886| 62980112 | The image format does not match. | 4887| 62980113 | Unknown image format. | 4888| 62980115 | Invalid image parameter. | 4889| 62980116 | Failed to decode the image. | 4890| 62980118| Failed to create the image plugin. | 4891| 62980122 | Failed to decode the image header. | 4892| 62980137 | Invalid media operation. | 4893| 62980173 | The DMA memory does not exist. | 4894| 62980174 | The DMA memory data is abnormal. | 4895 4896**Example** 4897 4898```ts 4899import { BusinessError } from '@kit.BasicServicesKit'; 4900 4901let decodeOpts: image.DecodingOptions = { 4902 sampleSize: 1, 4903 editable: true, 4904 desiredSize: { width: 198, height: 202 }, 4905 rotate: 0, 4906 desiredPixelFormat: 3, 4907 index: 0, 4908}; 4909imageSourceApi.createPixelMapList(decodeOpts).then((pixelMapList: Array<image.PixelMap>) => { 4910 console.info('Succeeded in creating pixelMapList object.'); 4911}).catch((err: BusinessError) => { 4912 console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`); 4913}) 4914``` 4915 4916### createPixelMapList<sup>10+</sup> 4917 4918createPixelMapList(callback: AsyncCallback<Array\<PixelMap>>): void 4919 4920Creates 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. 4921 4922**System capability**: SystemCapability.Multimedia.Image.ImageSource 4923 4924**Parameters** 4925 4926| Name | Type | Mandatory| Description | 4927| -------- | ------------------------------------- | ---- | -------------------------- | 4928| 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. | 4929 4930**Error codes** 4931 4932For details about the error codes, see [Image Error Codes](errorcode-image.md). 4933 4934| ID| Error Message| 4935| ------- | --------------------------------------------| 4936| 62980096 | The operation failed. | 4937| 62980099 | The shared memory data is abnormal. | 4938| 62980101 | The image data is abnormal. | 4939| 62980103 | The image data is not supported. | 4940| 62980106 | The image is too large. | 4941| 62980109 | Failed to crop the image. | 4942| 62980110 | The image source data is incorrect. | 4943| 62980111 | The image source data is incomplete. | 4944| 62980112 | The image format does not match. | 4945| 62980113 | Unknown image format. | 4946| 62980115 | Invalid image parameter. | 4947| 62980116 | Failed to decode the image. | 4948| 62980118 | Failed to create the image plugin. | 4949| 62980122 | Failed to decode the image header. | 4950| 62980137 | Invalid media operation. | 4951| 62980173 | The DMA memory does not exist. | 4952| 62980174 | The DMA memory data is abnormal. | 4953 4954**Example** 4955 4956```ts 4957import { BusinessError } from '@kit.BasicServicesKit'; 4958 4959imageSourceApi.createPixelMapList((err: BusinessError, pixelMapList: Array<image.PixelMap>) => { 4960 if (err) { 4961 console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`); 4962 } else { 4963 console.info('Succeeded in creating pixelMapList object.'); 4964 } 4965}) 4966``` 4967 4968### createPixelMapList<sup>10+</sup> 4969 4970createPixelMapList(options: DecodingOptions, callback: AsyncCallback<Array\<PixelMap>>): void 4971 4972Creates an array of **PixelMap** objects based on image decoding parameters. This API uses an asynchronous callback to return the result. For dynamic images such as GIF and WebP images, this API returns the data of each frame of the image. For static images, this API returns the data of the unique frame of the image. 4973 4974**System capability**: SystemCapability.Multimedia.Image.ImageSource 4975 4976**Parameters** 4977 4978| Name | Type | Mandatory| Description | 4979| -------- | -------------------- | ---- | ---------------------------------- | 4980| options | [DecodingOptions](#decodingoptions7) | Yes| Image decoding parameters.| 4981| 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. | 4982 4983**Error codes** 4984 4985For details about the error codes, see [Image Error Codes](errorcode-image.md). 4986 4987| ID| Error Message| 4988| ------- | --------------------------------------------| 4989| 62980096 | The operation failed. | 4990| 62980099 | The shared memory data is abnormal. | 4991| 62980101 | The image data is abnormal. | 4992| 62980103 | The image data is not supported. | 4993| 62980106 | The image is too large. | 4994| 62980109 | Failed to crop the image. | 4995| 62980110 | The image source data is incorrect. | 4996| 62980111 | The image source data is incomplete. | 4997| 62980112 | The image format does not match. | 4998| 62980113 | Unknown image format. | 4999| 62980115 | Invalid image parameter. | 5000| 62980116 | Failed to decode the image. | 5001| 62980118 | Failed to create the image plugin. | 5002| 62980122 | Failed to decode the image header. | 5003| 62980137 | Invalid media operation. | 5004| 62980173 | The DMA memory does not exist. | 5005| 62980174 | The DMA memory data is abnormal. | 5006 5007**Example** 5008 5009```ts 5010import { BusinessError } from '@kit.BasicServicesKit'; 5011 5012let decodeOpts: image.DecodingOptions = { 5013 sampleSize: 1, 5014 editable: true, 5015 desiredSize: { width: 198, height: 202 }, 5016 rotate: 0, 5017 desiredPixelFormat: 3, 5018 index: 0, 5019}; 5020imageSourceApi.createPixelMapList(decodeOpts, (err: BusinessError, pixelMapList: Array<image.PixelMap>) => { 5021 if (err) { 5022 console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`); 5023 } else { 5024 console.info('Succeeded in creating pixelMapList object.'); 5025 } 5026}) 5027``` 5028 5029### getDelayTimeList<sup>10+</sup> 5030 5031getDelayTimeList(callback: AsyncCallback<Array\<number>>): void 5032 5033Obtains 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. 5034 5035**System capability**: SystemCapability.Multimedia.Image.ImageSource 5036 5037**Parameters** 5038 5039| Name | Type | Mandatory| Description | 5040| -------- | -------------------- | ---- | ---------------------------------- | 5041| 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.| 5042 5043**Error codes** 5044 5045For details about the error codes, see [Image Error Codes](errorcode-image.md). 5046 5047| ID| Error Message| 5048| ------- | --------------------------------------------| 5049| 62980096| The operation failed. | 5050| 62980110| The image source data is incorrect. | 5051| 62980111| The image source data is incomplete. | 5052| 62980112 | The image format does not match. | 5053| 62980113| Unknown image format. | 5054| 62980115 | Invalid image parameter. | 5055| 62980116| Failed to decode the image. | 5056| 62980118| Failed to create the image plugin. | 5057| 62980122| Failed to decode the image header. | 5058| 62980137 | Invalid media operation. | 5059| 62980149 | Invalid MIME type for the image source. | 5060 5061**Example** 5062 5063```ts 5064import { BusinessError } from '@kit.BasicServicesKit'; 5065 5066imageSourceApi.getDelayTimeList((err: BusinessError, delayTimes: Array<number>) => { 5067 if (err) { 5068 console.error(`Failed to get delayTimes object.code is ${err.code},message is ${err.message}`); 5069 } else { 5070 console.info('Succeeded in getting delayTimes object.'); 5071 } 5072}) 5073``` 5074 5075### getDelayTimeList<sup>10+</sup> 5076 5077getDelayTimeList(): Promise<Array\<number>> 5078 5079Obtains 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. 5080 5081**System capability**: SystemCapability.Multimedia.Image.ImageSource 5082 5083**Return value** 5084 5085| Type | Description | 5086| -------------- | --------------------------- | 5087| Promise<Array\<number>> | Promise used to return an array of delay times.| 5088 5089**Error codes** 5090 5091For details about the error codes, see [Image Error Codes](errorcode-image.md). 5092 5093| ID| Error Message| 5094| ------- | --------------------------------------------| 5095| 62980096 | The operation failed. | 5096| 62980110 | The image source data is incorrect. | 5097| 62980111 | The image source data is incomplete. | 5098| 62980112 | The image format does not match. | 5099| 62980113 | Unknown image format. | 5100| 62980115 | Invalid image parameter. | 5101| 62980116 | Failed to decode the image. | 5102| 62980118 | Failed to create the image plugin. | 5103| 62980122 | Failed to decode the image header. | 5104| 62980137 | Invalid media operation. | 5105| 62980149 | Invalid MIME type for the image source. | 5106 5107**Example** 5108 5109```ts 5110import { BusinessError } from '@kit.BasicServicesKit'; 5111 5112imageSourceApi.getDelayTimeList().then((delayTimes: Array<number>) => { 5113 console.info('Succeeded in getting delayTimes object.'); 5114}).catch((err: BusinessError) => { 5115 console.error(`Failed to get delayTimes object.code is ${err.code},message is ${err.message}`); 5116}) 5117``` 5118 5119### getFrameCount<sup>10+</sup> 5120 5121getFrameCount(callback: AsyncCallback\<number>): void 5122 5123Obtains the number of frames. This API uses an asynchronous callback to return the result. 5124 5125**System capability**: SystemCapability.Multimedia.Image.ImageSource 5126 5127**Parameters** 5128 5129| Name | Type | Mandatory| Description | 5130| -------- | -------------------- | ---- | ---------------------------------- | 5131| 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.| 5132 5133**Error codes** 5134 5135For details about the error codes, see [Image Error Codes](errorcode-image.md). 5136 5137| ID| Error Message| 5138| ------- | --------------------------------------------| 5139| 62980096| The operation failed. | 5140| 62980110| The image source data is incorrect. | 5141| 62980111| The image source data is incomplete. | 5142| 62980112| The image format does not match. | 5143| 62980113| Unknown image format. | 5144| 62980115| Invalid image parameter. | 5145| 62980116| Failed to decode the image. | 5146| 62980118| Failed to create the image plugin. | 5147| 62980122| Failed to decode the image header. | 5148| 62980137| Invalid media operation. | 5149 5150**Example** 5151 5152```ts 5153import { BusinessError } from '@kit.BasicServicesKit'; 5154 5155imageSourceApi.getFrameCount((err: BusinessError, frameCount: number) => { 5156 if (err) { 5157 console.error(`Failed to get frame count.code is ${err.code},message is ${err.message}`); 5158 } else { 5159 console.info('Succeeded in getting frame count.'); 5160 } 5161}) 5162``` 5163 5164### getFrameCount<sup>10+</sup> 5165 5166getFrameCount(): Promise\<number> 5167 5168Obtains the number of frames. This API uses a promise to return the result. 5169 5170**System capability**: SystemCapability.Multimedia.Image.ImageSource 5171 5172**Return value** 5173 5174| Type | Description | 5175| -------------- | --------------------------- | 5176| Promise\<number> | Promise used to return the number of frames.| 5177 5178**Error codes** 5179 5180For details about the error codes, see [Image Error Codes](errorcode-image.md). 5181 5182| ID| Error Message| 5183| ------- | --------------------------------------------| 5184| 62980096 | The operation failed. | 5185| 62980110 | The image source data is incorrect. | 5186| 62980111 | The image source data is incomplete. | 5187| 62980112 | The image format does not match. | 5188| 62980113 | Unknown image format. | 5189| 62980115 | Invalid image parameter. | 5190| 62980116 | Failed to decode the image. | 5191| 62980118 | Failed to create the image plugin. | 5192| 62980122 | Failed to decode the image header. | 5193| 62980137 | Invalid media operation. | 5194 5195**Example** 5196 5197```ts 5198import { BusinessError } from '@kit.BasicServicesKit'; 5199 5200imageSourceApi.getFrameCount().then((frameCount: number) => { 5201 console.info('Succeeded in getting frame count.'); 5202}).catch((err: BusinessError) => { 5203 console.error(`Failed to get frame count.code is ${err.code},message is ${err.message}`); 5204}) 5205``` 5206 5207### getDisposalTypeList<sup>12+</sup> 5208 5209getDisposalTypeList(): Promise\<Array\<number>> 5210 5211Obtains the list of disposal types. This API uses a promise to return the result. It is used only for GIF images. 5212 5213**System capability**: SystemCapability.Multimedia.Image.ImageSource 5214 5215**Return value** 5216 5217| Type | Description | 5218| -------------- | --------------------------- | 5219| Promise\<Array\<number>> | Promise used to return an array of disposal types.| 5220 5221**Error codes** 5222 5223For details about the error codes, see [Image Error Codes](errorcode-image.md). 5224 5225| ID| Error Message| 5226| ------- | --------------------------------------------| 5227| 62980096 | The operation failed. | 5228| 62980101 | The image data is abnormal. | 5229| 62980137 | Invalid media operation. | 5230| 62980149 | Invalid MIME type for the image source. | 5231 5232**Example** 5233 5234```ts 5235import { BusinessError } from '@kit.BasicServicesKit'; 5236imageSourceApi.getDisposalTypeList().then((disposalTypes: Array<number>) => { 5237 console.info('Succeeded in getting disposalTypes object.'); 5238}).catch((err: BusinessError) => { 5239 console.error(`Failed to get disposalTypes object.code ${err.code},message is ${err.message}`); 5240}) 5241``` 5242 5243### release 5244 5245release(callback: AsyncCallback\<void>): void 5246 5247Releases this **ImageSource** instance. This API uses an asynchronous callback to return the result. 5248 5249ArkTS 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. 5250 5251**System capability**: SystemCapability.Multimedia.Image.ImageSource 5252 5253**Parameters** 5254 5255| Name | Type | Mandatory| Description | 5256| -------- | -------------------- | ---- | ---------------------------------- | 5257| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 5258 5259**Example** 5260 5261```ts 5262import { BusinessError } from '@kit.BasicServicesKit'; 5263 5264imageSourceApi.release((err: BusinessError) => { 5265 if (err) { 5266 console.error(`Failed to release the image source instance.code ${err.code},message is ${err.message}`); 5267 } else { 5268 console.info('Succeeded in releasing the image source instance.'); 5269 } 5270}) 5271``` 5272 5273### release 5274 5275release(): Promise\<void> 5276 5277Releases this **ImageSource** instance. This API uses a promise to return the result. 5278 5279ArkTS 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. 5280 5281**System capability**: SystemCapability.Multimedia.Image.ImageSource 5282 5283**Return value** 5284 5285| Type | Description | 5286| -------------- | --------------------------- | 5287| Promise\<void> | Promise that returns no value.| 5288 5289**Example** 5290 5291```ts 5292import { BusinessError } from '@kit.BasicServicesKit'; 5293 5294imageSourceApi.release().then(() => { 5295 console.info('Succeeded in releasing the image source instance.'); 5296}).catch((error: BusinessError) => { 5297 console.error(`Failed to release the image source instance.code ${error.code},message is ${error.message}`); 5298}) 5299``` 5300 5301## image.createImagePacker 5302 5303createImagePacker(): ImagePacker 5304 5305Creates an **ImagePacker** instance. 5306 5307**Atomic service API**: This API can be used in atomic services since API version 11. 5308 5309**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5310 5311**Return value** 5312 5313| Type | Description | 5314| --------------------------- | --------------------- | 5315| [ImagePacker](#imagepacker) | **ImagePacker** instance created.| 5316 5317**Example** 5318 5319```ts 5320const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5321``` 5322 5323## ImagePacker 5324 5325Provides 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). 5326 5327### Properties 5328 5329**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5330 5331| Name | Type | Readable| Writable| Description | 5332| ---------------- | -------------- | ---- | ---- | -------------------------- | 5333| supportedFormats | Array\<string> | Yes | No | Supported formats, including .jpeg, .webp, .png, and heif<sup>12+</sup> (depending on the hardware).| 5334 5335### packing 5336 5337packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void 5338 5339Packs an image. This API uses an asynchronous callback to return the result. 5340 5341**Atomic service API**: This API can be used in atomic services since API version 11. 5342 5343**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5344 5345**Parameters** 5346 5347| Name | Type | Mandatory| Description | 5348| -------- | ---------------------------------- | ---- | ---------------------------------- | 5349| source | [ImageSource](#imagesource) | Yes | Image to pack. | 5350| option | [PackingOption](#packingoption) | Yes | Option for image packing. | 5351| 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. | 5352 5353**Example** 5354 5355```ts 5356import { BusinessError } from '@kit.BasicServicesKit'; 5357 5358const context: Context = getContext(); 5359// '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. 5360let filePath: string = context.filesDir + "/test.jpg"; 5361const imageSourceApi: image.ImageSource = image.createImageSource(filePath); 5362let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }; 5363imagePackerApi.packing(imageSourceApi, packOpts, (err: BusinessError, data: ArrayBuffer) => { 5364 if (err) { 5365 console.error(`Failed to pack the image.code ${err.code},message is ${err.message}`); 5366 } else { 5367 console.info('Succeeded in packing the image.'); 5368 } 5369}) 5370``` 5371 5372### packing 5373 5374packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer> 5375 5376Packs an image. This API uses a promise to return the result. 5377 5378**Atomic service API**: This API can be used in atomic services since API version 11. 5379 5380**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5381 5382**Parameters** 5383 5384| Name| Type | Mandatory| Description | 5385| ------ | ------------------------------- | ---- | -------------- | 5386| source | [ImageSource](#imagesource) | Yes | Image to pack.| 5387| option | [PackingOption](#packingoption) | Yes | Option for image packing.| 5388 5389**Return value** 5390 5391| Type | Description | 5392| ---------------------------- | --------------------------------------------- | 5393| Promise\<ArrayBuffer> | Promise used to return the packed image data.| 5394 5395**Example** 5396 5397```ts 5398import { BusinessError } from '@kit.BasicServicesKit'; 5399 5400const context: Context = getContext(); 5401// '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. 5402let filePath: string = context.filesDir + "/test.jpg"; 5403const imageSourceApi: image.ImageSource = image.createImageSource(filePath); 5404let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 5405imagePackerApi.packing(imageSourceApi, packOpts) 5406 .then((data: ArrayBuffer) => { 5407 console.info('Succeeded in packing the image.'); 5408 }).catch((error: BusinessError) => { 5409 console.error(`Failed to pack the image.code ${error.code},message is ${error.message}`); 5410 }) 5411``` 5412 5413### packing<sup>8+</sup> 5414 5415packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void 5416 5417Packs an image. This API uses an asynchronous callback to return the result. 5418 5419**Atomic service API**: This API can be used in atomic services since API version 11. 5420 5421**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5422 5423**Parameters** 5424 5425| Name | Type | Mandatory| Description | 5426| -------- | ------------------------------- | ---- | ---------------------------------- | 5427| source | [PixelMap](#pixelmap7) | Yes | **PixelMap** object to pack. | 5428| option | [PackingOption](#packingoption) | Yes | Option for image packing. | 5429| 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. | 5430 5431**Example** 5432 5433```ts 5434import { BusinessError } from '@kit.BasicServicesKit'; 5435 5436const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 5437let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } 5438image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => { 5439 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 5440 imagePackerApi.packing(pixelMap, packOpts, (err: BusinessError, data: ArrayBuffer) => { 5441 if (err) { 5442 console.error(`Failed to pack the image.code ${err.code},message is ${err.message}`); 5443 } else { 5444 console.info('Succeeded in packing the image.'); 5445 } 5446 }) 5447}).catch((error: BusinessError) => { 5448 console.error(`Failed to create the PixelMap.code ${error.code},message is ${error.message}`); 5449}) 5450``` 5451 5452### packing<sup>8+</sup> 5453 5454packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer> 5455 5456Packs an image. This API uses a promise to return the result. 5457 5458**Atomic service API**: This API can be used in atomic services since API version 11. 5459 5460**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5461 5462**Parameters** 5463 5464| Name| Type | Mandatory| Description | 5465| ------ | ------------------------------- | ---- | ------------------ | 5466| source | [PixelMap](#pixelmap7) | Yes | **PixelMap** object to pack.| 5467| option | [PackingOption](#packingoption) | Yes | Option for image packing. | 5468 5469**Return value** 5470 5471| Type | Description | 5472| --------------------- | -------------------------------------------- | 5473| Promise\<ArrayBuffer> | Promise used to return the packed image data.| 5474 5475**Example** 5476 5477```ts 5478import { BusinessError } from '@kit.BasicServicesKit'; 5479 5480const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 5481let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } 5482image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => { 5483 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 5484 imagePackerApi.packing(pixelMap, packOpts) 5485 .then((data: ArrayBuffer) => { 5486 console.info('Succeeded in packing the image.'); 5487 }).catch((error: BusinessError) => { 5488 console.error(`Failed to pack the image.code ${error.code},message is ${error.message}`); 5489 }) 5490}).catch((error: BusinessError) => { 5491 console.error(`Failed to create PixelMap.code ${error.code},message is ${error.message}`); 5492}) 5493``` 5494 5495### packing<sup>13+</sup> 5496 5497packing(picture: Picture, options: PackingOption): Promise\<ArrayBuffer> 5498 5499Packs a picture. This API uses a promise to return the result. 5500 5501**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5502 5503**Parameters** 5504 5505| Name | Type | Mandatory| Description | 5506| ---------------- | ---------------------------------------------------- | ---- | -------------------- | 5507| picture | [Picture](#picture13) | Yes | **Picture** object to pack.| 5508| options | [PackingOption](#packingoption) | Yes | Option for image packing. | 5509 5510**Return value** 5511 5512| Type | Description | 5513| --------------------- | ------------------------------------- | 5514| Promise\<ArrayBuffer> | Promise used to return the packed image data.| 5515 5516**Error codes** 5517 5518For details about the error codes, see [Image Error Codes](errorcode-image.md). 5519 5520| ID| Error Message | 5521| -------- | ------------------------------------------------------------ | 5522| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 5523| 7800301 | Encode failed. | 5524 5525**Example** 5526 5527```ts 5528import { BusinessError } from '@kit.BasicServicesKit'; 5529import { image } from '@kit.ImageKit'; 5530 5531async function Packing() { 5532 const context = getContext(); 5533 const resourceMgr = context.resourceManager; 5534 const rawFile = await resourceMgr.getRawFileContent("test.jpg"); 5535 let ops: image.SourceOptions = { 5536 sourceDensity: 98, 5537 } 5538 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 5539 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 5540 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 5541 5542 let funcName = "Packing"; 5543 if (imagePackerApi != null) { 5544 let opts: image.PackingOption = { 5545 format: "image/jpeg", 5546 quality: 98, 5547 bufferSize: 10, 5548 desiredDynamicRange: image.PackingDynamicRange.AUTO, 5549 needsPackProperties: true}; 5550 await imagePackerApi.packing(pictureObj, opts).then((data: ArrayBuffer) => { 5551 console.info(funcName, 'Succeeded in packing the image.'+ data); 5552 }).catch((error: BusinessError) => { 5553 console.error(funcName, 'Failed to pack the image.code ${error.code},message is ${error.message}'); 5554 }); 5555 } 5556} 5557``` 5558 5559### release 5560 5561release(callback: AsyncCallback\<void>): void 5562 5563Releases this **ImagePacker** instance. This API uses an asynchronous callback to return the result. 5564 5565ArkTS 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. 5566 5567**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5568 5569**Parameters** 5570 5571| Name | Type | Mandatory| Description | 5572| -------- | -------------------- | ---- | ------------------------------ | 5573| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 5574 5575**Example** 5576 5577```ts 5578import { BusinessError } from '@kit.BasicServicesKit'; 5579 5580imagePackerApi.release((err: BusinessError)=>{ 5581 if (err) { 5582 console.error(`Failed to release image packaging.code ${err.code},message is ${err.message}`); 5583 } else { 5584 console.info('Succeeded in releasing image packaging.'); 5585 } 5586}) 5587``` 5588 5589### release 5590 5591release(): Promise\<void> 5592 5593Releases this **ImagePacker** instance. This API uses a promise to return the result. 5594 5595ArkTS 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. 5596 5597**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5598 5599**Return value** 5600 5601| Type | Description | 5602| -------------- | ------------------------------------------------------ | 5603| Promise\<void> | Promise that returns no value.| 5604 5605**Example** 5606 5607```ts 5608import { BusinessError } from '@kit.BasicServicesKit'; 5609 5610imagePackerApi.release().then(() => { 5611 console.info('Succeeded in releasing image packaging.'); 5612}).catch((error: BusinessError) => { 5613 console.error(`Failed to release image packaging.code ${error.code},message is ${error.message}`); 5614}) 5615``` 5616 5617### packToFile<sup>11+</sup> 5618 5619packToFile(source: ImageSource, fd: number, options: PackingOption, callback: AsyncCallback\<void>): void 5620 5621Encodes an **ImageSource** object and packs it into a file. This API uses an asynchronous callback to return the result. 5622 5623**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5624 5625**Parameters** 5626 5627| Name | Type | Mandatory| Description | 5628| -------- | ------------------------------- | ---- | ------------------------------ | 5629| source | [ImageSource](#imagesource) | Yes | Image to pack. | 5630| fd | number | Yes | File descriptor. | 5631| options | [PackingOption](#packingoption) | Yes | Option for image packing. | 5632| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 5633 5634**Example** 5635 5636```ts 5637import { BusinessError } from '@kit.BasicServicesKit'; 5638import { fileIo as fs } from '@kit.CoreFileKit'; 5639 5640const context: Context = getContext(this); 5641// '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. 5642const path: string = context.filesDir + "/test.png"; 5643const imageSourceApi: image.ImageSource = image.createImageSource(path); 5644let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }; 5645const filePath: string = context.filesDir + "/image_source.jpg"; 5646let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 5647const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5648imagePackerApi.packToFile(imageSourceApi, file.fd, packOpts, (err: BusinessError) => { 5649 if (err) { 5650 console.error(`Failed to pack the image to file.code ${err.code},message is ${err.message}`); 5651 } else { 5652 console.info('Succeeded in packing the image to file.'); 5653 } 5654}) 5655``` 5656 5657### packToFile<sup>11+</sup> 5658 5659packToFile (source: ImageSource, fd: number, options: PackingOption): Promise\<void> 5660 5661Encodes an **ImageSource** object and packs it into a file. This API uses a promise to return the result. 5662 5663**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5664 5665**Parameters** 5666 5667| Name| Type | Mandatory| Description | 5668| ------ | ------------------------------- | ---- | -------------- | 5669| source | [ImageSource](#imagesource) | Yes | Image to pack.| 5670| fd | number | Yes | File descriptor. | 5671| options | [PackingOption](#packingoption) | Yes | Option for image packing.| 5672 5673**Return value** 5674 5675| Type | Description | 5676| -------------- | --------------------------------- | 5677| Promise\<void> | Promise that returns no value.| 5678 5679**Example** 5680 5681```ts 5682import { BusinessError } from '@kit.BasicServicesKit'; 5683import { fileIo as fs } from '@kit.CoreFileKit'; 5684 5685const context: Context = getContext(this); 5686// '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. 5687const path: string = context.filesDir + "/test.png"; 5688const imageSourceApi: image.ImageSource = image.createImageSource(path); 5689let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }; 5690const filePath: string = context.filesDir + "/image_source.jpg"; 5691let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 5692const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5693imagePackerApi.packToFile(imageSourceApi, file.fd, packOpts).then(() => { 5694 console.info('Succeeded in packing the image to file.'); 5695}).catch((error: BusinessError) => { 5696 console.error(`Failed to pack the image to file.code ${error.code},message is ${error.message}`); 5697}) 5698``` 5699 5700### packToFile<sup>11+</sup> 5701 5702packToFile (source: PixelMap, fd: number, options: PackingOption, callback: AsyncCallback\<void>): void; 5703 5704Encodes a **PixelMap** object and packs it into a file. This API uses an asynchronous callback to return the result. 5705 5706**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5707 5708**Parameters** 5709 5710| Name | Type | Mandatory| Description | 5711| -------- | ------------------------------- | ---- | ------------------------------ | 5712| source | [PixelMap](#pixelmap7) | Yes | **PixelMap** object to pack. | 5713| fd | number | Yes | File descriptor. | 5714| options | [PackingOption](#packingoption) | Yes | Option for image packing. | 5715| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 5716 5717**Example** 5718 5719```ts 5720import { BusinessError } from '@kit.BasicServicesKit'; 5721import { fileIo as fs } from '@kit.CoreFileKit'; 5722 5723const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 5724let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } 5725const context: Context = getContext(this); 5726const path: string = context.filesDir + "/pixel_map.jpg"; 5727image.createPixelMap(color, opts).then((pixelmap: image.PixelMap) => { 5728 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 5729 let file = fs.openSync(path, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 5730 const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5731 imagePackerApi.packToFile(pixelmap, file.fd, packOpts, (err: BusinessError) => { 5732 if (err) { 5733 console.error(`Failed to pack the image to file.code ${err.code},message is ${err.message}`); 5734 } else { 5735 console.info('Succeeded in packing the image to file.'); 5736 } 5737 }) 5738}) 5739``` 5740 5741### packToFile<sup>11+</sup> 5742 5743packToFile (source: PixelMap, fd: number, options: PackingOption): Promise\<void> 5744 5745Encodes a **PixelMap** object and packs it into a file. This API uses a promise to return the result. 5746 5747**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5748 5749**Parameters** 5750 5751| Name| Type | Mandatory| Description | 5752| ------ | ------------------------------- | ---- | -------------------- | 5753| source | [PixelMap](#pixelmap7) | Yes | **PixelMap** object to pack.| 5754| fd | number | Yes | File descriptor. | 5755| options | [PackingOption](#packingoption) | Yes | Option for image packing. | 5756 5757**Return value** 5758 5759| Type | Description | 5760| -------------- | --------------------------------- | 5761| Promise\<void> | Promise that returns no value.| 5762 5763**Example** 5764 5765```ts 5766import { BusinessError } from '@kit.BasicServicesKit'; 5767import { fileIo as fs } from '@kit.CoreFileKit'; 5768 5769const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 5770let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } 5771const context: Context = getContext(this); 5772const path: string = context.filesDir + "/pixel_map.jpg"; 5773image.createPixelMap(color, opts).then((pixelmap: image.PixelMap) => { 5774 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 5775 let file = fs.openSync(path, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 5776 const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5777 imagePackerApi.packToFile(pixelmap, file.fd, packOpts) 5778 .then(() => { 5779 console.info('Succeeded in packing the image to file.'); 5780 }).catch((error: BusinessError) => { 5781 console.error(`Failed to pack the image to file.code ${error.code},message is ${error.message}`); 5782 }) 5783}) 5784``` 5785 5786### packToFile<sup>13+</sup> 5787 5788packToFile(picture: Picture, fd: number, options: PackingOption): Promise\<void> 5789 5790Encodes a **Picture** object and packs it into a file. This API uses a promise to return the result. 5791 5792**System capability**: SystemCapability.Multimedia.Image.ImagePacker 5793 5794**Parameters** 5795 5796| Name | Type | Mandatory| Description | 5797| ------- | ---------------------------- | ---- | -------------------- | 5798| picture | [Picture](#picture13) | Yes | **Picture** object to pack.| 5799| fd | number | Yes | File descriptor. | 5800| options | [PackingOption](#packingoption) | Yes | Option for image packing. | 5801 5802**Return value** 5803 5804| Type | Description | 5805| -------------- | ------------------------- | 5806| Promise\<void> | that returns no value.| 5807 5808**Error codes** 5809 5810For details about the error codes, see [Image Error Codes](errorcode-image.md). 5811 5812| ID| Error Message | 5813| -------- | ------------------------------------------------------------ | 5814| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 5815| 7800301 | Encode failed. | 5816 5817**Example** 5818 5819```ts 5820import { BusinessError } from '@kit.BasicServicesKit'; 5821import { image } from '@kit.ImageKit'; 5822import { fileIo as fs } from '@kit.CoreFileKit'; 5823 5824async function PackToFile() { 5825 const context = getContext(); 5826 const resourceMgr = context.resourceManager; 5827 const rawFile = await resourceMgr.getRawFileContent("test.jpg"); 5828 let ops: image.SourceOptions = { 5829 sourceDensity: 98, 5830 } 5831 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 5832 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 5833 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 5834 5835 let funcName = "PackToFile"; 5836 if (imagePackerApi != null) { 5837 const context: Context = getContext(); 5838 const filePath: string = context.filesDir + "/test.jpg"; 5839 let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 5840 let packOpts: image.PackingOption = { 5841 format: "image/jpeg", 5842 quality: 98, 5843 bufferSize: 10, 5844 desiredDynamicRange: image.PackingDynamicRange.AUTO, 5845 needsPackProperties: true}; 5846 await imagePackerApi.packToFile(pictureObj, file.fd, packOpts).then(() => { 5847 console.info(funcName, 'Succeeded in packing the image to file.'); 5848 }).catch((error: BusinessError) => { 5849 console.error(funcName, 'Failed to pack the image to file.code ${error.code},message is ${error.message}'); 5850 }); 5851 } 5852} 5853``` 5854 5855## image.createAuxiliaryPicture<sup>13+</sup> 5856 5857createAuxiliaryPicture(buffer: ArrayBuffer, size: Size, type: AuxiliaryPictureType): AuxiliaryPicture 5858 5859Creates an **AuxiliaryPicture** instance based on the ArrayBuffer image data, auxiliary picture size, and auxiliary picture type. 5860 5861**System capability**: SystemCapability.Multimedia.Image.Core 5862 5863**Parameters** 5864 5865| Name| Type | Mandatory| Description | 5866| ------ | ----------------------------------------------- | ---- | ---------------------------- | 5867| buffer | ArrayBuffer | Yes | Image data stored in the buffer.| 5868| size | [Size](#size) | Yes | Size of the auxiliary picture. | 5869| type | [AuxiliaryPictureType](#auxiliarypicturetype13) | Yes | Type of the auxiliary picture. | 5870 5871**Return value** 5872 5873| Type | Description | 5874| --------------------------------------- | ------------------------------------------ | 5875| [AuxiliaryPicture](#auxiliarypicture13) | **AuxiliaryPicture** instance if the operation is successful.| 5876 5877**Error codes** 5878 5879For details about the error codes, see [Image Error Codes](errorcode-image.md). 5880 5881| ID| Error Message | 5882| -------- | ------------------------------------------------------------ | 5883| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 5884 5885**Example** 5886 5887```ts 5888import { image } from '@kit.ImageKit'; 5889 5890async function CreateAuxiliaryPicture() { 5891 let funcName = "CreateAuxiliaryPicture"; 5892 const context = getContext(); 5893 const resourceMgr = context.resourceManager; 5894 const rawFile = await resourceMgr.getRawFileContent("hdr.jpg"); // Support for HDR images is required. 5895 let auxBuffer: ArrayBuffer = rawFile.buffer as ArrayBuffer; 5896 let auxSize: Size = { 5897 height: 180, 5898 width: 240 5899 }; 5900 let auxType: image.AuxiliaryPictureType = image.AuxiliaryPictureType.GAINMAP; 5901 let auxPictureObj: image.AuxiliaryPicture | null = image.createAuxiliaryPicture(auxBuffer, auxSize, auxType); 5902 if(auxPictureObj != null) { 5903 let type: image.AuxiliaryPictureType = auxPictureObj.getType(); 5904 console.info(funcName, 'CreateAuxiliaryPicture succeeded this.Aux_picture.type.' + JSON.stringify(type)); 5905 } else { 5906 console.error(funcName, 'CreateAuxiliaryPicture failed'); 5907 } 5908} 5909``` 5910 5911## AuxiliaryPicture<sup>13+</sup> 5912 5913The 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. 5914 5915### Properties 5916 5917**System capability**: SystemCapability.Multimedia.Image.Core 5918 5919### writePixelsFromBuffer<sup>13+</sup> 5920 5921writePixelsFromBuffer(data: ArrayBuffer): Promise\<void> 5922 5923Reads pixels from an ArrayBuffer and writes the data to this **AuxiliaryPicture** object. This API uses a promise to return the result. 5924 5925**System capability**: SystemCapability.Multimedia.Image.Core 5926 5927**Parameters** 5928 5929| Name| Type | Mandatory| Description | 5930| ------ | ----------- | ---- | ---------------- | 5931| data | ArrayBuffer | Yes | Pixels of the auxiliary picture.| 5932 5933**Return value** 5934 5935| Type | Description | 5936| -------------- | -------------------------------------- | 5937| Promise\<void> | Promise that returns no value.| 5938 5939**Error codes** 5940 5941For details about the error codes, see [Image Error Codes](errorcode-image.md). 5942 5943| ID| Error Message | 5944| -------- | ------------------------------------------------------------ | 5945| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 5946| 7600301 | Memory alloc failed. | 5947| 7600302 | Memory copy failed. | 5948 5949**Example** 5950 5951```ts 5952import { image } from '@kit.ImageKit'; 5953 5954async function WritePixelsFromBuffer() { 5955 const context = getContext(); 5956 const resourceMgr = context.resourceManager; 5957 const rawFile = await resourceMgr.getRawFileContent("hdr.jpg"); // Support for HDR images is required. 5958 let ops: image.SourceOptions = { 5959 sourceDensity: 98, 5960 } 5961 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 5962 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 5963 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 5964 let auxPictureObj: image.AuxiliaryPicture | null = pictureObj.getAuxiliaryPicture(image.AuxiliaryPictureType.GAINMAP); 5965 if(auxPictureObj != null) { 5966 let auxBuffer: ArrayBuffer = await auxPictureObj.readPixelsToBuffer(); 5967 await auxPictureObj.writePixelsFromBuffer(auxBuffer); 5968 console.info('Write pixels from buffer success.'); 5969 } else { 5970 console.error('AuxPictureObj is null.'); 5971 } 5972} 5973``` 5974 5975### readPixelsToBuffer<sup>13+</sup> 5976 5977readPixelsToBuffer(): Promise\<ArrayBuffer> 5978 5979Reads pixels of this auxiliary picture and writes the data to an ArrayBuffer. This API uses a promise to return the result. 5980 5981**System capability**: SystemCapability.Multimedia.Image.Core 5982 5983**Return value** 5984 5985| Type | Description | 5986| --------------------- | --------------------------------- | 5987| Promise\<ArrayBuffer> | Promise used to return the pixels of the auxiliary picture.| 5988 5989**Error codes** 5990 5991For details about the error codes, see [Image Error Codes](errorcode-image.md). 5992 5993| ID| Error Message | 5994| -------- | -------------------- | 5995| 7600301 | Memory alloc failed. | 5996| 7600302 | Memory copy failed. | 5997 5998**Example** 5999 6000```ts 6001import { BusinessError } from '@kit.BasicServicesKit'; 6002import { image } from '@kit.ImageKit'; 6003 6004async function ReadPixelsToBuffer() { 6005 const context = getContext(); 6006 const resourceMgr = context.resourceManager; 6007 const rawFile = await resourceMgr.getRawFileContent("hdr.jpg"); // Support for HDR images is required. 6008 let ops: image.SourceOptions = { 6009 sourceDensity: 98, 6010 } 6011 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6012 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6013 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6014 let auxPictureObj: image.AuxiliaryPicture | null = pictureObj.getAuxiliaryPicture(image.AuxiliaryPictureType.GAINMAP); 6015 if(auxPictureObj != null) { 6016 await auxPictureObj.readPixelsToBuffer().then((pixelsBuffer: ArrayBuffer) => { 6017 console.info('Read pixels to buffer success.' ); 6018 }).catch((error: BusinessError) => { 6019 console.error('Read pixels to buffer failed error.code: ' + JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message)); 6020 }); 6021 } else { 6022 console.error('AuxPictureObj is null.'); 6023 } 6024} 6025``` 6026 6027### getType<sup>13+</sup> 6028 6029getType(): AuxiliaryPictureType 6030 6031Obtains the type of this auxiliary picture. 6032 6033**System capability**: SystemCapability.Multimedia.Image.Core 6034 6035**Return value** 6036 6037| Type | Description | 6038| ----------------------------------------------- | ---------------------------- | 6039| [AuxiliaryPictureType](#auxiliarypicturetype13) | Type of the auxiliary picture.| 6040 6041**Example** 6042 6043```ts 6044import { image } from '@kit.ImageKit'; 6045 6046async function GetAuxiliaryPictureType() { 6047 if (auxPictureObj != null) { 6048 let type: image.AuxiliaryPictureType = auxPictureObj.getType(); 6049 console.info('Success get auxiliary picture type ' + JSON.stringify(type)); 6050 } else { 6051 console.info('Failed get auxiliary picture type '); 6052 } 6053} 6054``` 6055 6056### setMetadata<sup>13+</sup> 6057 6058setMetadata(metadataType: MetadataType, metadata: Metadata): Promise\<void> 6059 6060Sets the metadata for this auxiliary picture. 6061 6062**System capability**: SystemCapability.Multimedia.Image.Core 6063 6064**Parameters** 6065 6066| Name | Type | Mandatory| Description | 6067| ------------ | ------------------------------- | ---- | ------------------------------------ | 6068| metadataType | [MetadataType](#metadatatype13) | Yes | Metadata type, which is used to set the corresponding metadata.| 6069| metadata | [Metadata](#metadata13) | Yes | **Metadata** object. | 6070 6071**Return value** 6072 6073| Type | Description | 6074| -------------- | -------------------------------------- | 6075| Promise\<void> | Promise that returns no value.| 6076 6077**Error codes** 6078 6079For details about the error codes, see [Image Error Codes](errorcode-image.md). 6080 6081| ID| Error Message | 6082| -------- | ------------------------------------------------------------ | 6083| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6084| 7600202 | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. | 6085 6086**Example** 6087 6088```ts 6089import { BusinessError } from '@kit.BasicServicesKit'; 6090import { image } from '@kit.ImageKit'; 6091 6092async function SetAuxPictureObjMetadata() { 6093 const exifContext = getContext(); 6094 const exifResourceMgr = exifContext.resourceManager; 6095 const exifRawFile = await exifResourceMgr.getRawFileContent("exif.jpg");// The image contains EXIF metadata. 6096 let exifOps: image.SourceOptions = { 6097 sourceDensity: 98, 6098 } 6099 let exifImageSource: image.ImageSource = image.createImageSource(exifRawFile.buffer as ArrayBuffer, exifOps); 6100 let exifCommodityPixelMap: image.PixelMap = await exifImageSource.createPixelMap(); 6101 let exifPictureObj: image.Picture = image.createPicture(exifCommodityPixelMap); 6102 if (exifPictureObj != null) { 6103 console.info('Create picture succeeded'); 6104 } else { 6105 console.info('Create picture failed'); 6106 } 6107 6108 if (auxPictureObj != null) { 6109 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 6110 let exifMetaData: image.Metadata = await exifPictureObj.getMetadata(metadataType); 6111 auxPictureObj.setMetadata(metadataType, exifMetaData).then(() => { 6112 console.info('Set metadata success'); 6113 }).catch((error: BusinessError) => { 6114 console.error('Set metadata failed.error.code: ${error.code}, error.message: ${error.message}'); 6115 }); 6116 } else { 6117 console.info('AuxPictureObjMetaData is null'); 6118 } 6119} 6120``` 6121 6122### getMetadata<sup>13+</sup> 6123 6124getMetadata(metadataType: MetadataType): Promise\<Metadata> 6125 6126Obtains the metadata of this auxiliary picture. 6127 6128**System capability**: SystemCapability.Multimedia.Image.Core 6129 6130**Parameters** 6131 6132| Name | Type | Mandatory| Description | 6133| ------------ | ------------------------------- | ---- | -------------------------------------- | 6134| metadataType | [MetadataType](#metadatatype13) | Yes | Metadata type, which is used to obtain metadata of the corresponding type.| 6135 6136**Return value** 6137 6138| Type | Description | 6139| -------------------------------- | ---------------- | 6140| Promise<[Metadata](#metadata13)> | Metadata object.| 6141 6142**Error codes** 6143 6144For details about the error codes, see [Image Error Codes](errorcode-image.md). 6145 6146| ID| Error Message | 6147| -------- | ------------------------------------------------------------ | 6148| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6149| 7600202 | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. | 6150 6151**Example** 6152 6153```ts 6154import { image } from '@kit.ImageKit'; 6155 6156async function GetAuxPictureObjMetadata() { 6157 if (auxPictureObj != null) { 6158 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 6159 let auxPictureObjMetaData: image.Metadata | null = await auxPictureObj.getMetadata(metadataType); 6160 if (auxPictureObjMetaData != null) { 6161 console.info('Get auxpictureobj Metadata success' ); 6162 } else { 6163 console.info('Get auxpictureobj Metadata failed'); 6164 } 6165 } else { 6166 console.info('Get auxpictureobj is null.'); 6167 } 6168} 6169``` 6170 6171### getAuxiliaryPictureinfo<sup>13+</sup> 6172 6173getAuxiliaryPictureInfo(): AuxiliaryPictureInfo 6174 6175Obtains the auxiliary picture information. 6176 6177**System capability**: SystemCapability.Multimedia.Image.Core 6178 6179**Return value** 6180 6181| Type | Description | 6182| ----------------------------------------------- | --------------------------------- | 6183| [AuxiliaryPictureInfo](#auxiliarypictureinfo13) | Promise used to return the auxiliary picture information.| 6184 6185**Example** 6186 6187```ts 6188import { image } from '@kit.ImageKit'; 6189 6190async function GetAuxiliaryPictureInfo() { 6191 if(auxPictureObj != null) { 6192 let auxinfo: image.AuxiliaryPictureInfo = auxPictureObj.getAuxiliaryPictureInfo(); 6193 console.info('GetAuxiliaryPictureInfo Type: ' + auxinfo.auxiliaryPictureType + 6194 ' height: ' + auxinfo.size.height + ' width: ' + auxinfo.size.width + 6195 ' rowStride: ' + auxinfo.rowStride + ' pixelFormat: ' + auxinfo.pixelFormat + 6196 ' colorSpace: ' + auxinfo.colorSpace); 6197 } else { 6198 console.info('Get auxiliary picture information failed'); 6199 } 6200} 6201``` 6202 6203### setAuxiliaryPictureinfo<sup>13+</sup> 6204 6205setAuxiliaryPictureInfo(info: AuxiliaryPictureInfo): void 6206 6207Sets the auxiliary picture information. 6208 6209**System capability**: SystemCapability.Multimedia.Image.Core 6210 6211**Parameters** 6212 6213| Name| Type | Mandatory| Description | 6214| ------ | ----------------------------------------------- | ---- | ------------------ | 6215| info | [AuxiliaryPictureInfo](#auxiliarypictureinfo13) | Yes | Auxiliary picture information.| 6216 6217**Error codes** 6218 6219For details about the error codes, see [Image Error Codes](errorcode-image.md). 6220 6221| ID| Error Message | 6222| -------- | :----------------------------------------------------------- | 6223| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6224 6225**Example** 6226 6227```ts 6228import { colorSpaceManager } from '@kit.ArkGraphics2D'; 6229import { image } from '@kit.ImageKit'; 6230 6231async function SetAuxiliaryPictureInfo() { 6232 if(auxPictureObj != null) { 6233 let colorSpaceName = colorSpaceManager.ColorSpace.SRGB; 6234 let info: image.AuxiliaryPictureInfo = { 6235 auxiliaryPictureType: image.AuxiliaryPictureType.GAINMAP, 6236 size: {height: 100, width: 200}, 6237 pixelFormat: image.PixelMapFormat.RGBA_8888, 6238 rowStride: 0, 6239 colorSpace: colorSpaceManager.create(colorSpaceName), 6240 }; 6241 auxPictureObj.setAuxiliaryPictureInfo(info); 6242 } 6243} 6244``` 6245 6246### release<sup>13+</sup> 6247 6248release():void 6249 6250Releases this AuxiliaryPicture object. No value is returned. 6251 6252**System capability**: SystemCapability.Multimedia.Image.Core 6253 6254**Example** 6255 6256```ts 6257import { image } from '@kit.ImageKit'; 6258 6259async function Release() { 6260 let funcName = "Release"; 6261 if (auxPictureObj != null) { 6262 auxPictureObj.release(); 6263 if (auxPictureObj.getType() == null) { 6264 console.info(funcName, 'Success !'); 6265 } else { 6266 console.info(funcName, 'Failed !'); 6267 } 6268 } else { 6269 console.info('PictureObj is null'); 6270 } 6271} 6272``` 6273 6274## Metadata<sup>13+</sup> 6275 6276A class used to store image metadata. For details about the supported metadata types, see [MetadataType](#metadatatype13). 6277 6278### Properties 6279 6280**System capability**: SystemCapability.Multimedia.Image.Core 6281 6282### getProperties<sup>13+</sup> 6283 6284getProperties(key: Array\<string>): Promise\<Record\<string, string | null>> 6285 6286Obtains 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). 6287 6288**System capability**: SystemCapability.Multimedia.Image.Core 6289 6290**Parameters** 6291 6292| Name| Type | Mandatory| Description | 6293| ------ | -------------- | ---- | ------------------------ | 6294| key | Array\<string> | Yes | Names of the properties.| 6295 6296**Return value** 6297 6298| Type | Description | 6299| ---------------------------------------- | ------------------------------------------------------------ | 6300| Promise\<Record<string, string \| null>> | Promise used to return the property values. If the retrieval operation fails, an error code is returned.| 6301 6302**Error codes** 6303 6304For details about the error codes, see [Image Error Codes](errorcode-image.md). 6305 6306| ID| Error Message | 6307| -------- | ------------------------------------------------------------ | 6308| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 6309| 7600202 | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. | 6310 6311**Example** 6312 6313```ts 6314import { BusinessError } from '@kit.BasicServicesKit'; 6315import { image } from '@kit.ImageKit'; 6316 6317async function GetProperties() { 6318 const context = getContext(); 6319 const resourceMgr = context.resourceManager; 6320 const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); // The image contains EXIF metadata. 6321 let ops: image.SourceOptions = { 6322 sourceDensity: 98, 6323 } 6324 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6325 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6326 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6327 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 6328 let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType); 6329 if (metaData != null) { 6330 await metaData.getProperties(["ImageWidth", "ImageLength"]).then((data2) => { 6331 console.info('Get properties ',JSON.stringify(data2)); 6332 }).catch((error: BusinessError) => { 6333 console.info('Get properties failed error.code: ' +JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message)); 6334 }); 6335 } else { 6336 console.info('Metadata is null.'); 6337 } 6338} 6339``` 6340 6341### setProperties<sup>13+</sup> 6342 6343setProperties(records: Record\<string, string | null>): Promise\<void> 6344 6345Sets 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). 6346 6347**System capability**: SystemCapability.Multimedia.Image.Core 6348 6349**Parameters** 6350 6351| Name | Type | Mandatory| Description | 6352| ------- | ------------------------------ | ---- | ------------------------ | 6353| records | Record<string, string \| null> | Yes | Array of properties and their values.| 6354 6355**Return value** 6356 6357| Type | Description | 6358| -------------- | ------------------------------------- | 6359| Promise\<void> | Promise that returns no value. If the operation fails, an error code is returned.| 6360 6361**Error codes** 6362 6363For details about the error codes, see [Image Error Codes](errorcode-image.md). 6364 6365| ID| Error Message | 6366| -------- | ------------------------------------------------------------ | 6367| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 6368| 7600202 | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. | 6369 6370**Example** 6371 6372```ts 6373import { BusinessError } from '@kit.BasicServicesKit'; 6374import { image } from '@kit.ImageKit'; 6375 6376async function SetProperties() { 6377 const context = getContext(); 6378 const resourceMgr = context.resourceManager; 6379 const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); // The image contains EXIF metadata. 6380 let ops: image.SourceOptions = { 6381 sourceDensity: 98, 6382 } 6383 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6384 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6385 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6386 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 6387 let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType); 6388 if (metaData != null) { 6389 let setkey: Record<string, string | null> = { 6390 "ImageWidth": "200", 6391 "ImageLength": "300" 6392 }; 6393 await metaData.setProperties(setkey).then(async () => { 6394 console.info('Set auxpictureobj properties success.'); 6395 }).catch((error: BusinessError) => { 6396 console.error('Failed to set metadata Properties. code is ${error.code}, message is ${error.message}'); 6397 }) 6398 } else { 6399 console.info('AuxPictureObj metadata is null. '); 6400 } 6401} 6402``` 6403 6404### getAllProperties<sup>13+</sup> 6405 6406getAllProperties(): Promise\<Record<string, string | null>> 6407 6408Obtains 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). 6409 6410**System capability**: SystemCapability.Multimedia.Image.Core 6411 6412**Return value** 6413 6414| Type | Description | 6415| ---------------------------------------- | ------------------------------------------- | 6416| Promise\<Record<string, string \| null>> | Promise used to return the values of all properties.| 6417 6418**Example** 6419 6420```ts 6421import { BusinessError } from '@kit.BasicServicesKit'; 6422import { image } from '@kit.ImageKit'; 6423 6424async function GetAllProperties() { 6425 const context = getContext(); 6426 const resourceMgr = context.resourceManager; 6427 const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); // The image contains EXIF metadata. 6428 let ops: image.SourceOptions = { 6429 sourceDensity: 98, 6430 } 6431 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6432 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6433 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6434 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 6435 let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType); 6436 if (metaData != null) { 6437 await metaData.getAllProperties().then((data2) => { 6438 const count = Object.keys(data2).length; 6439 console.info('Metadata have ', count, ' properties'); 6440 console.info('Get metadata all properties: ', JSON.stringify(data2)); 6441 }).catch((error: BusinessError) => { 6442 console.error('Get metadata all properties failed error.code: ' +JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message)); 6443 }); 6444 } else { 6445 console.info('Metadata is null.'); 6446 } 6447} 6448``` 6449 6450### clone<sup>13+</sup> 6451 6452clone(): Promise\<Metadata> 6453 6454Clones the metadata. This API uses a promise to return the result. 6455 6456**System capability**: SystemCapability.Multimedia.Image.Core 6457 6458**Return value** 6459 6460| Type | Description | 6461| --------------------------------- | --------------------------------- | 6462| Promise\<[Metadata](#metadata13)> | Promise used to return the metadata instance.| 6463 6464**Error codes** 6465 6466For details about the error codes, see [Image Error Codes](errorcode-image.md). 6467 6468| ID| Error Message | 6469| -------- | -------------------- | 6470| 7600301 | Memory alloc failed. | 6471| 7600302 | Memory copy failed. | 6472 6473**Example** 6474 6475```ts 6476import { BusinessError } from '@kit.BasicServicesKit'; 6477import { image } from '@kit.ImageKit'; 6478 6479async function clone() { 6480 const context = getContext(); 6481 const resourceMgr = context.resourceManager; 6482 const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); // The image contains EXIF metadata. 6483 let ops: image.SourceOptions = { 6484 sourceDensity: 98, 6485 } 6486 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6487 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6488 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6489 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 6490 let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType); 6491 if (metaData != null) { 6492 let new_metadata: image.Metadata = await metaData.clone(); 6493 new_metadata.getProperties(["ImageWidth"]).then((data1) => { 6494 console.info('Clone new_metadata and get Properties.', JSON.stringify(data1)); 6495 }).catch((err: BusinessError) => { 6496 console.error('Clone new_metadata failed.', JSON.stringify(err)); 6497 }); 6498 } else { 6499 console.info('Metadata is null.'); 6500 } 6501} 6502``` 6503 6504## image.createImageReceiver<sup>11+</sup> 6505 6506createImageReceiver(size: Size, format: ImageFormat, capacity: number): ImageReceiver 6507 6508Creates an **ImageReceiver** instance by specifying the image size, format, and capacity. 6509 6510**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 6511 6512**Parameters** 6513 6514| Name | Type | Mandatory| Description | 6515| -------- | ------ | ---- | ---------------------- | 6516| size | [Size](#size) | Yes | Default size of the image. | 6517| 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.) | 6518| capacity | number | Yes | Maximum number of images that can be accessed at the same time.| 6519 6520**Return value** 6521 6522| Type | Description | 6523| -------------------------------- | --------------------------------------- | 6524| [ImageReceiver](#imagereceiver9) | Returns an **ImageReceiver** instance if the operation is successful.| 6525 6526**Error codes** 6527 6528For details about the error codes, see [Image Error Codes](errorcode-image.md). 6529 6530| ID| Error Message| 6531| ------- | --------------------------------------------| 6532| 401| Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; | 6533 6534**Example** 6535 6536```ts 6537let size: image.Size = { 6538 height: 8192, 6539 width: 8 6540} 6541let receiver: image.ImageReceiver = image.createImageReceiver(size, image.ImageFormat.JPEG, 8); 6542``` 6543 6544## image.createImageReceiver<sup>(deprecated)</sup> 6545 6546createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver 6547 6548Creates an **ImageReceiver** instance by specifying the image width, height, format, and capacity. 6549 6550> **NOTE** 6551> 6552> This API is deprecated since API version 11. You are advised to use [createImageReceiver](#imagecreateimagereceiver11). 6553 6554**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 6555 6556**Parameters** 6557 6558| Name | Type | Mandatory| Description | 6559| -------- | ------ | ---- | ---------------------- | 6560| width | number | Yes | Default image width. | 6561| height | number | Yes | Default image height. | 6562| 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.) | 6563| capacity | number | Yes | Maximum number of images that can be accessed at the same time.| 6564 6565**Return value** 6566 6567| Type | Description | 6568| -------------------------------- | --------------------------------------- | 6569| [ImageReceiver](#imagereceiver9) | Returns an **ImageReceiver** instance if the operation is successful.| 6570 6571**Example** 6572 6573```ts 6574let receiver: image.ImageReceiver = image.createImageReceiver(8192, 8, image.ImageFormat.JPEG, 8); 6575``` 6576 6577## ImageReceiver<sup>9+</sup> 6578 6579Provides APIs to obtain the surface ID of a component, read the latest image, read the next image, and release the **ImageReceiver** instance. 6580 6581Before calling any APIs in **ImageReceiver**, you must create an **ImageReceiver** instance. 6582 6583### Properties 6584 6585**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 6586 6587| Name | Type | Readable| Writable| Description | 6588| -------- | ---------------------------- | ---- | ---- | ------------------ | 6589| size | [Size](#size) | Yes | No | Image size. | 6590| capacity | number | Yes | No | Maximum number of images that can be accessed at the same time.| 6591| format | [ImageFormat](#imageformat9) | Yes | No | Image format. | 6592 6593### getReceivingSurfaceId<sup>9+</sup> 6594 6595getReceivingSurfaceId(callback: AsyncCallback\<string>): void 6596 6597Obtains a surface ID for the camera or other components. This API uses an asynchronous callback to return the result. 6598 6599**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 6600 6601**Parameters** 6602 6603| Name | Type | Mandatory| Description | 6604| -------- | ---------------------- | ---- | -------------------------- | 6605| 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.| 6606 6607**Example** 6608 6609```ts 6610import { BusinessError } from '@kit.BasicServicesKit'; 6611 6612receiver.getReceivingSurfaceId((err: BusinessError, id: string) => { 6613 if (err) { 6614 console.error(`Failed to get the ReceivingSurfaceId.code ${err.code},message is ${err.message}`); 6615 } else { 6616 console.info('Succeeded in getting the ReceivingSurfaceId.'); 6617 } 6618}); 6619``` 6620 6621### getReceivingSurfaceId<sup>9+</sup> 6622 6623getReceivingSurfaceId(): Promise\<string> 6624 6625Obtains a surface ID for the camera or other components. This API uses a promise to return the result. 6626 6627**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 6628 6629**Return value** 6630 6631| Type | Description | 6632| ---------------- | -------------------- | 6633| Promise\<string> | Promise used to return the surface ID.| 6634 6635**Example** 6636 6637```ts 6638import { BusinessError } from '@kit.BasicServicesKit'; 6639 6640receiver.getReceivingSurfaceId().then((id: string) => { 6641 console.info('Succeeded in getting the ReceivingSurfaceId.'); 6642}).catch((error: BusinessError) => { 6643 console.error(`Failed to get the ReceivingSurfaceId.code ${error.code},message is ${error.message}`); 6644}) 6645``` 6646 6647### readLatestImage<sup>9+</sup> 6648 6649readLatestImage(callback: AsyncCallback\<Image>): void 6650 6651Reads the latest image from the **ImageReceiver** instance. This API uses an asynchronous callback to return the result. 6652 6653**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. 6654 6655**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 6656 6657**Parameters** 6658 6659| Name | Type | Mandatory| Description | 6660| -------- | ------------------------------- | ---- | ------------------------ | 6661| 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. | 6662 6663**Example** 6664 6665```ts 6666import { BusinessError } from '@kit.BasicServicesKit'; 6667 6668receiver.readLatestImage((err: BusinessError, img: image.Image) => { 6669 if (err) { 6670 console.error(`Failed to read the latest Image.code ${err.code},message is ${err.message}`); 6671 } else { 6672 console.info('Succeeded in reading the latest Image.'); 6673 } 6674}); 6675``` 6676 6677### readLatestImage<sup>9+</sup> 6678 6679readLatestImage(): Promise\<Image> 6680 6681Reads the latest image from the **ImageReceiver** instance. This API uses a promise to return the result. 6682 6683**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. 6684 6685**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 6686 6687**Return value** 6688 6689| Type | Description | 6690| ------------------------- | ------------------ | 6691| Promise<[Image](#image9)> | Promise used to return the latest image.| 6692 6693**Example** 6694 6695```ts 6696import { BusinessError } from '@kit.BasicServicesKit'; 6697 6698receiver.readLatestImage().then((img: image.Image) => { 6699 console.info('Succeeded in reading the latest Image.'); 6700}).catch((error: BusinessError) => { 6701 console.error(`Failed to read the latest Image.code ${error.code},message is ${error.message}`); 6702}) 6703``` 6704 6705### readNextImage<sup>9+</sup> 6706 6707readNextImage(callback: AsyncCallback\<Image>): void 6708 6709Reads the next image from the **ImageReceiver** instance. This API uses an asynchronous callback to return the result. 6710 6711**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. 6712 6713**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 6714 6715**Parameters** 6716 6717| Name | Type | Mandatory| Description | 6718| -------- | ------------------------------- | ---- | -------------------------- | 6719| 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. | 6720 6721**Example** 6722 6723```ts 6724import { BusinessError } from '@kit.BasicServicesKit'; 6725 6726receiver.readNextImage((err: BusinessError, img: image.Image) => { 6727 if (err) { 6728 console.error(`Failed to read the next Image.code ${err.code},message is ${err.message}`); 6729 } else { 6730 console.info('Succeeded in reading the next Image.'); 6731 } 6732}); 6733``` 6734 6735### readNextImage<sup>9+</sup> 6736 6737readNextImage(): Promise\<Image> 6738 6739Reads the next image from the **ImageReceiver** instance. This API uses a promise to return the result. 6740 6741**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. 6742 6743**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 6744 6745**Return value** 6746 6747| Type | Description | 6748| ------------------------- | -------------------- | 6749| Promise<[Image](#image9)> | Promise used to return the next image.| 6750 6751**Example** 6752 6753```ts 6754import { BusinessError } from '@kit.BasicServicesKit'; 6755 6756receiver.readNextImage().then((img: image.Image) => { 6757 console.info('Succeeded in reading the next Image.'); 6758}).catch((error: BusinessError) => { 6759 console.error(`Failed to read the next Image.code ${error.code},message is ${error.message}`); 6760}) 6761``` 6762 6763### on<sup>9+</sup> 6764 6765on(type: 'imageArrival', callback: AsyncCallback\<void>): void 6766 6767Listens for image arrival events. 6768 6769**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 6770 6771**Parameters** 6772 6773| Name | Type | Mandatory| Description | 6774| -------- | -------------------- | ---- | ------------------------------------------------------ | 6775| type | string | Yes | Type of event to listen for. The value is fixed at **'imageArrival'**, which is triggered when an image is received.| 6776| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 6777 6778**Example** 6779 6780```ts 6781receiver.on('imageArrival', () => { 6782 // image arrival, do something. 6783}) 6784``` 6785 6786### off<sup>13+</sup> 6787 6788off(type: 'imageArrival', callback: AsyncCallback\<void>): void 6789 6790Unregisters the callback function that is triggered when the buffer is released. 6791 6792**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 6793 6794**Parameters** 6795 6796| Name | Type | Mandatory| Description | 6797| -------- | -------------------- |----|----------------------------------------| 6798| type | string | Yes | Type of event, which is **'imageArrival'**.| 6799| callback | AsyncCallback\<void> | No | Callback to unregister. | 6800 6801**Example** 6802 6803```ts 6804let callbackFunc = ()=>{ 6805 // do something 6806} 6807receover.on('imageArrival', callbackFunc) 6808receiver.off('imageArrival', callbackFunc) 6809``` 6810 6811### release<sup>9+</sup> 6812 6813release(callback: AsyncCallback\<void>): void 6814 6815Releases this **ImageReceiver** instance. This API uses an asynchronous callback to return the result. 6816 6817ArkTS 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. 6818 6819**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 6820 6821**Parameters** 6822 6823| Name | Type | Mandatory| Description | 6824| -------- | -------------------- | ---- | ------------------------ | 6825| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 6826 6827**Example** 6828 6829```ts 6830import { BusinessError } from '@kit.BasicServicesKit'; 6831 6832receiver.release((err: BusinessError) => { 6833 if (err) { 6834 console.error(`Failed to release the receiver.code ${err.code},message is ${err.message}`); 6835 } else { 6836 console.info('Succeeded in releasing the receiver.'); 6837 } 6838}) 6839``` 6840 6841### release<sup>9+</sup> 6842 6843release(): Promise\<void> 6844 6845Releases this **ImageReceiver** instance. This API uses a promise to return the result. 6846 6847ArkTS 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. 6848 6849**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 6850 6851**Return value** 6852 6853| Type | Description | 6854| -------------- | ------------------ | 6855| Promise\<void> | Promise that returns no value.| 6856 6857**Example** 6858 6859```ts 6860import { BusinessError } from '@kit.BasicServicesKit'; 6861 6862receiver.release().then(() => { 6863 console.info('Succeeded in releasing the receiver.'); 6864}).catch((error: BusinessError) => { 6865 console.error(`Failed to release the receiver.code ${error.code},message is ${error.message}`); 6866}) 6867``` 6868 6869## image.createImageCreator<sup>11+</sup> 6870 6871createImageCreator(size: Size, format: ImageFormat, capacity: number): ImageCreator 6872 6873Creates an **ImageCreator** instance by specifying the image size, format, and capacity. 6874 6875**System capability**: SystemCapability.Multimedia.Image.ImageCreator 6876 6877**Parameters** 6878 6879| Name | Type | Mandatory| Description | 6880| -------- | ------ | ---- | ---------------------- | 6881| size | [Size](#size) | Yes | Default size of the image. | 6882| format | [ImageFormat](#imageformat9) | Yes | Image format, for example, YCBCR_422_SP or JPEG. | 6883| capacity | number | Yes | Maximum number of images that can be accessed at the same time.| 6884 6885**Return value** 6886 6887| Type | Description | 6888| ------------------------------ | --------------------------------------- | 6889| [ImageCreator](#imagecreator9) | Returns an **ImageCreator** instance if the operation is successful.| 6890 6891 6892**Error codes** 6893 6894For details about the error codes, see [Image Error Codes](errorcode-image.md). 6895 6896| ID| Error Message| 6897| ------- | --------------------------------------------| 6898| 401| Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; | 6899 6900**Example** 6901 6902```ts 6903let size: image.Size = { 6904 height: 8192, 6905 width: 8 6906} 6907let creator: image.ImageCreator = image.createImageCreator(size, image.ImageFormat.JPEG, 8); 6908``` 6909 6910## image.createImageCreator<sup>(deprecated)</sup> 6911 6912createImageCreator(width: number, height: number, format: number, capacity: number): ImageCreator 6913 6914Creates an **ImageCreator** instance by specifying the image width, height, format, and capacity. 6915 6916> **NOTE** 6917> 6918> This API is deprecated since API version 11. You are advised to use [createImageCreator](#imagecreateimagecreator11). 6919 6920**System capability**: SystemCapability.Multimedia.Image.ImageCreator 6921 6922**Parameters** 6923 6924| Name | Type | Mandatory| Description | 6925| -------- | ------ | ---- | ---------------------- | 6926| width | number | Yes | Default image width. | 6927| height | number | Yes | Default image height. | 6928| format | number | Yes | Image format, for example, YCBCR_422_SP or JPEG. | 6929| capacity | number | Yes | Maximum number of images that can be accessed at the same time.| 6930 6931**Return value** 6932 6933| Type | Description | 6934| ------------------------------ | --------------------------------------- | 6935| [ImageCreator](#imagecreator9) | Returns an **ImageCreator** instance if the operation is successful.| 6936 6937**Example** 6938 6939```ts 6940let creator: image.ImageCreator = image.createImageCreator(8192, 8, image.ImageFormat.JPEG, 8); 6941``` 6942 6943## ImageCreator<sup>9+</sup> 6944 6945Provides APIs for applications to request an image native data area and compile native image data. 6946Before calling any APIs in **ImageCreator**, you must create an [ImageCreator](#imagecreator9) instance. **ImageCreator** does not support multiple threads. 6947 6948### Properties 6949 6950**System capability**: SystemCapability.Multimedia.Image.ImageCreator 6951 6952| Name | Type | Readable| Writable| Description | 6953| -------- | ---------------------------- | ---- | ---- | ------------------ | 6954| capacity | number | Yes | No | Maximum number of images that can be accessed at the same time.| 6955| format | [ImageFormat](#imageformat9) | Yes | No | Image format. | 6956 6957### dequeueImage<sup>9+</sup> 6958 6959dequeueImage(callback: AsyncCallback\<Image>): void 6960 6961Obtains an image buffer from the idle queue and writes image data into it. This API uses an asynchronous callback to return the result. 6962 6963**System capability**: SystemCapability.Multimedia.Image.ImageCreator 6964 6965**Parameters** 6966 6967| Name | Type | Mandatory| Description | 6968| ------------- | ---------------------------------------| ---- | -------------------- | 6969| 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. | 6970 6971**Example** 6972 6973```ts 6974import { BusinessError } from '@kit.BasicServicesKit'; 6975 6976creator.dequeueImage((err: BusinessError, img: image.Image) => { 6977 if (err) { 6978 console.error(`Failed to dequeue the Image.code ${err.code},message is ${err.message}`); 6979 } else { 6980 console.info('Succeeded in dequeuing the Image.'); 6981 } 6982}); 6983``` 6984 6985### dequeueImage<sup>9+</sup> 6986 6987dequeueImage(): Promise\<Image> 6988 6989Obtains an image buffer from the idle queue and writes image data into it. This API uses a promise to return the result. 6990 6991**System capability**: SystemCapability.Multimedia.Image.ImageCreator 6992 6993**Return value** 6994 6995| Type | Description | 6996| --------------- | ------------- | 6997| Promise\<[Image](#image9)> | Promise used to return the latest image.| 6998 6999**Example** 7000 7001```ts 7002import { BusinessError } from '@kit.BasicServicesKit'; 7003 7004creator.dequeueImage().then((img: image.Image) => { 7005 console.info('Succeeded in dequeuing the Image.'); 7006}).catch((error: BusinessError) => { 7007 console.error(`Failed to dequeue the Image.code ${error.code},message is ${error.message}`); 7008}) 7009``` 7010 7011### queueImage<sup>9+</sup> 7012 7013queueImage(interface: Image, callback: AsyncCallback\<void>): void 7014 7015Places the drawn image in the dirty queue. This API uses an asynchronous callback to return the result. 7016 7017**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7018 7019**Parameters** 7020 7021| Name | Type | Mandatory| Description | 7022| ------------- | -------------------------| ---- | -------------------- | 7023| interface | [Image](#image9) | Yes | Drawn image.| 7024| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 7025 7026**Example** 7027 7028```ts 7029import { BusinessError } from '@kit.BasicServicesKit'; 7030 7031creator.dequeueImage().then((img: image.Image) => { 7032 // Draw the image. 7033 img.getComponent(4).then((component : image.Component) => { 7034 let bufferArr: Uint8Array = new Uint8Array(component.byteBuffer); 7035 for (let i = 0; i < bufferArr.length; i += 4) { 7036 bufferArr[i] = 0; //B 7037 bufferArr[i + 1] = 0; //G 7038 bufferArr[i + 2] = 255; //R 7039 bufferArr[i + 3] = 255; //A 7040 } 7041 }) 7042 creator.queueImage(img, (err: BusinessError) => { 7043 if (err) { 7044 console.error(`Failed to queue the Image.code ${err.code},message is ${err.message}`); 7045 } else { 7046 console.info('Succeeded in queuing the Image.'); 7047 } 7048 }) 7049}) 7050 7051``` 7052 7053### queueImage<sup>9+</sup> 7054 7055queueImage(interface: Image): Promise\<void> 7056 7057Places the drawn image in the dirty queue. This API uses a promise to return the result. 7058 7059**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7060 7061**Parameters** 7062 7063| Name | Type | Mandatory| Description | 7064| ------------- | --------| ---- | ------------------- | 7065| interface | [Image](#image9) | Yes | Drawn image.| 7066 7067**Return value** 7068 7069| Type | Description | 7070| -------------- | ------------- | 7071| Promise\<void> | Promise that returns no value.| 7072 7073**Example** 7074 7075```ts 7076import { BusinessError } from '@kit.BasicServicesKit'; 7077 7078creator.dequeueImage().then((img: image.Image) => { 7079 // Draw the image. 7080 img.getComponent(4).then((component: image.Component) => { 7081 let bufferArr: Uint8Array = new Uint8Array(component.byteBuffer); 7082 for (let i = 0; i < bufferArr.length; i += 4) { 7083 bufferArr[i] = 0; //B 7084 bufferArr[i + 1] = 0; //G 7085 bufferArr[i + 2] = 255; //R 7086 bufferArr[i + 3] = 255; //A 7087 } 7088 }) 7089 creator.queueImage(img).then(() => { 7090 console.info('Succeeded in queuing the Image.'); 7091 }).catch((error: BusinessError) => { 7092 console.error(`Failed to queue the Image.code ${error.code},message is ${error.message}`); 7093 }) 7094}) 7095 7096``` 7097 7098### on<sup>9+</sup> 7099 7100on(type: 'imageRelease', callback: AsyncCallback\<void>): void 7101 7102Listens for image release events. This API uses an asynchronous callback to return the result. 7103 7104**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7105 7106**Parameters** 7107 7108| Name | Type | Mandatory| Description | 7109| ------------- | -------------------------| ---- | -------------------- | 7110| type | string | Yes | Type of event, which is **'imageRelease'**.| 7111| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 7112 7113**Example** 7114 7115```ts 7116import { BusinessError } from '@kit.BasicServicesKit'; 7117 7118creator.on('imageRelease', (err: BusinessError) => { 7119 if (err) { 7120 console.error(`Failed to get the imageRelease callback.code ${err.code},message is ${err.message}`); 7121 } else { 7122 console.info('Succeeded in getting imageRelease callback.'); 7123 } 7124}) 7125``` 7126 7127### off<sup>13+</sup> 7128 7129off(type: 'imageRelease', callback: AsyncCallback\<void>): void 7130 7131Unregisters the callback function that is triggered when the buffer is released. 7132 7133**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7134 7135**Parameters** 7136 7137| Name | Type | Mandatory| Description | 7138| ------------- | -------------------------|----|--------------------------------------------| 7139| type | string | Yes | Type of event, which is **'imageRelease'**. | 7140| callback | AsyncCallback\<void> | No | Callback to unregister.| 7141 7142**Example** 7143 7144```ts 7145let callbackFunc = ()=>{ 7146 // do something 7147} 7148creator.on('imageRelease', callbackFunc) 7149creator.off('imageRelease', callbackFunc) 7150``` 7151 7152### release<sup>9+</sup> 7153 7154release(callback: AsyncCallback\<void>): void 7155 7156Releases this **ImageCreator** instance. This API uses an asynchronous callback to return the result. 7157 7158ArkTS 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. 7159 7160**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7161 7162**Parameters** 7163 7164| Name | Type | Mandatory| Description | 7165| ------------- | -------------------------| ---- | -------------------- | 7166| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 7167 7168**Example** 7169 7170```ts 7171import { BusinessError } from '@kit.BasicServicesKit'; 7172 7173creator.release((err: BusinessError) => { 7174 if (err) { 7175 console.error(`Failed to release the creator.code ${err.code},message is ${err.message}`); 7176 } else { 7177 console.info('Succeeded in releasing creator.'); 7178 } 7179}); 7180``` 7181### release<sup>9+</sup> 7182 7183release(): Promise\<void> 7184 7185Releases this **ImageCreator** instance. This API uses a promise to return the result. 7186 7187ArkTS 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. 7188 7189**System capability**: SystemCapability.Multimedia.Image.ImageCreator 7190 7191**Return value** 7192 7193| Type | Description | 7194| -------------- | ------------- | 7195| Promise\<void> | Promise that returns no value.| 7196 7197**Example** 7198 7199```ts 7200import { BusinessError } from '@kit.BasicServicesKit'; 7201 7202creator.release().then(() => { 7203 console.info('Succeeded in releasing creator.'); 7204}).catch((error: BusinessError) => { 7205 console.error(`Failed to release the creator.code ${error.code},message is ${error.message}`); 7206}) 7207``` 7208 7209## Image<sup>9+</sup> 7210 7211Provides 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. 7212 7213### Properties 7214 7215**System capability**: SystemCapability.Multimedia.Image.Core 7216 7217| Name | Type | Readable| Writable| Description | 7218| -------- | ------------------ | ---- | ---- | -------------------------------------------------- | 7219| clipRect | [Region](#region8) | Yes | Yes | Image area to be cropped. | 7220| 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. | 7221| format | number | Yes | No | Image format. For details, see [OH_NativeBuffer_Format](../apis-arkgraphics2d/_o_h___native_buffer.md#oh_nativebuffer_format).| 7222| 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.| 7223 7224### getComponent<sup>9+</sup> 7225 7226getComponent(componentType: ComponentType, callback: AsyncCallback\<Component>): void 7227 7228Obtains the component buffer from the **Image** instance based on the color component type. This API uses an asynchronous callback to return the result. 7229 7230**System capability**: SystemCapability.Multimedia.Image.Core 7231 7232**Parameters** 7233 7234| Name | Type | Mandatory| Description | 7235| ------------- | --------------------------------------- | ---- | -------------------- | 7236| 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.) | 7237| 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. | 7238 7239**Example** 7240 7241```ts 7242import { BusinessError } from '@kit.BasicServicesKit'; 7243 7244img.getComponent(4, (err: BusinessError, component: image.Component) => { 7245 if (err) { 7246 console.error(`Failed to get the component.code ${err.code},message is ${err.message}`); 7247 } else { 7248 console.info('Succeeded in getting component.'); 7249 } 7250}) 7251``` 7252 7253### getComponent<sup>9+</sup> 7254 7255getComponent(componentType: ComponentType): Promise\<Component> 7256 7257Obtains the component buffer from the **Image** instance based on the color component type. This API uses a promise to return the result. 7258 7259**System capability**: SystemCapability.Multimedia.Image.Core 7260 7261**Parameters** 7262 7263| Name | Type | Mandatory| Description | 7264| ------------- | -------------------------------- | ---- | ---------------- | 7265| 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.)| 7266 7267**Return value** 7268 7269| Type | Description | 7270| --------------------------------- | --------------------------------- | 7271| Promise<[Component](#component9)> | Promise used to return the component buffer.| 7272 7273**Example** 7274 7275```ts 7276import { BusinessError } from '@kit.BasicServicesKit'; 7277 7278img.getComponent(4).then((component: image.Component) => { 7279 console.info('Succeeded in getting component.'); 7280}).catch((error: BusinessError) => { 7281 console.error(`Failed to get the component.code ${error.code},message is ${error.message}`); 7282}) 7283``` 7284 7285### release<sup>9+</sup> 7286 7287release(callback: AsyncCallback\<void>): void 7288 7289Releases this **Image** instance. This API uses an asynchronous callback to return the result. 7290 7291The corresponding resources must be released before another image arrives. 7292 7293ArkTS 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. 7294 7295**System capability**: SystemCapability.Multimedia.Image.Core 7296 7297**Parameters** 7298 7299| Name | Type | Mandatory| Description | 7300| -------- | -------------------- | ---- | -------------- | 7301| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | 7302 7303**Example** 7304 7305```ts 7306import { BusinessError } from '@kit.BasicServicesKit'; 7307 7308img.release((err: BusinessError) => { 7309 if (err) { 7310 console.error(`Failed to release the image instance.code ${err.code},message is ${err.message}`); 7311 } else { 7312 console.info('Succeeded in releasing the image instance.'); 7313 } 7314}) 7315``` 7316 7317### release<sup>9+</sup> 7318 7319release(): Promise\<void> 7320 7321Releases this **Image** instance. This API uses a promise to return the result. 7322 7323The corresponding resources must be released before another image arrives. 7324 7325ArkTS 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. 7326 7327**System capability**: SystemCapability.Multimedia.Image.Core 7328 7329**Return value** 7330 7331| Type | Description | 7332| -------------- | --------------------- | 7333| Promise\<void> | Promise that returns no value.| 7334 7335**Example** 7336 7337```ts 7338import { BusinessError } from '@kit.BasicServicesKit'; 7339 7340img.release().then(() => { 7341 console.info('Succeeded in releasing the image instance.'); 7342}).catch((error: BusinessError) => { 7343 console.error(`Failed to release the image instance.code ${error.code},message is ${error.message}`); 7344}) 7345``` 7346 7347## PositionArea<sup>7+</sup> 7348 7349Describes area information in an image. 7350 7351**Widget capability**: This API can be used in ArkTS widgets since API version 12. 7352 7353**Atomic service API**: This API can be used in atomic services since API version 11. 7354 7355**System capability**: SystemCapability.Multimedia.Image.Core 7356 7357| Name | Type | Read Only| Optional| Description | 7358| ------ | ------------------ | ---| -----|------------------------------------------------------- | 7359| pixels | ArrayBuffer | No| No | Pixels of the image. | 7360| offset | number | No| No | Offset for data reading. | 7361| 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. | 7362| 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.| 7363 7364## ImageInfo 7365 7366Describes image information. 7367 7368**System capability**: SystemCapability.Multimedia.Image.Core 7369 7370| Name| Type | Read Only| Optional| Description | 7371| ---- | ------------- | --- |-----|---------- | 7372| 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.| 7373| 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.| 7374| 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.| 7375| 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.| 7376| 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.| 7377| mimeType<sup>12+</sup> | string | No | No |Actual image format (MIME type). | 7378| 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.| 7379 7380## Size 7381 7382Describes the size of an image. 7383 7384**Widget capability**: This API can be used in ArkTS widgets since API version 12. 7385 7386**Atomic service API**: This API can be used in atomic services since API version 11. 7387 7388**System capability**: SystemCapability.Multimedia.Image.Core 7389 7390| Name | Type | Read Only| Optional |Description | 7391| ------ | ------ | -- |-----| -------------- | 7392| height | number | No | No |Image height, in px.| 7393| width | number | No | No| Image width, in px.| 7394 7395## PixelMapFormat<sup>7+</sup> 7396 7397Enumerates the pixel formats of images. 7398 7399**System capability**: SystemCapability.Multimedia.Image.Core 7400 7401| Name | Value | Description | 7402| ---------------------- | ------ | ----------------- | 7403| 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. | 7404| RGB_565 | 2 | RGB_565.<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. | 7405| RGBA_8888 | 3 | 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.| 7406| BGRA_8888<sup>9+</sup> | 4 | BGRA_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.| 7407| RGB_888<sup>9+</sup> | 5 | RGB_888.<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. | 7408| ALPHA_8<sup>9+</sup> | 6 | ALPHA_8.<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. | 7409| RGBA_F16<sup>9+</sup> | 7 | RGBA_F16.<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. | 7410| NV21<sup>9+</sup> | 8 | NV21.<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. | 7411| NV12<sup>9+</sup> | 9 | NV12.<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. | 7412| RGBA_1010102<sup>12+</sup> | 10 | RGBA_1010102.| 7413| YCBCR_P010<sup>12+</sup> | 11 | YCBCR_P010.| 7414| YCRCB_P010<sup>12+</sup> | 12 | YCRCB_P010.| 7415 7416## AlphaType<sup>9+</sup> 7417 7418Enumerates the alpha types of images. 7419 7420**Widget capability**: This API can be used in ArkTS widgets since API version 12. 7421 7422**Atomic service API**: This API can be used in atomic services since API version 11. 7423 7424**System capability**: SystemCapability.Multimedia.Image.Core 7425 7426| Name | Value | Description | 7427| -------- | ------ | ----------------------- | 7428| UNKNOWN | 0 | Unknown alpha type. | 7429| OPAQUE | 1 | There is no alpha or the image is opaque.| 7430| PREMUL | 2 | Premultiplied alpha. | 7431| UNPREMUL | 3 | RGB non-premultiplied alpha. | 7432 7433## AuxiliaryPictureType<sup>13+</sup> 7434 7435Enumerates the auxiliary pictures types. 7436 7437**System capability**: SystemCapability.Multimedia.Image.Core 7438 7439| Name | Value | Description | 7440| ------------- | ---- | ------------ | 7441| 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. | 7442| 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. | 7443| 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. | 7444| 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. | 7445| 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.| 7446 7447## AuxiliaryPictureInfo<sup>13+</sup> 7448 7449Describes the auxiliary picture information. 7450 7451**System capability**: SystemCapability.Multimedia.Image.Core 7452 7453| Name | Type | Read Only| Optional| Description | 7454| ------------------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ | 7455| auxiliaryPictureType | [AuxiliaryPictureType](#auxiliarypicturetype13) | No | No | Auxiliary picture type. | 7456| size | [Size](#size) | No | No | Image size.| 7457| rowStride | number | No | No | Row stride. | 7458| pixelFormat | [PixelMapFormat](#pixelmapformat7) | No | No | Pixel format.| 7459| colorSpace | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | No | No | Color space. | 7460 7461## MetadataType<sup>13+</sup> 7462 7463Enumerates image metadata types. 7464 7465**System capability**: SystemCapability.Multimedia.Image.Core 7466 7467| Name | Value | Description | 7468| ----------------- | ---- | ------------------ | 7469| EXIF_METADATA | 1 | EXIF data. | 7470| FRAGMENT_METADATA | 2 | Fragment map metadata.| 7471 7472## ScaleMode<sup>9+</sup> 7473 7474Enumerates the scale modes of images. 7475 7476**Widget capability**: This API can be used in ArkTS widgets since API version 12. 7477 7478**Atomic service API**: This API can be used in atomic services since API version 11. 7479 7480**System capability**: SystemCapability.Multimedia.Image.Core 7481 7482| Name | Value | Description | 7483| --------------- | ------ | -------------------------------------------------- | 7484| CENTER_CROP | 1 | Scales the image so that it fills the requested bounds of the target and crops the extra.| 7485| FIT_TARGET_SIZE | 0 | Reduces the image size to the dimensions of the target. | 7486 7487## SourceOptions<sup>9+</sup> 7488 7489Defines image source initialization options. 7490 7491**Widget capability**: This API can be used in ArkTS widgets since API version 12. 7492 7493**Atomic service API**: This API can be used in atomic services since API version 11. 7494 7495**System capability**: SystemCapability.Multimedia.Image.Core 7496 7497| Name | Type | Read Only| Optional| Description | 7498| ----------------- | ---------------------------------- | ---- | ---- | ------------------ | 7499| 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.| 7500| sourcePixelFormat | [PixelMapFormat](#pixelmapformat7) | No | Yes | Image pixel format. The default value is **UNKNOWN**. | 7501| sourceSize | [Size](#size) | No | Yes | Image pixel size. The default value is null. | 7502 7503 7504## InitializationOptions<sup>8+</sup> 7505 7506Defines PixelMap initialization options. 7507 7508**System capability**: SystemCapability.Multimedia.Image.Core 7509 7510| Name | Type | Read Only|Optional| Description | 7511| ------------------------ | ---------------------------------- | ----| -----| -------------- | 7512| 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. | 7513| 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.| 7514| srcPixelFormat<sup>12+</sup> | [PixelMapFormat](#pixelmapformat7) | No| Yes| Pixel format of the passed-in buffer data. The default value is **BGRA_8888**.| 7515| 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. | 7516| 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. | 7517| 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.| 7518 7519## DecodingOptions<sup>7+</sup> 7520 7521Describes the image decoding options. 7522 7523**System capability**: SystemCapability.Multimedia.Image.ImageSource 7524 7525| Name | Type | Read Only| Optional| Description | 7526| ------------------ | ---------------------------------- | ---- | ---- | ---------------- | 7527| 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.| 7528| 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. | 7529| 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. | 7530| desiredSize | [Size](#size) | No | Yes | Expected output size. The default value is null.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12. | 7531| desiredRegion | [Region](#region8) | No | Yes | Region to decode. The default value is null.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12. | 7532| 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.| 7533| 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. | 7534| 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. | 7535| desiredColorSpace<sup>11+</sup> | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | No | Yes | Target color space. The default value is **UNKNOWN**.| 7536| 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.| 7537 7538## DecodingOptionsForPicture<sup>13+</sup> 7539 7540Describes the image decoding options. 7541 7542**System capability**: SystemCapability.Multimedia.Image.ImageSource 7543 7544| Name | Type | Read Only| Optional| Description | 7545| ------------------------ | ------------------------------------------------------- | ---- | ---- | ------------------------------------------------------------ | 7546| desiredAuxiliaryPictures | Array\<[AuxiliaryPictureType](#auxiliarypicturetype13)> | No | No | Auxiliary picture type. By default, all auxiliary picture types are decoded.| 7547 7548## Region<sup>8+</sup> 7549 7550Describes the region information. 7551 7552**Widget capability**: This API can be used in ArkTS widgets since API version 12. 7553 7554**Atomic service API**: This API can be used in atomic services since API version 11. 7555 7556**System capability**: SystemCapability.Multimedia.Image.Core 7557 7558| Name| Type | Read Only| Optional| Description | 7559| ---- | ------------- | ---- | ---- | ------------ | 7560| size | [Size](#size) | No | No | Region size. | 7561| x | number | No | No | X coordinate to translate.| 7562| y | number | No | No | Y coordinate of the region.| 7563 7564## PackingOption 7565 7566Describes the options for image packing. 7567 7568**System capability**: SystemCapability.Multimedia.Image.ImagePacker 7569 7570| Name | Type | Read Only| Optional| Description | 7571| ------- | ------ | ---- | ---- | --------------------------------------------------- | 7572| format | string | No | No | Format of the packed image.<br>Currently, only image/jpeg, image/webp, image/png, and 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.| 7573| 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.| 7574| 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.| 7575| desiredDynamicRange<sup>12+</sup> | [PackingDynamicRange](#packingdynamicrange12) | No | Yes | Desired dynamic range. The default value is **SDR**.| 7576| needsPackProperties<sup>12+</sup> | boolean | No | Yes | Whether to encode image property information, for example, EXIF. The default value is **false**.| 7577 7578## ImagePropertyOptions<sup>11+</sup> 7579 7580Describes the image properties. 7581 7582**System capability**: SystemCapability.Multimedia.Image.ImageSource 7583 7584| Name | Type | Read Only| Optional| Description | 7585| ------------ | ------ | ---- | ---- | ------------ | 7586| index | number | Yes | Yes | Index of the image. The default value is **0**. | 7587| defaultValue | string | Yes | Yes | Default property value. The default value is null.| 7588 7589## GetImagePropertyOptions<sup>(deprecated)</sup> 7590 7591Describes the image properties. 7592 7593> **NOTE** 7594> 7595> This API is deprecated since API version 11. You are advised to use [ImagePropertyOptions](#imagepropertyoptions11). 7596 7597**System capability**: SystemCapability.Multimedia.Image.ImageSource 7598 7599| Name | Type | Read Only| Optional| Description | 7600| ------------ | ------ | ---- | ---- | ------------ | 7601| index | number | No | Yes | Index of the image. The default value is **0**. | 7602| defaultValue | string | No | Yes | Default property value. The default value is null.| 7603 7604## PropertyKey<sup>7+</sup> 7605 7606Describes the exchangeable image file format (EXIF) data of an image. 7607 7608**System capability**: SystemCapability.Multimedia.Image.Core 7609 7610| Name | Value | Description | 7611| ----------------- | ----------------------- |---------------------------| 7612| 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.| 7613| 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.| 7614| IMAGE_WIDTH | "ImageWidth" | **Read/Write capability**: readable and writable<br> Image width.| 7615| IMAGE_LENGTH | "ImageLength" | **Read/Write capability**: readable and writable<br> Image length.| 7616| BITS_PER_SAMPLE | "BitsPerSample" | **Read/Write capability**: readable and writable<br> Number of bits per component.| 7617| COMPRESSION <sup>12+</sup> | "Compression" | **Read/Write capability**: readable and writable<br> Compression scheme used on the image data.| 7618| PHOTOMETRIC_INTERPRETATION <sup>12+</sup> | "PhotometricInterpretation" | **Read/Write capability**: readable and writable<br> Color space of the image data, for example, RGB or YCbCr.| 7619| IMAGE_DESCRIPTION<sup>10+</sup> | "ImageDescription" | **Read/Write capability**: readable and writable<br> Image description.| 7620| MAKE<sup>10+</sup> | "Make" | **Read/Write capability**: readable and writable<br> Manufacturer.| 7621| MODEL<sup>10+</sup> | "Model" | **Read/Write capability**: readable and writable<br> Device model.| 7622| STRIP_OFFSETS <sup>12+</sup> | "StripOffsets" | **Read/Write capability**: readable and writable<br> Byte offset of each strip.| 7623| 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.| 7624| 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.| 7625| ROWS_PER_STRIP <sup>12+</sup> | "RowsPerStrip" | **Read/Write capability**: readable and writable<br> Number of rows per strip.| 7626| STRIP_BYTE_COUNTS <sup>12+</sup> | "StripByteCounts" | **Read/Write capability**: readable and writable<br> Number of bytes in each strip after compression.| 7627| X_RESOLUTION <sup>12+</sup> | "XResolution" | **Read/Write capability**: readable and writable<br> Number of pixels per ResolutionUnit in the image width (X) direction.| 7628| Y_RESOLUTION <sup>12+</sup> | "YResolution" | **Read/Write capability**: readable and writable<br> Number of pixels per ResolutionUnit in the image height (Y) direction.| 7629| 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.| 7630| RESOLUTION_UNIT <sup>12+</sup> | "ResolutionUnit" | **Read/Write capability**: readable and writable<br> Unit of measurement for XResolution and YResolution.| 7631| 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.| 7632| SOFTWARE <sup>12+</sup> | "Software" | **Read/Write capability**: readable and writable<br> Name and version number of the software used to create the image.| 7633| DATE_TIME<sup>10+</sup> | "DateTime" | **Read/Write capability**: readable and writable<br> Date and time of image creation.| 7634| ARTIST <sup>12+</sup> | "Artist" | **Read/Write capability**: readable and writable<br> Person who created the image.| 7635| WHITE_POINT <sup>12+</sup> | "WhitePoint" | **Read/Write capability**: readable and writable<br> Chromaticity of the white point of the image.| 7636| PRIMARY_CHROMATICITIES <sup>12+</sup> | "PrimaryChromaticities" | **Read/Write capability**: readable and writable<br> Chromaticities of the primaries of the image.| 7637| PHOTO_MODE<sup>10+</sup> | "PhotoMode" | **Read/Write capability**: readable and writable<br> Photographing mode.| 7638| 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.| 7639| JPEG_INTERCHANGE_FORMAT_LENGTH <sup>12+</sup> | "JPEGInterchangeFormatLength" | **Read/Write capability**: readable and writable<br> Number of bytes of the JPEG stream.| 7640| YCBCR_COEFFICIENTS <sup>12+</sup> | "YCbCrCoefficients" | **Read/Write capability**: readable and writable<br> Transformation from RGB to YCbCr image data.| 7641| 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.| 7642| YCBCR_POSITIONING <sup>12+</sup> | "YCbCrPositioning" | **Read/Write capability**: readable and writable<br> Positioning of subsampled chrominance components relative to luminance samples.| 7643| 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.| 7644| COPYRIGHT <sup>12+</sup> | "Copyright" | **Read/Write capability**: readable and writable<br> Copyright notice of the image.| 7645| EXPOSURE_TIME<sup>9+</sup> | "ExposureTime" | **Read/Write capability**: readable and writable<br> Exposure time, for example, 1/33 seconds.| 7646| F_NUMBER<sup>9+</sup> | "FNumber" | **Read/Write capability**: readable and writable<br> F number, for example, f/1.8.| 7647| 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.| 7648| SPECTRAL_SENSITIVITY <sup>12+</sup> | "SpectralSensitivity" | **Read/Write capability**: readable and writable<br> Spectral sensitivity of each channel of the camera.| 7649| GPS_VERSION_ID <sup>12+</sup> | "GPSVersionID" | **Read/Write capability**: readable and writable<br> Version of GPSInfoIFD.| 7650| GPS_LATITUDE_REF | "GPSLatitudeRef" | **Read/Write capability**: readable and writable<br> Whether the latitude is north or south latitude.| 7651| 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.| 7652| GPS_LONGITUDE_REF | "GPSLongitudeRef" | **Read/Write capability**: readable and writable<br> Whether the longitude is east or west longitude.| 7653| 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.| 7654| GPS_ALTITUDE_REF <sup>12+</sup> | "GPSAltitudeRef" | **Read/Write capability**: readable and writable<br> Whether the latitude is north or south latitude.| 7655| GPS_ALTITUDE <sup>12+</sup> | "GPSAltitude" | **Read/Write capability**: readable and writable<br> Altitude based on the reference in GPSAltitudeRef.| 7656| GPS_TIME_STAMP<sup>10+</sup> | "GPSTimeStamp" | **Read/Write capability**: readable and writable<br> GPS timestamp.| 7657| GPS_SATELLITES <sup>12+</sup> | "GPSSatellites" | **Read/Write capability**: readable and writable<br> GPS satellites used for measurement.| 7658| GPS_STATUS <sup>12+</sup> | "GPSStatus" | **Read/Write capability**: readable and writable<br> Status of the GPS receiver when the image was recorded.| 7659| GPS_MEASURE_MODE <sup>12+</sup> | "GPSMeasureMode" | **Read/Write capability**: readable and writable<br> GPS measurement pmode.| 7660| GPS_DOP <sup>12+</sup> | "GPSDOP" | **Read/Write capability**: readable and writable<br> GPS DOP (data degree of precision)| 7661| 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.| 7662| GPS_SPEED <sup>12+</sup> | "GPSSpeed" | **Read/Write capability**: readable and writable<br> Movement speed of the GPS receiver.| 7663| GPS_TRACK_REF <sup>12+</sup> | "GPSTrackRef" | **Read/Write capability**: readable and writable<br> Reference of the movement direction of the GPS receiver.| 7664| GPS_TRACK <sup>12+</sup> | "GPSTrack" | **Read/Write capability**: readable and writable<br> Movement direction of the GPS receiver.| 7665| 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.| 7666| GPS_IMG_DIRECTION <sup>12+</sup> | "GPSImgDirection" | **Read/Write capability**: readable and writable<br> Direction of the image when it was captured.| 7667| GPS_MAP_DATUM <sup>12+</sup> | "GPSMapDatum" | **Read/Write capability**: readable and writable<br> Geodetic survey data used by the GPS receiver.| 7668| 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.| 7669| GPS_DEST_LATITUDE <sup>12+</sup> | "GPSDestLatitude" | **Read/Write capability**: readable and writable<br> Latitude of the destination point.| 7670| 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.| 7671| GPS_DEST_LONGITUDE <sup>12+</sup> | "GPSDestLongitude" | **Read/Write capability**: readable and writable<br> Longitude of the destination point.| 7672| GPS_DEST_BEARING_REF <sup>12+</sup> | "GPSDestBearingRef" | **Read/Write capability**: readable and writable<br> Reference of the bearing to the destination point.| 7673| GPS_DEST_BEARING <sup>12+</sup> | "GPSDestBearing" | **Read/Write capability**: readable and writable<br> Bearing to the destination point.| 7674| 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.| 7675| GPS_DEST_DISTANCE <sup>12+</sup> | "GPSDestDistance" | **Read/Write capability**: readable and writable<br> Distance to the destination point.| 7676| 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.| 7677| GPS_AREA_INFORMATION <sup>12+</sup> | "GPSAreaInformation" | **Read/Write capability**: readable and writable<br> String that records the name of the GPS area.| 7678| GPS_DATE_STAMP<sup>10+</sup> | "GPSDateStamp" | **Read/Write capability**: readable and writable<br> GPS date stamp.| 7679| 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.| 7680| GPS_H_POSITIONING_ERROR <sup>12+</sup> | "GPSHPositioningError" | **Read/Write capability**: readable and writable<br> Horizontal positioning error, in meters.| 7681| ISO_SPEED_RATINGS<sup>9+</sup> | "ISOSpeedRatings" | **Read/Write capability**: readable and writable<br> ISO sensitivity or ISO speed, for example, 400.| 7682| 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.| 7683| OECF <sup>12+</sup> | "OECF" | **Read/Write capability**: readable and writable<br> Opto-Electric Conversion Function (OECF) specified in ISO 14524.| 7684| SENSITIVITY_TYPE<sup>10+</sup> | "SensitivityType" | **Read/Write capability**: readable and writable<br> Sensitivity type.| 7685| STANDARD_OUTPUT_SENSITIVITY<sup>10+</sup> | "StandardOutputSensitivity" | **Read/Write capability**: readable and writable<br> Standard output sensitivity.| 7686| RECOMMENDED_EXPOSURE_INDEX<sup>10+</sup> | "RecommendedExposureIndex" | **Read/Write capability**: readable and writable<br> Recommended exposure index.| 7687| ISO_SPEED<sup>10+</sup> | "ISOSpeedRatings" | **Read/Write capability**: readable and writable<br> ISO speed.| 7688| 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.| 7689| 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.| 7690| EXIF_VERSION <sup>12+</sup> | "ExifVersion" | **Read/Write capability**: readable and writable<br> Version of the supported EXIF standard.| 7691| 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.| 7692| 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.| 7693| 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.| 7694| 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.| 7695| 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.| 7696| COMPONENTS_CONFIGURATION <sup>12+</sup> | "ComponentsConfiguration" | **Read/Write capability**: readable and writable<br> Specific information about compressed data.| 7697| 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.| 7698| SHUTTER_SPEED <sup>12+</sup> | "ShutterSpeedValue" | **Read/Write capability**: readable and writable<br> Shutter speed, expressed in Additive System of Photographic Exposure (APEX) values.| 7699| APERTURE_VALUE<sup>10+</sup> | "ApertureValue" | **Read/Write capability**: readable and writable<br> Lens aperture.| 7700| BRIGHTNESS_VALUE <sup>12+</sup> | "BrightnessValue" | **Read/Write capability**: readable and writable<br> Value of brightness, expressed in APEX values.| 7701| EXPOSURE_BIAS_VALUE<sup>10+</sup> | "ExposureBiasValue" | **Read/Write capability**: readable and writable<br> Exposure bias.| 7702| MAX_APERTURE_VALUE <sup>12+</sup> | "MaxApertureValue" | **Read/Write capability**: readable and writable<br> Smallest F number of the lens.| 7703| SUBJECT_DISTANCE <sup>12+</sup> | "SubjectDistance" | **Read/Write capability**: readable and writable<br> Distance to the subject, in meters.| 7704| METERING_MODE<sup>10+</sup> | "MeteringMode" | **Read/Write capability**: readable and writable<br> Metering mode.| 7705| LIGHT_SOURCE<sup>10+</sup> | "LightSource" | **Read/Write capability**: readable and writable<br> Light source.| 7706| FLASH <sup>10+</sup> | "Flash" | **Read/Write capability**: readable and writable<br> Flash status.| 7707| FOCAL_LENGTH <sup>10+</sup> | "FocalLength" | **Read/Write capability**: readable and writable<br> Focal length of the lens.| 7708| SUBJECT_AREA <sup>12+</sup> | "SubjectArea" | **Read/Write capability**: readable and writable<br> Location and area of the main subject in the entire scene.| 7709| MAKER_NOTE <sup>12+</sup> | "MakerNote" | **Read/Write capability**: read-only<br> Marker used by EXIF/DCF manufacturers to record any required information.| 7710| SCENE_POINTER <sup>12+</sup> | "HwMnoteScenePointer" | **Read/Write capability**: read-only<br> Pointer to the scene.| 7711| SCENE_VERSION <sup>12+</sup> | "HwMnoteSceneVersion" | **Read/Write capability**: read-only<br> Scene algorithm version.| 7712| SCENE_FOOD_CONF<sup>11+</sup> | "HwMnoteSceneFoodConf" | **Read/Write capability**: read-only<br> Photographing scene: food.| 7713| SCENE_STAGE_CONF<sup>11+</sup> | "HwMnoteSceneStageConf" | **Read/Write capability**: read-only<br> Photographing scene: stage.| 7714| SCENE_BLUE_SKY_CONF<sup>11+</sup> | "HwMnoteSceneBlueSkyConf" | **Read/Write capability**: read-only<br> Photographing scene: blue sky.| 7715| SCENE_GREEN_PLANT_CONF<sup>11+</sup> | "HwMnoteSceneGreenPlantConf" | **Read/Write capability**: read-only<br> Photographing scene: green plant.| 7716| SCENE_BEACH_CONF<sup>11+</sup> | "HwMnoteSceneBeachConf" | **Read/Write capability**: read-only<br> Photographing scene: beach.| 7717| SCENE_SNOW_CONF<sup>11+</sup> | "HwMnoteSceneSnowConf" | **Read/Write capability**: read-only<br> Photographing scene: snow.| 7718| SCENE_SUNSET_CONF<sup>11+</sup> | "HwMnoteSceneSunsetConf" | **Read/Write capability**: read-only<br> Photographing scene: sunset.| 7719| SCENE_FLOWERS_CONF<sup>11+</sup> | "HwMnoteSceneFlowersConf" | **Read/Write capability**: read-only<br> Photographing scene: flowers.| 7720| SCENE_NIGHT_CONF<sup>11+</sup> | "HwMnoteSceneNightConf" | **Read/Write capability**: read-only<br> Photographing scene: night.| 7721| SCENE_TEXT_CONF<sup>11+</sup> | "HwMnoteSceneTextConf" | **Read/Write capability**: read-only<br> Photographing scene: text.| 7722| FACE_POINTER <sup>12+</sup> | "HwMnoteFacePointer" | **Read/Write capability**: read-only<br> Face pointer.| 7723| FACE_VERSION <sup>12+</sup> | "HwMnoteFaceVersion" | **Read/Write capability**: read-only<br> Facial recognition algorithm version.| 7724| FACE_COUNT<sup>11+</sup> | "HwMnoteFaceCount" | **Read/Write capability**: read-only<br> Number of faces.| 7725| FACE_CONF <sup>12+</sup> | "HwMnoteFaceConf" | **Read/Write capability**: read-only<br> Face confidence.| 7726| FACE_SMILE_SCORE <sup>12+</sup> | "HwMnoteFaceSmileScore" | **Read/Write capability**: read-only<br> Smile score of for faces.| 7727| FACE_RECT <sup>12+</sup> | "HwMnoteFaceRect" | **Read/Write capability**: read-only<br> Face rectangle.| 7728| FACE_LEYE_CENTER <sup>12+</sup> | "HwMnoteFaceLeyeCenter" | **Read/Write capability**: read-only<br> Left eye centered.| 7729| FACE_REYE_CENTER <sup>12+</sup> | "HwMnoteFaceReyeCenter" | **Read/Write capability**: read-only<br> Right eye centered.| 7730| FACE_MOUTH_CENTER <sup>12+</sup> | "HwMnoteFaceMouthCenter" | **Read/Write capability**: read-only<br> Mouth centered.| 7731| CAPTURE_MODE <sup>10+</sup> | "HwMnoteCaptureMode" | **Read/Write capability**: readable and writable<br> Capture mode.| 7732| BURST_NUMBER <sup>12+</sup> | "HwMnoteBurstNumber" | **Read/Write capability**: read-only<br> Number of burst shooting times.| 7733| FRONT_CAMERA <sup>12+</sup> | "HwMnoteFrontCamera" | **Read/Write capability**: read-only<br> Whether the front camera is used to take a selfie.| 7734| ROLL_ANGLE <sup>11+</sup> | "HwMnoteRollAngle" | **Read/Write capability**: read-only<br> Roll angle.| 7735| PITCH_ANGLE<sup>11+</sup> | "HwMnotePitchAngle" | **Read/Write capability**: read-only<br> Pitch angle.| 7736| PHYSICAL_APERTURE <sup>10+</sup> | "HwMnotePhysicalAperture" | **Read/Write capability**: read-only<br> Physical aperture.| 7737| FOCUS_MODE<sup>11+</sup> | "HwMnoteFocusMode" | **Read/Write capability**: read-only<br> Focus mode.| 7738| USER_COMMENT <sup>10+</sup> | "UserComment" | **Read/Write capability**: readable and writable<br> User comments.| 7739| SUBSEC_TIME <sup>12+</sup> | "SubsecTime" | **Read/Write capability**: readable and writable<br> Tag used to record fractions of seconds for the **DateTime** tag.| 7740| 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.| 7741| 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.| 7742| 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.| 7743| 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.| 7744| PIXEL_X_DIMENSION <sup>10+</sup> | "PixelXDimension" | **Read/Write capability**: readable and writable<br> Pixel X dimension.| 7745| PIXEL_Y_DIMENSION<sup>10+</sup> | "PixelYDimension" | **Read/Write capability**: readable and writable<br> Pixel Y dimension.| 7746| RELATED_SOUND_FILE <sup>12+</sup> | "RelatedSoundFile" | **Read/Write capability**: readable and writable<br> Name of an audio file related to the image data.| 7747| 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).| 7748| SPATIAL_FREQUENCY_RESPONSE <sup>12+</sup> | "SpatialFrequencyResponse" | **Read/Write capability**: readable and writable<br> Spatial frequency table of the camera or input device.| 7749| 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.| 7750| 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.| 7751| FOCAL_PLANE_RESOLUTION_UNIT <sup>12+</sup> | "FocalPlaneResolutionUnit" | **Read/Write capability**: readable and writable<br> Unit for measuring FocalPlaneXResolution and FocalPlaneYResolution.| 7752| SUBJECT_LOCATION <sup>12+</sup> | "SubjectLocation" | **Read/Write capability**: readable and writable<br> Location of the main subject relative to the left edge.| 7753| EXPOSURE_INDEX <sup>12+</sup> | "ExposureIndex" | **Read/Write capability**: readable and writable<br> Exposure index selected at the time the image is captured.| 7754| SENSING_METHOD <sup>12+</sup> | "SensingMethod" | **Read/Write capability**: readable and writable<br> Type of the image sensor on the camera.| 7755| FILE_SOURCE <sup>12+</sup> | "FileSource" | **Read/Write capability**: readable and writable<br> Image source.| 7756| SCENE_TYPE<sup>9+</sup> | "SceneType" | **Read/Write capability**: readable and writable<br> Type of the scene, for example, portrait, scenery, motion, and night.| 7757| CFA_PATTERN <sup>12+</sup> | "CFAPattern" | **Read/Write capability**: readable and writable<br> Color Filter Array (CFA) geometric pattern of the image sensor.| 7758| CUSTOM_RENDERED <sup>12+</sup> | "CustomRendered" | **Read/Write capability**: readable and writable<br> Special processing on image data.| 7759| EXPOSURE_MODE <sup>12+</sup> | "ExposureMode" | **Read/Write capability**: readable and writable<br> Exposure mode set when the image was captured.| 7760| WHITE_BALANCE <sup>10+</sup> | "WhiteBalance" | **Read/Write capability**: readable and writable<br> White balance.| 7761| DIGITAL_ZOOM_RATIO <sup>12+</sup> | "DigitalZoomRatio" | **Read/Write capability**: readable and writable<br> Digital zoom ratio when the image was captured.| 7762| FOCAL_LENGTH_IN_35_MM_FILM <sup>10+</sup> | "FocalLengthIn35mmFilm" | **Read/Write capability**: readable and writable<br> Focal length in 35mm film.| 7763| SCENE_CAPTURE_TYPE <sup>12+</sup> | "SceneCaptureType" | **Read/Write capability**: readable and writable<br> Type of the scene that was captured.| 7764| GAIN_CONTROL <sup>12+</sup> | "GainControl" | **Read/Write capability**: readable and writable<br> Degree of overall image gain adjustment.| 7765| CONTRAST <sup>12+</sup> | "Contrast" | **Read/Write capability**: readable and writable<br> Direction of contrast processing used by the camera.| 7766| SATURATION <sup>12+</sup> | "Saturation" | **Read/Write capability**: readable and writable<br> Direction of saturation processing used by the camera.| 7767| SHARPNESS <sup>12+</sup> | "Sharpness" | **Read/Write capability**: readable and writable<br> Direction of sharpness processing used by the camera.| 7768| DEVICE_SETTING_DESCRIPTION <sup>12+</sup> | "DeviceSettingDescription" | **Read/Write capability**: readable and writable<br> Information about the photographing conditions of a specific camera model.| 7769| SUBJECT_DISTANCE_RANGE <sup>12+</sup> | "SubjectDistanceRange" | **Read/Write capability**: readable and writable<br> Distance to the subject.| 7770| IMAGE_UNIQUE_ID <sup>12+</sup> | "ImageUniqueID" | **Read/Write capability**: readable and writable<br> Unique identifier assigned to each image.| 7771| CAMERA_OWNER_NAME <sup>12+</sup> | "CameraOwnerName" | **Read/Write capability**: readable and writable<br> Name of the camera owner.| 7772| BODY_SERIAL_NUMBER <sup>12+</sup> | "BodySerialNumber" | **Read/Write capability**: readable and writable<br> Serial number of the camera body.| 7773| LENS_SPECIFICATION <sup>12+</sup> | "LensSpecification" | **Read/Write capability**: readable and writable<br> Specifications of the lens.| 7774| LENS_MAKE <sup>12+</sup> | "LensMake" | **Read/Write capability**: readable and writable<br> Manufacturer of the lens.| 7775| LENS_MODEL <sup>12+</sup> | "LensModel" | **Read/Write capability**: readable and writable<br> Model of the lens.| 7776| LENS_SERIAL_NUMBER <sup>12+</sup> | "LensSerialNumber" | **Read/Write capability**: readable and writable<br> Serial number of the lens.| 7777| COMPOSITE_IMAGE <sup>12+</sup> | "CompositeImage" | **Read/Write capability**: readable and writable<br> Whether the image is a composite image.| 7778| 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.| 7779| 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.| 7780| GAMMA <sup>12+</sup> | "Gamma" | **Read/Write capability**: readable and writable<br> Gamma value.| 7781| DNG_VERSION <sup>12+</sup> | "DNGVersion" | **Read/Write capability**: readable and writable<br> DNG version. It encodes the DNG 4-tier version number.| 7782| 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.| 7783| 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.| 7784| IS_XMAGE_SUPPORTED <sup>12+</sup> | "HwMnoteIsXmageSupported" | **Read/Write capability**: readable and writable<br>Whether XMAGE is supported.| 7785| XMAGE_MODE <sup>12+</sup> | "HwMnoteXmageMode" | **Read/Write capability**: readable and writable<br>XMAGE watermark mode.| 7786| XMAGE_LEFT <sup>12+</sup> | "HwMnoteXmageLeft" | **Read/Write capability**: readable and writable<br>X1 coordinate of the watermark region.| 7787| XMAGE_TOP <sup>12+</sup> | "HwMnoteXmageTop" | **Read/Write capability**: readable and writable<br>Y1 coordinate of the watermark region.| 7788| XMAGE_RIGHT <sup>12+</sup> | "HwMnoteXmageRight" | **Read/Write capability**: readable and writable<br>X2 coordinate of the watermark region.| 7789| XMAGE_BOTTOM <sup>12+</sup> | "HwMnoteXmageBottom" | **Read/Write capability**: readable and writable<br>Y2 coordinate of the watermark region.| 7790| CLOUD_ENHANCEMENT_MODE <sup>12+</sup> | "HwMnoteCloudEnhancementMode" | **Read/Write capability**: readable and writable<br>Cloud enhancement mode.| 7791| WIND_SNAPSHOT_MODE <sup>12+</sup> | "HwMnoteWindSnapshotMode" | **Read/Write capability**: read-only<br>Motion snapshot mode.| 7792 7793## FragmentMapPropertyKey<sup>13+</sup> 7794 7795Enumerates the fragment map information. 7796 7797**System capability**: SystemCapability.Multimedia.Image.Core 7798 7799| Name | Value | Description | 7800| ------------- | --------------------- | ----------------------------------- | 7801| X_IN_ORIGINAL | "XInOriginal" | X coordinate of the upper left corner of the fragment map in the original image.| 7802| Y_IN_ORIGINAL | "YInOriginal" | Y coordinate of the upper left corner of the fragment map in the original image.| 7803| WIDTH | "FragmentImageWidth" | Width of the fragment map. | 7804| HEIGHT | "FragmentImageHeight" | Height of the fragment map. | 7805 7806## ImageFormat<sup>9+</sup> 7807 7808Enumerates the image formats. 7809 7810**System capability**: SystemCapability.Multimedia.Image.Core 7811 7812| Name | Value | Description | 7813| ------------ | ------ | -------------------- | 7814| YCBCR_422_SP | 1000 | YCBCR422 semi-planar format.| 7815| JPEG | 2000 | JPEG encoding format. | 7816 7817## ComponentType<sup>9+</sup> 7818 7819Enumerates the color component types of images. 7820 7821**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 7822 7823| Name | Value | Description | 7824| ----- | ------ | ----------- | 7825| YUV_Y | 1 | Luminance component. | 7826| YUV_U | 2 | Chrominance component. | 7827| YUV_V | 3 | Chrominance component. | 7828| JPEG | 4 | JPEG type.| 7829 7830## Component<sup>9+</sup> 7831 7832Describes the color components of an image. 7833 7834**System capability**: SystemCapability.Multimedia.Image.Core 7835 7836| Name | Type | Read Only| Optional| Description | 7837| ------------- | -------------------------------- | ---- | ---- | ------------ | 7838| componentType | [ComponentType](#componenttype9) | Yes | No | Color component type. | 7839| 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). | 7840| pixelStride | number | Yes | No | Pixel stride. | 7841| byteBuffer | ArrayBuffer | Yes | No | Component buffer.| 7842 7843## DecodingDynamicRange<sup>12+</sup> 7844 7845Describes the desired dynamic range of an image during decoding. 7846 7847**System capability**: SystemCapability.Multimedia.Image.Core 7848 7849| Name | Value | Description | 7850| ------------- | ----------| ------------ | 7851| 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. | 7852| SDR | 1 | The image is decoded according to the standard dynamic range. | 7853| 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. | 7854 7855## PackingDynamicRange<sup>12+</sup> 7856 7857Describes the desired dynamic range of a PixelMap during encoding. 7858 7859**System capability**: SystemCapability.Multimedia.Image.Core 7860 7861| Name | Value | Description | 7862| ------------- | ----------| ------------ | 7863| 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. | 7864| SDR | 1 | The image is decoded according to the standard dynamic range. | 7865 7866## HdrMetadataKey<sup>12+</sup> 7867 7868Enumerates the keys of HDR metadata used by [pixelmap](#pixelmap7). 7869 7870**System capability**: SystemCapability.Multimedia.Image.Core 7871 7872| Name | Value | Description | 7873| ------------- | ----------| ------------ | 7874| HDR_METADATA_TYPE | 0 | Metadata type used by [pixelmap](#pixelmap7). | 7875| HDR_STATIC_METADATA | 1 | Static metadata. | 7876| HDR_DYNAMIC_METADATA | 2 | Dynamic metadata. | 7877| HDR_GAINMAP_METADATA | 3 | Metadata used by gain maps. | 7878 7879## HdrMetadataType<sup>12+</sup> 7880 7881Enumerates the values available for **HDR_METADATA_TYPE** in [HdrMetadataKey](#hdrmetadatakey12). 7882 7883**System capability**: SystemCapability.Multimedia.Image.Core 7884 7885| Name | Value | Description | 7886| ------------- | ----------| ------------ | 7887| NONE | 0 | No metadata. | 7888| BASE | 1 | Metadata used for base graphics. | 7889| GAINMAP | 2 | Metadata used for gain maps. | 7890| ALTERNATE| 3 | Metadata used for synthesized HDR graphics. | 7891 7892## HdrStaticMetadata<sup>12+</sup> 7893 7894Describes the static metadata keys, that is, the values available for **HDR_STATIC_METADATA** in [HdrMetadataKey](#hdrmetadatakey12). 7895 7896**System capability**: SystemCapability.Multimedia.Image.Core 7897 7898| Name | Type | Read Only| Optional| Description | 7899| ------------- | ----------| -- | -- | ------------ | 7900| 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]. | 7901| 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]. | 7902| 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]. | 7903| 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]. | 7904| maxLuminance | number | No| No| Maximum luminance of the main monitor. The unit is 1, and the maximum value is 65535. | 7905| minLuminance | number | No| No| Minimum luminance of the main monitor. The unit is 0.0001, and the maximum value is 6.55535. | 7906| maxContentLightLevel | number | No| No| Maximum luminance of the displayed content. The unit is 1, and the maximum value is 65535. | 7907| maxFrameAverageLightLevel | number | No| No| Maximum average luminance of the displayed content. The unit is 1, and the maximum value is 65535.| 7908 7909## GainmapChannel<sup>12+</sup> 7910 7911Describes the data content of a single channel of the gain map. For details, see ISO 21496-1. 7912 7913**System capability**: SystemCapability.Multimedia.Image.Core 7914 7915| Name | Type | Read Only| Optional| Description | 7916| ------------- | ----------| -- | -- | ------------ | 7917| gainmapMax | number | No| No| Maximum value of the gain map. For details, see ISO 21496-1. | 7918| gainmapMin | number | No| No| Minimum value of the gain map. For details, see ISO 21496-1. | 7919| gamma | number | No| No| Gamma. For details, see ISO 21496-1. | 7920| baseOffset | number | No| No| Offset of the base graphic. For details, see ISO 21496-1. | 7921| alternateOffset | number | No| No| Offset of the alternative graphic that can be extracted. For details, see ISO 21496-1. | 7922 7923## HdrGainmapMetadata<sup>12+</sup> 7924 7925Describes 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. 7926 7927**System capability**: SystemCapability.Multimedia.Image.Core 7928 7929| Name | Type | Read Only| Optional| Description | 7930| ------------- | ----------| -- | -- | ------------ | 7931| writerVersion | number | No| No| Version used by the metadata editor. | 7932| miniVersion | number | No| No| Minimum version that needs to be understood for metadata parsing. | 7933| 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. | 7934| useBaseColorFlag | boolean | No| No| Whether to use the color space of the base graphic. For details, see ISO 21496-1. | 7935| 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. | 7936| alternateHeadroom | number | No| No| Headroom of the alternate graphic. For details, see ISO 21496-1. | 7937| channels | Array<[GainmapChannel](#gainmapchannel12)> | No| No| Number of channels. The length is 3. For details, see ISO 21496-1.| 7938 7939## HdrMetadataValue<sup>12+</sup> 7940 7941type HdrMetadataValue = HdrMetadataType | HdrStaticMetadata | ArrayBuffer | HdrGainmapMetadata 7942 7943Describes the HDR metadata values used by a PixelMap, which corresponds to the values available for [HdrMetadataKey](#hdrmetadatakey12). 7944 7945**System capability**: SystemCapability.Multimedia.Image.Core 7946 7947| Type | Description | 7948| ------------------- | ----------------------------------------------- | 7949| [HdrMetadataType](#hdrmetadatatype12) | Metadata value corresponding to the **HDR_GAINMAP_METADATA** key in [HdrMetadataKey](#hdrmetadatakey12).| 7950| [HdrStaticMetadata](#hdrstaticmetadata12) | Metadata value corresponding to the **HDR_STATIC_METADATA** key in [HdrMetadataKey](#hdrmetadatakey12).| 7951| ArrayBuffer | Metadata value corresponding to the **HDR_DYNAMIC_METADATA** key in [HdrMetadataKey](#hdrmetadatakey12).| 7952| [HdrGainmapMetadata](#hdrgainmapmetadata12) | Metadata value corresponding to the **HDR_GAINMAP_METADATA** key in [HdrMetadataKey](#hdrmetadatakey12).| 7953 7954## AntiAliasingLevel<sup>12+</sup> 7955 7956Enumerates the anti-aliasing levels. 7957 7958**System capability**: SystemCapability.Multimedia.Image.Core 7959 7960| Name | Value | Description | 7961| ---------------------- | ------ | ----------------- | 7962| NONE | 0 | The nearest neighbor interpolation algorithm is used by default. | 7963| LOW | 1 | Bilinear interpolation. | 7964| MEDIUM | 2 | Bilinear interpolation with mipmap enabled.| 7965| HIGH | 3 | Cubic convolution.| 7966 7967## Supplementary Information 7968### SVG Tags 7969 7970The 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: 7971- a 7972- circla 7973- clipPath 7974- defs 7975- ellipse 7976- feBlend 7977- feColorMatrix 7978- feComposite 7979- feDiffuseLighting 7980- feDisplacementMap 7981- feDistantLight 7982- feFlood 7983- feGaussianBlur 7984- feImage 7985- feMorphology 7986- feOffset 7987- fePointLight 7988- feSpecularLighting 7989- feSpotLight 7990- feTurbulence 7991- filter 7992- g 7993- image 7994- line 7995- linearGradient 7996- mask 7997- path 7998- pattern 7999- polygon 8000- polyline 8001- radialGradient 8002- rect 8003- stop 8004- svg 8005- text 8006- textPath 8007- tspan 8008- use 8009