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