1# Functions 2<!--Kit: Image Kit--> 3<!--Subsystem: Multimedia--> 4<!--Owner: @aulight02--> 5<!--Designer: @liyang_bryan--> 6<!--Tester: @xchaosioda--> 7<!--Adviser: @zengyawen--> 8 9> **说明:** 10> 11> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 12 13## 导入模块 14 15```ts 16import { image } from '@kit.ImageKit'; 17``` 18 19## image.createPicture<sup>13+</sup> 20 21createPicture(mainPixelmap : PixelMap): Picture 22 23通过主图的pixelmap创建一个Picture对象。 24 25**系统能力:** SystemCapability.Multimedia.Image.Core 26 27**参数:** 28 29| 参数名 | 类型 | 必填 | 说明 | 30| ------------ | ------------------- | ---- | ---------------- | 31| mainPixelmap | [PixelMap](arkts-apis-image-PixelMap.md) | 是 | 主图的pixelmap。 | 32 33**返回值:** 34 35| 类型 | 说明 | 36| ------------------ | ----------------- | 37| [Picture](arkts-apis-image-Picture.md) | 返回Picture对象。 | 38 39**错误码:** 40 41以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。 42 43| 错误码ID | 错误信息 | 44| -------- | ------------------------------------------------------------ | 45| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. | 46 47**示例:** 48 49```ts 50async function CreatePicture(context: Context) { 51 const resourceMgr = context.resourceManager; 52 const rawFile = await resourceMgr.getRawFileContent("test.jpg"); 53 let ops: image.SourceOptions = { 54 sourceDensity: 98, 55 } 56 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 57 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 58 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 59 if (pictureObj != null) { 60 console.info('Create picture succeeded'); 61 } else { 62 console.error('Create picture failed'); 63 } 64} 65``` 66 67## image.createPictureFromParcel<sup>13+</sup> 68 69createPictureFromParcel(sequence: rpc.MessageSequence): Picture 70 71从MessageSequence中获取Picture。 72 73**系统能力:** SystemCapability.Multimedia.Image.Core 74 75**参数:** 76 77| 参数名 | 类型 | 必填 | 说明 | 78| -------- | ------------------------------------------------------------------- | ---- | ------------------------------------ | 79| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | 是 | 保存有Picture信息的MessageSequence。 | 80 81**返回值:** 82 83| 类型 | 说明 | 84| ------------------ | ----------------- | 85| [Picture](arkts-apis-image-Picture.md) | 返回Picture对象。 | 86 87**错误码:** 88 89以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Image错误码](errorcode-image.md)。 90 91| 错误码ID | 错误信息 | 92| -------- | ------------------------------------------------------------ | 93| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. | 94| 62980097 | IPC error. Possible cause: 1.IPC communication failed. 2. Image upload exception. 3. Decode process exception. 4. Insufficient memory. | 95 96**示例:** 97 98```ts 99import { rpc } from '@kit.IPCKit'; 100import { BusinessError } from '@kit.BasicServicesKit'; 101 102class MySequence implements rpc.Parcelable { 103 picture: image.Picture | null = null; 104 constructor(conPicture: image.Picture) { 105 this.picture = conPicture; 106 } 107 marshalling(messageSequence: rpc.MessageSequence) { 108 if(this.picture != null) { 109 this.picture.marshalling(messageSequence); 110 console.info('Marshalling success !'); 111 return true; 112 } else { 113 console.error('Marshalling failed !'); 114 return false; 115 } 116 } 117 unmarshalling(messageSequence : rpc.MessageSequence) { 118 this.picture = image.createPictureFromParcel(messageSequence); 119 this.picture.getMainPixelmap().getImageInfo().then((imageInfo : image.ImageInfo) => { 120 console.info(`Unmarshalling to get mainPixelmap information height:${imageInfo.size.height} width:${imageInfo.size.width}`); 121 }).catch((error: BusinessError) => { 122 console.error(`Unmarshalling failed error.code: ${error.code} ,error.message: ${error.message}`); 123 }); 124 return true; 125 } 126} 127 128async function Marshalling_UnMarshalling(context: Context) { 129 const resourceMgr = context.resourceManager; 130 const rawFile = await resourceMgr.getRawFileContent("test.jpg"); 131 let ops: image.SourceOptions = { 132 sourceDensity: 98, 133 } 134 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 135 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 136 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 137 if (pictureObj != null) { 138 let parcelable: MySequence = new MySequence(pictureObj); 139 let data: rpc.MessageSequence = rpc.MessageSequence.create(); 140 // 序列化。 141 data.writeParcelable(parcelable); 142 let ret: MySequence = new MySequence(pictureObj); 143 // 反序列化。 144 data.readParcelable(ret); 145 } else { 146 console.error('PictureObj is null'); 147 } 148} 149``` 150 151## image.createPixelMap<sup>8+</sup> 152 153createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<PixelMap> 154 155通过属性创建PixelMap,默认采用BGRA_8888格式处理数据,通过Promise返回结果。 156 157**系统能力:** SystemCapability.Multimedia.Image.Core 158 159**参数:** 160 161| 参数名 | 类型 | 必填 | 说明 | 162| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 163| colors | ArrayBuffer | 是 | 图像像素数据的缓冲区,用于初始化PixelMap的像素。初始化前,缓冲区中的像素格式需要由[InitializationOptions](arkts-apis-image-i.md#initializationoptions8).srcPixelFormat指定。<br>**说明:** 图像像素数据的缓冲区长度:length = width * height * 单位像素字节数。 | 164| options | [InitializationOptions](arkts-apis-image-i.md#initializationoptions8) | 是 | 创建像素的属性,包括透明度,尺寸,缩略值,像素格式和是否可编辑。 | 165 166**返回值:** 167 168| 类型 | 说明 | 169| -------------------------------- | ----------------------------------------------------------------------- | 170| Promise\<[PixelMap](arkts-apis-image-PixelMap.md)> | Promise对象,返回PixelMap。<br>当创建的pixelMap大小超过原图大小时,返回原图pixelMap大小。| 171 172**示例:** 173 174```ts 175import { BusinessError } from '@kit.BasicServicesKit'; 176 177async function CreatePixelMap() { 178 const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4。 179 let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 180 image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => { 181 console.info('Succeeded in creating pixelmap.'); 182 }).catch((error: BusinessError) => { 183 console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`); 184 }) 185} 186``` 187 188## image.createPixelMap<sup>8+</sup> 189 190createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: AsyncCallback\<PixelMap>): void 191 192通过属性创建PixelMap,默认采用BGRA_8888格式处理数据,通过callback返回结果。 193 194**系统能力:** SystemCapability.Multimedia.Image.Core 195 196**参数:** 197 198| 参数名 | 类型 | 必填 | 说明 | 199| -------- | ------------------------------------------------ | ---- | -------------------------- | 200| colors | ArrayBuffer | 是 | 图像像素数据的缓冲区,用于初始化PixelMap的像素。初始化前,缓冲区中的像素格式需要由[InitializationOptions](arkts-apis-image-i.md#initializationoptions8).srcPixelFormat指定。<br>**说明:** 图像像素数据的缓冲区长度:length = width * height * 单位像素字节数。 | 201| options | [InitializationOptions](arkts-apis-image-i.md#initializationoptions8) | 是 | 创建像素的属性,包括透明度、尺寸、缩略值、像素格式和是否可编辑。 | 202| callback | AsyncCallback\<[PixelMap](arkts-apis-image-PixelMap.md)> | 是 | 回调函数,当创建PixelMap成功,err为undefined,data为获取到的PixelMap对象;否则为错误对象。 | 203 204**示例:** 205 206```ts 207import { BusinessError } from '@kit.BasicServicesKit'; 208 209async function CreatePixelMap() { 210 const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4。 211 let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 212 image.createPixelMap(color, opts, (error: BusinessError, pixelMap: image.PixelMap) => { 213 if(error) { 214 console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`); 215 return; 216 } else { 217 console.info('Succeeded in creating pixelmap.'); 218 } 219 }) 220} 221``` 222 223## image.createPixelMapUsingAllocator<sup>20+</sup> 224 225createPixelMapUsingAllocator(colors: ArrayBuffer, param: InitializationOptions, allocatorType?: AllocatorType): Promise\<PixelMap> 226 227通过属性创建以及指定内存类型创建PixelMap,默认采用BGRA_8888格式处理数据。使用Promise异步回调。 228 229**系统能力:** SystemCapability.Multimedia.Image.Core 230 231**参数:** 232 233| 参数名 | 类型 | 必填 | 说明 | 234| -------- | ------------------------------------------------ | ---- | -------------------------- | 235| colors | ArrayBuffer | 是 | 图像像素数据的缓冲区,用于初始化PixelMap的像素。初始化前,缓冲区中的像素格式需要由[InitializationOptions](arkts-apis-image-i.md#initializationoptions8).srcPixelFormat指定。<br>**说明:** 图像像素数据的缓冲区长度:length = width * height * 单位像素字节数。 | 236| param | [InitializationOptions](arkts-apis-image-i.md#initializationoptions8) | 是 | 创建像素的属性,包括透明度、尺寸、缩略值、像素格式和是否可编辑。 | 237| allocatorType | [AllocatorType](arkts-apis-image-e.md#allocatortype15) | 否 | 指定创建pixelmap的内存类型,默认内存类型是AllocatorType.AUTO。<br> 1. image.AllocatorType.AUTO:不支持该内存类型的格式有UNKNOWN、YCBCR_P010、YCRCB_P010和ASTC_4x4。RGBA_1010102默认申请DMA内存。其他格式(RGB_565、RGBA_8888、BGRA_8888和RGBAF_16)尺寸大于512*512默认申请DMA内存,否则申请共享内存。<br>2. image.AllocatorType.DMA:RGBA_1010102、RGB_565、RGBA_8888、BGRA_8888和RGBAF_16支持DMA内存类型,其余格式不支持。<br>3. image.AllocatorType.SHARED:UNKNOWN、RGBA_1010102、YCBCR_P010、YCRCB_P010和ASTC_4x4不支持共享内存,其余格式支持。| 238 239**返回值:** 240 241| 类型 | 说明 | 242| -------------------------------- | ----------------------------------------------------------------------- | 243| Promise\<[PixelMap](arkts-apis-image-PixelMap.md)> | Promise对象,返回PixelMap。| 244 245**错误码:** 246 247以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 248 249| 错误码ID | 错误信息 | 250| ------- | --------------------------------------------| 251| 7600201 | Unsupported operation. | 252| 7600301 | Memory alloc failed. | 253| 7600302 | Memory copy failed. | 254 255**示例:** 256 257```ts 258import { BusinessError } from '@kit.BasicServicesKit'; 259 260async function CreatePixelMapUseAllocator() { 261 const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4。 262 let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 263 image.createPixelMapUsingAllocator(color, opts, image.AllocatorType.AUTO).then((pixelMap: image.PixelMap) => { 264 console.info('Succeeded in creating pixelmap.'); 265 }).catch((error: BusinessError) => { 266 console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`); 267 }) 268} 269``` 270 271## image.createPixelMapFromParcel<sup>11+</sup> 272 273createPixelMapFromParcel(sequence: rpc.MessageSequence): PixelMap 274 275从MessageSequence中获取PixelMap。 276 277**系统能力:** SystemCapability.Multimedia.Image.Core 278 279**参数:** 280 281| 参数名 | 类型 | 必填 | 说明 | 282| ---------------------- | ----------------------------------------------------- | ---- | ---------------------------------------- | 283| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | 是 | 保存有PixelMap信息的MessageSequence。 | 284 285**返回值:** 286 287| 类型 | 说明 | 288| -------------------------------- | --------------------- | 289| [PixelMap](arkts-apis-image-PixelMap.md) | 成功同步返回PixelMap对象,失败抛出异常。 | 290 291**错误码:** 292 293以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 294 295| 错误码ID | 错误信息 | 296| ------- | --------------------------------------------| 297| 62980096 | The operation failed. Possible cause: 1.Image upload exception. 2. Decoding process exception. 3. Insufficient memory.| 298| 62980097 | IPC error. Possible cause: 1.IPC communication failed. 2. Image upload exception. 3. Decode process exception. 4. Insufficient memory.| 299| 62980115 | Invalid input parameter.| 300| 62980105 | Failed to get the data.| 301| 62980177 | Abnormal API environment.| 302| 62980178 | Failed to create the PixelMap.| 303| 62980179 | Abnormal buffer size.| 304| 62980180 | FD mapping failed. Possible cause: 1. Size and address does not match. 2. Memory map in memalloc failed.| 305| 62980246 | Failed to read the PixelMap.| 306 307**示例:** 308 309```ts 310import { rpc } from '@kit.IPCKit'; 311import { BusinessError } from '@kit.BasicServicesKit'; 312 313class MySequence implements rpc.Parcelable { 314 pixel_map: image.PixelMap; 315 constructor(conPixelmap: image.PixelMap) { 316 this.pixel_map = conPixelmap; 317 } 318 marshalling(messageSequence: rpc.MessageSequence) { 319 this.pixel_map.marshalling(messageSequence); 320 return true; 321 } 322 unmarshalling(messageSequence: rpc.MessageSequence) { 323 try { 324 this.pixel_map = image.createPixelMapFromParcel(messageSequence); 325 } catch(e) { 326 let error = e as BusinessError; 327 console.error(`createPixelMapFromParcel error. code is ${error.code}, message is ${error.message}`); 328 return false; 329 } 330 return true; 331 } 332} 333async function CreatePixelMapFromParcel() { 334 const color: ArrayBuffer = new ArrayBuffer(96); 335 let bufferArr: Uint8Array = new Uint8Array(color); 336 for (let i = 0; i < bufferArr.length; i++) { 337 bufferArr[i] = 0x80; 338 } 339 let opts: image.InitializationOptions = { 340 editable: true, 341 pixelFormat: image.PixelMapFormat.BGRA_8888, 342 size: { height: 4, width: 6 }, 343 alphaType: image.AlphaType.UNPREMUL 344 } 345 let pixelMap: image.PixelMap | undefined = undefined; 346 await image.createPixelMap(color, opts).then((srcPixelMap: image.PixelMap) => { 347 pixelMap = srcPixelMap; 348 }) 349 if (pixelMap != undefined) { 350 // 序列化。 351 let parcelable: MySequence = new MySequence(pixelMap); 352 let data: rpc.MessageSequence = rpc.MessageSequence.create(); 353 data.writeParcelable(parcelable); 354 355 // 反序列化rpc获取到data。 356 let ret: MySequence = new MySequence(pixelMap); 357 data.readParcelable(ret); 358 359 // 获取到pixelmap。 360 let unmarshPixelmap = ret.pixel_map; 361 } 362} 363``` 364 365## image.createPixelMapFromSurface<sup>11+</sup> 366 367createPixelMapFromSurface(surfaceId: string, region: Region): Promise\<PixelMap> 368 369根据Surface ID和区域信息创建一个PixelMap对象。该区域的大小由[Region](arkts-apis-image-i.md#region8).size指定。使用Promise形式返回。 370 371> **说明:** 372> 当设备为折叠屏,且折叠状态切换时,可能因Surface自带旋转角度导致接口创建失败。需将宽高适配旋转角度。推荐使用[image.createPixelMapFromSurface](#imagecreatepixelmapfromsurface15)。 373 374**系统能力:** SystemCapability.Multimedia.Image.Core 375 376**参数:** 377 378| 参数名 | 类型 | 必填 | 说明 | 379| ---------------------- | ------------- | ---- | ---------------------------------------- | 380| surfaceId | string | 是 | 对应Surface的ID,可通过预览组件获取,如[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)组件。 | 381| region | [Region](arkts-apis-image-i.md#region8) | 是 | 截取的画面区域。仅支持从画面左上角开始截取部分或整个画面,即Region中的x和y必须为0,Region.size中width和height的取值范围分别为[1, 预览流宽度]和[1, 预览流高度]。如需截取任意区域,可先使用[image.createPixelMapFromSurface](#imagecreatepixelmapfromsurface15)获取整个画面,再使用[crop](arkts-apis-image-PixelMap.md#crop9)截取所需区域。 | 382 383**返回值:** 384 385| 类型 | 说明 | 386| -------------------------------- | --------------------- | 387| Promise\<[PixelMap](arkts-apis-image-PixelMap.md)> | Promise对象,返回PixelMap。 | 388 389**错误码:** 390 391以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 392 393| 错误码ID | 错误信息 | 394| ------- | --------------------------------------------| 395| 62980115 | If the image parameter invalid.| 396| 62980105 | Failed to get the data.| 397| 62980178 | Failed to create the PixelMap.| 398 399**示例:** 400 401```ts 402import { BusinessError } from '@kit.BasicServicesKit'; 403 404async function CreatePixelMapFromSurface(surfaceId: string) { 405 let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 406 image.createPixelMapFromSurface(surfaceId, region).then(() => { 407 console.info('Succeeded in creating pixelmap from Surface'); 408 }).catch((error: BusinessError) => { 409 console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`); 410 }); 411} 412``` 413 414## image.createPixelMapFromSurfaceSync<sup>12+</sup> 415 416createPixelMapFromSurfaceSync(surfaceId: string, region: Region): PixelMap 417 418以同步方式,根据Surface ID和区域信息创建一个PixelMap对象。该区域的大小由[Region](arkts-apis-image-i.md#region8).size指定。 419 420> **说明:** 421> 当设备为折叠屏,且折叠状态切换时,可能因Surface自带旋转角度导致接口创建失败。需将宽高适配旋转角度。推荐使用[image.createPixelMapFromSurfaceSync](#imagecreatepixelmapfromsurfacesync15)。 422 423**系统能力:** SystemCapability.Multimedia.Image.Core 424 425**参数:** 426 427| 参数名 | 类型 | 必填 | 说明 | 428| ---------------------- | ------------- | ---- | ---------------------------------------- | 429| surfaceId | string | 是 | 对应Surface的ID,可通过预览组件获取,如[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)组件。 | 430| region | [Region](arkts-apis-image-i.md#region8) | 是 | 截取的画面区域。仅支持从画面左上角开始截取部分或整个画面,即Region中的x和y必须为0,Region.size中width和height的取值范围分别为[1, 预览流宽度]和[1, 预览流高度]。如需截取任意区域,可先使用[image.createPixelMapFromSurfaceSync](#imagecreatepixelmapfromsurfacesync15)获取整个画面,再使用[cropSync](arkts-apis-image-PixelMap.md#cropsync12)截取所需区域。 | 431 432**返回值:** 433 434| 类型 | 说明 | 435| -------------------------------- | --------------------- | 436| [PixelMap](arkts-apis-image-PixelMap.md) | 成功同步返回PixelMap对象,失败抛出异常。 | 437 438**错误码:** 439 440以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Image错误码](errorcode-image.md)。 441 442| 错误码ID | 错误信息 | 443| ------- | --------------------------------------------| 444| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.| 445| 62980105 | Failed to get the data.| 446| 62980178 | Failed to create the PixelMap.| 447 448**示例:** 449 450```ts 451async function Demo(surfaceId: string) { 452 let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 453 let pixelMap: image.PixelMap = image.createPixelMapFromSurfaceSync(surfaceId, region); 454 return pixelMap; 455} 456``` 457 458## image.createPixelMapFromSurface<sup>15+</sup> 459 460createPixelMapFromSurface(surfaceId: string): Promise\<PixelMap> 461 462从Surface ID创建一个PixelMap对象。使用Promise异步回调,返回PixelMap。 463 464**系统能力:** SystemCapability.Multimedia.Image.Core 465 466**参数:** 467 468| 参数名 | 类型 | 必填 | 说明 | 469| ---------------------- | ------------- | ---- | ---------------------------------------- | 470| surfaceId | string | 是 | 对应Surface的ID,可通过预览组件获取,如[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)组件。 | 471 472**返回值:** 473 474| 类型 | 说明 | 475| -------------------------------- | --------------------- | 476| Promise\<[PixelMap](arkts-apis-image-PixelMap.md)> | Promise对象,返回PixelMap。 | 477 478**错误码:** 479 480以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Image错误码](errorcode-image.md)。 481 482| 错误码ID | 错误信息 | 483| ------- | --------------------------------------------| 484| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 485| 62980105 | Failed to get the data| 486| 62980178 | Failed to create the PixelMap| 487 488**示例:** 489 490```ts 491import { BusinessError } from '@kit.BasicServicesKit'; 492 493async function CreatePixelMapFromSurface(surfaceId: string) { 494 image.createPixelMapFromSurface(surfaceId).then(() => { 495 console.info('Succeeded in creating pixelmap from Surface'); 496 }).catch((error: BusinessError) => { 497 console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`); 498 }); 499} 500``` 501 502## image.createPixelMapFromSurfaceSync<sup>15+</sup> 503 504createPixelMapFromSurfaceSync(surfaceId: string): PixelMap 505 506从Surface ID创建一个PixelMap对象,同步返回PixelMap结果。 507 508**系统能力:** SystemCapability.Multimedia.Image.Core 509 510**参数:** 511 512| 参数名 | 类型 | 必填 | 说明 | 513| ---------------------- | ------------- | ---- | ---------------------------------------- | 514| surfaceId | string | 是 | 对应Surface的ID,可通过预览组件获取,如[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)组件。 | 515 516**返回值:** 517 518| 类型 | 说明 | 519| -------------------------------- | --------------------- | 520| [PixelMap](arkts-apis-image-PixelMap.md) | 成功同步返回PixelMap对象,失败抛出异常。 | 521 522**错误码:** 523 524以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Image错误码](errorcode-image.md)。 525 526| 错误码ID | 错误信息 | 527| ------- | --------------------------------------------| 528| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 529| 62980105 | Failed to get the data| 530| 62980178 | Failed to create the PixelMap| 531 532**示例:** 533 534```ts 535async function CreatePixelMapFromSurfaceSync(surfaceId: string) { 536 let pixelMap : image.PixelMap = image.createPixelMapFromSurfaceSync(surfaceId); 537 return pixelMap; 538} 539``` 540 541## image.createPixelMapSync<sup>12+</sup> 542 543createPixelMapSync(colors: ArrayBuffer, options: InitializationOptions): PixelMap 544 545通过属性创建PixelMap,默认采用BGRA_8888格式处理数据,同步返回结果。 546 547**系统能力:** SystemCapability.Multimedia.Image.Core 548 549**参数:** 550 551| 参数名 | 类型 | 必填 | 说明 | 552| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 553| colors | ArrayBuffer | 是 | 图像像素数据的缓冲区,用于初始化PixelMap的像素。初始化前,缓冲区中的像素格式需要由[InitializationOptions](arkts-apis-image-i.md#initializationoptions8).srcPixelFormat指定。<br>**说明:** 图像像素数据的缓冲区长度:length = width * height * 单位像素字节数。 | 554| options | [InitializationOptions](arkts-apis-image-i.md#initializationoptions8) | 是 | 创建像素的属性,包括透明度,尺寸,缩略值,像素格式和是否可编辑。 | 555 556**返回值:** 557 558| 类型 | 说明 | 559| -------------------------------- | --------------------- | 560| [PixelMap](arkts-apis-image-PixelMap.md) | 成功同步返回PixelMap对象,失败抛出异常。 | 561 562**错误码:** 563 564以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。 565 566| 错误码ID | 错误信息 | 567| ------- | --------------------------------------------| 568| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 569 570**示例:** 571 572```ts 573function CreatePixelMapSync() { 574 const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4。 575 let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 576 let pixelMap : image.PixelMap = image.createPixelMapSync(color, opts); 577 return pixelMap; 578} 579``` 580 581## image.createPixelMapSync<sup>12+</sup> 582 583createPixelMapSync(options: InitializationOptions): PixelMap 584 585通过属性创建PixelMap,同步返回PixelMap结果。 586 587**系统能力:** SystemCapability.Multimedia.Image.Core 588 589**参数:** 590 591| 参数名 | 类型 | 必填 | 说明 | 592| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 593| options | [InitializationOptions](arkts-apis-image-i.md#initializationoptions8) | 是 | 创建像素的属性,包括透明度,尺寸,缩略值,像素格式和是否可编辑。 | 594 595**返回值:** 596| 类型 | 说明 | 597| -------------------------------- | --------------------- | 598| [PixelMap](arkts-apis-image-PixelMap.md) | 成功同步返回PixelMap对象,失败抛出异常。 | 599 600**错误码:** 601 602以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。 603 604| 错误码ID | 错误信息 | 605| ------- | --------------------------------------------| 606| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 607 608**示例:** 609 610```ts 611function CreatePixelMapSync() { 612 let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 613 let pixelMap : image.PixelMap = image.createPixelMapSync(opts); 614 return pixelMap; 615} 616``` 617 618## image.createPixelMapUsingAllocatorSync<sup>20+</sup> 619 620createPixelMapUsingAllocatorSync(colors: ArrayBuffer, param: InitializationOptions, allocatorType?: AllocatorType): PixelMap 621 622通过指定属性以及内存类型创建PixelMap,默认采用BGRA_8888格式处理数据,同步返回结果。 623 624**系统能力:** SystemCapability.Multimedia.Image.Core 625 626**参数:** 627 628| 参数名 | 类型 | 必填 | 说明 | 629| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 630| colors | ArrayBuffer | 是 | 图像像素数据的缓冲区,用于初始化PixelMap的像素。初始化前,缓冲区中的像素格式需要由[InitializationOptions](arkts-apis-image-i.md#initializationoptions8).srcPixelFormat指定。<br>**说明:** 图像像素数据的缓冲区长度:length = width * height * 单位像素字节数。 | 631| param | [InitializationOptions](arkts-apis-image-i.md#initializationoptions8) | 是 | 创建像素的属性,包括透明度、尺寸、缩略值、像素格式和是否可编辑。 | 632| allocatorType | [AllocatorType](arkts-apis-image-e.md#allocatortype15) | 否 | 指定创建pixelmap的内存类型,默认内存类型是AllocatorType.AUTO。<br> 1. image.AllocatorType.AUTO:不支持该内存类型的格式有UNKNOWN、YCBCR_P010、YCRCB_P010和ASTC_4x4。RGBA_1010102默认申请DMA内存。其他格式(RGB_565、RGBA_8888、BGRA_8888和RGBAF_16)尺寸大于512*512默认申请DMA内存,否则申请共享内存。<br>2. image.AllocatorType.DMA:RGBA_1010102、RGB_565、RGBA_8888、BGRA_8888和RGBAF_16支持DMA内存类型,其余格式不支持。<br>3. image.AllocatorType.SHARED:UNKNOWN、RGBA_1010102、YCBCR_P010、YCRCB_P010和ASTC_4x4不支持共享内存,其余格式支持。| 633 634**返回值:** 635 636| 类型 | 说明 | 637| -------------------------------- | --------------------- | 638| [PixelMap](arkts-apis-image-PixelMap.md) | 成功同步返回PixelMap对象,失败抛出异常。 | 639 640**错误码:** 641 642以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 643 644| 错误码ID | 错误信息 | 645| ------- | --------------------------------------------| 646| 7600201 | Unsupported operation. | 647| 7600301 | Memory alloc failed. | 648| 7600302 | Memory copy failed. | 649 650**示例:** 651 652```ts 653function CreatePixelMapSync() { 654 const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4。 655 let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 656 let pixelMap : image.PixelMap = image.createPixelMapUsingAllocatorSync(color, opts, image.AllocatorType.AUTO); 657 return pixelMap; 658} 659``` 660 661## image.createPixelMapUsingAllocatorSync<sup>20+</sup> 662 663createPixelMapUsingAllocatorSync(param: InitializationOptions, allocatorType?: AllocatorType): PixelMap 664 665通过属性创建PixelMap,同步返回PixelMap结果。 666 667**系统能力:** SystemCapability.Multimedia.Image.Core 668 669**参数:** 670 671| 参数名 | 类型 | 必填 | 说明 | 672| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 673| param | [InitializationOptions](arkts-apis-image-i.md#initializationoptions8) | 是 | 创建像素的属性,包括透明度、尺寸、缩略值、像素格式和是否可编辑。 | 674| allocatorType | [AllocatorType](arkts-apis-image-e.md#allocatortype15) | 否 | 指定创建pixelmap的内存类型,默认内存类型是AllocatorType.AUTO。<br> 1. image.AllocatorType.AUTO:不支持该内存类型的格式有UNKNOWN和ASTC_4x4。RGBA_1010102、YCBCR_P010、YCRCB_P010格式默认申请DMA内存。其他格式(RGB_565, RGBA_8888, BGRA_8888, RGBAF_16)尺寸大于512*512默认申请DMA内存,否则申请共享内存。<br>2. image.AllocatorType.DMA:RGB_565、RGBA_8888、BGRA_8888、RGBAF_16、RGBA_1010102、YCBCR_P010和YCRCB_P010支持DMA内存类型,其余格式不支持。<br>3. image.AllocatorType.SHARED:UNKNOWN、RGBA_1010102、YCBCR_P010、YCRCB_P010和ASTC_4x4不支持共享内存,其余格式支持。| 675 676**返回值:** 677 678| 类型 | 说明 | 679| -------------------------------- | --------------------- | 680| [PixelMap](arkts-apis-image-PixelMap.md) | 成功同步返回PixelMap对象,失败抛出异常。 | 681 682**错误码:** 683 684以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 685 686| 错误码ID | 错误信息 | 687| ------- | --------------------------------------------| 688| 7600201 | Unsupported operation.| 689| 7600301 | Memory alloc failed. | 690 691**示例:** 692 693```ts 694function CreatePixelMapSync() { 695 let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 696 let pixelMap : image.PixelMap = image.createPixelMapUsingAllocatorSync(opts, image.AllocatorType.AUTO); 697 return pixelMap; 698} 699``` 700 701## image.createPremultipliedPixelMap<sup>12+</sup> 702 703createPremultipliedPixelMap(src: PixelMap, dst: PixelMap, callback: AsyncCallback\<void>): void 704 705将PixelMap的透明通道非预乘模式转变为预乘模式,转换后的数据存入目标PixelMap,通过回调函数返回结果。 706 707**系统能力:** SystemCapability.Multimedia.Image.Core 708 709**参数:** 710 711| 参数名 | 类型 | 必填 | 说明 | 712| -------- | ------------------------------------------------ | ---- | -------------------------- | 713| src | [PixelMap](arkts-apis-image-PixelMap.md) | 是 | 源PixelMap对象。 | 714| dst | [PixelMap](arkts-apis-image-PixelMap.md) | 是 | 目标PixelMap对象。 | 715|callback | AsyncCallback\<void> | 是 | 回调函数,当创建PixelMap成功,err为undefined,否则为错误对象。 | 716 717**错误码:** 718 719以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Image错误码](errorcode-image.md)。 720 721| 错误码ID | 错误信息 | 722| ------- | --------------------------------------------| 723| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 724| 62980103 | The image data is not supported | 725| 62980246 | Failed to read the pixelMap | 726| 62980248 | Pixelmap not allow modify | 727 728**示例:** 729 730```ts 731import { BusinessError } from '@kit.BasicServicesKit'; 732 733async function CreatePremultipliedPixelMap() { 734 const color: ArrayBuffer = new ArrayBuffer(16); // 16为需要创建的像素buffer大小,取值为:height * width *4。 735 let bufferArr = new Uint8Array(color); 736 for (let i = 0; i < bufferArr.length; i += 4) { 737 bufferArr[i] = 255; 738 bufferArr[i+1] = 255; 739 bufferArr[i+2] = 122; 740 bufferArr[i+3] = 122; 741 } 742 let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.UNPREMUL} 743 let srcPixelmap = image.createPixelMapSync(color, optsForUnpre); 744 let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.PREMUL} 745 let dstPixelMap = image.createPixelMapSync(optsForPre); 746 image.createPremultipliedPixelMap(srcPixelmap, dstPixelMap, (error: BusinessError) => { 747 if(error) { 748 console.error(`Failed to convert pixelmap, error code is ${error}`); 749 return; 750 } else { 751 console.info('Succeeded in converting pixelmap.'); 752 } 753 }) 754} 755``` 756 757## image.createPremultipliedPixelMap<sup>12+</sup> 758 759createPremultipliedPixelMap(src: PixelMap, dst: PixelMap): Promise\<void> 760 761将PixelMap数据按照透明度非预乘格式转为预乘格式,转换后的数据存入另一个PixelMap,通过Promise返回结果。 762 763**系统能力:** SystemCapability.Multimedia.Image.Core 764 765**参数:** 766 767| 参数名 | 类型 | 必填 | 说明 | 768| -------- | ------------------------------------------------ | ---- | -------------------------- | 769| src | [PixelMap](arkts-apis-image-PixelMap.md) | 是 | 源PixelMap对象。 | 770| dst | [PixelMap](arkts-apis-image-PixelMap.md) | 是 | 目标PixelMap对象。 | 771 772**返回值:** 773 774| 类型 | 说明 | 775| -------------------------------- | ----------------------------------------------------------------------- | 776| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 777 778**错误码:** 779 780以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Image错误码](errorcode-image.md)。 781 782| 错误码ID | 错误信息 | 783| ------- | --------------------------------------------| 784| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 785| 62980103 | The image data is not supported | 786| 62980246 | Failed to read the pixelMap | 787| 62980248 | Pixelmap not allow modify | 788 789**示例:** 790 791```ts 792import { BusinessError } from '@kit.BasicServicesKit'; 793 794async function CreatePremultipliedPixelMap() { 795 const color: ArrayBuffer = new ArrayBuffer(16); // 16为需要创建的像素buffer大小,取值为:height * width *4。 796 let bufferArr = new Uint8Array(color); 797 for (let i = 0; i < bufferArr.length; i += 4) { 798 bufferArr[i] = 255; 799 bufferArr[i+1] = 255; 800 bufferArr[i+2] = 122; 801 bufferArr[i+3] = 122; 802 } 803 let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.UNPREMUL} 804 let srcPixelmap = image.createPixelMapSync(color, optsForUnpre); 805 let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.PREMUL} 806 let dstPixelMap = image.createPixelMapSync(optsForPre); 807 image.createPremultipliedPixelMap(srcPixelmap, dstPixelMap).then(() => { 808 console.info('Succeeded in converting pixelmap.'); 809 }).catch((error: BusinessError) => { 810 console.error(`Failed to convert pixelmap, error code is ${error}`); 811 }) 812} 813``` 814 815## image.createUnpremultipliedPixelMap<sup>12+</sup> 816 817createUnpremultipliedPixelMap(src: PixelMap, dst: PixelMap, callback: AsyncCallback\<void>): void 818 819将PixelMap的透明通道预乘模式转变为非预乘模式,转换后的数据存入目标PixelMap,通过回调函数返回结果。 820 821**系统能力:** SystemCapability.Multimedia.Image.Core 822 823**参数:** 824 825| 参数名 | 类型 | 必填 | 说明 | 826| -------- | ------------------------------------------------ | ---- | -------------------------- | 827| src | [PixelMap](arkts-apis-image-PixelMap.md) | 是 | 源PixelMap对象。 | 828| dst | [PixelMap](arkts-apis-image-PixelMap.md) | 是 | 目标PixelMap对象。| 829|callback | AsyncCallback\<void> | 是 | 回调函数,当创建PixelMap成功,err为undefined,否则为错误对象。| 830 831**错误码:** 832 833以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Image错误码](errorcode-image.md)。 834 835| 错误码ID | 错误信息 | 836| ------- | --------------------------------------------| 837| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 838| 62980103 | The image data is not supported | 839| 62980246 | Failed to read the pixelMap | 840| 62980248 | Pixelmap not allow modify | 841 842**示例:** 843 844```ts 845import { BusinessError } from '@kit.BasicServicesKit'; 846 847async function CreateUnpremultipliedPixelMap() { 848 const color: ArrayBuffer = new ArrayBuffer(16); // 16为需要创建的像素buffer大小,取值为:height * width *4。 849 let bufferArr = new Uint8Array(color); 850 for (let i = 0; i < bufferArr.length; i += 4) { 851 bufferArr[i] = 255; 852 bufferArr[i+1] = 255; 853 bufferArr[i+2] = 122; 854 bufferArr[i+3] = 122; 855 } 856 let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.PREMUL} 857 let srcPixelmap = image.createPixelMapSync(color, optsForPre); 858 let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.UNPREMUL} 859 let dstPixelMap = image.createPixelMapSync(optsForUnpre); 860 image.createUnpremultipliedPixelMap(srcPixelmap, dstPixelMap, (error: BusinessError) => { 861 if(error) { 862 console.error(`Failed to convert pixelmap, error code is ${error}`); 863 return; 864 } else { 865 console.info('Succeeded in converting pixelmap.'); 866 } 867 }) 868} 869``` 870 871## image.createUnpremultipliedPixelMap<sup>12+</sup> 872 873createUnpremultipliedPixelMap(src: PixelMap, dst: PixelMap): Promise\<void> 874 875将PixelMap的透明通道预乘模式转变为非预乘模式,转换后的数据存入目标PixelMap,通过Promise返回结果。 876 877**系统能力:** SystemCapability.Multimedia.Image.Core 878 879**参数:** 880 881| 参数名 | 类型 | 必填 | 说明 | 882| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 883| src | [PixelMap](arkts-apis-image-PixelMap.md) | 是 | 源PixelMap对象。 | 884| dst | [PixelMap](arkts-apis-image-PixelMap.md) | 是 | 目标PixelMap对象。 | 885 886**返回值:** 887 888| 类型 | 说明 | 889| -------------------------------- | ----------------------------------------------------------------------- | 890| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 891 892**错误码:** 893 894以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Image错误码](errorcode-image.md)。 895 896| 错误码ID | 错误信息 | 897| ------- | --------------------------------------------| 898| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.| 899| 62980103 | The image data is not supported. | 900| 62980246 | Failed to read the pixelMap. | 901| 62980248 | Pixelmap not allow modify. | 902 903**示例:** 904 905```ts 906import { BusinessError } from '@kit.BasicServicesKit'; 907 908async function CreateUnpremultipliedPixelMap() { 909 const color: ArrayBuffer = new ArrayBuffer(16); // 16为需要创建的像素buffer大小,取值为:height * width *4。 910 let bufferArr = new Uint8Array(color); 911 for (let i = 0; i < bufferArr.length; i += 4) { 912 bufferArr[i] = 255; 913 bufferArr[i+1] = 255; 914 bufferArr[i+2] = 122; 915 bufferArr[i+3] = 122; 916 } 917 let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.PREMUL} 918 let srcPixelmap = image.createPixelMapSync(color, optsForPre); 919 let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.UNPREMUL} 920 let dstPixelMap = image.createPixelMapSync(optsForUnpre); 921 image.createUnpremultipliedPixelMap(srcPixelmap, dstPixelMap).then(() => { 922 console.info('Succeeded in converting pixelmap.'); 923 }).catch((error: BusinessError) => { 924 console.error(`Failed to convert pixelmap, error code is ${error}`); 925 }) 926} 927``` 928 929## image.createImageSource 930 931createImageSource(uri: string): ImageSource 932 933通过传入的uri创建ImageSource实例。 934 935 936**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 937 938**系统能力:** SystemCapability.Multimedia.Image.ImageSource 939 940**参数:** 941 942| 参数名 | 类型 | 必填 | 说明 | 943| ------ | ------ | ---- | ---------------------------------- | 944| uri | string | 是 | 图片路径,当前仅支持应用沙箱路径。</br>当前支持格式有:.jpg .png .gif .bmp .webp .dng .heic<sup>12+</sup>(不同硬件设备支持情况不同) [.svg<sup>10+</sup>](#svg标签说明) .ico<sup>11+</sup>。 | 945 946**返回值:** 947 948| 类型 | 说明 | 949| --------------------------- | -------------------------------------------- | 950| [ImageSource](arkts-apis-image-ImageSource.md) | 返回ImageSource类实例,失败时返回undefined。 | 951 952**示例:** 953```ts 954async function CreateImageSource(context : Context) { 955 // 此处'test.jpg'仅作示例,请开发者自行替换。否则imageSource会创建失败,导致后续无法正常执行。 956 const path: string = context.filesDir + "/test.jpg"; 957 const imageSourceObj: image.ImageSource = image.createImageSource(path); 958} 959``` 960 961## image.createImageSource<sup>9+</sup> 962 963createImageSource(uri: string, options: SourceOptions): ImageSource 964 965通过传入的uri创建ImageSource实例。 966 967**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 968 969**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 970 971**系统能力:** SystemCapability.Multimedia.Image.ImageSource 972 973**参数:** 974 975| 参数名 | 类型 | 必填 | 说明 | 976| ------- | ------------------------------- | ---- | ----------------------------------- | 977| uri | string | 是 | 图片路径,当前仅支持应用沙箱路径。</br>当前支持格式有:.jpg .png .gif .bmp .webp .dng .heic<sup>12+</sup>(不同硬件设备支持情况不同)[.svg<sup>10+</sup>](#svg标签说明) .ico<sup>11+</sup>。 | 978| options | [SourceOptions](arkts-apis-image-i.md#sourceoptions9) | 是 | 图片属性,包括图片像素密度、像素格式和图片尺寸。| 979 980**返回值:** 981 982| 类型 | 说明 | 983| --------------------------- | -------------------------------------------- | 984| [ImageSource](arkts-apis-image-ImageSource.md) | 返回ImageSource类实例,失败时返回undefined。 | 985 986**示例:** 987 988```ts 989async function CreateImageSource(context : Context) { 990 let sourceOptions: image.SourceOptions = { sourceDensity: 120 }; 991 // 此处'test.png'仅作示例,请开发者自行替换。否则imageSource会创建失败,导致后续无法正常执行。 992 const path: string = context.filesDir + "/test.png"; 993 let imageSourceObj: image.ImageSource = image.createImageSource(path, sourceOptions); 994} 995``` 996 997## image.createImageSource<sup>7+</sup> 998 999createImageSource(fd: number): ImageSource 1000 1001通过传入文件描述符来创建ImageSource实例。 1002 1003**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1004 1005**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1006 1007**参数:** 1008 1009| 参数名 | 类型 | 必填 | 说明 | 1010| ------ | ------ | ---- | ------------- | 1011| fd | number | 是 | 文件描述符fd。| 1012 1013**返回值:** 1014 1015| 类型 | 说明 | 1016| --------------------------- | -------------------------------------------- | 1017| [ImageSource](arkts-apis-image-ImageSource.md) | 返回ImageSource类实例,失败时返回undefined。 | 1018 1019**示例:** 1020 1021```ts 1022import { fileIo as fs } from '@kit.CoreFileKit'; 1023 1024async function CreateImageSource(context : Context) { 1025 // 此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource会创建失败导致后续无法正常执行。 1026 let filePath: string = context.filesDir + "/test.jpg"; 1027 let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 1028 const imageSourceObj: image.ImageSource = image.createImageSource(file.fd); 1029} 1030``` 1031 1032## image.createImageSource<sup>9+</sup> 1033 1034createImageSource(fd: number, options: SourceOptions): ImageSource 1035 1036通过传入文件描述符来创建ImageSource实例。 1037 1038**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 1039 1040**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1041 1042**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1043 1044**参数:** 1045 1046| 参数名 | 类型 | 必填 | 说明 | 1047| ------- | ------------------------------- | ---- | ----------------------------------- | 1048| fd | number | 是 | 文件描述符fd。 | 1049| options | [SourceOptions](arkts-apis-image-i.md#sourceoptions9) | 是 | 图片属性,包括图片像素密度、像素格式和图片尺寸。| 1050 1051**返回值:** 1052 1053| 类型 | 说明 | 1054| --------------------------- | -------------------------------------------- | 1055| [ImageSource](arkts-apis-image-ImageSource.md) | 返回ImageSource类实例,失败时返回undefined。 | 1056 1057**示例:** 1058 1059```ts 1060import { fileIo as fs } from '@kit.CoreFileKit'; 1061 1062async function CreateImageSource(context : Context) { 1063 let sourceOptions: image.SourceOptions = { sourceDensity: 120 }; 1064 // 此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。 1065 const filePath: string = context.filesDir + "/test.jpg"; 1066 let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 1067 const imageSourceObj: image.ImageSource = image.createImageSource(file.fd, sourceOptions); 1068} 1069``` 1070 1071## image.createImageSource<sup>9+</sup> 1072 1073createImageSource(buf: ArrayBuffer): ImageSource 1074 1075通过缓冲区创建ImageSource实例。buf数据应该是未解码的数据,不要传入类似于RBGA,YUV的像素buffer数据,如果想通过像素buffer数据创建pixelMap,可以调用[image.createPixelMapSync](arkts-apis-image-ImageSource.md#createpixelmapsync12)这一类接口。 1076 1077**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 1078 1079**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1080 1081**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1082 1083**参数:** 1084 1085| 参数名 | 类型 | 必填 | 说明 | 1086| ------ | ----------- | ---- | ---------------- | 1087| buf | ArrayBuffer | 是 | 图像缓冲区数组。 | 1088 1089**返回值:** 1090 1091| 类型 | 说明 | 1092| --------------------------- | -------------------------------------------- | 1093| [ImageSource](arkts-apis-image-ImageSource.md) | 返回ImageSource类实例,失败时返回undefined。 | 1094 1095**示例:** 1096 1097```ts 1098async function CreateImageSource() { 1099 const buf: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4。 1100 const imageSourceObj: image.ImageSource = image.createImageSource(buf); 1101} 1102``` 1103 1104## image.createImageSource<sup>9+</sup> 1105 1106createImageSource(buf: ArrayBuffer, options: SourceOptions): ImageSource 1107 1108通过缓冲区创建ImageSource实例。buf数据应该是未解码的数据,不要传入类似于RBGA,YUV的像素buffer数据,如果想通过像素buffer数据创建pixelMap,可以调用[image.createPixelMapSync](arkts-apis-image-ImageSource.md#createpixelmapsync12)这一类接口。 1109 1110**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 1111 1112**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1113 1114**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1115 1116**参数:** 1117 1118| 参数名 | 类型 | 必填 | 说明 | 1119| ------ | -------------------------------- | ---- | ------------------------------------ | 1120| buf | ArrayBuffer | 是 | 图像缓冲区数组。 | 1121| options | [SourceOptions](arkts-apis-image-i.md#sourceoptions9) | 是 | 图片属性,包括图片像素密度、像素格式和图片尺寸。 | 1122 1123**返回值:** 1124 1125| 类型 | 说明 | 1126| --------------------------- | -------------------------------------------- | 1127| [ImageSource](arkts-apis-image-ImageSource.md) | 返回ImageSource类实例,失败时返回undefined。 | 1128 1129**示例:** 1130 1131```ts 1132async function CreateImageSource() { 1133 const data: ArrayBuffer = new ArrayBuffer(112); 1134 let sourceOptions: image.SourceOptions = { sourceDensity: 120 }; 1135 const imageSourceObj: image.ImageSource = image.createImageSource(data, sourceOptions); 1136} 1137``` 1138 1139## image.createImageSource<sup>11+</sup> 1140 1141createImageSource(rawfile: resourceManager.RawFileDescriptor, options?: SourceOptions): ImageSource 1142 1143通过图像资源文件的RawFileDescriptor创建ImageSource实例。 1144 1145**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1146 1147**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1148 1149**参数:** 1150 1151| 参数名 | 类型 | 必填 | 说明 | 1152| ------ | -------------------------------- | ---- | ------------------------------------ | 1153| rawfile | [resourceManager.RawFileDescriptor](../apis-localization-kit/js-apis-resource-manager.md#rawfiledescriptor9) | 是 | 图像资源文件的RawFileDescriptor。 | 1154| options | [SourceOptions](arkts-apis-image-i.md#sourceoptions9) | 否 | 图片属性,包括图片像素密度、像素格式和图片尺寸。 | 1155 1156**返回值:** 1157 1158| 类型 | 说明 | 1159| --------------------------- | -------------------------------------------- | 1160| [ImageSource](arkts-apis-image-ImageSource.md) | 返回ImageSource类实例,失败时返回undefined。 | 1161 1162**示例:** 1163 1164```ts 1165import { resourceManager } from '@kit.LocalizationKit'; 1166import { BusinessError } from '@kit.BasicServicesKit'; 1167 1168async function CreateImageSource(context : Context) { 1169 // 获取resourceManager资源管理器。 1170 const resourceMgr: resourceManager.ResourceManager = context.resourceManager; 1171 // 此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。 1172 resourceMgr.getRawFd('test.jpg').then((rawFileDescriptor: resourceManager.RawFileDescriptor) => { 1173 const imageSourceObj: image.ImageSource = image.createImageSource(rawFileDescriptor); 1174 }).catch((error: BusinessError) => { 1175 console.error(`Failed to get RawFileDescriptor.code is ${error.code}, message is ${error.message}`); 1176 }) 1177} 1178``` 1179 1180## image.CreateIncrementalSource<sup>9+</sup> 1181 1182CreateIncrementalSource(buf: ArrayBuffer): ImageSource 1183 1184通过缓冲区以增量的方式创建ImageSource实例,IncrementalSource不支持读写Exif信息。 1185 1186以增量方式创建的ImageSource实例,仅支持使用以下功能,同步、异步callback、异步Promise均支持。 1187 1188- 获取图片信息:指定序号-[getImageInfo](arkts-apis-image-ImageSource.md#getimageinfo)、直接获取-[getImageInfo](arkts-apis-image-ImageSource.md#getimageinfo-1) 1189- 获取图片中给定索引处图像的指定属性键的值:[getImageProperty](arkts-apis-image-ImageSource.md#getimageproperty11) 1190- 批量获取图片中的指定属性键的值:[getImageProperties](arkts-apis-image-ImageSource.md#getimageproperties12) 1191- 更新增量数据:[updateData](arkts-apis-image-ImageSource.md#updatedata9) 1192- 创建PixelMap对象:通过图片解码参数创建-[createPixelMap](arkts-apis-image-ImageSource.md#createpixelmap7)、通过默认参数创建-[createPixelMap](arkts-apis-image-ImageSource.md#createpixelmap7-1) 、通过图片解码参数-[createPixelMap](arkts-apis-image-ImageSource.md#createpixelmap7-2) 1193- 释放ImageSource实例:[release](arkts-apis-image-ImageSource.md#release) 1194 1195**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1196 1197**参数:** 1198 1199| 参数名 | 类型 | 必填 | 说明 | 1200| ------- | ------------| ---- | ----------| 1201| buf | ArrayBuffer | 是 | 增量数据。| 1202 1203**返回值:** 1204 1205| 类型 | 说明 | 1206| --------------------------- | --------------------------------- | 1207| [ImageSource](arkts-apis-image-ImageSource.md) | 返回ImageSource,失败时返回undefined。 | 1208 1209**示例:** 1210 1211```ts 1212import { BusinessError } from '@kit.BasicServicesKit'; 1213 1214async function CreateIncrementalImageSource(context : Context) { 1215 let imageArray = context.resourceManager.getMediaContentSync($r('app.media.startIcon').id); // 获取图像资源。 1216 // 此处'app.media.startIcon'仅作示例,请开发者自行替换,否则imageArray创建失败会导致后续无法正常执行。 1217 let splitBuff1 = imageArray.slice(0, imageArray.byteLength / 2); // 分片。 1218 let splitBuff2 = imageArray.slice(imageArray.byteLength / 2); 1219 const imageSourceIncrementalSApi: image.ImageSource = image.CreateIncrementalSource(new ArrayBuffer(imageArray.byteLength)); 1220 imageSourceIncrementalSApi.updateData(splitBuff1, false, 0, splitBuff1.byteLength).then(() => { 1221 imageSourceIncrementalSApi.updateData(splitBuff2, true, 0, splitBuff2.byteLength).then(() => { 1222 let pixelMap = imageSourceIncrementalSApi.createPixelMapSync(); 1223 let imageInfo = pixelMap.getImageInfoSync(); 1224 console.info('Succeeded in creating pixelMap'); 1225 }).catch((error : BusinessError) => { 1226 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`); 1227 }) 1228 }).catch((error : BusinessError) => { 1229 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`); 1230 }) 1231} 1232``` 1233 1234## image.CreateIncrementalSource<sup>9+</sup> 1235 1236CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource 1237 1238通过缓冲区以增量的方式创建ImageSource实例,IncrementalSource不支持读写Exif信息。 1239 1240此接口支持的功能与[CreateIncrementalSource(buf: ArrayBuffer): ImageSource](#imagecreateincrementalsource9)所生成的实例支持的功能相同。 1241 1242**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1243 1244**参数:** 1245 1246| 参数名 | 类型 | 必填 | 说明 | 1247| ------- | ------------------------------- | ---- | ------------------------------------ | 1248| buf | ArrayBuffer | 是 | 增量数据。 | 1249| options | [SourceOptions](arkts-apis-image-i.md#sourceoptions9) | 否 | 图片属性,包括图片像素密度、像素格式和图片尺寸。 | 1250 1251**返回值:** 1252 1253| 类型 | 说明 | 1254| --------------------------- | --------------------------------- | 1255| [ImageSource](arkts-apis-image-ImageSource.md) | 返回ImageSource,失败时返回undefined。 | 1256 1257**示例:** 1258 1259```ts 1260import { BusinessError } from '@kit.BasicServicesKit'; 1261 1262async function CreateIncrementalImageSource(context : Context) { 1263 let imageArray = context.resourceManager.getMediaContentSync($r('app.media.startIcon').id); // 获取图像资源。 1264 // 此处'app.media.startIcon'仅作示例,请开发者自行替换,否则imageArray创建失败会导致后续无法正常执行。 1265 let splitBuff1 = imageArray.slice(0, imageArray.byteLength / 2); // 分片。 1266 let splitBuff2 = imageArray.slice(imageArray.byteLength / 2); 1267 let sourceOptions: image.SourceOptions = { sourceDensity: 120}; 1268 1269 const imageSourceIncrementalSApi: image.ImageSource = image.CreateIncrementalSource(new ArrayBuffer(imageArray.byteLength), sourceOptions); 1270 imageSourceIncrementalSApi.updateData(splitBuff1, false, 0, splitBuff1.byteLength).then(() => { 1271 imageSourceIncrementalSApi.updateData(splitBuff2, true, 0, splitBuff2.byteLength).then(() => { 1272 let pixelMap = imageSourceIncrementalSApi.createPixelMapSync(); 1273 let imageInfo = pixelMap.getImageInfoSync(); 1274 console.info('Succeeded in creating pixelMap'); 1275 }).catch((error : BusinessError) => { 1276 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`); 1277 }) 1278 }).catch((error : BusinessError) => { 1279 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`); 1280 }) 1281} 1282``` 1283 1284## image.getImageSourceSupportedFormats<sup>20+</sup> 1285 1286getImageSourceSupportedFormats(): string[] 1287 1288获取支持解码的图片格式,图片格式以mime type表示。 1289 1290**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1291 1292**返回值:** 1293 1294| 类型 | 说明 | 1295| -------- | ------------------------------------------ | 1296| string[] | 支持解码的图片格式(mime type)列表。 | 1297 1298**示例:** 1299 1300```ts 1301async function GetImageSourceSupportedFormats() { 1302 let formats = image.getImageSourceSupportedFormats(); 1303 console.info('formats:', formats); 1304} 1305``` 1306 1307## image.createImagePacker 1308 1309createImagePacker(): ImagePacker 1310 1311创建ImagePacker实例。 1312 1313**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1314 1315**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 1316 1317**返回值:** 1318 1319| 类型 | 说明 | 1320| --------------------------- | --------------------- | 1321| [ImagePacker](arkts-apis-image-ImagePacker.md) | 返回ImagePacker实例。 | 1322 1323**示例:** 1324 1325```ts 1326async function CreateImagePacker() { 1327 const imagePackerObj: image.ImagePacker = image.createImagePacker(); 1328} 1329``` 1330 1331## image.getImagePackerSupportedFormats<sup>20+</sup> 1332 1333getImagePackerSupportedFormats(): string[] 1334 1335获取支持编码的图片格式,图片格式以mime type表示。 1336 1337**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 1338 1339**返回值:** 1340 1341| 类型 | 说明 | 1342| -------- | ------------------------------------------ | 1343| string[] | 支持编码的图片格式(mime type)列表。 | 1344 1345**示例:** 1346 1347```ts 1348async function GetImagePackerSupportedFormats() { 1349 let formats = image.getImagePackerSupportedFormats(); 1350 console.info('formats:', formats); 1351} 1352``` 1353 1354## image.createAuxiliaryPicture<sup>13+</sup> 1355 1356createAuxiliaryPicture(buffer: ArrayBuffer, size: Size, type: AuxiliaryPictureType): AuxiliaryPicture 1357 1358通过ArrayBuffer图片数据、辅助图尺寸、辅助图类型创建AuxiliaryPicture实例。 1359 1360**系统能力:** SystemCapability.Multimedia.Image.Core 1361 1362**参数:** 1363 1364| 参数名 | 类型 | 必填 | 说明 | 1365| ------ | ----------------------------------------------- | ---- | ---------------------------- | 1366| buffer | ArrayBuffer | 是 | 以buffer形式存放的图像数据。 | 1367| size | [Size](arkts-apis-image-i.md#size) | 是 | 辅助图的尺寸。单位:像素。 | 1368| type | [AuxiliaryPictureType](arkts-apis-image-e.md#auxiliarypicturetype13) | 是 | 辅助图类型。 | 1369 1370**返回值:** 1371 1372| 类型 | 说明 | 1373| --------------------------------------- | ------------------------------------------ | 1374| [AuxiliaryPicture](arkts-apis-image-AuxiliaryPicture.md) | 如果操作成功,则返回AuxiliaryPicture实例。 | 1375 1376**错误码:** 1377 1378以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。 1379 1380| 错误码ID | 错误信息 | 1381| -------- | ------------------------------------------------------------ | 1382| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 1383 1384**示例:** 1385 1386```ts 1387async function CreateAuxiliaryPicture(context: Context) { 1388 let funcName = "CreateAuxiliaryPicture"; 1389 const resourceMgr = context.resourceManager; 1390 const rawFile = await resourceMgr.getRawFileContent("hdr.jpg"); // 需要支持hdr的图片。 1391 let auxBuffer: ArrayBuffer = rawFile.buffer as ArrayBuffer; 1392 let auxSize: Size = { 1393 height: 180, 1394 width: 240 1395 }; 1396 let auxType: image.AuxiliaryPictureType = image.AuxiliaryPictureType.GAINMAP; 1397 let auxPictureObj: image.AuxiliaryPicture | null = image.createAuxiliaryPicture(auxBuffer, auxSize, auxType); 1398 if(auxPictureObj != null) { 1399 let type: image.AuxiliaryPictureType = auxPictureObj.getType(); 1400 console.info(funcName, `CreateAuxiliaryPicture succeeded this.Aux_picture.type ${type}`); 1401 } else { 1402 console.error(funcName, 'CreateAuxiliaryPicture failed'); 1403 } 1404} 1405``` 1406 1407## image.createImageReceiver<sup>11+</sup> 1408 1409createImageReceiver(size: Size, format: ImageFormat, capacity: number): ImageReceiver 1410 1411通过图片大小、图片格式、容量创建ImageReceiver实例。ImageReceiver做为图片的接收方、消费者,它的参数属性实际上不会对接收到的图片产生影响。图片属性的配置应在发送方、生产者进行,如相机预览流[createPreviewOutput](../apis-camera-kit/arkts-apis-camera-CameraManager.md#createpreviewoutput)。 1412 1413**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 1414 1415**参数:** 1416 1417| 参数名 | 类型 | 必填 | 说明 | 1418| -------- | ------ | ---- | ---------------------- | 1419| size | [Size](arkts-apis-image-i.md#size) | 是 | 图像的默认大小。该参数不会影响接收到的图片大小,实际返回大小由生产者决定,如相机。 | 1420| format | [ImageFormat](arkts-apis-image-e.md#imageformat9) | 是 | 图像格式,取值为[ImageFormat](arkts-apis-image-e.md#imageformat9)常量(目前仅支持 ImageFormat:JPEG,实际返回格式由生产者决定,如相机)。 | 1421| capacity | number | 是 | 同时访问的最大图像数。该参数仅作为期望值,实际capacity由设备硬件决定。 | 1422 1423**返回值:** 1424 1425| 类型 | 说明 | 1426| -------------------------------- | --------------------------------------- | 1427| [ImageReceiver](arkts-apis-image-ImageReceiver.md) | 如果操作成功,则返回ImageReceiver实例。 | 1428 1429**错误码:** 1430 1431以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。 1432 1433| 错误码ID | 错误信息 | 1434| ------- | --------------------------------------------| 1435| 401| Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; | 1436 1437**示例:** 1438 1439```ts 1440let size: image.Size = { 1441 height: 8192, 1442 width: 8192 1443} 1444let receiver: image.ImageReceiver = image.createImageReceiver(size, image.ImageFormat.JPEG, 8); 1445``` 1446 1447## image.createImageCreator<sup>11+</sup> 1448 1449createImageCreator(size: Size, format: ImageFormat, capacity: number): ImageCreator 1450 1451通过图片大小、图片格式、容量创建ImageCreator实例。 1452 1453**系统能力:** SystemCapability.Multimedia.Image.ImageCreator 1454 1455**参数:** 1456 1457| 参数名 | 类型 | 必填 | 说明 | 1458| -------- | ------ | ---- | ---------------------- | 1459| size | [Size](arkts-apis-image-i.md#size) | 是 | 图像的默认大小。 | 1460| format | [ImageFormat](arkts-apis-image-e.md#imageformat9) | 是 | 图像格式,如YCBCR_422_SP,JPEG。 | 1461| capacity | number | 是 | 同时访问的最大图像数。该参数仅作为期望值,实际capacity由设备硬件决定。 | 1462 1463**返回值:** 1464 1465| 类型 | 说明 | 1466| ------------------------------ | --------------------------------------- | 1467| [ImageCreator](arkts-apis-image-ImageCreator.md) | 如果操作成功,则返回ImageCreator实例。 | 1468 1469 1470**错误码:** 1471 1472以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。 1473 1474| 错误码ID | 错误信息 | 1475| ------- | --------------------------------------------| 1476| 401| Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; | 1477 1478**示例:** 1479 1480```ts 1481let size: image.Size = { 1482 height: 8192, 1483 width: 8192 1484} 1485let creator: image.ImageCreator = image.createImageCreator(size, image.ImageFormat.JPEG, 8); 1486``` 1487 1488## image.createImageReceiver<sup>(deprecated)</sup> 1489 1490createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver 1491 1492通过宽、高、图片格式、容量创建ImageReceiver实例。ImageReceiver做为图片的接收方、消费者,它的参数属性实际上不会对接收到的图片产生影响。图片属性的配置应在发送方、生产者进行,如相机预览流[createPreviewOutput](../apis-camera-kit/arkts-apis-camera-CameraManager.md#createpreviewoutput)。 1493 1494> **说明:** 1495> 1496> 从API version 9开始支持,从API version 11废弃,建议使用[createImageReceiver](#imagecreateimagereceiver11)代替。 1497 1498**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 1499 1500**参数:** 1501 1502| 参数名 | 类型 | 必填 | 说明 | 1503| -------- | ------ | ---- | ---------------------- | 1504| width | number | 是 | 图像的默认宽度。单位:像素。该参数不会影响接收到的图片宽度,实际宽度由生产者决定,如相机。 | 1505| height | number | 是 | 图像的默认高度。单位:像素。该参数不会影响接收到的图片高度,实际高度由生产者决定,如相机。 | 1506| format | number | 是 | 图像格式,取值为[ImageFormat](arkts-apis-image-e.md#imageformat9)常量(目前仅支持 ImageFormat:JPEG,实际返回格式由生产者决定,如相机)。 | 1507| capacity | number | 是 | 同时访问的最大图像数。该参数仅作为期望值,实际capacity由设备硬件决定。 | 1508 1509**返回值:** 1510 1511| 类型 | 说明 | 1512| -------------------------------- | --------------------------------------- | 1513| [ImageReceiver](arkts-apis-image-ImageReceiver.md) | 如果操作成功,则返回ImageReceiver实例。 | 1514 1515**示例:** 1516 1517```ts 1518let receiver: image.ImageReceiver = image.createImageReceiver(8192, 8192, image.ImageFormat.JPEG, 8); 1519``` 1520 1521## image.createImageCreator<sup>(deprecated)</sup> 1522 1523createImageCreator(width: number, height: number, format: number, capacity: number): ImageCreator 1524 1525通过宽、高、图片格式、容量创建ImageCreator实例。 1526 1527> **说明:** 1528> 1529> 从API version 9开始支持,从API version 11废弃,建议使用[createImageCreator](#imagecreateimagecreator11)代替。 1530 1531**系统能力:** SystemCapability.Multimedia.Image.ImageCreator 1532 1533**参数:** 1534 1535| 参数名 | 类型 | 必填 | 说明 | 1536| -------- | ------ | ---- | ---------------------- | 1537| width | number | 是 | 图像的默认宽度。单位:像素。 | 1538| height | number | 是 | 图像的默认高度。单位:像素。 | 1539| format | number | 是 | 图像格式,如YCBCR_422_SP,JPEG。 | 1540| capacity | number | 是 | 同时访问的最大图像数。该参数仅作为期望值,实际capacity由设备硬件决定。 | 1541 1542**返回值:** 1543 1544| 类型 | 说明 | 1545| ------------------------------ | --------------------------------------- | 1546| [ImageCreator](arkts-apis-image-ImageCreator.md) | 如果操作成功,则返回ImageCreator实例。 | 1547 1548**示例:** 1549 1550```ts 1551let creator: image.ImageCreator = image.createImageCreator(8192, 8192, image.ImageFormat.JPEG, 8); 1552``` 1553 1554## SVG标签说明 1555 1556从API version 10开始支持SVG标签,使用版本为(SVG) 1.1,SVG标签需设置width,height。SVG文件可添加xml声明,应以“<?xml”开头,当前支持的标签列表有: 1557 1558- a 1559- circle 1560- clipPath 1561- defs 1562- ellipse 1563- feBlend 1564- feColorMatrix 1565- feComposite 1566- feDiffuseLighting 1567- feDisplacementMap 1568- feDistantLight 1569- feFlood 1570- feGaussianBlur 1571- feImage 1572- feMorphology 1573- feOffset 1574- fePointLight 1575- feSpecularLighting 1576- feSpotLight 1577- feTurbulence 1578- filter 1579- g 1580- image 1581- line 1582- linearGradient 1583- mask 1584- path 1585- pattern 1586- polygon 1587- polyline 1588- radialGradient 1589- rect 1590- stop 1591- svg 1592- text 1593- textPath 1594- tspan 1595- use