1# Functions 2<!--Kit: Image Kit--> 3<!--Subsystem: Multimedia--> 4<!--Owner: @aulight02--> 5<!--SE: @liyang_bryan--> 6<!--TSE: @xchaosioda--> 7 8> **NOTE** 9> 10> 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. 11 12## Modules to Import 13 14```ts 15import { image } from '@kit.ImageKit'; 16``` 17 18## image.createPicture<sup>13+</sup> 19 20createPicture(mainPixelmap : PixelMap): Picture 21 22Creates a Picture object based on a main PixelMap. 23 24**System capability**: SystemCapability.Multimedia.Image.Core 25 26**Parameters** 27 28| Name | Type | Mandatory| Description | 29| ------------ | ------------------- | ---- | ---------------- | 30| mainPixelmap | [PixelMap](arkts-apis-image-PixelMap.md) | Yes | Main PixelMap.| 31 32**Return value** 33 34| Type | Description | 35| ------------------ | ----------------- | 36| [Picture](arkts-apis-image-Picture.md) | Picture object.| 37 38**Error codes** 39 40For details about the error codes, see [Image Error Codes](errorcode-image.md). 41 42| ID| Error Message | 43| -------- | ------------------------------------------------------------ | 44| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. | 45 46**Example** 47 48```ts 49import { image } from '@kit.ImageKit'; 50 51async function CreatePicture(context: Context) { 52 const resourceMgr = context.resourceManager; 53 const rawFile = await resourceMgr.getRawFileContent("test.jpg"); 54 let ops: image.SourceOptions = { 55 sourceDensity: 98, 56 } 57 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 58 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 59 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 60 if (pictureObj != null) { 61 console.info('Create picture succeeded'); 62 } else { 63 console.error('Create picture failed'); 64 } 65} 66``` 67 68## image.createPictureFromParcel<sup>13+</sup> 69 70createPictureFromParcel(sequence: rpc.MessageSequence): Picture 71 72Creates a Picture object from a MessageSequence object. 73 74**System capability**: SystemCapability.Multimedia.Image.Core 75 76**Parameters** 77 78| Name | Type | Mandatory| Description | 79| -------- | ------------------------------------------------------------------- | ---- | ------------------------------------ | 80| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | Yes | MessageSequence object that stores the Picture information.| 81 82**Return value** 83 84| Type | Description | 85| ------------------ | ----------------- | 86| [Picture](arkts-apis-image-Picture.md) | Picture object.| 87 88**Error codes** 89 90For details about the error codes, see [Image Error Codes](errorcode-image.md). 91 92| ID| Error Message | 93| -------- | ------------------------------------------------------------ | 94| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. | 95| 62980097 | IPC error. Possible cause: 1.IPC communication failed. 2. Image upload exception. 3. Decode process exception. 4. Insufficient memory. | 96 97**Example** 98 99```ts 100import { rpc } from '@kit.IPCKit'; 101import { BusinessError } from '@kit.BasicServicesKit'; 102import { image } from '@kit.ImageKit'; 103 104class MySequence implements rpc.Parcelable { 105 picture: image.Picture | null = null; 106 constructor(conPicture: image.Picture) { 107 this.picture = conPicture; 108 } 109 marshalling(messageSequence: rpc.MessageSequence) { 110 if(this.picture != null) { 111 this.picture.marshalling(messageSequence); 112 console.info('Marshalling success !'); 113 return true; 114 } else { 115 console.error('Marshalling failed !'); 116 return false; 117 } 118 } 119 unmarshalling(messageSequence : rpc.MessageSequence) { 120 this.picture = image.createPictureFromParcel(messageSequence); 121 this.picture.getMainPixelmap().getImageInfo().then((imageInfo : image.ImageInfo) => { 122 console.info('Unmarshalling to get mainPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width); 123 }).catch((error: BusinessError) => { 124 console.error('Unmarshalling failed error.code: ${error.code} ,error.message: ${error.message}'); 125 }); 126 return true; 127 } 128} 129 130async function Marshalling_UnMarshalling(context: Context) { 131 const resourceMgr = context.resourceManager; 132 const rawFile = await resourceMgr.getRawFileContent("test.jpg"); 133 let ops: image.SourceOptions = { 134 sourceDensity: 98, 135 } 136 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 137 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 138 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 139 if (pictureObj != null) { 140 let parcelable: MySequence = new MySequence(pictureObj); 141 let data: rpc.MessageSequence = rpc.MessageSequence.create(); 142 // marshalling. 143 data.writeParcelable(parcelable); 144 let ret: MySequence = new MySequence(pictureObj); 145 // unmarshalling. 146 data.readParcelable(ret); 147 } else { 148 console.error('PictureObj is null'); 149 } 150} 151``` 152 153## image.createPixelMap<sup>8+</sup> 154 155createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<PixelMap> 156 157Creates a PixelMap object with the specified properties. By default, the BGRA_8888 format is used to process data. This API uses a promise to return the result. 158 159**System capability**: SystemCapability.Multimedia.Image.Core 160 161**Parameters** 162 163| Name | Type | Mandatory| Description | 164| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 165| colors | ArrayBuffer | Yes | Buffer for storing the pixel data. It is used to initialize the pixels of the PixelMap. Before initialization, the pixel format in the buffer must be specified by [InitializationOptions](arkts-apis-image-i.md#initializationoptions8).srcPixelFormat.<br>**NOTE**: The length of the buffer required for storing the pixel data is determined by multiplying the width, height, and the number of bytes per pixel.| 166| options | [InitializationOptions](arkts-apis-image-i.md#initializationoptions8) | Yes | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.| 167 168**Return value** 169 170| Type | Description | 171| -------------------------------- | ----------------------------------------------------------------------- | 172| Promise\<[PixelMap](arkts-apis-image-PixelMap.md)> | Promise used to return the PixelMap object.<br>If the size of the created PixelMap exceeds that of the original image, the PixelMap size of the original image is returned.| 173 174**Example** 175 176```ts 177import { BusinessError } from '@kit.BasicServicesKit'; 178 179async function CreatePixelMap() { 180 const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 181 let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 182 image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => { 183 console.info('Succeeded in creating pixelmap.'); 184 }).catch((error: BusinessError) => { 185 console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`); 186 }) 187} 188``` 189 190## image.createPixelMap<sup>8+</sup> 191 192createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: AsyncCallback\<PixelMap>): void 193 194Creates a PixelMap object with the specified properties. By default, the BGRA_8888 format is used to process data. This API uses an asynchronous callback to return the result. 195 196**System capability**: SystemCapability.Multimedia.Image.Core 197 198**Parameters** 199 200| Name | Type | Mandatory| Description | 201| -------- | ------------------------------------------------ | ---- | -------------------------- | 202| colors | ArrayBuffer | Yes | Buffer for storing the pixel data. It is used to initialize the pixels of the PixelMap. Before initialization, the pixel format in the buffer must be specified by [InitializationOptions](arkts-apis-image-i.md#initializationoptions8).srcPixelFormat.<br>**NOTE**: The length of the buffer required for storing the pixel data is determined by multiplying the width, height, and the number of bytes per pixel.| 203| options | [InitializationOptions](arkts-apis-image-i.md#initializationoptions8) | Yes | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.| 204| callback | AsyncCallback\<[PixelMap](arkts-apis-image-PixelMap.md)> | 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.| 205 206**Example** 207 208```ts 209import { BusinessError } from '@kit.BasicServicesKit'; 210 211async function CreatePixelMap() { 212 const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 213 let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 214 image.createPixelMap(color, opts, (error: BusinessError, pixelMap: image.PixelMap) => { 215 if(error) { 216 console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`); 217 return; 218 } else { 219 console.info('Succeeded in creating pixelmap.'); 220 } 221 }) 222} 223``` 224 225## image.createPixelMapUsingAllocator<sup>20+</sup> 226 227createPixelMapUsingAllocator(colors: ArrayBuffer, param: InitializationOptions, allocatorType?: AllocatorType): Promise\<PixelMap> 228 229Creates a PixelMap object with the specified properties and memory type. By default, the BGRA_8888 format is used to process data. This API uses a promise to return the result. 230 231**System capability**: SystemCapability.Multimedia.Image.Core 232 233**Parameters** 234 235| Name | Type | Mandatory| Description | 236| -------- | ------------------------------------------------ | ---- | -------------------------- | 237| colors | ArrayBuffer | Yes | Buffer for storing the pixel data. It is used to initialize the pixels of the PixelMap. Before initialization, the pixel format in the buffer must be specified by [InitializationOptions](arkts-apis-image-i.md#initializationoptions8).srcPixelFormat.<br>**NOTE**: The length of the buffer required for storing the pixel data is determined by multiplying the width, height, and the number of bytes per pixel.| 238| param | [InitializationOptions](arkts-apis-image-i.md#initializationoptions8) | Yes | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.| 239| allocatorType | [AllocatorType](arkts-apis-image-e.md#allocatortype15) | No | Memory type for creating the PixelMap. The default memory type is **AllocatorType.AUTO**.<br> 1. **image.AllocatorType.AUTO**: The following formats are not supported for this memory type: UNKNOWN, YCBCR_P010, YCRCB_P010, and ASTC_4x4. For RGBA_1010102, DMA memory is allocated by default. For other formats (RGB_565, RGBA_8888, BGRA_8888, and RGBAF_16), DMA memory is allocated if the dimensions exceed 512*512; otherwise, shared memory is allocated.<br>2. **image.AllocatorType.DMA**: The formats RGBA_1010102, RGB_565, RGBA_8888, BGRA_8888, and RGBAF_16 support DMA memory types. Other formats do not support DMA memory types.<br>3. **image.AllocatorType.SHARED**: The formats UNKNOWN, RGBA_1010102, YCBCR_P010, YCRCB_P010, and ASTC_4x4 do not support shared memory. Other formats support shared memory.| 240 241**Return value** 242 243| Type | Description | 244| -------------------------------- | ----------------------------------------------------------------------- | 245| Promise\<[PixelMap](arkts-apis-image-PixelMap.md)> | Promise used to return the PixelMap object.| 246 247**Error codes** 248 249For details about the error codes, see [Image Error Codes](errorcode-image.md). 250 251| ID| Error Message| 252| ------- | --------------------------------------------| 253| 7600201 | Unsupported operation. | 254| 7600301 | Memory alloc failed. | 255| 7600302 | Memory copy failed. | 256 257**Example** 258 259```ts 260import { BusinessError } from '@kit.BasicServicesKit'; 261 262async function CreatePixelMapUseAllocator() { 263 const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 264 let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 265 image.createPixelMapUsingAllocator(color, opts, image.AllocatorType.AUTO).then((pixelMap: image.PixelMap) => { 266 console.info('Succeeded in creating pixelmap.'); 267 }).catch((error: BusinessError) => { 268 console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`); 269 }) 270} 271``` 272 273## image.createPixelMapFromParcel<sup>11+</sup> 274 275createPixelMapFromParcel(sequence: rpc.MessageSequence): PixelMap 276 277Creates a PixelMap object from a MessageSequence object. 278 279**System capability**: SystemCapability.Multimedia.Image.Core 280 281**Parameters** 282 283| Name | Type | Mandatory| Description | 284| ---------------------- | ----------------------------------------------------- | ---- | ---------------------------------------- | 285| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | Yes | MessageSequence object that stores the PixelMap information. | 286 287**Return value** 288 289| Type | Description | 290| -------------------------------- | --------------------- | 291| [PixelMap](arkts-apis-image-PixelMap.md) | PixelMap object. If the operation fails, an error is thrown.| 292 293**Error codes** 294 295For details about the error codes, see [Image Error Codes](errorcode-image.md). 296 297| ID| Error Message| 298| ------- | --------------------------------------------| 299| 62980096 | The operation failed. Possible cause: 1.Image upload exception. 2. Decoding process exception. 3. Insufficient memory.| 300| 62980097 | IPC error. Possible cause: 1.IPC communication failed. 2. Image upload exception. 3. Decode process exception. 4. Insufficient memory.| 301| 62980115 | Invalid input parameter.| 302| 62980105 | Failed to get the data.| 303| 62980177 | Abnormal API environment.| 304| 62980178 | Failed to create the PixelMap.| 305| 62980179 | Abnormal buffer size.| 306| 62980180 | FD mapping failed. Possible cause: 1. Size and address does not match. 2. Memory map in memalloc failed.| 307| 62980246 | Failed to read the PixelMap.| 308 309**Example** 310 311```ts 312import { image } from '@kit.ImageKit'; 313import { rpc } from '@kit.IPCKit'; 314import { BusinessError } from '@kit.BasicServicesKit'; 315 316class MySequence implements rpc.Parcelable { 317 pixel_map: image.PixelMap; 318 constructor(conPixelmap: image.PixelMap) { 319 this.pixel_map = conPixelmap; 320 } 321 marshalling(messageSequence: rpc.MessageSequence) { 322 this.pixel_map.marshalling(messageSequence); 323 return true; 324 } 325 unmarshalling(messageSequence: rpc.MessageSequence) { 326 try { 327 this.pixel_map = image.createPixelMapFromParcel(messageSequence); 328 } catch(e) { 329 let error = e as BusinessError; 330 console.error(`createPixelMapFromParcel error. code is ${error.code}, message is ${error.message}`); 331 return false; 332 } 333 return true; 334 } 335} 336async function CreatePixelMapFromParcel() { 337 const color: ArrayBuffer = new ArrayBuffer(96); 338 let bufferArr: Uint8Array = new Uint8Array(color); 339 for (let i = 0; i < bufferArr.length; i++) { 340 bufferArr[i] = 0x80; 341 } 342 let opts: image.InitializationOptions = { 343 editable: true, 344 pixelFormat: image.PixelMapFormat.BGRA_8888, 345 size: { height: 4, width: 6 }, 346 alphaType: image.AlphaType.UNPREMUL 347 } 348 let pixelMap: image.PixelMap | undefined = undefined; 349 await image.createPixelMap(color, opts).then((srcPixelMap: image.PixelMap) => { 350 pixelMap = srcPixelMap; 351 }) 352 if (pixelMap != undefined) { 353 // Implement serialization. 354 let parcelable: MySequence = new MySequence(pixelMap); 355 let data: rpc.MessageSequence = rpc.MessageSequence.create(); 356 data.writeParcelable(parcelable); 357 358 // Implement deserialization to obtain data through the RPC. 359 let ret: MySequence = new MySequence(pixelMap); 360 data.readParcelable(ret); 361 362 // Obtain the PixelMap object. 363 let unmarshPixelmap = ret.pixel_map; 364 } 365} 366``` 367 368## image.createPixelMapFromSurface<sup>11+</sup> 369 370createPixelMapFromSurface(surfaceId: string, region: Region): Promise\<PixelMap> 371 372Creates a PixelMap object based on the surface ID and region information. The size of the region is specified by [Region](arkts-apis-image-i.md#region8).size. This API uses a promise to return the result. 373 374> **NOTE** 375> 376> When working with foldable devices, switching between folded and unfolded states may cause the API call to fail due to the rotation angle of surface. To address this, you need to adjust the width and height according to the rotation angle. In such cases, [image.createPixelMapFromSurface](#imagecreatepixelmapfromsurface15) is recommended. 377 378**System capability**: SystemCapability.Multimedia.Image.Core 379 380**Parameters** 381 382| Name | Type | Mandatory| Description | 383| ---------------------- | ------------- | ---- | ---------------------------------------- | 384| surfaceId | string | Yes | Surface ID, which can be obtained through the preview component, for example, [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md).| 385| region | [Region](arkts-apis-image-i.md#region8) | Yes | Region information. The width and height in [Region](arkts-apis-image-i.md#region8).size must be the same as those of the preview stream.| 386 387**Return value** 388 389| Type | Description | 390| -------------------------------- | --------------------- | 391| Promise\<[PixelMap](arkts-apis-image-PixelMap.md)> | Promise used to return the PixelMap object.| 392 393**Error codes** 394 395For details about the error codes, see [Image Error Codes](errorcode-image.md). 396 397| ID| Error Message| 398| ------- | --------------------------------------------| 399| 62980115 | If the image parameter invalid.| 400| 62980105 | Failed to get the data.| 401| 62980178 | Failed to create the PixelMap.| 402 403**Example** 404 405```ts 406import { BusinessError } from '@kit.BasicServicesKit'; 407 408async function CreatePixelMapFromSurface(surfaceId: string) { 409 let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 410 image.createPixelMapFromSurface(surfaceId, region).then(() => { 411 console.info('Succeeded in creating pixelmap from Surface'); 412 }).catch((error: BusinessError) => { 413 console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`); 414 }); 415} 416``` 417 418## image.createPixelMapFromSurfaceSync<sup>12+</sup> 419 420createPixelMapFromSurfaceSync(surfaceId: string, region: Region): PixelMap 421 422Creates a PixelMap object based on the surface ID and region information. This API returns the result synchronously. The size of the region is specified by [Region](arkts-apis-image-i.md#region8).size. 423 424> **NOTE** 425> 426> When working with foldable devices, switching between folded and unfolded states may cause the API call to fail due to the rotation angle of surface. To address this, you need to adjust the width and height according to the rotation angle. In such cases, [image.createPixelMapFromSurfaceSync](#imagecreatepixelmapfromsurfacesync15) is recommended. 427 428**System capability**: SystemCapability.Multimedia.Image.Core 429 430**Parameters** 431 432| Name | Type | Mandatory| Description | 433| ---------------------- | ------------- | ---- | ---------------------------------------- | 434| surfaceId | string | Yes | Surface ID, which can be obtained through the preview component, for example, [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md).| 435| region | [Region](arkts-apis-image-i.md#region8) | Yes | Region information. The width and height in [Region](arkts-apis-image-i.md#region8).size must be the same as those of the preview stream.| 436 437**Return value** 438 439| Type | Description | 440| -------------------------------- | --------------------- | 441| [PixelMap](arkts-apis-image-PixelMap.md) | PixelMap object. If the operation fails, an error is thrown.| 442 443**Error codes** 444 445For details about the error codes, see [Image Error Codes](errorcode-image.md). 446 447| ID| Error Message| 448| ------- | --------------------------------------------| 449| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.| 450| 62980105 | Failed to get the data.| 451| 62980178 | Failed to create the PixelMap.| 452 453**Example** 454 455```ts 456import { BusinessError } from '@kit.BasicServicesKit'; 457 458async function Demo(surfaceId: string) { 459 let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 460 let pixelMap : image.PixelMap = image.createPixelMapFromSurfaceSync(surfaceId, region); 461 return pixelMap; 462} 463``` 464 465## image.createPixelMapFromSurface<sup>15+</sup> 466 467createPixelMapFromSurface(surfaceId: string): Promise\<PixelMap> 468 469Creates a PixelMap object from a surface ID. This API uses a promise to return the result. 470 471**System capability**: SystemCapability.Multimedia.Image.Core 472 473**Parameters** 474 475| Name | Type | Mandatory| Description | 476| ---------------------- | ------------- | ---- | ---------------------------------------- | 477| surfaceId | string | Yes | Surface ID, which can be obtained through the preview component, for example, [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md).| 478 479**Return value** 480 481| Type | Description | 482| -------------------------------- | --------------------- | 483| Promise\<[PixelMap](arkts-apis-image-PixelMap.md)> | Promise used to return the PixelMap object.| 484 485**Error codes** 486 487For details about the error codes, see [Image Error Codes](errorcode-image.md). 488 489| ID| Error Message| 490| ------- | --------------------------------------------| 491| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 492| 62980105 | Failed to get the data| 493| 62980178 | Failed to create the PixelMap| 494 495**Example** 496 497```ts 498import { BusinessError } from '@kit.BasicServicesKit'; 499 500async function Demo(surfaceId: string) { 501 image.createPixelMapFromSurface(surfaceId).then(() => { 502 console.info('Succeeded in creating pixelmap from Surface'); 503 }).catch((error: BusinessError) => { 504 console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`); 505 }); 506} 507``` 508 509## image.createPixelMapFromSurfaceSync<sup>15+</sup> 510 511createPixelMapFromSurfaceSync(surfaceId: string): PixelMap 512 513Creates a PixelMap object from a surface ID. This API returns the result synchronously. 514 515**System capability**: SystemCapability.Multimedia.Image.Core 516 517**Parameters** 518 519| Name | Type | Mandatory| Description | 520| ---------------------- | ------------- | ---- | ---------------------------------------- | 521| surfaceId | string | Yes | Surface ID, which can be obtained through the preview component, for example, [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md).| 522 523**Return value** 524 525| Type | Description | 526| -------------------------------- | --------------------- | 527| [PixelMap](arkts-apis-image-PixelMap.md) | PixelMap object. If the operation fails, an error is thrown.| 528 529**Error codes** 530 531For details about the error codes, see [Image Error Codes](errorcode-image.md). 532 533| ID| Error Message| 534| ------- | --------------------------------------------| 535| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 536| 62980105 | Failed to get the data| 537| 62980178 | Failed to create the PixelMap| 538 539**Example** 540 541```ts 542import { BusinessError } from '@kit.BasicServicesKit'; 543 544async function Demo(surfaceId: string) { 545 let pixelMap : image.PixelMap = image.createPixelMapFromSurfaceSync(surfaceId); 546 return pixelMap; 547} 548``` 549## image.createPixelMapSync<sup>12+</sup> 550 551createPixelMapSync(colors: ArrayBuffer, options: InitializationOptions): PixelMap 552 553Creates a PixelMap object with the specified properties. By default, the BGRA_8888 format is used to process data. This API returns the result synchronously. 554 555**System capability**: SystemCapability.Multimedia.Image.Core 556 557**Parameters** 558 559| Name | Type | Mandatory| Description | 560| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 561| colors | ArrayBuffer | Yes | Buffer for storing the pixel data. It is used to initialize the pixels of the PixelMap. Before initialization, the pixel format in the buffer must be specified by [InitializationOptions](arkts-apis-image-i.md#initializationoptions8).srcPixelFormat.<br>**NOTE**: The length of the buffer required for storing the pixel data is determined by multiplying the width, height, and the number of bytes per pixel.| 562| options | [InitializationOptions](arkts-apis-image-i.md#initializationoptions8) | Yes | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.| 563 564**Return value** 565 566| Type | Description | 567| -------------------------------- | --------------------- | 568| [PixelMap](arkts-apis-image-PixelMap.md) | PixelMap object. If the operation fails, an error is thrown.| 569 570**Error codes** 571 572For details about the error codes, see [Image Error Codes](errorcode-image.md). 573 574| ID| Error Message| 575| ------- | --------------------------------------------| 576| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 577 578**Example** 579 580```ts 581import { BusinessError } from '@kit.BasicServicesKit'; 582 583async function CreatePixelMapSync() { 584 const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 585 let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 586 let pixelMap : image.PixelMap = image.createPixelMapSync(color, opts); 587 return pixelMap; 588} 589``` 590 591## image.createPixelMapSync<sup>12+</sup> 592 593createPixelMapSync(options: InitializationOptions): PixelMap 594 595Creates a PixelMap object with the specified pixel properties. This API returns the result synchronously. 596 597**System capability**: SystemCapability.Multimedia.Image.Core 598 599**Parameters** 600 601| Name | Type | Mandatory| Description | 602| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 603| options | [InitializationOptions](arkts-apis-image-i.md#initializationoptions8) | Yes | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.| 604 605**Return value** 606| Type | Description | 607| -------------------------------- | --------------------- | 608| [PixelMap](arkts-apis-image-PixelMap.md) | PixelMap object. If the operation fails, an error is thrown.| 609 610**Error codes** 611 612For details about the error codes, see [Image Error Codes](errorcode-image.md). 613 614| ID| Error Message| 615| ------- | --------------------------------------------| 616| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 617 618**Example** 619 620```ts 621import { BusinessError } from '@kit.BasicServicesKit'; 622 623async function CreatePixelMapSync() { 624 let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 625 let pixelMap : image.PixelMap = image.createPixelMapSync(opts); 626 return pixelMap; 627} 628``` 629 630## image.createPixelMapUsingAllocatorSync<sup>20+</sup> 631 632createPixelMapUsingAllocatorSync(colors: ArrayBuffer, param: InitializationOptions, allocatorType?: AllocatorType): PixelMap 633 634Creates a PixelMap object with the specified properties and memory type. By default, the BGRA_8888 format is used to process data. This API returns the result synchronously. 635 636**System capability**: SystemCapability.Multimedia.Image.Core 637 638**Parameters** 639 640| Name | Type | Mandatory| Description | 641| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 642| colors | ArrayBuffer | Yes | Buffer for storing the pixel data. It is used to initialize the pixels of the PixelMap. Before initialization, the pixel format in the buffer must be specified by [InitializationOptions](arkts-apis-image-i.md#initializationoptions8).srcPixelFormat.<br>**NOTE**: The length of the buffer required for storing the pixel data is determined by multiplying the width, height, and the number of bytes per pixel.| 643| param | [InitializationOptions](arkts-apis-image-i.md#initializationoptions8) | Yes | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.| 644| allocatorType | [AllocatorType](arkts-apis-image-e.md#allocatortype15) | No | Memory type for creating the PixelMap. The default memory type is **AllocatorType.AUTO**.<br> 1. **image.AllocatorType.AUTO**: The following formats are not supported for this memory type: UNKNOWN, YCBCR_P010, YCRCB_P010, and ASTC_4x4. For RGBA_1010102, DMA memory is allocated by default. For other formats (RGB_565, RGBA_8888, BGRA_8888, and RGBAF_16), DMA memory is allocated if the dimensions exceed 512*512; otherwise, shared memory is allocated.<br>2. **image.AllocatorType.DMA**: The formats RGBA_1010102, RGB_565, RGBA_8888, BGRA_8888, and RGBAF_16 support DMA memory types. Other formats do not support DMA memory types.<br>3. **image.AllocatorType.SHARED**: The formats UNKNOWN, RGBA_1010102, YCBCR_P010, YCRCB_P010, and ASTC_4x4 do not support shared memory. Other formats support shared memory.| 645 646**Return value** 647 648| Type | Description | 649| -------------------------------- | --------------------- | 650| [PixelMap](arkts-apis-image-PixelMap.md) | PixelMap object. If the operation fails, an error is thrown.| 651 652**Error codes** 653 654For details about the error codes, see [Image Error Codes](errorcode-image.md). 655 656| ID| Error Message| 657| ------- | --------------------------------------------| 658| 7600201 | Unsupported operation. | 659| 7600301 | Memory alloc failed. | 660| 7600302 | Memory copy failed. | 661 662**Example** 663 664```ts 665import { BusinessError } from '@kit.BasicServicesKit'; 666 667async function CreatePixelMapSync() { 668 const color: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 669 let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 670 let pixelMap : image.PixelMap = image.createPixelMapUsingAllocatorSync(color, opts, image.AllocatorType.AUTO); 671 return pixelMap; 672} 673``` 674 675## image.createPixelMapUsingAllocatorSync<sup>20+</sup> 676 677createPixelMapUsingAllocatorSync(param: InitializationOptions, allocatorType?: AllocatorType): PixelMap 678 679Creates a PixelMap object with the specified pixel properties. This API returns the result synchronously. 680 681**System capability**: SystemCapability.Multimedia.Image.Core 682 683**Parameters** 684 685| Name | Type | Mandatory| Description | 686| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 687| param | [InitializationOptions](arkts-apis-image-i.md#initializationoptions8) | Yes | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.| 688| allocatorType | [AllocatorType](arkts-apis-image-e.md#allocatortype15) | No | Memory type for creating the PixelMap. The default memory type is **AllocatorType.AUTO**.<br> 1. **image.AllocatorType.AUTO**: The following formats are not supported for this memory type: UNKNOWN and ASTC_4x4. For RGBA_1010102, YCBCR_P010, and YCRCB_P010, DMA memory is allocated by default. For other formats (RGB_565, RGBA_8888, BGRA_8888, and RGBAF_16), DMA memory is allocated if the dimensions exceed 512*512; otherwise, shared memory is allocated.<br>2. **image.AllocatorType.DMA**: The formats RGB_565, RGBA_8888, BGRA_8888, RGBAF_16, RGBA_1010102, YCBCR_P010, and YCRCB_P010 support DMA memory type. Other formats do not support DMA memory type.<br>3. **image.AllocatorType.SHARED**: The formats UNKNOWN, RGBA_1010102, YCBCR_P010, YCRCB_P010, and ASTC_4x4 do not support shared memory. Other formats support shared memory.| 689 690**Return value** 691 692| Type | Description | 693| -------------------------------- | --------------------- | 694| [PixelMap](arkts-apis-image-PixelMap.md) | PixelMap object. If the operation fails, an error is thrown.| 695 696**Error codes** 697 698For details about the error codes, see [Image Error Codes](errorcode-image.md). 699 700| ID| Error Message| 701| ------- | --------------------------------------------| 702| 7600201 | Unsupported operation.| 703| 7600301 | Memory alloc failed. | 704 705**Example** 706 707```ts 708import { BusinessError } from '@kit.BasicServicesKit'; 709 710async function CreatePixelMapSync() { 711 let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 712 let pixelMap : image.PixelMap = image.createPixelMapUsingAllocatorSync(opts, image.AllocatorType.AUTO); 713 return pixelMap; 714} 715``` 716 717## image.createPremultipliedPixelMap<sup>12+</sup> 718 719createPremultipliedPixelMap(src: PixelMap, dst: PixelMap, callback: AsyncCallback\<void>): void 720 721Converts a non-premultiplied alpha of a PixelMap to a premultiplied one and stores the converted data to a target PixelMap. This API uses an asynchronous callback to return the result. 722 723**System capability**: SystemCapability.Multimedia.Image.Core 724 725**Parameters** 726 727| Name | Type | Mandatory| Description | 728| -------- | ------------------------------------------------ | ---- | -------------------------- | 729| src | [PixelMap](arkts-apis-image-PixelMap.md) | Yes | Source PixelMap object.| 730| dst | [PixelMap](arkts-apis-image-PixelMap.md) | Yes | Target PixelMap object.| 731|callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 732 733**Error codes** 734 735For details about the error codes, see [Image Error Codes](errorcode-image.md). 736 737| ID| Error Message| 738| ------- | --------------------------------------------| 739| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 740| 62980103 | The image data is not supported | 741| 62980246 | Failed to read the pixelMap | 742| 62980248 | Pixelmap not allow modify | 743 744**Example** 745 746```ts 747import { BusinessError } from '@kit.BasicServicesKit'; 748 749async function CreatePremultipliedPixelMap() { 750 const color: ArrayBuffer = new ArrayBuffer(16); // 16 is the size of the pixel buffer to create. The value is calculated as follows: height * width * 4. 751 let bufferArr = new Uint8Array(color); 752 for (let i = 0; i < bufferArr.length; i += 4) { 753 bufferArr[i] = 255; 754 bufferArr[i+1] = 255; 755 bufferArr[i+2] = 122; 756 bufferArr[i+3] = 122; 757 } 758 let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.UNPREMUL} 759 let srcPixelmap = image.createPixelMapSync(color, optsForUnpre); 760 let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.PREMUL} 761 let dstPixelMap = image.createPixelMapSync(optsForPre); 762 image.createPremultipliedPixelMap(srcPixelmap, dstPixelMap, (error: BusinessError) => { 763 if(error) { 764 console.error(`Failed to convert pixelmap, error code is ${error}`); 765 return; 766 } else { 767 console.info('Succeeded in converting pixelmap.'); 768 } 769 }) 770} 771``` 772 773## image.createPremultipliedPixelMap<sup>12+</sup> 774 775createPremultipliedPixelMap(src: PixelMap, dst: PixelMap): Promise\<void> 776 777Converts a non-premultiplied alpha of a PixelMap to a premultiplied one and stores the converted data to a target PixelMap. This API uses a promise to return the result. 778 779**System capability**: SystemCapability.Multimedia.Image.Core 780 781**Parameters** 782 783| Name | Type | Mandatory| Description | 784| -------- | ------------------------------------------------ | ---- | -------------------------- | 785| src | [PixelMap](arkts-apis-image-PixelMap.md) | Yes | Source PixelMap object.| 786| dst | [PixelMap](arkts-apis-image-PixelMap.md) | Yes | Target PixelMap object.| 787 788**Return value** 789 790| Type | Description | 791| -------------------------------- | ----------------------------------------------------------------------- | 792| Promise\<void> | Promise that returns no value.| 793 794**Error codes** 795 796For details about the error codes, see [Image Error Codes](errorcode-image.md). 797 798| ID| Error Message| 799| ------- | --------------------------------------------| 800| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 801| 62980103 | The image data is not supported | 802| 62980246 | Failed to read the pixelMap | 803| 62980248 | Pixelmap not allow modify | 804 805**Example** 806 807```ts 808import { BusinessError } from '@kit.BasicServicesKit'; 809 810async function CreatePremultipliedPixelMap() { 811 const color: ArrayBuffer = new ArrayBuffer(16); // 16 is the size of the pixel buffer to create. The value is calculated as follows: height * width * 4. 812 let bufferArr = new Uint8Array(color); 813 for (let i = 0; i < bufferArr.length; i += 4) { 814 bufferArr[i] = 255; 815 bufferArr[i+1] = 255; 816 bufferArr[i+2] = 122; 817 bufferArr[i+3] = 122; 818 } 819 let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.UNPREMUL} 820 let srcPixelmap = image.createPixelMapSync(color, optsForUnpre); 821 let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.PREMUL} 822 let dstPixelMap = image.createPixelMapSync(optsForPre); 823 image.createPremultipliedPixelMap(srcPixelmap, dstPixelMap).then(() => { 824 console.info('Succeeded in converting pixelmap.'); 825 }).catch((error: BusinessError) => { 826 console.error(`Failed to convert pixelmap, error code is ${error}`); 827 }) 828} 829``` 830 831## image.createUnpremultipliedPixelMap<sup>12+</sup> 832 833createUnpremultipliedPixelMap(src: PixelMap, dst: PixelMap, callback: AsyncCallback\<void>): void 834 835Converts a premultiplied alpha of a PixelMap to a non-premultiplied one and stores the converted data to a target PixelMap. This API uses an asynchronous callback to return the result. 836 837**System capability**: SystemCapability.Multimedia.Image.Core 838 839**Parameters** 840 841| Name | Type | Mandatory| Description | 842| -------- | ------------------------------------------------ | ---- | -------------------------- | 843| src | [PixelMap](arkts-apis-image-PixelMap.md) | Yes | Source PixelMap object.| 844| dst | [PixelMap](arkts-apis-image-PixelMap.md) | Yes | Target PixelMap object.| 845|callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 846 847**Error codes** 848 849For details about the error codes, see [Image Error Codes](errorcode-image.md). 850 851| ID| Error Message| 852| ------- | --------------------------------------------| 853| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 854| 62980103 | The image data is not supported | 855| 62980246 | Failed to read the pixelMap | 856| 62980248 | Pixelmap not allow modify | 857 858**Example** 859 860```ts 861import { BusinessError } from '@kit.BasicServicesKit'; 862 863async function CreateUnpremultipliedPixelMap() { 864 const color: ArrayBuffer = new ArrayBuffer(16); // 16 is the size of the pixel buffer to create. The value is calculated as follows: height * width * 4. 865 let bufferArr = new Uint8Array(color); 866 for (let i = 0; i < bufferArr.length; i += 4) { 867 bufferArr[i] = 255; 868 bufferArr[i+1] = 255; 869 bufferArr[i+2] = 122; 870 bufferArr[i+3] = 122; 871 } 872 let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.PREMUL} 873 let srcPixelmap = image.createPixelMapSync(color, optsForPre); 874 let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.UNPREMUL} 875 let dstPixelMap = image.createPixelMapSync(optsForUnpre); 876 image.createUnpremultipliedPixelMap(srcPixelmap, dstPixelMap, (error: BusinessError) => { 877 if(error) { 878 console.error(`Failed to convert pixelmap, error code is ${error}`); 879 return; 880 } else { 881 console.info('Succeeded in converting pixelmap.'); 882 } 883 }) 884} 885``` 886 887## image.createUnpremultipliedPixelMap<sup>12+</sup> 888 889createUnpremultipliedPixelMap(src: PixelMap, dst: PixelMap): Promise\<void> 890 891Converts a premultiplied alpha of a PixelMap to a non-premultiplied one and stores the converted data to a target PixelMap. This API uses a promise to return the result. 892 893**System capability**: SystemCapability.Multimedia.Image.Core 894 895**Parameters** 896 897| Name | Type | Mandatory| Description | 898| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 899| src | [PixelMap](arkts-apis-image-PixelMap.md) | Yes | Source PixelMap object.| 900| dst | [PixelMap](arkts-apis-image-PixelMap.md) | Yes | Target PixelMap object.| 901 902**Return value** 903 904| Type | Description | 905| -------------------------------- | ----------------------------------------------------------------------- | 906| Promise\<void> | Promise that returns no value.| 907 908**Error codes** 909 910For details about the error codes, see [Image Error Codes](errorcode-image.md). 911 912| ID| Error Message| 913| ------- | --------------------------------------------| 914| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.| 915| 62980103 | The image data is not supported. | 916| 62980246 | Failed to read the pixelMap. | 917| 62980248 | Pixelmap not allow modify. | 918 919**Example** 920 921```ts 922import { BusinessError } from '@kit.BasicServicesKit'; 923 924async function CreateUnpremultipliedPixelMap() { 925 const color: ArrayBuffer = new ArrayBuffer(16); // 16 is the size of the pixel buffer to create. The value is calculated as follows: height * width * 4. 926 let bufferArr = new Uint8Array(color); 927 for (let i = 0; i < bufferArr.length; i += 4) { 928 bufferArr[i] = 255; 929 bufferArr[i+1] = 255; 930 bufferArr[i+2] = 122; 931 bufferArr[i+3] = 122; 932 } 933 let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.PREMUL} 934 let srcPixelmap = image.createPixelMapSync(color, optsForPre); 935 let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.UNPREMUL} 936 let dstPixelMap = image.createPixelMapSync(optsForUnpre); 937 image.createUnpremultipliedPixelMap(srcPixelmap, dstPixelMap).then(() => { 938 console.info('Succeeded in converting pixelmap.'); 939 }).catch((error: BusinessError) => { 940 console.error(`Failed to convert pixelmap, error code is ${error}`); 941 }) 942} 943``` 944 945## image.createImageSource 946 947createImageSource(uri: string): ImageSource 948 949Creates an ImageSource instance based on a given URI. 950 951 952**Atomic service API**: This API can be used in atomic services since API version 11. 953 954**System capability**: SystemCapability.Multimedia.Image.ImageSource 955 956**Parameters** 957 958| Name| Type | Mandatory| Description | 959| ------ | ------ | ---- | ---------------------------------- | 960| uri | string | Yes | Image path. Currently, only the application sandbox path is supported.<br>The following formats are supported: .jpg, .png, .gif, .bmp, .webp, .dng, .heic<sup>12+</sup> (depending on the hardware), [.svg<sup>10+</sup>](#svg-tags), and .ico<sup>11+</sup>.| 961 962**Return value** 963 964| Type | Description | 965| --------------------------- | -------------------------------------------- | 966| [ImageSource](arkts-apis-image-ImageSource.md) | ImageSource instance. If the operation fails, undefined is returned.| 967 968**Example** 969 970<!--code_no_check--> 971```ts 972import { common } from '@kit.AbilityKit'; 973 974// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext. 975let context = this.getUIContext().getHostContext() as common.UIAbilityContext; 976// '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. 977const path: string = context.filesDir + "/test.jpg"; 978const imageSourceApi: image.ImageSource = image.createImageSource(path); 979``` 980 981## image.createImageSource<sup>9+</sup> 982 983createImageSource(uri: string, options: SourceOptions): ImageSource 984 985Creates an ImageSource instance based on a given URI. 986 987**Widget capability**: This API can be used in ArkTS widgets since API version 12. 988 989**Atomic service API**: This API can be used in atomic services since API version 11. 990 991**System capability**: SystemCapability.Multimedia.Image.ImageSource 992 993**Parameters** 994 995| Name | Type | Mandatory| Description | 996| ------- | ------------------------------- | ---- | ----------------------------------- | 997| uri | string | Yes | Image path. Currently, only the application sandbox path is supported.<br>The following formats are supported: .jpg, .png, .gif, .bmp, .webp, .dng, .heic<sup>12+</sup> (depending on the hardware), [.svg<sup>10+</sup>](#svg-tags), and .ico<sup>11+</sup>.| 998| options | [SourceOptions](arkts-apis-image-i.md#sourceoptions9) | Yes | Image properties, including the image pixel density, pixel format, and image size.| 999 1000**Return value** 1001 1002| Type | Description | 1003| --------------------------- | -------------------------------------------- | 1004| [ImageSource](arkts-apis-image-ImageSource.md) | ImageSource instance. If the operation fails, undefined is returned.| 1005 1006**Example** 1007 1008<!--code_no_check--> 1009```ts 1010import { common } from '@kit.AbilityKit'; 1011 1012let sourceOptions: image.SourceOptions = { sourceDensity: 120 }; 1013// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext. 1014let context = this.getUIContext().getHostContext() as common.UIAbilityContext; 1015// '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. 1016const path: string = context.filesDir + "/test.png"; 1017let imageSourceApi: image.ImageSource = image.createImageSource(path, sourceOptions); 1018``` 1019 1020## image.createImageSource<sup>7+</sup> 1021 1022createImageSource(fd: number): ImageSource 1023 1024Creates an ImageSource instance based on a given file descriptor. 1025 1026**Atomic service API**: This API can be used in atomic services since API version 11. 1027 1028**System capability**: SystemCapability.Multimedia.Image.ImageSource 1029 1030**Parameters** 1031 1032| Name| Type | Mandatory| Description | 1033| ------ | ------ | ---- | ------------- | 1034| fd | number | Yes | File descriptor.| 1035 1036**Return value** 1037 1038| Type | Description | 1039| --------------------------- | -------------------------------------------- | 1040| [ImageSource](arkts-apis-image-ImageSource.md) | ImageSource instance. If the operation fails, undefined is returned.| 1041 1042**Example** 1043 1044<!--code_no_check--> 1045```ts 1046import { fileIo as fs } from '@kit.CoreFileKit'; 1047import { common } from '@kit.AbilityKit'; 1048 1049// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext. 1050let context = this.getUIContext().getHostContext() as common.UIAbilityContext; 1051// '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. 1052let filePath: string = context.filesDir + "/test.jpg"; 1053let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 1054const imageSourceApi: image.ImageSource = image.createImageSource(file.fd); 1055``` 1056 1057## image.createImageSource<sup>9+</sup> 1058 1059createImageSource(fd: number, options: SourceOptions): ImageSource 1060 1061Creates an ImageSource instance based on a given file descriptor. 1062 1063**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1064 1065**Atomic service API**: This API can be used in atomic services since API version 11. 1066 1067**System capability**: SystemCapability.Multimedia.Image.ImageSource 1068 1069**Parameters** 1070 1071| Name | Type | Mandatory| Description | 1072| ------- | ------------------------------- | ---- | ----------------------------------- | 1073| fd | number | Yes | File descriptor. | 1074| options | [SourceOptions](arkts-apis-image-i.md#sourceoptions9) | Yes | Image properties, including the image pixel density, pixel format, and image size.| 1075 1076**Return value** 1077 1078| Type | Description | 1079| --------------------------- | -------------------------------------------- | 1080| [ImageSource](arkts-apis-image-ImageSource.md) | ImageSource instance. If the operation fails, undefined is returned.| 1081 1082**Example** 1083 1084<!--code_no_check--> 1085```ts 1086import { fileIo as fs } from '@kit.CoreFileKit'; 1087import { common } from '@kit.AbilityKit'; 1088 1089let sourceOptions: image.SourceOptions = { sourceDensity: 120 }; 1090// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext. 1091let context = this.getUIContext().getHostContext() as common.UIAbilityContext; 1092// '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. 1093const filePath: string = context.filesDir + "/test.jpg"; 1094let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 1095const imageSourceApi: image.ImageSource = image.createImageSource(file.fd, sourceOptions); 1096``` 1097 1098## image.createImageSource<sup>9+</sup> 1099 1100createImageSource(buf: ArrayBuffer): ImageSource 1101 1102Creates an ImageSource instance based on buffers. The data passed by **buf** must be undecoded. Do not pass the pixel buffer data such as RBGA and YUV. If you want to create a PixelMap based on the pixel buffer data, call [image.createPixelMapSync](arkts-apis-image-ImageSource.md#createpixelmapsync12). 1103 1104**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1105 1106**Atomic service API**: This API can be used in atomic services since API version 11. 1107 1108**System capability**: SystemCapability.Multimedia.Image.ImageSource 1109 1110**Parameters** 1111 1112| Name| Type | Mandatory| Description | 1113| ------ | ----------- | ---- | ---------------- | 1114| buf | ArrayBuffer | Yes | Array of image buffers.| 1115 1116**Return value** 1117 1118| Type | Description | 1119| --------------------------- | -------------------------------------------- | 1120| [ImageSource](arkts-apis-image-ImageSource.md) | ImageSource instance. If the operation fails, undefined is returned.| 1121 1122 1123**Example** 1124 1125```ts 1126const buf: ArrayBuffer = new ArrayBuffer(96); // 96 is the size of the pixel buffer to create. The value is calculated as follows: height * width *4. 1127const imageSourceApi: image.ImageSource = image.createImageSource(buf); 1128``` 1129 1130## image.createImageSource<sup>9+</sup> 1131 1132createImageSource(buf: ArrayBuffer, options: SourceOptions): ImageSource 1133 1134Creates an ImageSource instance based on buffers. The data passed by **buf** must be undecoded. Do not pass the pixel buffer data such as RBGA and YUV. If you want to create a PixelMap based on the pixel buffer data, call [image.createPixelMapSync](arkts-apis-image-ImageSource.md#createpixelmapsync12). 1135 1136**Widget capability**: This API can be used in ArkTS widgets since API version 12. 1137 1138**Atomic service API**: This API can be used in atomic services since API version 11. 1139 1140**System capability**: SystemCapability.Multimedia.Image.ImageSource 1141 1142**Parameters** 1143 1144| Name| Type | Mandatory| Description | 1145| ------ | -------------------------------- | ---- | ------------------------------------ | 1146| buf | ArrayBuffer | Yes | Array of image buffers. | 1147| options | [SourceOptions](arkts-apis-image-i.md#sourceoptions9) | Yes | Image properties, including the image pixel density, pixel format, and image size.| 1148 1149**Return value** 1150 1151| Type | Description | 1152| --------------------------- | -------------------------------------------- | 1153| [ImageSource](arkts-apis-image-ImageSource.md) | ImageSource instance. If the operation fails, undefined is returned.| 1154 1155**Example** 1156 1157```ts 1158const data: ArrayBuffer = new ArrayBuffer(112); 1159let sourceOptions: image.SourceOptions = { sourceDensity: 120 }; 1160const imageSourceApi: image.ImageSource = image.createImageSource(data, sourceOptions); 1161``` 1162 1163## image.createImageSource<sup>11+</sup> 1164 1165createImageSource(rawfile: resourceManager.RawFileDescriptor, options?: SourceOptions): ImageSource 1166 1167Creates an ImageSource instance based on the raw file descriptor of an image resource file. 1168 1169**Atomic service API**: This API can be used in atomic services since API version 11. 1170 1171**System capability**: SystemCapability.Multimedia.Image.ImageSource 1172 1173**Parameters** 1174 1175| Name| Type | Mandatory| Description | 1176| ------ | -------------------------------- | ---- | ------------------------------------ | 1177| rawfile | [resourceManager.RawFileDescriptor](../apis-localization-kit/js-apis-resource-manager.md#rawfiledescriptor9) | Yes| Raw file descriptor of the image resource file.| 1178| options | [SourceOptions](arkts-apis-image-i.md#sourceoptions9) | No| Image properties, including the image pixel density, pixel format, and image size.| 1179 1180**Return value** 1181 1182| Type | Description | 1183| --------------------------- | -------------------------------------------- | 1184| [ImageSource](arkts-apis-image-ImageSource.md) | ImageSource instance. If the operation fails, undefined is returned.| 1185 1186**Example** 1187 1188<!--code_no_check--> 1189```ts 1190import { resourceManager } from '@kit.LocalizationKit'; 1191import { common } from '@kit.AbilityKit'; 1192 1193// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext. 1194let context = this.getUIContext().getHostContext() as common.UIAbilityContext; 1195// Obtain a resource manager. 1196const resourceMgr: resourceManager.ResourceManager = context.resourceManager; 1197// '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. 1198resourceMgr.getRawFd('test.jpg').then((rawFileDescriptor: resourceManager.RawFileDescriptor) => { 1199 const imageSourceApi: image.ImageSource = image.createImageSource(rawFileDescriptor); 1200}).catch((error: BusinessError) => { 1201 console.error(`Failed to get RawFileDescriptor.code is ${error.code}, message is ${error.message}`); 1202}) 1203``` 1204 1205## image.CreateIncrementalSource<sup>9+</sup> 1206 1207CreateIncrementalSource(buf: ArrayBuffer): ImageSource 1208 1209Creates an ImageSource instance in incremental mode based on buffers. Such an instance does not support reading or writing of EXIF information. 1210 1211The ImageSource instance created in incremental mode supports the following capabilities (applicable to synchronous, callback, and promise modes): 1212 1213- Obtaining image information: Call [getImageInfo](arkts-apis-image-ImageSource.md#getimageinfo) to obtain image information by index, or call [getImageInfo](arkts-apis-image-ImageSource.md#getimageinfo-1) to directly obtain image information. 1214- Obtaining an image property: Call [getImageProperty](arkts-apis-image-ImageSource.md#getimageproperty11) to obtain the value of a property with the specified index in an image. 1215- Obtaining image properties: Call [getImageProperties](arkts-apis-image-ImageSource.md#getimageproperties12) to obtain the values of properties with the given names in an image. 1216- Updating incremental data: Call [updateData](arkts-apis-image-ImageSource.md#updatedata9). 1217- Creating a PixelMap object: Call [createPixelMap](arkts-apis-image-ImageSource.md#createpixelmap7) or [createPixelMap](arkts-apis-image-ImageSource.md#createpixelmap7-2) to create a PixelMap object based on decoding options; call [createPixelMap](arkts-apis-image-ImageSource.md#createpixelmap7-1) to create a PixelMap object based on default parameters. 1218- Releasing an ImageSource instance: Call [release](arkts-apis-image-ImageSource.md#release). 1219 1220**System capability**: SystemCapability.Multimedia.Image.ImageSource 1221 1222**Parameters** 1223 1224| Name | Type | Mandatory| Description | 1225| ------- | ------------| ---- | ----------| 1226| buf | ArrayBuffer | Yes | Incremental data.| 1227 1228**Return value** 1229 1230| Type | Description | 1231| --------------------------- | --------------------------------- | 1232| [ImageSource](arkts-apis-image-ImageSource.md) | ImageSource instance. If the operation fails, undefined is returned.| 1233 1234**Example** 1235 1236<!--code_no_check--> 1237```ts 1238import { common } from '@kit.AbilityKit'; 1239import { BusinessError } from '@kit.BasicServicesKit'; 1240import { resourceManager } from '@kit.LocalizationKit'; 1241import { image } from '@kit.ImageKit'; 1242 1243// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext. 1244let context = this.getUIContext().getHostContext() as common.UIAbilityContext; 1245let imageArray = context.resourceManager.getMediaContentSync($r('app.media.startIcon').id); // Obtain the image resource. 1246// '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. 1247let splitBuff1 = imageArray.slice(0, imageArray.byteLength / 2); // Image slice. 1248let splitBuff2 = imageArray.slice(imageArray.byteLength / 2); 1249const imageSourceIncrementalSApi: image.ImageSource = image.CreateIncrementalSource(new ArrayBuffer(imageArray.byteLength)); 1250imageSourceIncrementalSApi.updateData(splitBuff1, false, 0, splitBuff1.byteLength).then(() => { 1251 imageSourceIncrementalSApi.updateData(splitBuff2, true, 0, splitBuff2.byteLength).then(() => { 1252 let pixelMap = imageSourceIncrementalSApi.createPixelMapSync(); 1253 let imageInfo = pixelMap.getImageInfoSync(); 1254 console.info('Succeeded in creating pixelMap'); 1255 }).catch((error : BusinessError) => { 1256 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`); 1257 }) 1258}).catch((error : BusinessError) => { 1259 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`); 1260}) 1261``` 1262 1263## image.CreateIncrementalSource<sup>9+</sup> 1264 1265CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource 1266 1267Creates an ImageSource instance in incremental mode based on buffers. Such an instance does not support reading or writing of EXIF information. 1268 1269The 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). 1270 1271**System capability**: SystemCapability.Multimedia.Image.ImageSource 1272 1273**Parameters** 1274 1275| Name | Type | Mandatory| Description | 1276| ------- | ------------------------------- | ---- | ------------------------------------ | 1277| buf | ArrayBuffer | Yes | Incremental data. | 1278| options | [SourceOptions](arkts-apis-image-i.md#sourceoptions9) | No | Image properties, including the image pixel density, pixel format, and image size.| 1279 1280**Return value** 1281 1282| Type | Description | 1283| --------------------------- | --------------------------------- | 1284| [ImageSource](arkts-apis-image-ImageSource.md) | ImageSource instance. If the operation fails, undefined is returned.| 1285 1286**Example** 1287 1288<!--code_no_check--> 1289```ts 1290import { common } from '@kit.AbilityKit'; 1291import { BusinessError } from '@kit.BasicServicesKit'; 1292import { resourceManager } from '@kit.LocalizationKit'; 1293import { image } from '@kit.ImageKit'; 1294 1295// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext. 1296let context = this.getUIContext().getHostContext() as common.UIAbilityContext; 1297let imageArray = context.resourceManager.getMediaContentSync($r('app.media.startIcon').id) // Obtain the image resource. 1298// '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. 1299let splitBuff1 = imageArray.slice(0, imageArray.byteLength / 2); // Image slice. 1300let splitBuff2 = imageArray.slice(imageArray.byteLength / 2); 1301let sourceOptions: image.SourceOptions = { sourceDensity: 120}; 1302 1303const imageSourceIncrementalSApi: image.ImageSource = image.CreateIncrementalSource(new ArrayBuffer(imageArray.byteLength), sourceOptions); 1304imageSourceIncrementalSApi.updateData(splitBuff1, false, 0, splitBuff1.byteLength).then(() => { 1305 imageSourceIncrementalSApi.updateData(splitBuff2, true, 0, splitBuff2.byteLength).then(() => { 1306 let pixelMap = imageSourceIncrementalSApi.createPixelMapSync(); 1307 let imageInfo = pixelMap.getImageInfoSync(); 1308 console.info('Succeeded in creating pixelMap'); 1309 }).catch((error : BusinessError) => { 1310 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`); 1311 }) 1312}).catch((error : BusinessError) => { 1313 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`); 1314}) 1315``` 1316 1317## image.getImageSourceSupportedFormats<sup>20+</sup> 1318 1319getImageSourceSupportedFormats(): string[] 1320 1321Obtains the supported decoding formats, represented by MIME types. 1322 1323**System capability**: SystemCapability.Multimedia.Image.ImageSource 1324 1325**Return value** 1326 1327| Type | Description | 1328| -------- | ------------------------------------------ | 1329| string[] | List of supported decoding formats (MIME types).| 1330 1331**Example** 1332 1333```ts 1334import { image } from '@kit.ImageKit'; 1335function GetImageSourceSupportedFormats() { 1336 let formats = image.getImageSourceSupportedFormats(); 1337 console.info('formats:', formats); 1338} 1339``` 1340 1341## image.createImagePacker 1342 1343createImagePacker(): ImagePacker 1344 1345Creates an ImagePacker instance. 1346 1347**Atomic service API**: This API can be used in atomic services since API version 11. 1348 1349**System capability**: SystemCapability.Multimedia.Image.ImagePacker 1350 1351**Return value** 1352 1353| Type | Description | 1354| --------------------------- | --------------------- | 1355| [ImagePacker](arkts-apis-image-ImagePacker.md) | ImagePacker instance created.| 1356 1357**Example** 1358 1359```ts 1360const imagePackerApi: image.ImagePacker = image.createImagePacker(); 1361``` 1362 1363## image.getImagePackerSupportedFormats<sup>20+</sup> 1364 1365getImagePackerSupportedFormats(): string[] 1366 1367Obtains the supported encoding formats, represented by MIME types. 1368 1369**System capability**: SystemCapability.Multimedia.Image.ImagePacker 1370 1371**Return value** 1372 1373| Type | Description | 1374| -------- | ------------------------------------------ | 1375| string[] | List of supported encoding formats (MIME types).| 1376 1377**Example** 1378 1379```ts 1380import { image } from '@kit.ImageKit'; 1381function GetImagePackerSupportedFormats() { 1382 let formats = image.getImagePackerSupportedFormats(); 1383 console.info('formats:', formats); 1384} 1385``` 1386 1387## image.createAuxiliaryPicture<sup>13+</sup> 1388 1389createAuxiliaryPicture(buffer: ArrayBuffer, size: Size, type: AuxiliaryPictureType): AuxiliaryPicture 1390 1391Creates an AuxiliaryPicture instance based on the ArrayBuffer image data, auxiliary picture size, and auxiliary picture type. 1392 1393**System capability**: SystemCapability.Multimedia.Image.Core 1394 1395**Parameters** 1396 1397| Name| Type | Mandatory| Description | 1398| ------ | ----------------------------------------------- | ---- | ---------------------------- | 1399| buffer | ArrayBuffer | Yes | Image data stored in the buffer. | 1400| size | [Size](arkts-apis-image-i.md#size) | Yes | Size of the auxiliary picture, in px. | 1401| type | [AuxiliaryPictureType](arkts-apis-image-e.md#auxiliarypicturetype13) | Yes | Type of the auxiliary picture. | 1402 1403**Return value** 1404 1405| Type | Description | 1406| --------------------------------------- | ------------------------------------------ | 1407| [AuxiliaryPicture](arkts-apis-image-AuxiliaryPicture.md) | AuxiliaryPicture instance.| 1408 1409**Error codes** 1410 1411For details about the error codes, see [Image Error Codes](errorcode-image.md). 1412 1413| ID| Error Message | 1414| -------- | ------------------------------------------------------------ | 1415| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 1416 1417**Example** 1418 1419```ts 1420import { image } from '@kit.ImageKit'; 1421 1422async function CreateAuxiliaryPicture(context: Context) { 1423 let funcName = "CreateAuxiliaryPicture"; 1424 const resourceMgr = context.resourceManager; 1425 const rawFile = await resourceMgr.getRawFileContent("hdr.jpg"); // Support for HDR images is required. 1426 let auxBuffer: ArrayBuffer = rawFile.buffer as ArrayBuffer; 1427 let auxSize: Size = { 1428 height: 180, 1429 width: 240 1430 }; 1431 let auxType: image.AuxiliaryPictureType = image.AuxiliaryPictureType.GAINMAP; 1432 let auxPictureObj: image.AuxiliaryPicture | null = image.createAuxiliaryPicture(auxBuffer, auxSize, auxType); 1433 if(auxPictureObj != null) { 1434 let type: image.AuxiliaryPictureType = auxPictureObj.getType(); 1435 console.info(funcName, 'CreateAuxiliaryPicture succeeded this.Aux_picture.type.' + JSON.stringify(type)); 1436 } else { 1437 console.error(funcName, 'CreateAuxiliaryPicture failed'); 1438 } 1439} 1440``` 1441 1442## image.createImageReceiver<sup>11+</sup> 1443 1444createImageReceiver(size: Size, format: ImageFormat, capacity: number): ImageReceiver 1445 1446Creates an ImageReceiver instance by specifying the image size, format, and capacity. The ImageReceiver acts as the receiver and consumer of images. Its parameter properties do not actually affect the received images. The configuration of image properties should be done on the sending side (the producer), such as when creating a camera preview stream with [createPreviewOutput](../apis-camera-kit/arkts-apis-camera-CameraManager.md#createpreviewoutput). 1447 1448**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 1449 1450**Parameters** 1451 1452| Name | Type | Mandatory| Description | 1453| -------- | ------ | ---- | ---------------------- | 1454| size | [Size](arkts-apis-image-i.md#size) | Yes | Default size of the image. This parameter does not affect the size of the received image. The actual returned size is determined by the producer, for example, the camera. | 1455| format | [ImageFormat](arkts-apis-image-e.md#imageformat9) | Yes | Image format, which is a constant of [ImageFormat](arkts-apis-image-e.md#imageformat9). (Currently, only **ImageFormat:JPEG** is supported. The format actually returned is determined by the producer, for example, camera.) | 1456| capacity | number | Yes | Maximum number of images that can be accessed at the same time.| 1457 1458**Return value** 1459 1460| Type | Description | 1461| -------------------------------- | --------------------------------------- | 1462| [ImageReceiver](arkts-apis-image-ImageReceiver.md) | ImageReceiver instance.| 1463 1464**Error codes** 1465 1466For details about the error codes, see [Image Error Codes](errorcode-image.md). 1467 1468| ID| Error Message| 1469| ------- | --------------------------------------------| 1470| 401| Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; | 1471 1472**Example** 1473 1474```ts 1475let size: image.Size = { 1476 height: 8192, 1477 width: 8 1478} 1479let receiver: image.ImageReceiver = image.createImageReceiver(size, image.ImageFormat.JPEG, 8); 1480``` 1481 1482## image.createImageCreator<sup>11+</sup> 1483 1484createImageCreator(size: Size, format: ImageFormat, capacity: number): ImageCreator 1485 1486Creates an ImageCreator instance by specifying the image size, format, and capacity. 1487 1488**System capability**: SystemCapability.Multimedia.Image.ImageCreator 1489 1490**Parameters** 1491 1492| Name | Type | Mandatory| Description | 1493| -------- | ------ | ---- | ---------------------- | 1494| size | [Size](arkts-apis-image-i.md#size) | Yes | Default size of the image. | 1495| format | [ImageFormat](arkts-apis-image-e.md#imageformat9) | Yes | Image format, for example, YCBCR_422_SP or JPEG. | 1496| capacity | number | Yes | Maximum number of images that can be accessed at the same time.| 1497 1498**Return value** 1499 1500| Type | Description | 1501| ------------------------------ | --------------------------------------- | 1502| [ImageCreator](arkts-apis-image-ImageCreator.md) | ImageCreator instance.| 1503 1504 1505**Error codes** 1506 1507For details about the error codes, see [Image Error Codes](errorcode-image.md). 1508 1509| ID| Error Message| 1510| ------- | --------------------------------------------| 1511| 401| Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; | 1512 1513**Example** 1514 1515```ts 1516let size: image.Size = { 1517 height: 8192, 1518 width: 8 1519} 1520let creator: image.ImageCreator = image.createImageCreator(size, image.ImageFormat.JPEG, 8); 1521``` 1522 1523## image.createImageReceiver<sup>(deprecated)</sup> 1524 1525createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver 1526 1527Creates an ImageReceiver instance by specifying the image width, height, format, and capacity. The ImageReceiver acts as the receiver and consumer of images. Its parameter properties do not actually affect the received images. The configuration of image properties should be done on the sending side (the producer), such as when creating a camera preview stream with [createPreviewOutput](../apis-camera-kit/arkts-apis-camera-CameraManager.md#createpreviewoutput). 1528 1529> **NOTE** 1530> 1531> This API is deprecated since API version 11. You are advised to use [createImageReceiver](#imagecreateimagereceiver11). 1532 1533**System capability**: SystemCapability.Multimedia.Image.ImageReceiver 1534 1535**Parameters** 1536 1537| Name | Type | Mandatory| Description | 1538| -------- | ------ | ---- | ---------------------- | 1539| width | number | Yes | Default image width, in px. This parameter does not affect the width of the received image. The actual width is determined by the producer, for example, the camera. | 1540| height | number | Yes | Default image height, in px. This parameter does not affect the height of the received image. The actual height is determined by the producer, for example, the camera. | 1541| format | number | Yes | Image format, which is a constant of [ImageFormat](arkts-apis-image-e.md#imageformat9). (Currently, only **ImageFormat:JPEG** is supported. The format actually returned is determined by the producer, for example, camera.) | 1542| capacity | number | Yes | Maximum number of images that can be accessed at the same time.| 1543 1544**Return value** 1545 1546| Type | Description | 1547| -------------------------------- | --------------------------------------- | 1548| [ImageReceiver](arkts-apis-image-ImageReceiver.md) | ImageReceiver instance.| 1549 1550**Example** 1551 1552```ts 1553let receiver: image.ImageReceiver = image.createImageReceiver(8192, 8, image.ImageFormat.JPEG, 8); 1554``` 1555 1556## image.createImageCreator<sup>(deprecated)</sup> 1557 1558createImageCreator(width: number, height: number, format: number, capacity: number): ImageCreator 1559 1560Creates an ImageCreator instance by specifying the image width, height, format, and capacity. 1561 1562> **NOTE** 1563> 1564> This API is deprecated since API version 11. You are advised to use [createImageCreator](#imagecreateimagecreator11). 1565 1566**System capability**: SystemCapability.Multimedia.Image.ImageCreator 1567 1568**Parameters** 1569 1570| Name | Type | Mandatory| Description | 1571| -------- | ------ | ---- | ---------------------- | 1572| width | number | Yes | Default image width, in px. | 1573| height | number | Yes | Default image height, in px. | 1574| format | number | Yes | Image format, for example, YCBCR_422_SP or JPEG. | 1575| capacity | number | Yes | Maximum number of images that can be accessed at the same time.| 1576 1577**Return value** 1578 1579| Type | Description | 1580| ------------------------------ | --------------------------------------- | 1581| [ImageCreator](arkts-apis-image-ImageCreator.md) | ImageCreator instance.| 1582 1583**Example** 1584 1585```ts 1586let creator: image.ImageCreator = image.createImageCreator(8192, 8, image.ImageFormat.JPEG, 8); 1587``` 1588 1589## SVG Tags 1590 1591The SVG tags are supported since API version 10. The used version is (SVG) 1.1, and the width and height of the SVG tag must be set. An XML declaration can be added to an SVG file and start with **<?xml**. The following tags are supported: 1592 1593- a 1594- circla 1595- clipPath 1596- defs 1597- ellipse 1598- feBlend 1599- feColorMatrix 1600- feComposite 1601- feDiffuseLighting 1602- feDisplacementMap 1603- feDistantLight 1604- feFlood 1605- feGaussianBlur 1606- feImage 1607- feMorphology 1608- feOffset 1609- fePointLight 1610- feSpecularLighting 1611- feSpotLight 1612- feTurbulence 1613- filter 1614- g 1615- image 1616- line 1617- linearGradient 1618- mask 1619- path 1620- pattern 1621- polygon 1622- polyline 1623- radialGradient 1624- rect 1625- stop 1626- svg 1627- text 1628- textPath 1629- tspan 1630- use 1631