1# @ohos.multimedia.image (图片处理) 2 3本模块提供图片处理效果,包括通过属性创建PixelMap、读取图像像素数据、读取区域内的图片数据等。 4 5> **说明:** 6> 7> - 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8> 9> - 从API version 12开始,本模块接口支持在ArkTS卡片中使用。 10 11## 导入模块 12 13```ts 14import { image } from '@kit.ImageKit'; 15``` 16 17## image.createPicture<sup>13+</sup> 18 19createPicture(mainPixelmap : PixelMap): Picture 20 21通过主图的pixelmap创建一个Picture对象。 22 23**系统能力:** SystemCapability.Multimedia.Image.Core 24 25**参数:** 26 27| 参数名 | 类型 | 必填 | 说明 | 28| ------------ | ------------------- | ---- | ---------------- | 29| mainPixelmap | [PixelMap](#pixelmap7) | 是 | 主图的pixelmap。 | 30 31**返回值:** 32 33| 类型 | 说明 | 34| ------------------ | ----------------- | 35| [Picture](#picture13) | 返回Picture对象。 | 36 37**错误码:** 38 39以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 40 41| 错误码ID | 错误信息 | 42| -------- | ------------------------------------------------------------ | 43| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. | 44 45**示例:** 46 47```ts 48import { image } from '@kit.ImageKit'; 49 50async function CreatePicture() { 51 const context = getContext(); 52 const resourceMgr = context.resourceManager; 53 const rawFile = await resourceMgr.getRawFileContent("test.jpg"); 54 let ops: image.SourceOptions = { 55 sourceDensity: 98, 56 } 57 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 58 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 59 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 60 if (pictureObj != null) { 61 console.info('Create picture succeeded'); 62 } else { 63 console.info('Create picture failed'); 64 } 65} 66``` 67 68## image.createPictureFromParcel<sup>13+</sup> 69 70createPictureFromParcel(sequence: rpc.MessageSequence): Picture 71 72从MessageSequence中获取Picture。 73 74**系统能力:** SystemCapability.Multimedia.Image.Core 75 76**参数:** 77 78| 参数名 | 类型 | 必填 | 说明 | 79| -------- | ------------------------------------------------------------------- | ---- | ------------------------------------ | 80| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | 是 | 保存有Picture信息的MessageSequence。 | 81 82**返回值:** 83 84| 类型 | 说明 | 85| ------------------ | ----------------- | 86| [Picture](#picture13) | 返回Picture对象。 | 87 88**错误码:** 89 90以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 91 92| 错误码ID | 错误信息 | 93| -------- | ------------------------------------------------------------ | 94| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. | 95| 62980097 | IPC error. | 96 97**示例:** 98 99```ts 100import { rpc } from '@kit.IPCKit'; 101import { BusinessError } from '@kit.BasicServicesKit'; 102import { image } from '@kit.ImageKit'; 103 104class MySequence implements rpc.Parcelable { 105 picture: image.Picture | null = null; 106 constructor(conPicture: image.Picture) { 107 this.picture = conPicture; 108 } 109 marshalling(messageSequence: rpc.MessageSequence) { 110 if(this.picture != null) { 111 this.picture.marshalling(messageSequence); 112 console.info('Marshalling success !'); 113 return true; 114 } else { 115 console.info('Marshalling failed !'); 116 return false; 117 } 118 } 119 unmarshalling(messageSequence : rpc.MessageSequence) { 120 this.picture = image.createPictureFromParcel(messageSequence); 121 this.picture.getMainPixelmap().getImageInfo().then((imageInfo : image.ImageInfo) => { 122 console.info('Unmarshalling to get mainPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width); 123 }).catch((error: BusinessError) => { 124 console.error('Unmarshalling failed error.code: ${error.code} ,error.message: ${error.message}'); 125 }); 126 return true; 127 } 128} 129 130async function Marshalling_UnMarshalling() { 131 const context = getContext(); 132 const resourceMgr = context.resourceManager; 133 const rawFile = await resourceMgr.getRawFileContent("test.jpg"); 134 let ops: image.SourceOptions = { 135 sourceDensity: 98, 136 } 137 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 138 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 139 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 140 if (pictureObj != null) { 141 let parcelable: MySequence = new MySequence(pictureObj); 142 let data: rpc.MessageSequence = rpc.MessageSequence.create(); 143 // marshalling 144 data.writeParcelable(parcelable); 145 let ret: MySequence = new MySequence(pictureObj); 146 // unmarshalling 147 data.readParcelable(ret); 148 } else { 149 console.info('PictureObj is null'); 150 } 151} 152``` 153 154## image.createPixelMap<sup>8+</sup> 155 156createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<PixelMap> 157 158通过属性创建PixelMap,默认采用BGRA_8888格式处理数据,通过Promise返回结果。 159 160**系统能力:** SystemCapability.Multimedia.Image.Core 161 162**参数:** 163 164| 参数名 | 类型 | 必填 | 说明 | 165| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 166| colors | ArrayBuffer | 是 | 图像像素数据的缓冲区,用于初始化PixelMap的像素。初始化前,缓冲区中的像素格式需要由[InitializationOptions](#initializationoptions8).srcPixelFormat指定。<br>**说明:** 图像像素数据的缓冲区长度:length = width * height * 单位像素字节数 | 167| options | [InitializationOptions](#initializationoptions8) | 是 | 创建像素的属性,包括透明度,尺寸,缩略值,像素格式和是否可编辑。 | 168 169**返回值:** 170 171| 类型 | 说明 | 172| -------------------------------- | ----------------------------------------------------------------------- | 173| Promise\<[PixelMap](#pixelmap7)> | Promise对象,返回PixelMap。<br>当创建的pixelMap大小超过原图大小时,返回原图pixelMap大小。| 174 175**示例:** 176 177```ts 178import { BusinessError } from '@kit.BasicServicesKit'; 179 180async function CreatePixelMap() { 181 const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4 182 let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 183 image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => { 184 console.info('Succeeded in creating pixelmap.'); 185 }).catch((error: BusinessError) => { 186 console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`); 187 }) 188} 189``` 190 191## image.createPixelMap<sup>8+</sup> 192 193createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: AsyncCallback\<PixelMap>): void 194 195通过属性创建PixelMap,默认采用BGRA_8888格式处理数据,通过callback返回结果。 196 197**系统能力:** SystemCapability.Multimedia.Image.Core 198 199**参数:** 200 201| 参数名 | 类型 | 必填 | 说明 | 202| -------- | ------------------------------------------------ | ---- | -------------------------- | 203| colors | ArrayBuffer | 是 | 图像像素数据的缓冲区,用于初始化PixelMap的像素。初始化前,缓冲区中的像素格式需要由[InitializationOptions](#initializationoptions8).srcPixelFormat指定。<br>**说明:** 图像像素数据的缓冲区长度:length = width * height * 单位像素字节数 | 204| options | [InitializationOptions](#initializationoptions8) | 是 | 创建像素的属性,包括透明度,尺寸,缩略值,像素格式和是否可编辑。 | 205| callback | AsyncCallback\<[PixelMap](#pixelmap7)> | 是 | 回调函数,当创建PixelMap成功,err为undefined,data为获取到的PixelMap对象;否则为错误对象。 | 206 207**示例:** 208 209```ts 210import { BusinessError } from '@kit.BasicServicesKit'; 211 212async function CreatePixelMap() { 213 const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4 214 let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 215 image.createPixelMap(color, opts, (error: BusinessError, pixelMap: image.PixelMap) => { 216 if(error) { 217 console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`); 218 return; 219 } else { 220 console.info('Succeeded in creating pixelmap.'); 221 } 222 }) 223} 224``` 225 226## image.createPixelMapFromParcel<sup>11+</sup> 227 228createPixelMapFromParcel(sequence: rpc.MessageSequence): PixelMap 229 230从MessageSequence中获取PixelMap。 231 232**系统能力:** SystemCapability.Multimedia.Image.Core 233 234**参数:** 235 236| 参数名 | 类型 | 必填 | 说明 | 237| ---------------------- | ----------------------------------------------------- | ---- | ---------------------------------------- | 238| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | 是 | 保存有PixelMap信息的MessageSequence。 | 239 240**返回值:** 241 242| 类型 | 说明 | 243| -------------------------------- | --------------------- | 244| [PixelMap](#pixelmap7) | 成功同步返回PixelMap对象,失败抛出异常。 | 245 246**错误码:** 247 248以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 249 250| 错误码ID | 错误信息 | 251| ------- | --------------------------------------------| 252| 62980096 | Operation failed| 253| 62980097 | IPC error.| 254| 62980115 | Invalid input parameter| 255| 62980105 | Failed to get the data| 256| 62980177 | Abnormal API environment| 257| 62980178 | Failed to create the PixelMap| 258| 62980179 | Abnormal buffer size| 259| 62980180 | FD mapping failed| 260| 62980246 | Failed to read the PixelMap| 261 262**示例:** 263 264```ts 265import { image } from '@kit.ImageKit'; 266import { rpc } from '@kit.IPCKit'; 267import { BusinessError } from '@kit.BasicServicesKit'; 268 269class MySequence implements rpc.Parcelable { 270 pixel_map: image.PixelMap; 271 constructor(conPixelmap: image.PixelMap) { 272 this.pixel_map = conPixelmap; 273 } 274 marshalling(messageSequence: rpc.MessageSequence) { 275 this.pixel_map.marshalling(messageSequence); 276 return true; 277 } 278 unmarshalling(messageSequence: rpc.MessageSequence) { 279 try { 280 this.pixel_map = image.createPixelMapFromParcel(messageSequence); 281 } catch(e) { 282 let error = e as BusinessError; 283 console.error(`createPixelMapFromParcel error. code is ${error.code}, message is ${error.message}`); 284 return false; 285 } 286 return true; 287 } 288} 289async function CreatePixelMapFromParcel() { 290 const color: ArrayBuffer = new ArrayBuffer(96); 291 let bufferArr: Uint8Array = new Uint8Array(color); 292 for (let i = 0; i < bufferArr.length; i++) { 293 bufferArr[i] = 0x80; 294 } 295 let opts: image.InitializationOptions = { 296 editable: true, 297 pixelFormat: image.PixelMapFormat.BGRA_8888, 298 size: { height: 4, width: 6 }, 299 alphaType: image.AlphaType.UNPREMUL 300 } 301 let pixelMap: image.PixelMap | undefined = undefined; 302 image.createPixelMap(color, opts).then((srcPixelMap: image.PixelMap) => { 303 pixelMap = srcPixelMap; 304 }) 305 if (pixelMap != undefined) { 306 // 序列化 307 let parcelable: MySequence = new MySequence(pixelMap); 308 let data: rpc.MessageSequence = rpc.MessageSequence.create(); 309 data.writeParcelable(parcelable); 310 311 // 反序列化 rpc获取到data 312 let ret: MySequence = new MySequence(pixelMap); 313 data.readParcelable(ret); 314 315 // 获取到pixelmap 316 let unmarshPixelmap = ret.pixel_map; 317 } 318} 319``` 320 321## image.createPixelMapFromSurface<sup>11+</sup> 322 323createPixelMapFromSurface(surfaceId: string, region: Region): Promise\<PixelMap> 324 325根据Surface id和区域信息,创建一个PixelMap对象。该区域的大小由[Region](#region8).size指定。使用Promise形式返回。 326 327> **说明:** 328> 1. [Region](#region8).size的宽高需和[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)组件的宽高保持一致。 329> 2. 当开发设备为折叠屏,折叠状态切换时,需自行调整[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)组件的宽高。 330 331**系统能力:** SystemCapability.Multimedia.Image.Core 332 333**参数:** 334 335| 参数名 | 类型 | 必填 | 说明 | 336| ---------------------- | ------------- | ---- | ---------------------------------------- | 337| surfaceId | string | 是 | 从[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)组件获取的surfaceId。| 338| region | [Region](#region8) | 是 | 区域信息。 | 339 340**返回值:** 341| 类型 | 说明 | 342| -------------------------------- | --------------------- | 343| Promise\<[PixelMap](#pixelmap7)> | Promise对象,返回PixelMap。 | 344 345**错误码:** 346 347以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 348 349| 错误码ID | 错误信息 | 350| ------- | --------------------------------------------| 351| 62980115 | If the image parameter invalid.| 352| 62980105 | Failed to get the data| 353| 62980178 | Failed to create the PixelMap| 354 355**示例:** 356 357```ts 358import { BusinessError } from '@kit.BasicServicesKit'; 359 360async function CreatePixelMapFromSurface(surfaceId: string) { 361 let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 362 image.createPixelMapFromSurface(surfaceId, region).then(() => { 363 console.info('Succeeded in creating pixelmap from Surface'); 364 }).catch((error: BusinessError) => { 365 console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`); 366 }); 367} 368``` 369 370## image.createPixelMapFromSurfaceSync<sup>12+</sup> 371 372createPixelMapFromSurfaceSync(surfaceId: string, region: Region): PixelMap 373 374以同步方式,根据Surface id和区域信息,创建一个PixelMap对象。该区域的大小由[Region](#region8).size指定。 375 376> **说明:** 377> 1. [Region](#region8).size的宽高需和[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)组件的宽高保持一致。 378> 2. 当开发设备为折叠屏,折叠状态切换时,需自行调整[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)组件的宽高。 379 380**系统能力:** SystemCapability.Multimedia.Image.Core 381 382**参数:** 383 384| 参数名 | 类型 | 必填 | 说明 | 385| ---------------------- | ------------- | ---- | ---------------------------------------- | 386| surfaceId | string | 是 | 从[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)组件获取的surfaceId。| 387| region | [Region](#region8) | 是 | 区域信息。 | 388 389**返回值:** 390| 类型 | 说明 | 391| -------------------------------- | --------------------- | 392| [PixelMap](#pixelmap7) | 成功同步返回PixelMap对象,失败抛出异常。 | 393 394**错误码:** 395 396以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 397 398| 错误码ID | 错误信息 | 399| ------- | --------------------------------------------| 400| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 401| 62980105 | Failed to get the data| 402| 62980178 | Failed to create the PixelMap| 403 404**示例:** 405 406```ts 407import { BusinessError } from '@kit.BasicServicesKit'; 408 409async function Demo(surfaceId: string) { 410 let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 411 let pixelMap : image.PixelMap = image.createPixelMapFromSurfaceSync(surfaceId, region); 412 return pixelMap; 413} 414``` 415 416## image.createPixelMapSync<sup>12+</sup> 417 418createPixelMapSync(colors: ArrayBuffer, options: InitializationOptions): PixelMap 419 420通过属性创建PixelMap,默认采用BGRA_8888格式处理数据,同步返回结果。 421 422**系统能力:** SystemCapability.Multimedia.Image.Core 423 424**参数:** 425 426| 参数名 | 类型 | 必填 | 说明 | 427| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 428| colors | ArrayBuffer | 是 | 图像像素数据的缓冲区,用于初始化PixelMap的像素。初始化前,缓冲区中的像素格式需要由[InitializationOptions](#initializationoptions8).srcPixelFormat指定。<br>**说明:** 图像像素数据的缓冲区长度:length = width * height * 单位像素字节数 | 429| options | [InitializationOptions](#initializationoptions8) | 是 | 创建像素的属性,包括透明度,尺寸,缩略值,像素格式和是否可编辑。 | 430 431**返回值:** 432| 类型 | 说明 | 433| -------------------------------- | --------------------- | 434| [PixelMap](#pixelmap7) | 成功同步返回PixelMap对象,失败抛出异常。 | 435 436**错误码:** 437 438以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 439 440| 错误码ID | 错误信息 | 441| ------- | --------------------------------------------| 442| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 443 444**示例:** 445 446```ts 447import { BusinessError } from '@kit.BasicServicesKit'; 448 449async function CreatePixelMapSync() { 450 const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4 451 let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 452 let pixelMap : image.PixelMap = image.createPixelMapSync(color, opts); 453 return pixelMap; 454} 455``` 456 457## image.createPixelMapSync<sup>12+</sup> 458 459createPixelMapSync(options: InitializationOptions): PixelMap 460 461通过属性创建PixelMap,同步返回PixelMap结果。 462 463**系统能力:** SystemCapability.Multimedia.Image.Core 464 465**参数:** 466 467| 参数名 | 类型 | 必填 | 说明 | 468| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 469| options | [InitializationOptions](#initializationoptions8) | 是 | 创建像素的属性,包括透明度,尺寸,缩略值,像素格式和是否可编辑。 | 470 471**返回值:** 472| 类型 | 说明 | 473| -------------------------------- | --------------------- | 474| [PixelMap](#pixelmap7) | 成功同步返回PixelMap对象,失败抛出异常。 | 475 476**错误码:** 477 478以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 479 480| 错误码ID | 错误信息 | 481| ------- | --------------------------------------------| 482| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 483 484**示例:** 485 486```ts 487import { BusinessError } from '@kit.BasicServicesKit'; 488 489async function CreatePixelMapSync() { 490 let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 491 let pixelMap : image.PixelMap = image.createPixelMapSync(opts); 492 return pixelMap; 493} 494``` 495 496## image.createPremultipliedPixelMap<sup>12+</sup> 497 498createPremultipliedPixelMap(src: PixelMap, dst: PixelMap, callback: AsyncCallback\<void>): void 499 500将PixelMap的透明通道非预乘模式转变为预乘模式,转换后的数据存入目标PixelMap,通过回调函数返回结果。 501 502**系统能力:** SystemCapability.Multimedia.Image.Core 503 504**参数:** 505 506| 参数名 | 类型 | 必填 | 说明 | 507| -------- | ------------------------------------------------ | ---- | -------------------------- | 508| src | [PixelMap](#pixelmap7) | 是 | 源PixelMap对象。 | 509| dst | [PixelMap](#pixelmap7) | 是 | 目标PixelMap对象。 | 510|callback | AsyncCallback\<void> | 是 | 回调函数,当创建PixelMap成功,err为undefined,否则为错误对象。 | 511 512**错误码:** 513 514以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 515 516| 错误码ID | 错误信息 | 517| ------- | --------------------------------------------| 518| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 519| 62980103 | The image data is not supported | 520| 62980246 | Failed to read the pixelMap | 521| 62980248 | Pixelmap not allow modify | 522 523**示例:** 524 525```ts 526import { BusinessError } from '@kit.BasicServicesKit'; 527 528async function CreatePremultipliedPixelMap() { 529 const color: ArrayBuffer = new ArrayBuffer(16); // 16为需要创建的像素buffer大小,取值为:height * width *4 530 let bufferArr = new Uint8Array(color); 531 for (let i = 0; i < bufferArr.length; i += 4) { 532 bufferArr[i] = 255; 533 bufferArr[i+1] = 255; 534 bufferArr[i+2] = 122; 535 bufferArr[i+3] = 122; 536 } 537 let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.UNPREMUL} 538 let srcPixelmap = image.createPixelMapSync(color, optsForUnpre); 539 let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.PREMUL} 540 let dstPixelMap = image.createPixelMapSync(optsForPre); 541 image.createPremultipliedPixelMap(srcPixelmap, dstPixelMap, (error: BusinessError) => { 542 if(error) { 543 console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`); 544 return; 545 } else { 546 console.info('Succeeded in converting pixelmap.'); 547 } 548 }) 549} 550``` 551 552## image.createPremultipliedPixelMap<sup>12+</sup> 553 554createPremultipliedPixelMap(src: PixelMap, dst: PixelMap): Promise\<void> 555 556将PixelMap数据按照透明度非预乘格式转为预乘格式,转换后的数据存入另一个PixelMap,通过Promise返回结果。 557 558**系统能力:** SystemCapability.Multimedia.Image.Core 559 560**参数:** 561 562| 参数名 | 类型 | 必填 | 说明 | 563| -------- | ------------------------------------------------ | ---- | -------------------------- | 564| src | [PixelMap](#pixelmap7) | 是 | 源PixelMap对象 | 565| dst | [PixelMap](#pixelmap7) | 是 | 目标PixelMap对象 | 566 567**返回值:** 568 569| 类型 | 说明 | 570| -------------------------------- | ----------------------------------------------------------------------- | 571| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 572 573**错误码:** 574 575以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 576 577| 错误码ID | 错误信息 | 578| ------- | --------------------------------------------| 579| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 580| 62980103 | The image data is not supported | 581| 62980246 | Failed to read the pixelMap | 582| 62980248 | Pixelmap not allow modify | 583 584**示例:** 585 586```ts 587import { BusinessError } from '@kit.BasicServicesKit'; 588 589async function CreatePremultipliedPixelMap() { 590 const color: ArrayBuffer = new ArrayBuffer(16); // 16为需要创建的像素buffer大小,取值为:height * width *4 591 let bufferArr = new Uint8Array(color); 592 for (let i = 0; i < bufferArr.length; i += 4) { 593 bufferArr[i] = 255; 594 bufferArr[i+1] = 255; 595 bufferArr[i+2] = 122; 596 bufferArr[i+3] = 122; 597 } 598 let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.UNPREMUL} 599 let srcPixelmap = image.createPixelMapSync(color, optsForUnpre); 600 let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.PREMUL} 601 let dstPixelMap = image.createPixelMapSync(optsForPre); 602 image.createPremultipliedPixelMap(srcPixelmap, dstPixelMap).then(() => { 603 console.info('Succeeded in converting pixelmap.'); 604 }).catch((error: BusinessError) => { 605 console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`); 606 }) 607} 608``` 609 610## image.createUnpremultipliedPixelMap<sup>12+</sup> 611 612createUnpremultipliedPixelMap(src: PixelMap, dst: PixelMap, callback: AsyncCallback\<void>): void 613 614将PixelMap的透明通道预乘模式转变为非预乘模式,转换后的数据存入目标PixelMap,通过回调函数返回结果。 615 616**系统能力:** SystemCapability.Multimedia.Image.Core 617 618**参数:** 619 620| 参数名 | 类型 | 必填 | 说明 | 621| -------- | ------------------------------------------------ | ---- | -------------------------- | 622| src | [PixelMap](#pixelmap7) | 是 | 源PixelMap对象。 | 623| dst | [PixelMap](#pixelmap7) | 是 | 目标PixelMap对象。| 624|callback | AsyncCallback\<void> | 是 | 回调函数,当创建PixelMap成功,err为undefined,否则为错误对象。| 625 626**错误码:** 627 628以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 629 630| 错误码ID | 错误信息 | 631| ------- | --------------------------------------------| 632| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 633| 62980103 | The image data is not supported | 634| 62980246 | Failed to read the pixelMap | 635| 62980248 | Pixelmap not allow modify | 636 637**示例:** 638 639```ts 640import { BusinessError } from '@kit.BasicServicesKit'; 641 642async function CreateUnpremultipliedPixelMap() { 643 const color: ArrayBuffer = new ArrayBuffer(16); // 16为需要创建的像素buffer大小,取值为:height * width *4 644 let bufferArr = new Uint8Array(color); 645 for (let i = 0; i < bufferArr.length; i += 4) { 646 bufferArr[i] = 255; 647 bufferArr[i+1] = 255; 648 bufferArr[i+2] = 122; 649 bufferArr[i+3] = 122; 650 } 651 let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.PREMUL} 652 let srcPixelmap = image.createPixelMapSync(color, optsForPre); 653 let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.UNPREMUL} 654 let dstPixelMap = image.createPixelMapSync(optsForUnpre); 655 image.createUnpremultipliedPixelMap(srcPixelmap, dstPixelMap, (error: BusinessError) => { 656 if(error) { 657 console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`); 658 return; 659 } else { 660 console.info('Succeeded in converting pixelmap.'); 661 } 662 }) 663} 664``` 665 666## image.createUnpremultipliedPixelMap<sup>12+</sup> 667 668createUnpremultipliedPixelMap(src: PixelMap, dst: PixelMap): Promise\<void> 669 670将PixelMap的透明通道预乘模式转变为非预乘模式,转换后的数据存入目标PixelMap,通过Promise返回结果。 671 672**系统能力:** SystemCapability.Multimedia.Image.Core 673 674**参数:** 675 676| 参数名 | 类型 | 必填 | 说明 | 677| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 678| src | [PixelMap](#pixelmap7) | 是 | 源PixelMap对象。 | 679| dst | [PixelMap](#pixelmap7) | 是 | 目标PixelMap对象。 | 680 681**返回值:** 682 683| 类型 | 说明 | 684| -------------------------------- | ----------------------------------------------------------------------- | 685| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 686 687**错误码:** 688 689以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 690 691| 错误码ID | 错误信息 | 692| ------- | --------------------------------------------| 693| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed| 694| 62980103 | The image data is not supported | 695| 62980246 | Failed to read the pixelMap. | 696| 62980248 | Pixelmap not allow modify. | 697 698**示例:** 699 700```ts 701import { BusinessError } from '@kit.BasicServicesKit'; 702 703async function CreateUnpremultipliedPixelMap() { 704 const color: ArrayBuffer = new ArrayBuffer(16); // 16为需要创建的像素buffer大小,取值为:height * width *4 705 let bufferArr = new Uint8Array(color); 706 for (let i = 0; i < bufferArr.length; i += 4) { 707 bufferArr[i] = 255; 708 bufferArr[i+1] = 255; 709 bufferArr[i+2] = 122; 710 bufferArr[i+3] = 122; 711 } 712 let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.PREMUL} 713 let srcPixelmap = image.createPixelMapSync(color, optsForPre); 714 let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.UNPREMUL} 715 let dstPixelMap = image.createPixelMapSync(optsForUnpre); 716 image.createUnpremultipliedPixelMap(srcPixelmap, dstPixelMap).then(() => { 717 console.info('Succeeded in converting pixelmap.'); 718 }).catch((error: BusinessError) => { 719 console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`); 720 }) 721} 722``` 723 724 725## Picture<sup>13+</sup> 726 727一些包含特殊信息的图片可以解码为多图对象,多图对象一般包含主图、辅助图和元数据。其中主图包含图像的大部分信息,主要用于显示图像内容;辅助图用于存储与主图相关但不同的数据,展示图像更丰富的信息;元数据一般用来存储关于图像文件的信息。多图对象类用于读取或写入多图对象。在调用Picture的方法前,需要先通过[createPicture](#imagecreatepicture13)创建一个Picture实例。 728 729### 属性 730 731**系统能力:** SystemCapability.Multimedia.Image.Core 732 733### getMainPixelmap<sup>13+</sup> 734 735getMainPixelmap(): PixelMap 736 737获取主图的pixelmap。 738 739**系统能力:** SystemCapability.Multimedia.Image.Core 740 741**返回值:** 742 743| 类型 | 说明 | 744| ------------------- | ---------------------- | 745| [PixelMap](#pixelmap7) | 同步返回PixelMap对象。 | 746 747**示例:** 748 749```ts 750import { BusinessError } from '@kit.BasicServicesKit'; 751import { image } from '@kit.ImageKit'; 752 753async function GetMainPixelmap() { 754 let funcName = "getMainPixelmap"; 755 if (pictureObj != null) { 756 let mainPixelmap: image.PixelMap = pictureObj.getMainPixelmap(); 757 if (mainPixelmap != null) { 758 mainPixelmap.getImageInfo().then((imageInfo: image.ImageInfo) => { 759 if (imageInfo != null) { 760 console.info('GetMainPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width); 761 } 762 }).catch((error: BusinessError) => { 763 console.error(funcName, 'Failed error.code: ${error.code} ,error.message: ${error.message}'); 764 }); 765 } 766 } else { 767 console.info('PictureObj is null'); 768 } 769} 770``` 771 772### getHdrComposedPixelmap<sup>13+</sup> 773 774getHdrComposedPixelmap(): Promise\<PixelMap> 775 776合成hdr图并获取hdr图的pixelmap,使用Promise形式返回结果。 777 778**系统能力:** SystemCapability.Multimedia.Image.Core 779 780**返回值:** 781 782| 类型 | 说明 | 783| ----------------------------- | --------------------------- | 784| Promise\<[PixelMap](#pixelmap7)> | Promise对象,返回PixelMap。 | 785 786**错误码:** 787 788以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 789 790| 错误码ID | 错误信息 | 791| -------- | ---------------------- | 792| 7600901 | Unknown error. | 793| 7600201 | Unsupported operation. | 794 795**示例:** 796 797```ts 798import { BusinessError } from '@kit.BasicServicesKit'; 799import { image } from '@kit.ImageKit'; 800 801async function GetHdrComposedPixelmap() { 802 let funcName = "getHdrComposedPixelmap"; 803 if (pictureObj != null) { //图片包含Hdr图 804 let hdrComposedPixelmap: image.PixelMap = await pictureObj.getHdrComposedPixelmap(); 805 if (hdrComposedPixelmap != null) { 806 hdrComposedPixelmap.getImageInfo().then((imageInfo: image.ImageInfo) => { 807 if (imageInfo != null) { 808 console.info('GetHdrComposedPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width); 809 } 810 }).catch((error: BusinessError) => { 811 console.error(funcName, 'Failed error.code: ${error.code} ,error.message: ${error.message}'); 812 }); 813 } 814 } else { 815 console.info('PictureObj is null'); 816 } 817} 818``` 819 820### getGainmapPixelmap<sup>13+</sup> 821 822getGainmapPixelmap(): PixelMap | null 823 824获取增益图的pixelmap。 825 826**系统能力:** SystemCapability.Multimedia.Image.Core 827 828**返回值:** 829 830| 类型 | 说明 | 831| ------------------------- | -------------------------------------- | 832| [PixelMap](#pixelmap7) \| null | 返回Pixelmap对象,如果没有则返回null。 | 833 834**示例:** 835 836```ts 837import { BusinessError } from '@kit.BasicServicesKit'; 838import { image } from '@kit.ImageKit'; 839 840async function GetGainmapPixelmap() { 841 let funcName = "getGainmapPixelmap"; 842 if (pictureObj != null) { //图片包含增益图 843 let gainPixelmap: image.PixelMap | null = pictureObj.getGainmapPixelmap(); 844 if (gainPixelmap != null) { 845 gainPixelmap.getImageInfo().then((imageInfo: image.ImageInfo) => { 846 if (imageInfo != null) { 847 console.info('GetGainmapPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width); 848 } else { 849 console.info('GainPixelmap is null'); 850 } 851 }).catch((error: BusinessError) => { 852 console.error(funcName, 'Failed error.code: ${error.code} ,error.message: ${error.message}'); 853 }); 854 } else { 855 console.info('GainPixelmap is null'); 856 } 857 } else { 858 console.info('PictureObj is null'); 859 } 860} 861``` 862 863### setAuxiliaryPicture<sup>13+</sup> 864 865setAuxiliaryPicture(type: AuxiliaryPictureType, auxiliaryPicture: AuxiliaryPicture): void 866 867设置辅助图。 868 869**系统能力:** SystemCapability.Multimedia.Image.Core 870 871**参数:** 872 873| 参数名 | 类型 | 必填 | 说明 | 874| ---------------- | -------------------- | ---- | ------------ | 875| type | [AuxiliaryPictureType](#auxiliarypicturetype13) | 是 | 辅助图类型。 | 876| auxiliaryPicture | [AuxiliaryPicture](#auxiliarypicture13) | 是 | 辅助图对象。 | 877 878**错误码:** 879 880以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 881 882| 错误码ID | 错误信息 | 883| -------- | ------------------------------------------------------------ | 884| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 885 886**示例:** 887 888```ts 889import { image } from '@kit.ImageKit'; 890 891async function SetAuxiliaryPicture() { 892 const context = getContext(); 893 const resourceMgr = context.resourceManager; 894 const rawFile = await resourceMgr.getRawFileContent("hdr.jpg");//需要支持hdr的图片 895 let ops: image.SourceOptions = { 896 sourceDensity: 98, 897 } 898 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 899 let pixelMap: image.PixelMap = await imageSource.createPixelMap(); 900 let auxPicture: image.Picture = image.createPicture(pixelMap); 901 if (auxPicture != null) { 902 console.info('Create picture succeeded'); 903 } else { 904 console.info('Create picture failed'); 905 } 906 907 if (pictureObj != null) { 908 let type: image.AuxiliaryPictureType = image.AuxiliaryPictureType.GAINMAP; 909 let auxPictureObj: image.AuxiliaryPicture | null = await auxPicture.getAuxiliaryPicture(type); 910 if (auxPictureObj != null) { 911 pictureObj.setAuxiliaryPicture(type, auxPictureObj); 912 } 913 } 914} 915``` 916 917### getAuxiliaryPicture<sup>13+</sup> 918 919getAuxiliaryPicture(type: AuxiliaryPictureType): AuxiliaryPicture | null 920 921根据类型获取辅助图。 922 923**系统能力:** SystemCapability.Multimedia.Image.Core 924 925**参数:** 926 927| 参数名 | 类型 | 必填 | 说明 | 928| ------ | -------------------- | ---- | ------------ | 929| type | [AuxiliaryPictureType](#auxiliarypicturetype13) | 是 | 辅助图类型。 | 930 931**返回值:** 932 933| 类型 | 说明 | 934| ---------------------- | ---------------------------------------------- | 935| [AuxiliaryPicture](#auxiliarypicture13) \| null | 返回AuxiliaryPicture对象,如果没有则返回null。 | 936 937**错误码:** 938 939以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 940 941| 错误码ID | 错误信息 | 942| -------- | ------------------------------------------------------------ | 943| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 944 945**示例:** 946 947```ts 948import { image } from '@kit.ImageKit'; 949 950async function GetAuxiliaryPicture() { 951 if (pictureObj != null) { 952 let type: image.AuxiliaryPictureType = image.AuxiliaryPictureType.GAINMAP; 953 let auxPictureObj: image.AuxiliaryPicture | null = pictureObj.getAuxiliaryPicture(type); 954 } 955} 956``` 957 958### setMetadata<sup>13+</sup> 959 960setMetadata(metadataType: MetadataType, metadata: Metadata): Promise\<void> 961 962设置主图的元数据。 963 964**系统能力:** SystemCapability.Multimedia.Image.Core 965 966**参数:** 967 968| 参数名 | 类型 | 必填 | 说明 | 969| ------------ | ------------ | ---- | ------------ | 970| metadataType | [MetadataType](#metadatatype13) | 是 | 元数据类型。 | 971| metadata | [Metadata](#metadata13) | 是 | 元数据对象。 | 972 973**返回值:** 974 975| 类型 | 说明 | 976| -------------- | -------------------------------------- | 977| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 978 979**错误码:** 980 981以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 982 983| 错误码ID | 错误信息 | 984| -------- | ------------------------------------------------------------ | 985| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 986| 7600202 | Unsupported metadata. Possible causes: Unsupported metadata type. | 987 988**示例:** 989 990```ts 991import { BusinessError } from '@kit.BasicServicesKit'; 992import { image } from '@kit.ImageKit'; 993 994async function SetPictureObjMetadata() { 995 const exifContext = getContext(); 996 const exifResourceMgr = exifContext.resourceManager; 997 const exifRawFile = await exifResourceMgr.getRawFileContent("exif.jpg");//含有exif metadata的图片 998 let exifOps: image.SourceOptions = { 999 sourceDensity: 98, 1000 } 1001 let exifImageSource: image.ImageSource = image.createImageSource(exifRawFile.buffer as ArrayBuffer, exifOps); 1002 let exifCommodityPixelMap: image.PixelMap = await exifImageSource.createPixelMap(); 1003 let exifPictureObj: image.Picture = image.createPicture(exifCommodityPixelMap); 1004 if (exifPictureObj != null) { 1005 console.info('Create picture succeeded'); 1006 } else { 1007 console.info('Create picture failed'); 1008 } 1009 1010 if (pictureObj != null) { 1011 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 1012 let exifMetaData: image.Metadata = await exifPictureObj.getMetadata(metadataType); 1013 pictureObj.setMetadata(metadataType, exifMetaData).then(() => { 1014 console.info('Set metadata success'); 1015 }).catch((error: BusinessError) => { 1016 console.error('Failed to set metadata. error.code: ' +JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message)); 1017 }); 1018 } else { 1019 console.info('PictureObj is null'); 1020 } 1021} 1022``` 1023 1024### getMetadata<sup>13+</sup> 1025 1026getMetadata(metadataType: MetadataType): Promise\<Metadata> 1027 1028获取主图的元数据。 1029 1030**系统能力:** SystemCapability.Multimedia.Image.Core 1031 1032**参数:** 1033 1034| 参数名 | 类型 | 必填 | 说明 | 1035| ------------ | ------------ | ---- | ------------ | 1036| metadataType | [MetadataType](#metadatatype13) | 是 | 元数据类型。 | 1037 1038**返回值:** 1039 1040| 类型 | 说明 | 1041| ------------------ | ------------------------- | 1042| Promise\<[Metadata](#metadata13)> | Promise对象。返回元数据。 | 1043 1044**错误码:** 1045 1046以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 1047 1048| 错误码ID | 错误信息 | 1049| -------- | ------------------------------------------------------------ | 1050| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 1051| 7600202 | Unsupported metadata. Possible causes: Unsupported metadata type. | 1052 1053**示例:** 1054 1055```ts 1056import { image } from '@kit.ImageKit'; 1057 1058async function GetPictureObjMetadataProperties() { 1059 if (pictureObj != null) { 1060 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 1061 let pictureObjMetaData: image.Metadata = await pictureObj.getMetadata(metadataType); 1062 if (pictureObjMetaData != null) { 1063 console.info('get picture metadata success'); 1064 } else { 1065 console.info('get picture metadata is failed'); 1066 } 1067 } else { 1068 console.info(" pictureObj is null"); 1069 } 1070} 1071``` 1072 1073### marshalling<sup>13+</sup> 1074 1075marshalling(sequence: rpc.MessageSequence): void 1076 1077将picture序列化后写入MessageSequence。 1078 1079**系统能力:** SystemCapability.Multimedia.Image.Core 1080 1081**参数:** 1082 1083| 参数名 | 类型 | 必填 | 说明 | 1084| -------- | ------------------------------------------------------------------- | ---- | ------------------------- | 1085| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | 是 | 新创建的MessageSequence。 | 1086 1087**错误码:** 1088 1089以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 1090 1091| 错误码ID | 错误信息 | 1092| -------- | ------------------------------------------------------------ | 1093| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 1094| 62980097 | IPC error. | 1095 1096**示例:** 1097 1098```ts 1099import { BusinessError } from '@kit.BasicServicesKit'; 1100import { image } from '@kit.ImageKit'; 1101import { rpc } from '@kit.IPCKit'; 1102 1103class MySequence implements rpc.Parcelable { 1104 picture: image.Picture | null = null; 1105 constructor(conPicture: image.Picture) { 1106 this.picture = conPicture; 1107 } 1108 marshalling(messageSequence: rpc.MessageSequence) { 1109 if(this.picture != null) { 1110 this.picture.marshalling(messageSequence); 1111 console.info('Marshalling success !'); 1112 return true; 1113 } else { 1114 console.info('Marshalling failed !'); 1115 return false; 1116 } 1117 } 1118 unmarshalling(messageSequence : rpc.MessageSequence) { 1119 this.picture = image.createPictureFromParcel(messageSequence); 1120 this.picture.getMainPixelmap().getImageInfo().then((imageInfo : image.ImageInfo) => { 1121 console.info('Unmarshalling to get mainPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width); 1122 }).catch((error: BusinessError) => { 1123 console.error('Unmarshalling failed error.code: ${error.code} ,error.message: ${error.message}'); 1124 }); 1125 return true; 1126 } 1127} 1128 1129async function Marshalling_UnMarshalling() { 1130 if (pictureObj != null) { 1131 let parcelable: MySequence = new MySequence(pictureObj); 1132 let data: rpc.MessageSequence = rpc.MessageSequence.create(); 1133 // marshalling 1134 data.writeParcelable(parcelable); 1135 let ret: MySequence = new MySequence(pictureObj); 1136 // unmarshalling 1137 data.readParcelable(ret); 1138 } else { 1139 console.info('PictureObj is null'); 1140 } 1141} 1142``` 1143 1144### release<sup>13+</sup> 1145 1146release(): void 1147 1148释放picture对象。 1149 1150**系统能力:** SystemCapability.Multimedia.Image.Core 1151 1152**示例:** 1153 1154```ts 1155import { image } from '@kit.ImageKit'; 1156 1157async function Release() { 1158 let funcName = "Release"; 1159 if (pictureObj != null) { 1160 pictureObj.release(); 1161 if (pictureObj.getMainPixelmap() == null) { 1162 console.info(funcName, 'Success !'); 1163 } else { 1164 console.info(funcName, 'Failed !'); 1165 } 1166 } else { 1167 console.info('PictureObj is null'); 1168 } 1169} 1170``` 1171 1172## PixelMap<sup>7+</sup> 1173 1174图像像素类,用于读取或写入图像数据以及获取图像信息。在调用PixelMap的方法前,需要先通过[createPixelMap](#imagecreatepixelmap8)创建一个PixelMap实例。目前pixelmap序列化大小最大128MB,超过会送显失败。大小计算方式为(宽\*高\*每像素占用字节数)。 1175 1176从API version 11开始,PixelMap支持通过worker跨线程调用。当PixelMap通过[Worker](../apis-arkts/js-apis-worker.md)跨线程后,原线程的PixelMap的所有接口均不能调用,否则将报错501 服务器不具备完成请求的功能。 1177 1178在调用PixelMap的方法前,需要先通过[image.createPixelMap](#imagecreatepixelmap8)构建一个PixelMap对象。 1179 1180### 属性 1181 1182**系统能力:** SystemCapability.Multimedia.Image.Core 1183 1184| 名称 | 类型 | 可读 | 可写 | 说明 | 1185| -----------------| ------- | ---- | ---- | -------------------------- | 1186| isEditable | boolean | 是 | 否 | 设定是否图像像素可被编辑。 <br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 1187| isStrideAlignment<sup>11+</sup> | boolean | 是 | 否 | 设定图像内存是否为DMA内存。 | 1188 1189### readPixelsToBuffer<sup>7+</sup> 1190 1191readPixelsToBuffer(dst: ArrayBuffer): Promise\<void> 1192 1193按照PixelMap的像素格式,读取PixelMap的图像像素数据,并写入缓冲区中,使用Promise形式返回。 1194 1195**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 1196 1197**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1198 1199**系统能力:** SystemCapability.Multimedia.Image.Core 1200 1201**参数:** 1202 1203| 参数名 | 类型 | 必填 | 说明 | 1204| ------ | ----------- | ---- | ----------------------------------------------------------------------------------------------------- | 1205| dst | ArrayBuffer | 是 | 缓冲区,函数执行结束后获取的图像像素数据写入到该内存区域内。缓冲区大小由[getPixelBytesNumber](#getpixelbytesnumber7)接口获取。 | 1206 1207**返回值:** 1208 1209| 类型 | 说明 | 1210| -------------- | ----------------------------------------------- | 1211| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 1212 1213**示例:** 1214 1215```ts 1216import { BusinessError } from '@kit.BasicServicesKit'; 1217 1218async function ReadPixelsToBuffer() { 1219 const readBuffer: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4 1220 if (pixelMap != undefined) { 1221 pixelMap.readPixelsToBuffer(readBuffer).then(() => { 1222 console.info('Succeeded in reading image pixel data.'); // 符合条件则进入 1223 }).catch((error: BusinessError) => { 1224 console.error(`Failed to read image pixel data. code is ${error.code}, message is ${error.message}`);// 不符合条件则进入 1225 }) 1226 } 1227} 1228``` 1229 1230### readPixelsToBuffer<sup>7+</sup> 1231 1232readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\<void>): void 1233 1234按照PixelMap的像素格式,读取PixelMap的图像像素数据,并写入缓冲区中,使用callback形式返回。 1235 1236**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 1237 1238**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1239 1240**系统能力:** SystemCapability.Multimedia.Image.Core 1241 1242**参数:** 1243 1244| 参数名 | 类型 | 必填 | 说明 | 1245| -------- | -------------------- | ---- | ----------------------------------------------------------------------------------------------------- | 1246| dst | ArrayBuffer | 是 | 缓冲区,函数执行结束后获取的图像像素数据写入到该内存区域内。缓冲区大小由[getPixelBytesNumber](#getpixelbytesnumber7)接口获取。 | 1247| callback | AsyncCallback\<void> | 是 | 回调函数。当读取像素数据到ArrayBuffer成功,err为undefined,否则为错误对象。 | 1248 1249**示例:** 1250 1251```ts 1252import { BusinessError } from '@kit.BasicServicesKit'; 1253 1254async function ReadPixelsToBuffer() { 1255 const readBuffer: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4 1256 if (pixelMap != undefined) { 1257 pixelMap.readPixelsToBuffer(readBuffer, (error: BusinessError, res: void) => { 1258 if(error) { 1259 console.error(`Failed to read image pixel data. code is ${error.code}, message is ${error.message}`);// 不符合条件则进入 1260 return; 1261 } else { 1262 console.info('Succeeded in reading image pixel data.'); //符合条件则进入 1263 } 1264 }) 1265 } 1266} 1267``` 1268 1269### readPixelsToBufferSync<sup>12+</sup> 1270 1271readPixelsToBufferSync(dst: ArrayBuffer): void 1272 1273按照PixelMap的像素格式,读取PixelMap的图像像素数据,并写入缓冲区中,同步返回结果。 1274 1275**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 1276 1277**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1278 1279**系统能力:** SystemCapability.Multimedia.Image.Core 1280 1281**参数:** 1282 1283| 参数名 | 类型 | 必填 | 说明 | 1284| -------- | -------------------- | ---- | ----------------------------------------------------------------------------------------------------- | 1285| dst | ArrayBuffer | 是 | 缓冲区,函数执行结束后获取的图像像素数据写入到该内存区域内。缓冲区大小由[getPixelBytesNumber](#getpixelbytesnumber7)接口获取。 | 1286 1287**错误码:** 1288 1289以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 1290 1291| 错误码ID | 错误信息 | 1292| ------- | --------------------------------------------| 1293| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 1294| 501 | Resource Unavailable | 1295 1296**示例:** 1297 1298```ts 1299import { BusinessError } from '@kit.BasicServicesKit'; 1300 1301async function ReadPixelsToBufferSync() { 1302 const readBuffer: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4 1303 if (pixelMap != undefined) { 1304 pixelMap.readPixelsToBufferSync(readBuffer); 1305 } 1306} 1307``` 1308 1309### readPixels<sup>7+</sup> 1310 1311readPixels(area: PositionArea): Promise\<void> 1312 1313固定按照BGRA_8888格式,读取PixelMap指定区域内的图像像素数据,并写入[PositionArea](#positionarea7).pixels缓冲区中,该区域由[PositionArea](#positionarea7).region指定,使用Promise形式返回。 1314 1315可用公式计算PositionArea需要申请的内存大小。 1316 1317YUV的区域计算公式:读取区域(region.size{width * height})* 1.5 (1倍的Y分量+0.25倍U分量+0.25倍V分量) 1318 1319RGBA的区域计算公式:读取区域(region.size{width * height})* 4 (1倍的R分量+1倍G分量+1倍B分量+1倍A分量) 1320 1321**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 1322 1323**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1324 1325**系统能力:** SystemCapability.Multimedia.Image.Core 1326 1327**参数:** 1328 1329| 参数名 | 类型 | 必填 | 说明 | 1330| ------ | ------------------------------ | ---- | ------------------------ | 1331| area | [PositionArea](#positionarea7) | 是 | 区域大小,根据区域读取。 | 1332 1333**返回值:** 1334 1335| 类型 | 说明 | 1336| :------------- | :-------------------------------------------------- | 1337| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 1338 1339**示例:** 1340 1341```ts 1342import { BusinessError } from '@kit.BasicServicesKit'; 1343 1344async function ReadPixelsRGBA() { 1345 const area: image.PositionArea = { 1346 pixels: new ArrayBuffer(8), // 8为需要创建的像素buffer大小,取值为:height * width *4 1347 offset: 0, 1348 stride: 8, 1349 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 1350 }; 1351 if (pixelMap != undefined) { 1352 pixelMap.readPixels(area).then(() => { 1353 console.info('Succeeded in reading the image data in the area.'); //符合条件则进入 1354 }).catch((error: BusinessError) => { 1355 console.error(`Failed to read the image data in the area. code is ${error.code}, message is ${error.message}`);// 不符合条件则进入 1356 }) 1357 } 1358} 1359 1360async function ReadPixelsYUV() { 1361 const area: image.PositionArea = { 1362 pixels: new ArrayBuffer(6), // 6为需要创建的像素buffer大小,取值为:height * width *1.5 1363 offset: 0, 1364 stride: 8, 1365 region: { size: { height: 2, width: 2 }, x: 0, y: 0 } 1366 }; 1367 if (pixelMap != undefined) { 1368 pixelMap.readPixels(area).then(() => { 1369 console.info('Succeeded in reading the image data in the area.'); //符合条件则进入 1370 }).catch((error: BusinessError) => { 1371 console.error(`Failed to read the image data in the area. code is ${error.code}, message is ${error.message}`);// 不符合条件则进入 1372 }) 1373 } 1374} 1375``` 1376 1377### readPixels<sup>7+</sup> 1378 1379readPixels(area: PositionArea, callback: AsyncCallback\<void>): void 1380 1381固定按照BGRA_8888格式,读取PixelMap指定区域内的图像像素数据,并写入[PositionArea](#positionarea7).pixels缓冲区中,该区域由[PositionArea](#positionarea7).region指定,使用callback形式返回。 1382 1383可用公式计算PositionArea需要申请的内存大小。 1384 1385YUV的区域计算公式:读取区域(region.size{width * height})* 1.5 (1倍的Y分量+0.25倍U分量+0.25倍V分量) 1386 1387RGBA的区域计算公式:读取区域(region.size{width * height})* 4 (1倍的R分量+1倍G分量+1倍B分量+1倍A分量) 1388 1389**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 1390 1391**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1392 1393**系统能力:** SystemCapability.Multimedia.Image.Core 1394 1395**参数:** 1396 1397| 参数名 | 类型 | 必填 | 说明 | 1398| -------- | ------------------------------ | ---- | ------------------------------ | 1399| area | [PositionArea](#positionarea7) | 是 | 区域大小,根据区域读取。 | 1400| callback | AsyncCallback\<void> | 是 | 回调函数。当读取区域内的图片数据成功,err为undefined,否则为错误对象。 | 1401 1402**示例:** 1403 1404```ts 1405import { BusinessError } from '@kit.BasicServicesKit'; 1406 1407async function ReadPixelsRGBA() { 1408 const area: image.PositionArea = { 1409 pixels: new ArrayBuffer(8), // 8为需要创建的像素buffer大小,取值为:height * width *4 1410 offset: 0, 1411 stride: 8, 1412 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 1413 }; 1414 if (pixelMap != undefined) { 1415 pixelMap.readPixels(area, (error: BusinessError) => { 1416 if (error) { 1417 console.error(`Failed to read pixelmap from the specified area. code is ${error.code}, message is ${error.message}`); 1418 return; 1419 } else { 1420 console.info('Succeeded in reading pixelmap from the specified area.'); 1421 } 1422 }) 1423 } 1424} 1425 1426async function ReadPixelsYUV() { 1427 const area: image.PositionArea = { 1428 pixels: new ArrayBuffer(6), // 6为需要创建的像素buffer大小,取值为:height * width *1.5 1429 offset: 0, 1430 stride: 8, 1431 region: { size: { height: 2, width: 2 }, x: 0, y: 0 } 1432 }; 1433 if (pixelMap != undefined) { 1434 pixelMap.readPixels(area, (error: BusinessError) => { 1435 if (error) { 1436 console.error(`Failed to read pixelmap from the specified area. code is ${error.code}, message is ${error.message}`); 1437 return; 1438 } else { 1439 console.info('Succeeded in reading pixelmap from the specified area.'); 1440 } 1441 }) 1442 } 1443} 1444``` 1445 1446### readPixelsSync<sup>12+</sup> 1447 1448readPixelsSync(area: PositionArea): void 1449 1450固定按照BGRA_8888格式,读取PixelMap指定区域内的图像像素数据,并写入[PositionArea](#positionarea7).pixels缓冲区中,该区域由[PositionArea](#positionarea7).region指定,同步返回结果。 1451 1452**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1453 1454**系统能力:** SystemCapability.Multimedia.Image.Core 1455 1456**参数:** 1457 1458| 参数名 | 类型 | 必填 | 说明 | 1459| ------ | ------------------------------ | ---- | ------------------------ | 1460| area | [PositionArea](#positionarea7) | 是 | 区域大小,根据区域读取。 | 1461 1462**错误码:** 1463 1464以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 1465 1466| 错误码ID | 错误信息 | 1467| ------- | --------------------------------------------| 1468| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 1469| 501 | Resource Unavailable | 1470 1471**示例:** 1472 1473```ts 1474import { BusinessError } from '@kit.BasicServicesKit'; 1475 1476async function ReadPixelsSync() { 1477 const area : image.PositionArea = { 1478 pixels: new ArrayBuffer(8), 1479 offset: 0, 1480 stride: 8, 1481 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 1482 }; 1483 if (pixelMap != undefined) { 1484 pixelMap.readPixelsSync(area); 1485 } 1486} 1487``` 1488 1489### writePixels<sup>7+</sup> 1490 1491writePixels(area: PositionArea): Promise\<void> 1492 1493固定按照BGRA_8888格式,读取[PositionArea](#positionarea7).pixels缓冲区中的图像像素数据,并写入PixelMap指定区域内,该区域由[PositionArea](#positionarea7).region指定,使用Promise形式返回。 1494 1495可用公式计算PositionArea需要申请的内存大小。 1496 1497YUV的区域计算公式:读取区域(region.size{width * height})* 1.5 (1倍的Y分量+0.25倍U分量+0.25倍V分量) 1498 1499RGBA的区域计算公式:读取区域(region.size{width * height})* 4 (1倍的R分量+1倍G分量+1倍B分量+1倍A分量) 1500 1501**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 1502 1503**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1504 1505**系统能力:** SystemCapability.Multimedia.Image.Core 1506 1507**参数:** 1508 1509| 参数名 | 类型 | 必填 | 说明 | 1510| ------ | ------------------------------ | ---- | -------------------- | 1511| area | [PositionArea](#positionarea7) | 是 | 区域,根据区域写入。 | 1512 1513**返回值:** 1514 1515| 类型 | 说明 | 1516| :------------- | :-------------------------------------------------- | 1517| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 1518 1519**示例:** 1520 1521```ts 1522import { BusinessError } from '@kit.BasicServicesKit'; 1523 1524async function WritePixelsRGBA() { 1525 const area: image.PositionArea = { 1526 pixels: new ArrayBuffer(8), // 8为需要创建的像素buffer大小,取值为:height * width *4 1527 offset: 0, 1528 stride: 8, 1529 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 1530 }; 1531 let bufferArr: Uint8Array = new Uint8Array(area.pixels); 1532 for (let i = 0; i < bufferArr.length; i++) { 1533 bufferArr[i] = i + 1; 1534 } 1535 if (pixelMap != undefined) { 1536 pixelMap.writePixels(area).then(() => { 1537 console.info('Succeeded in writing pixelmap into the specified area.'); 1538 }).catch((error: BusinessError) => { 1539 console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`); 1540 }) 1541 } 1542} 1543 1544async function WritePixelsYUV() { 1545 const area: image.PositionArea = { 1546 pixels: new ArrayBuffer(6), // 6为需要创建的像素buffer大小,取值为:height * width *1.5 1547 offset: 0, 1548 stride: 8, 1549 region: { size: { height: 2, width: 2 }, x: 0, y: 0 } 1550 }; 1551 let bufferArr: Uint8Array = new Uint8Array(area.pixels); 1552 for (let i = 0; i < bufferArr.length; i++) { 1553 bufferArr[i] = i + 1; 1554 } 1555 if (pixelMap != undefined) { 1556 pixelMap.writePixels(area).then(() => { 1557 console.info('Succeeded in writing pixelmap into the specified area.'); 1558 }).catch((error: BusinessError) => { 1559 console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`); 1560 }) 1561 } 1562} 1563``` 1564 1565### writePixels<sup>7+</sup> 1566 1567writePixels(area: PositionArea, callback: AsyncCallback\<void>): void 1568 1569固定按照BGRA_8888格式,读取[PositionArea](#positionarea7).pixels缓冲区中的图像像素数据,并写入PixelMap指定区域内,该区域由[PositionArea](#positionarea7).region指定,使用callback形式返回。 1570 1571可用公式计算PositionArea需要申请的内存大小。 1572 1573YUV的区域计算公式:读取区域(region.size{width * height})* 1.5 (1倍的Y分量+0.25倍U分量+0.25倍V分量) 1574 1575RGBA的区域计算公式:读取区域(region.size{width * height})* 4 (1倍的R分量+1倍G分量+1倍B分量+1倍A分量) 1576 1577**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 1578 1579**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1580 1581**系统能力:** SystemCapability.Multimedia.Image.Core 1582 1583**参数:** 1584 1585| 参数名 | 类型 | 必填 | 说明 | 1586| --------- | ------------------------------ | ---- | ------------------------------ | 1587| area | [PositionArea](#positionarea7) | 是 | 区域,根据区域写入。 | 1588| callback | AsyncCallback\<void> | 是 | 回调函数,当写入成功,err为undefined,否则为错误对象。 | 1589 1590**示例:** 1591 1592```ts 1593import { BusinessError } from '@kit.BasicServicesKit'; 1594 1595async function WritePixelsRGBA() { 1596 const area: image.PositionArea = { pixels: new ArrayBuffer(8), // 8为需要创建的像素buffer大小,取值为:height * width *4 1597 offset: 0, 1598 stride: 8, 1599 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 1600 }; 1601 let bufferArr: Uint8Array = new Uint8Array(area.pixels); 1602 for (let i = 0; i < bufferArr.length; i++) { 1603 bufferArr[i] = i + 1; 1604 } 1605 if (pixelMap != undefined) { 1606 pixelMap.writePixels(area, (error : BusinessError) => { 1607 if (error) { 1608 console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`); 1609 return; 1610 } else { 1611 console.info('Succeeded in writing pixelmap into the specified area.'); 1612 } 1613 }) 1614 } 1615} 1616 1617async function WritePixelsYUV() { 1618 const area: image.PositionArea = { pixels: new ArrayBuffer(6), // 6为需要创建的像素buffer大小,取值为:height * width *1.5 1619 offset: 0, 1620 stride: 8, 1621 region: { size: { height: 2, width: 2 }, x: 0, y: 0 } 1622 }; 1623 let bufferArr: Uint8Array = new Uint8Array(area.pixels); 1624 for (let i = 0; i < bufferArr.length; i++) { 1625 bufferArr[i] = i + 1; 1626 } 1627 if (pixelMap != undefined) { 1628 pixelMap.writePixels(area, (error : BusinessError) => { 1629 if (error) { 1630 console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`); 1631 return; 1632 } else { 1633 console.info('Succeeded in writing pixelmap into the specified area.'); 1634 } 1635 }) 1636 } 1637} 1638``` 1639 1640### writePixelsSync<sup>12+</sup> 1641 1642writePixelsSync(area: PositionArea): void 1643 1644固定按照BGRA_8888格式,读取[PositionArea](#positionarea7).pixels缓冲区中的图像像素数据,并写入PixelMap指定区域内,该区域由[PositionArea](#positionarea7).region指定,同步回结果。 1645 1646**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 1647 1648**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1649 1650**系统能力:** SystemCapability.Multimedia.Image.Core 1651 1652**参数:** 1653 1654| 参数名 | 类型 | 必填 | 说明 | 1655| ------ | ------------------------------ | ---- | -------------------- | 1656| area | [PositionArea](#positionarea7) | 是 | 区域,根据区域写入。 | 1657 1658**错误码:** 1659 1660以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 1661 1662| 错误码ID | 错误信息 | 1663| ------- | --------------------------------------------| 1664| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 1665| 501 | Resource Unavailable | 1666 1667**示例:** 1668 1669```ts 1670import { BusinessError } from '@kit.BasicServicesKit'; 1671 1672async function WritePixelsSync() { 1673 const area: image.PositionArea = { 1674 pixels: new ArrayBuffer(8), 1675 offset: 0, 1676 stride: 8, 1677 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 1678 }; 1679 let bufferArr: Uint8Array = new Uint8Array(area.pixels); 1680 for (let i = 0; i < bufferArr.length; i++) { 1681 bufferArr[i] = i + 1; 1682 } 1683 if (pixelMap != undefined) { 1684 pixelMap.writePixelsSync(area); 1685 } 1686} 1687``` 1688 1689### writeBufferToPixels<sup>7+</sup> 1690 1691writeBufferToPixels(src: ArrayBuffer): Promise\<void> 1692 1693按照PixelMap的像素格式,读取缓冲区中的图像像素数据,并写入PixelMap,使用Promise形式返回。 1694 1695**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 1696 1697**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1698 1699**系统能力:** SystemCapability.Multimedia.Image.Core 1700 1701**参数:** 1702 1703| 参数名 | 类型 | 必填 | 说明 | 1704| ------ | ----------- | ---- | -------------- | 1705| src | ArrayBuffer | 是 | 缓冲区,函数执行时会将该缓冲区中的图像像素数据写入到PixelMap。缓冲区大小由[getPixelBytesNumber](#getpixelbytesnumber7)接口获取。 | 1706 1707**返回值:** 1708 1709| 类型 | 说明 | 1710| -------------- | ----------------------------------------------- | 1711| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 1712 1713**示例:** 1714 1715```ts 1716import { BusinessError } from '@kit.BasicServicesKit'; 1717 1718async function WriteBufferToPixels() { 1719 const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4 1720 let bufferArr: Uint8Array = new Uint8Array(color); 1721 for (let i = 0; i < bufferArr.length; i++) { 1722 bufferArr[i] = i + 1; 1723 } 1724 if (pixelMap != undefined) { 1725 pixelMap.writeBufferToPixels(color).then(() => { 1726 console.info("Succeeded in writing data from a buffer to a PixelMap."); 1727 }).catch((error: BusinessError) => { 1728 console.error(`Failed to write data from a buffer to a PixelMap. code is ${error.code}, message is ${error.message}`); 1729 }) 1730 } 1731} 1732``` 1733 1734### writeBufferToPixels<sup>7+</sup> 1735 1736writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\<void>): void 1737 1738按照PixelMap的像素格式,读取缓冲区中的图像像素数据,并写入PixelMap,使用callback形式返回。 1739 1740**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 1741 1742**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1743 1744**系统能力:** SystemCapability.Multimedia.Image.Core 1745 1746**参数:** 1747 1748| 参数名 | 类型 | 必填 | 说明 | 1749| -------- | -------------------- | ---- | ------------------------------ | 1750| src | ArrayBuffer | 是 | 缓冲区,函数执行时会将该缓冲区中的图像像素数据写入到PixelMap。缓冲区大小由[getPixelBytesNumber](#getpixelbytesnumber7)接口获取。 | 1751| callback | AsyncCallback\<void> | 是 | 回调函数。当缓冲区中的图像像素数据写入PixelMap成功,err为undefined,否则为错误对象。 | 1752 1753**示例:** 1754 1755```ts 1756import { BusinessError } from '@kit.BasicServicesKit'; 1757 1758async function WriteBufferToPixels() { 1759 const color: ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 1760 let bufferArr: Uint8Array = new Uint8Array(color); 1761 for (let i = 0; i < bufferArr.length; i++) { 1762 bufferArr[i] = i + 1; 1763 } 1764 if (pixelMap != undefined) { 1765 pixelMap.writeBufferToPixels(color, (error: BusinessError) => { 1766 if (error) { 1767 console.error(`Failed to write data from a buffer to a PixelMap. code is ${error.code}, message is ${error.message}`); 1768 return; 1769 } else { 1770 console.info("Succeeded in writing data from a buffer to a PixelMap."); 1771 } 1772 }) 1773 } 1774} 1775``` 1776 1777### writeBufferToPixelsSync<sup>12+</sup> 1778 1779writeBufferToPixelsSync(src: ArrayBuffer): void 1780 1781按照PixelMap的像素格式,读取缓冲区中的图像像素数据,并写入PixelMap,同步返回结果。 1782 1783**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1784 1785**系统能力:** SystemCapability.Multimedia.Image.Core 1786 1787**参数:** 1788 1789| 参数名 | 类型 | 必填 | 说明 | 1790| ------ | ----------- | ---- | -------------- | 1791| src | ArrayBuffer | 是 | 缓冲区,函数执行时会将该缓冲区中的图像像素数据写入到PixelMap。缓冲区大小由[getPixelBytesNumber](#getpixelbytesnumber7)接口获取。 | 1792 1793**错误码:** 1794 1795以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 1796 1797| 错误码ID | 错误信息 | 1798| ------- | --------------------------------------------| 1799| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 1800| 501 | Resource Unavailable | 1801 1802**示例:** 1803 1804```ts 1805import { BusinessError } from '@kit.BasicServicesKit'; 1806 1807async function WriteBufferToPixelsSync() { 1808 const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 1809 let bufferArr : Uint8Array = new Uint8Array(color); 1810 for (let i = 0; i < bufferArr.length; i++) { 1811 bufferArr[i] = i + 1; 1812 } 1813 if (pixelMap != undefined) { 1814 pixelMap.writeBufferToPixelsSync(color); 1815 } 1816} 1817``` 1818 1819 1820### getImageInfo<sup>7+</sup> 1821 1822getImageInfo(): Promise\<ImageInfo> 1823 1824获取图像像素信息,使用Promise形式返回获取的图像像素信息。 1825 1826**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 1827 1828**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1829 1830**系统能力:** SystemCapability.Multimedia.Image.Core 1831 1832**返回值:** 1833 1834| 类型 | 说明 | 1835| --------------------------------- | ----------------------------------------------------------- | 1836| Promise\<[ImageInfo](#imageinfo)> | Promise对象,返回图像像素信息。 | 1837 1838**示例:** 1839 1840```ts 1841import { BusinessError } from '@kit.BasicServicesKit'; 1842 1843async function GetImageInfo() { 1844 if (pixelMap != undefined) { 1845 pixelMap.getImageInfo().then((imageInfo: image.ImageInfo) => { 1846 if (imageInfo != undefined) { 1847 console.info("Succeeded in obtaining the image pixel map information."+ imageInfo.size.height); 1848 } 1849 }).catch((error: BusinessError) => { 1850 console.error(`Failed to obtain the image pixel map information. code is ${error.code}, message is ${error.message}`); 1851 }) 1852 } 1853} 1854``` 1855 1856### getImageInfo<sup>7+</sup> 1857 1858getImageInfo(callback: AsyncCallback\<ImageInfo>): void 1859 1860获取图像像素信息,使用callback形式返回获取的图像像素信息。 1861 1862**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 1863 1864**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1865 1866**系统能力:** SystemCapability.Multimedia.Image.Core 1867 1868**参数:** 1869 1870| 参数名 | 类型 | 必填 | 说明 | 1871| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | 1872| callback | AsyncCallback\<[ImageInfo](#imageinfo)> | 是 | 回调函数。当获取图像像素信息成功,err为undefined,data为获取到的图像像素信息;否则为错误对象。 | 1873 1874**示例:** 1875 1876```ts 1877import { BusinessError } from '@kit.BasicServicesKit'; 1878 1879async function GetImageInfo() { 1880 if (pixelMap != undefined) { 1881 pixelMap.getImageInfo((error: BusinessError, imageInfo: image.ImageInfo) => { 1882 if (error) { 1883 console.error(`Failed to obtain the image pixel map information. code is ${error.code}, message is ${error.message}`); 1884 return; 1885 } else { 1886 console.info("Succeeded in obtaining the image pixel map information."+ imageInfo.size.height); 1887 } 1888 }) 1889 } 1890} 1891``` 1892 1893### getImageInfoSync<sup>12+</sup> 1894 1895getImageInfoSync(): ImageInfo 1896 1897以同步方法获取图像像素信息。 1898 1899**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 1900 1901**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1902 1903**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1904 1905**返回值:** 1906 1907| 类型 | 说明 | 1908| --------------------------------- | ----------------------------------------------------------- | 1909| [ImageInfo](#imageinfo) | 图像像素信息 | 1910 1911**错误码:** 1912 1913以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 1914 1915| 错误码ID | 错误信息 | 1916| ------- | --------------------------------------------| 1917| 501 | Resource Unavailable | 1918 1919**示例:** 1920 1921```ts 1922import { BusinessError } from '@kit.BasicServicesKit'; 1923 1924async function GetImageInfoSync() { 1925 if (pixelMap != undefined) { 1926 let imageInfo : image.ImageInfo = pixelMap.getImageInfoSync(); 1927 return imageInfo; 1928 } 1929 return undefined; 1930} 1931``` 1932 1933### getBytesNumberPerRow<sup>7+</sup> 1934 1935getBytesNumberPerRow(): number 1936 1937获取图像像素每行字节数。 1938 1939**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 1940 1941**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1942 1943**系统能力:** SystemCapability.Multimedia.Image.Core 1944 1945**返回值:** 1946 1947| 类型 | 说明 | 1948| ------ | -------------------- | 1949| number | 图像像素的行字节数。 | 1950 1951**示例:** 1952 1953```ts 1954let rowCount: number = pixelMap.getBytesNumberPerRow(); 1955``` 1956 1957### getPixelBytesNumber<sup>7+</sup> 1958 1959getPixelBytesNumber(): number 1960 1961获取图像像素的总字节数。 1962 1963**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 1964 1965**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1966 1967**系统能力:** SystemCapability.Multimedia.Image.Core 1968 1969**返回值:** 1970 1971| 类型 | 说明 | 1972| ------ | -------------------- | 1973| number | 图像像素的总字节数。 | 1974 1975**示例:** 1976 1977```ts 1978let pixelBytesNumber: number = pixelMap.getPixelBytesNumber(); 1979``` 1980 1981### getDensity<sup>9+</sup> 1982 1983getDensity():number 1984 1985获取当前图像像素的密度。 1986 1987**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 1988 1989**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1990 1991**系统能力:** SystemCapability.Multimedia.Image.Core 1992 1993**返回值:** 1994 1995| 类型 | 说明 | 1996| ------ | --------------- | 1997| number | 图像像素的密度。| 1998 1999**示例:** 2000 2001```ts 2002let getDensity: number = pixelMap.getDensity(); 2003``` 2004 2005### opacity<sup>9+</sup> 2006 2007opacity(rate: number, callback: AsyncCallback\<void>): void 2008 2009通过设置透明比率来让PixelMap达到对应的透明效果,yuv图片不支持设置透明度,使用callback形式返回。 2010 2011**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 2012 2013**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2014 2015**系统能力:** SystemCapability.Multimedia.Image.Core 2016 2017**参数:** 2018 2019| 参数名 | 类型 | 必填 | 说明 | 2020| -------- | -------------------- | ---- | ------------------------------ | 2021| rate | number | 是 | 透明比率的值。 | 2022| callback | AsyncCallback\<void> | 是 | 回调函数。当设置透明比率成功,err为undefined,否则为错误对象。 | 2023 2024**示例:** 2025 2026```ts 2027import { BusinessError } from '@kit.BasicServicesKit'; 2028 2029async function Opacity() { 2030 let rate: number = 0.5; 2031 if (pixelMap != undefined) { 2032 pixelMap.opacity(rate, (err: BusinessError) => { 2033 if (err) { 2034 console.error(`Failed to set opacity. code is ${err.code}, message is ${err.message}`); 2035 return; 2036 } else { 2037 console.info("Succeeded in setting opacity."); 2038 } 2039 }) 2040 } 2041} 2042``` 2043 2044### opacity<sup>9+</sup> 2045 2046opacity(rate: number): Promise\<void> 2047 2048通过设置透明比率来让PixelMap达到对应的透明效果,yuv图片不支持设置透明度,使用Promise形式返回。 2049 2050**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 2051 2052**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2053 2054**系统能力:** SystemCapability.Multimedia.Image.Core 2055 2056**参数:** 2057 2058| 参数名 | 类型 | 必填 | 说明 | 2059| ------ | ------ | ---- | --------------------------- | 2060| rate | number | 是 | 透明比率的值。| 2061 2062**返回值:** 2063 2064| 类型 | 说明 | 2065| -------------- | ----------------------------------------------- | 2066| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 2067 2068**示例:** 2069 2070```ts 2071import { BusinessError } from '@kit.BasicServicesKit'; 2072 2073async function Opacity() { 2074 let rate: number = 0.5; 2075 if (pixelMap != undefined) { 2076 pixelMap.opacity(rate).then(() => { 2077 console.info('Succeeded in setting opacity.'); 2078 }).catch((err: BusinessError) => { 2079 console.error(`Failed to set opacity. code is ${err.code}, message is ${err.message}`); 2080 }) 2081 } 2082} 2083``` 2084 2085### opacitySync<sup>12+</sup> 2086 2087opacitySync(rate: number): void 2088 2089设置PixelMap的透明比率,yuv图片不支持设置透明度,初始化PixelMap并同步返回结果。 2090 2091**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2092 2093**系统能力:** SystemCapability.Multimedia.Image.Core 2094 2095**参数:** 2096 2097| 参数名 | 类型 | 必填 | 说明 | 2098| -------- | -------------------- | ---- | ------------------------------ | 2099| rate | number | 是 | 透明比率的值。 | 2100 2101**错误码:** 2102 2103以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 2104 2105| 错误码ID | 错误信息 | 2106| ------- | --------------------------------------------| 2107| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2108| 501 | Resource Unavailable | 2109 2110**示例:** 2111 2112```ts 2113import { BusinessError } from '@kit.BasicServicesKit'; 2114 2115async function OpacitySync() { 2116 let rate : number = 0.5; 2117 if (pixelMap != undefined) { 2118 pixelMap.opacitySync(rate); 2119 } 2120} 2121``` 2122 2123### createAlphaPixelmap<sup>9+</sup> 2124 2125createAlphaPixelmap(): Promise\<PixelMap> 2126 2127根据Alpha通道的信息,来生成一个仅包含Alpha通道信息的pixelmap,可用于阴影效果,yuv格式不支持此接口,使用Promise形式返回。 2128 2129**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 2130 2131**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2132 2133**系统能力:** SystemCapability.Multimedia.Image.Core 2134 2135**返回值:** 2136 2137| 类型 | 说明 | 2138| -------------------------------- | --------------------------- | 2139| Promise\<[PixelMap](#pixelmap7)> | Promise对象,返回PixelMap。 | 2140 2141**示例:** 2142 2143```ts 2144import { BusinessError } from '@kit.BasicServicesKit'; 2145 2146async function CreateAlphaPixelmap() { 2147 if (pixelMap != undefined) { 2148 pixelMap.createAlphaPixelmap().then((alphaPixelMap: image.PixelMap) => { 2149 console.info('Succeeded in creating alpha pixelmap.'); 2150 }).catch((error: BusinessError) => { 2151 console.error(`Failed to create alpha pixelmap. code is ${error.code}, message is ${error.message}`); 2152 }) 2153 } 2154} 2155``` 2156 2157### createAlphaPixelmap<sup>9+</sup> 2158 2159createAlphaPixelmap(callback: AsyncCallback\<PixelMap>): void 2160 2161根据Alpha通道的信息,来生成一个仅包含Alpha通道信息的pixelmap,可用于阴影效果,yuv格式不支持此接口,使用callback形式返回。 2162 2163**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 2164 2165**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2166 2167**系统能力:** SystemCapability.Multimedia.Image.Core 2168 2169**参数:** 2170 2171| 参数名 | 类型 | 必填 | 说明 | 2172| -------- | ------------------------ | ---- | ------------------------ | 2173| callback | AsyncCallback\<[PixelMap](#pixelmap7)> | 是 | 回调函数,当创建PixelMap成功,err为undefined,data为获取到的PixelMap对象;否则为错误对象。 | 2174 2175**示例:** 2176 2177```ts 2178import { BusinessError } from '@kit.BasicServicesKit'; 2179 2180async function CreateAlphaPixelmap() { 2181 if (pixelMap != undefined) { 2182 pixelMap.createAlphaPixelmap((err: BusinessError, alphaPixelMap: image.PixelMap) => { 2183 if (alphaPixelMap == undefined) { 2184 console.error(`Failed to obtain new pixel map. code is ${err.code}, message is ${err.message}`); 2185 return; 2186 } else { 2187 console.info('Succeeded in obtaining new pixel map.'); 2188 } 2189 }) 2190 } 2191} 2192``` 2193 2194### createAlphaPixelmapSync<sup>12+</sup> 2195 2196createAlphaPixelmapSync(): PixelMap 2197 2198根据Alpha通道的信息,生成一个仅包含Alpha通道信息的PixelMap,可用于阴影效果,yuv格式不支持此接口,同步返回PixelMap类型的结果。 2199 2200**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2201 2202**系统能力:** SystemCapability.Multimedia.Image.Core 2203 2204**返回值:** 2205 2206| 类型 | 说明 | 2207| -------------------------------- | --------------------- | 2208| [PixelMap](#pixelmap7) | 成功同步返回PixelMap对象,失败抛出异常。 | 2209 2210**错误码:** 2211 2212以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 2213 2214| 错误码ID | 错误信息 | 2215| ------- | --------------------------------------------| 2216| 401 | Parameter error. Possible causes: 1.Parameter verification failed | 2217| 501 | Resource Unavailable | 2218 2219**示例:** 2220 2221```ts 2222import { BusinessError } from '@kit.BasicServicesKit'; 2223 2224async function CreateAlphaPixelmapSync() { 2225 if (pixelMap != undefined) { 2226 let pixelmap : image.PixelMap = pixelMap.createAlphaPixelmapSync(); 2227 return pixelmap; 2228 } 2229 return undefined; 2230} 2231``` 2232 2233### scale<sup>9+</sup> 2234 2235scale(x: number, y: number, callback: AsyncCallback\<void>): void 2236 2237根据输入的宽高的缩放倍数对图片进行缩放,使用callback形式返回。 2238 2239> **说明:** 2240> 1. 建议宽高的缩放倍数取非负数,否则会产生翻转效果。 2241> 2. 宽高的缩放倍数 = 缩放后的图片宽高 / 缩放前的图片宽高 2242 2243**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 2244 2245**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2246 2247**系统能力:** SystemCapability.Multimedia.Image.Core 2248 2249**参数:** 2250 2251| 参数名 | 类型 | 必填 | 说明 | 2252| -------- | -------------------- | ---- | ------------------------------- | 2253| x | number | 是 | 宽度的缩放倍数。| 2254| y | number | 是 | 高度的缩放倍数。| 2255| callback | AsyncCallback\<void> | 是 | 回调函数。当对图片进行缩放成功,err为undefined,否则为错误对象。 | 2256 2257**示例:** 2258 2259```ts 2260import { BusinessError } from '@kit.BasicServicesKit'; 2261 2262async function Scale() { 2263 let scaleX: number = 2.0; 2264 let scaleY: number = 1.0; 2265 if (pixelMap != undefined) { 2266 pixelMap.scale(scaleX, scaleY, (err: BusinessError) => { 2267 if (err) { 2268 console.error(`Failed to scale pixelmap. code is ${err.code}, message is ${err.message}`); 2269 return; 2270 } else { 2271 console.info("Succeeded in scaling pixelmap."); 2272 } 2273 }) 2274 } 2275} 2276``` 2277 2278### scale<sup>9+</sup> 2279 2280scale(x: number, y: number): Promise\<void> 2281 2282根据输入的宽高的缩放倍数对图片进行缩放,使用Promise形式返回。 2283 2284> **说明:** 2285> 1. 建议宽高的缩放倍数取非负数,否则会产生翻转效果。 2286> 2. 宽高的缩放倍数 = 缩放后的图片宽高 / 缩放前的图片宽高 2287 2288**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 2289 2290**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2291 2292**系统能力:** SystemCapability.Multimedia.Image.Core 2293 2294**参数:** 2295 2296| 参数名 | 类型 | 必填 | 说明 | 2297| ------ | ------ | ---- | ------------------------------- | 2298| x | number | 是 | 宽度的缩放倍数。| 2299| y | number | 是 | 高度的缩放倍数。| 2300 2301**返回值:** 2302 2303| 类型 | 说明 | 2304| -------------- | --------------------------- | 2305| Promise\<void> | Promise对象。无返回结果的Promise对象。| 2306 2307**示例:** 2308 2309```ts 2310import { BusinessError } from '@kit.BasicServicesKit'; 2311 2312async function Scale() { 2313 let scaleX: number = 2.0; 2314 let scaleY: number = 1.0; 2315 if (pixelMap != undefined) { 2316 pixelMap.scale(scaleX, scaleY).then(() => { 2317 console.info('Succeeded in scaling pixelmap.'); 2318 }).catch((err: BusinessError) => { 2319 console.error(`Failed to scale pixelmap. code is ${err.code}, message is ${err.message}`); 2320 2321 }) 2322 } 2323} 2324``` 2325 2326### scaleSync<sup>12+</sup> 2327 2328scaleSync(x: number, y: number): void 2329 2330根据输入的宽高的缩放倍数对图片进行缩放,同步返回结果。 2331 2332> **说明:** 2333> 1. 建议宽高的缩放倍数取非负数,否则会产生翻转效果。 2334> 2. 宽高的缩放倍数 = 缩放后的图片宽高 / 缩放前的图片宽高 2335 2336**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2337 2338**系统能力:** SystemCapability.Multimedia.Image.Core 2339 2340**参数:** 2341 2342| 参数名 | 类型 | 必填 | 说明 | 2343| ------ | ------ | ---- | ------------------------------- | 2344| x | number | 是 | 宽度的缩放倍数。| 2345| y | number | 是 | 高度的缩放倍数。| 2346 2347**错误码:** 2348 2349以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 2350 2351| 错误码ID | 错误信息 | 2352| ------- | --------------------------------------------| 2353| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2354| 501 | Resource Unavailable | 2355 2356**示例:** 2357 2358```ts 2359import { BusinessError } from '@kit.BasicServicesKit'; 2360 2361async function ScaleSync() { 2362 let scaleX: number = 2.0; 2363 let scaleY: number = 1.0; 2364 if (pixelMap != undefined) { 2365 pixelMap.scaleSync(scaleX, scaleY); 2366 } 2367} 2368``` 2369 2370### scale<sup>12+</sup> 2371 2372scale(x: number, y: number, level: AntiAliasingLevel): Promise\<void> 2373 2374根据指定的缩放算法和输入的宽高的缩放倍数对图片进行缩放,使用Promise形式返回。 2375 2376> **说明:** 2377> 1. 建议宽高的缩放倍数取非负数,否则会产生翻转效果。 2378> 2. 宽高的缩放倍数 = 缩放后的图片宽高 / 缩放前的图片宽高 2379 2380**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 2381 2382**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2383 2384**系统能力:** SystemCapability.Multimedia.Image.Core 2385 2386**参数:** 2387 2388| 参数名 | 类型 | 必填 | 说明 | 2389| ------ | ------ | ---- | ------------------------------- | 2390| x | number | 是 | 宽度的缩放倍数。| 2391| y | number | 是 | 高度的缩放倍数。| 2392| level | [AntiAliasingLevel](#antialiasinglevel12) | 是 | 采用的缩放算法。| 2393 2394**返回值:** 2395 2396| 类型 | 说明 | 2397| -------------- | --------------------------- | 2398| Promise\<void> | Promise对象。无返回结果的Promise对象。| 2399 2400**错误码:** 2401 2402以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 2403 2404| 错误码ID | 错误信息 | 2405| ------- | --------------------------------------------| 2406| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2407| 501 | Resource Unavailable | 2408 2409**示例:** 2410 2411```ts 2412import { BusinessError } from '@kit.BasicServicesKit'; 2413 2414async function Scale() { 2415 let scaleX: number = 2.0; 2416 let scaleY: number = 1.0; 2417 if (pixelMap != undefined) { 2418 pixelMap.scale(scaleX, scaleY, image.AntiAliasingLevel.LOW).then(() => { 2419 console.info('Succeeded in scaling pixelmap.'); 2420 }).catch((err: BusinessError) => { 2421 console.error(`Failed to scale pixelmap. code is ${err.code}, message is ${err.message}`); 2422 2423 }) 2424 } 2425} 2426``` 2427 2428### scaleSync<sup>12+</sup> 2429 2430scaleSync(x: number, y: number, level: AntiAliasingLevel): void 2431 2432根据指定的缩放算法和输入的宽高的缩放倍数对图片进行缩放,同步返回结果。 2433 2434> **说明:** 2435> 1. 建议宽高的缩放倍数取非负数,否则会产生翻转效果。 2436> 2. 宽高的缩放倍数 = 缩放后的图片宽高 / 缩放前的图片宽高 2437 2438**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2439 2440**系统能力:** SystemCapability.Multimedia.Image.Core 2441 2442**参数:** 2443 2444| 参数名 | 类型 | 必填 | 说明 | 2445| ------ | ------ | ---- | ------------------------------- | 2446| x | number | 是 | 宽度的缩放倍数。| 2447| y | number | 是 | 高度的缩放倍数。| 2448| level | [AntiAliasingLevel](#antialiasinglevel12) | 是 | 采用的缩放算法。| 2449 2450**错误码:** 2451 2452以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 2453 2454| 错误码ID | 错误信息 | 2455| ------- | --------------------------------------------| 2456| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2457| 501 | Resource Unavailable | 2458 2459**示例:** 2460 2461```ts 2462import { BusinessError } from '@kit.BasicServicesKit'; 2463 2464async function ScaleSync() { 2465 let scaleX: number = 2.0; 2466 let scaleY: number = 1.0; 2467 if (pixelMap != undefined) { 2468 pixelMap.scaleSync(scaleX, scaleY, image.AntiAliasingLevel.LOW); 2469 } 2470} 2471``` 2472 2473### translate<sup>9+</sup> 2474 2475translate(x: number, y: number, callback: AsyncCallback\<void>): void 2476 2477根据输入的坐标对图片进行位置变换,使用callback形式返回。 2478 2479translate后的图片尺寸改变为:width+X ,height+Y,建议translate后的图片尺寸宽高不要超过屏幕的宽高。 2480 2481**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 2482 2483**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2484 2485**系统能力:** SystemCapability.Multimedia.Image.Core 2486 2487**参数:** 2488 2489| 参数名 | 类型 | 必填 | 说明 | 2490| -------- | -------------------- | ---- | ----------------------------- | 2491| x | number | 是 | 区域横坐标。单位:像素。 | 2492| y | number | 是 | 区域纵坐标。单位:像素。 | 2493| callback | AsyncCallback\<void> | 是 | 回调函数。当对图片进行位置变换成功,err为undefined,否则为错误对象。| 2494 2495**示例:** 2496 2497```ts 2498import { BusinessError } from '@kit.BasicServicesKit'; 2499 2500async function Translate() { 2501 let translateX: number = 50.0; 2502 let translateY: number = 10.0; 2503 if (pixelMap != undefined) { 2504 pixelMap.translate(translateX, translateY, (err: BusinessError) => { 2505 if (err) { 2506 console.error(`Failed to translate pixelmap. code is ${err.code}, message is ${err.message}`); 2507 return; 2508 } else { 2509 console.info("Succeeded in translating pixelmap."); 2510 } 2511 }) 2512 } 2513} 2514``` 2515 2516### translate<sup>9+</sup> 2517 2518translate(x: number, y: number): Promise\<void> 2519 2520根据输入的坐标对图片进行位置变换,使用Promise形式返回。 2521 2522translate后的图片尺寸改变为:width+X ,height+Y,建议translate后的图片尺寸宽高不要超过屏幕的宽高。 2523 2524**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 2525 2526**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2527 2528**系统能力:** SystemCapability.Multimedia.Image.Core 2529 2530**参数:** 2531 2532| 参数名 | 类型 | 必填 | 说明 | 2533| ------ | ------ | ---- | ----------- | 2534| x | number | 是 | 区域横坐标。单位:像素。 | 2535| y | number | 是 | 区域纵坐标。单位:像素。 | 2536 2537**返回值:** 2538 2539| 类型 | 说明 | 2540| -------------- | --------------------------- | 2541| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 2542 2543**示例:** 2544 2545```ts 2546import { BusinessError } from '@kit.BasicServicesKit'; 2547 2548async function Translate() { 2549 let translateX: number = 50.0; 2550 let translateY: number = 10.0; 2551 if (pixelMap != undefined) { 2552 pixelMap.translate(translateX, translateY).then(() => { 2553 console.info('Succeeded in translating pixelmap.'); 2554 }).catch((err: BusinessError) => { 2555 console.error(`Failed to translate pixelmap. code is ${err.code}, message is ${err.message}`); 2556 }) 2557 } 2558} 2559``` 2560 2561### translateSync<sup>12+</sup> 2562 2563translateSync(x: number, y: number): void 2564 2565根据输入的坐标对图片进行位置变换,同步返回结果。 2566 2567translate后的图片尺寸改变为:width+X ,height+Y,建议translate后的图片尺寸宽高不要超过屏幕的宽高。 2568 2569**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2570 2571**系统能力:** SystemCapability.Multimedia.Image.Core 2572 2573**参数:** 2574 2575| 参数名 | 类型 | 必填 | 说明 | 2576| -------- | -------------------- | ---- | ------------------------------- | 2577| x | number | 是 | 区域横坐标。单位:像素。 | 2578| y | number | 是 | 区域纵坐标。单位:像素。 | 2579 2580**错误码:** 2581 2582以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 2583 2584| 错误码ID | 错误信息 | 2585| ------- | --------------------------------------------| 2586| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2587| 501 | Resource Unavailable | 2588 2589**示例:** 2590 2591```ts 2592import { BusinessError } from '@kit.BasicServicesKit'; 2593 2594async function TranslateSync() { 2595 let translateX : number = 50.0; 2596 let translateY : number = 10.0; 2597 if (pixelMap != undefined) { 2598 pixelMap.translateSync(translateX, translateY); 2599 } 2600} 2601``` 2602 2603### rotate<sup>9+</sup> 2604 2605rotate(angle: number, callback: AsyncCallback\<void>): void 2606 2607根据输入的角度对图片进行旋转,使用callback形式返回。 2608 2609> **说明:** 2610> 1. 图片旋转的角度取值范围:0-360。超出取值范围时,根据圆周360度自动矫正。例如,-100度与260度效果相同。 2611> 2. 如果图片旋转的角度不是90的整数倍,旋转后图片的尺寸会发生改变。 2612 2613**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 2614 2615**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2616 2617**系统能力:** SystemCapability.Multimedia.Image.Core 2618 2619**参数:** 2620 2621| 参数名 | 类型 | 必填 | 说明 | 2622| -------- | -------------------- | ---- | ----------------------------- | 2623| angle | number | 是 | 图片旋转的角度。 | 2624| callback | AsyncCallback\<void> | 是 | 回调函数。当对图片进行旋转成功,err为undefined,否则为错误对象。| 2625 2626**示例:** 2627 2628```ts 2629import { BusinessError } from '@kit.BasicServicesKit'; 2630 2631async function Rotate() { 2632 let angle: number = 90.0; 2633 if (pixelMap != undefined) { 2634 pixelMap.rotate(angle, (err: BusinessError) => { 2635 if (err) { 2636 console.error(`Failed to rotate pixelmap. code is ${err.code}, message is ${err.message}`); 2637 return; 2638 } else { 2639 console.info("Succeeded in rotating pixelmap."); 2640 } 2641 }) 2642 } 2643} 2644``` 2645 2646### rotate<sup>9+</sup> 2647 2648rotate(angle: number): Promise\<void> 2649 2650根据输入的角度对图片进行旋转,使用Promise形式返回。 2651 2652> **说明:** 2653> 1. 图片旋转的角度取值范围:0-360。超出取值范围时,根据圆周360度自动矫正。例如,-100度与260度效果相同。 2654> 2. 如果图片旋转的角度不是90的整数倍,旋转后图片的尺寸会发生改变。 2655 2656**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 2657 2658**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2659 2660**系统能力:** SystemCapability.Multimedia.Image.Core 2661 2662**参数:** 2663 2664| 参数名 | 类型 | 必填 | 说明 | 2665| ------ | ------ | ---- | ----------------------------- | 2666| angle | number | 是 | 图片旋转的角度。 | 2667 2668**返回值:** 2669 2670| 类型 | 说明 | 2671| -------------- | --------------------------- | 2672| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 2673 2674**示例:** 2675 2676```ts 2677import { BusinessError } from '@kit.BasicServicesKit'; 2678 2679async function Rotate() { 2680 let angle: number = 90.0; 2681 if (pixelMap != undefined) { 2682 pixelMap.rotate(angle).then(() => { 2683 console.info('Succeeded in rotating pixelmap.'); 2684 }).catch((err: BusinessError) => { 2685 console.error(`Failed to rotate pixelmap. code is ${err.code}, message is ${err.message}`); 2686 }) 2687 } 2688} 2689``` 2690 2691### rotateSync<sup>12+</sup> 2692 2693rotateSync(angle: number): void 2694 2695根据输入的角度对图片进行旋转,同步返回结果。 2696 2697> **说明:** 2698> 1. 图片旋转的角度取值范围:0-360。超出取值范围时,根据圆周360度自动矫正。例如,-100度与260度效果相同。 2699> 2. 如果图片旋转的角度不是90的整数倍,旋转后图片的尺寸会发生改变。 2700 2701**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2702 2703**系统能力:** SystemCapability.Multimedia.Image.Core 2704 2705**参数:** 2706 2707| 参数名 | 类型 | 必填 | 说明 | 2708| -------- | -------------------- | ---- | ----------------------------- | 2709| angle | number | 是 | 图片旋转的角度。 | 2710 2711**错误码:** 2712 2713以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 2714 2715| 错误码ID | 错误信息 | 2716| ------- | --------------------------------------------| 2717| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2718| 501 | Resource Unavailable | 2719 2720**示例:** 2721 2722```ts 2723import { BusinessError } from '@kit.BasicServicesKit'; 2724 2725async function RotateSync() { 2726 let angle : number = 90.0; 2727 if (pixelMap != undefined) { 2728 pixelMap.rotateSync(angle); 2729 } 2730} 2731``` 2732 2733### flip<sup>9+</sup> 2734 2735flip(horizontal: boolean, vertical: boolean, callback: AsyncCallback\<void>): void 2736 2737根据输入的条件对图片进行翻转,使用callback形式返回。 2738 2739**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 2740 2741**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2742 2743**系统能力:** SystemCapability.Multimedia.Image.Core 2744 2745**参数:** 2746 2747| 参数名 | 类型 | 必填 | 说明 | 2748| ---------- | -------------------- | ---- | ----------------------------- | 2749| horizontal | boolean | 是 | 水平翻转。 | 2750| vertical | boolean | 是 | 垂直翻转。 | 2751| callback | AsyncCallback\<void> | 是 | 回调函数,当对图片翻转成功,err为undefined,否则为错误对象。| 2752 2753**示例:** 2754 2755```ts 2756import { BusinessError } from '@kit.BasicServicesKit'; 2757 2758async function Flip() { 2759 let horizontal: boolean = true; 2760 let vertical: boolean = false; 2761 if (pixelMap != undefined) { 2762 pixelMap.flip(horizontal, vertical, (err: BusinessError) => { 2763 if (err) { 2764 console.error(`Failed to flip pixelmap. code is ${err.code}, message is ${err.message}`); 2765 return; 2766 } else { 2767 console.info("Succeeded in flipping pixelmap."); 2768 } 2769 }) 2770 } 2771} 2772``` 2773 2774### flip<sup>9+</sup> 2775 2776flip(horizontal: boolean, vertical: boolean): Promise\<void> 2777 2778根据输入的条件对图片进行翻转,使用Promise形式返回。 2779 2780**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 2781 2782**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2783 2784**系统能力:** SystemCapability.Multimedia.Image.Core 2785 2786**参数:** 2787 2788| 参数名 | 类型 | 必填 | 说明 | 2789| ---------- | ------- | ---- | --------- | 2790| horizontal | boolean | 是 | 水平翻转。| 2791| vertical | boolean | 是 | 垂直翻转。| 2792 2793**返回值:** 2794 2795| 类型 | 说明 | 2796| -------------- | --------------------------- | 2797| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 2798 2799**示例:** 2800 2801```ts 2802import { BusinessError } from '@kit.BasicServicesKit'; 2803 2804async function Flip() { 2805 let horizontal: boolean = true; 2806 let vertical: boolean = false; 2807 if (pixelMap != undefined) { 2808 pixelMap.flip(horizontal, vertical).then(() => { 2809 console.info('Succeeded in flipping pixelmap.'); 2810 }).catch((err: BusinessError) => { 2811 console.error(`Failed to flip pixelmap. code is ${err.code}, message is ${err.message}`); 2812 }) 2813 } 2814} 2815``` 2816 2817### flipSync<sup>12+</sup> 2818 2819flipSync(horizontal: boolean, vertical: boolean): void 2820 2821根据输入的条件对图片进行翻转并同步返回结果。 2822 2823**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2824 2825**系统能力:** SystemCapability.Multimedia.Image.Core 2826 2827**参数:** 2828 2829| 参数名 | 类型 | 必填 | 说明 | 2830| ---------- | -------------------- | ---- | ----------------------------- | 2831| horizontal | boolean | 是 | 水平翻转。 | 2832| vertical | boolean | 是 | 垂直翻转。 | 2833 2834**错误码:** 2835 2836以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 2837 2838| 错误码ID | 错误信息 | 2839| ------- | --------------------------------------------| 2840| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2841| 501 | Resource Unavailable | 2842 2843**示例:** 2844 2845```ts 2846import { BusinessError } from '@kit.BasicServicesKit'; 2847 2848async function FlipSync() { 2849 let horizontal : boolean = true; 2850 let vertical : boolean = false; 2851 if (pixelMap != undefined) { 2852 pixelMap.flipSync(horizontal, vertical); 2853 } 2854} 2855``` 2856 2857### crop<sup>9+</sup> 2858 2859crop(region: Region, callback: AsyncCallback\<void>): void 2860 2861根据输入的尺寸对图片进行裁剪,使用callback形式返回。 2862 2863**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 2864 2865**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2866 2867**系统能力:** SystemCapability.Multimedia.Image.Core 2868 2869**参数:** 2870 2871| 参数名 | 类型 | 必填 | 说明 | 2872| -------- | -------------------- | ---- | ----------------------------- | 2873| region | [Region](#region8) | 是 | 裁剪的尺寸。 | 2874| callback | AsyncCallback\<void> | 是 | 回调函数。当对图片进行裁剪成功,err为undefined,否则为错误对象。| 2875 2876**示例:** 2877 2878```ts 2879import { BusinessError } from '@kit.BasicServicesKit'; 2880 2881async function Crop() { 2882 let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 2883 if (pixelMap != undefined) { 2884 pixelMap.crop(region, (err: BusinessError) => { 2885 if (err) { 2886 console.error(`Failed to crop pixelmap. code is ${err.code}, message is ${err.message}`); 2887 return; 2888 } else { 2889 console.info("Succeeded in cropping pixelmap."); 2890 } 2891 }) 2892 } 2893} 2894``` 2895 2896### crop<sup>9+</sup> 2897 2898crop(region: Region): Promise\<void> 2899 2900根据输入的尺寸对图片进行裁剪,使用Promise形式返回。 2901 2902**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 2903 2904**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2905 2906**系统能力:** SystemCapability.Multimedia.Image.Core 2907 2908**参数:** 2909 2910| 参数名 | 类型 | 必填 | 说明 | 2911| ------ | ------------------ | ---- | ----------- | 2912| region | [Region](#region8) | 是 | 裁剪的尺寸。| 2913 2914**返回值:** 2915 2916| 类型 | 说明 | 2917| -------------- | --------------------------- | 2918| Promise\<void> | Promise对象。无返回结果的Promise对象。| 2919 2920**示例:** 2921 2922```ts 2923import { BusinessError } from '@kit.BasicServicesKit'; 2924 2925async function Crop() { 2926 let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 2927 if (pixelMap != undefined) { 2928 pixelMap.crop(region).then(() => { 2929 console.info('Succeeded in cropping pixelmap.'); 2930 }).catch((err: BusinessError) => { 2931 console.error(`Failed to crop pixelmap. code is ${err.code}, message is ${err.message}`); 2932 2933 }); 2934 } 2935} 2936``` 2937 2938### cropSync<sup>12+</sup> 2939 2940cropSync(region: Region): void 2941 2942根据输入的尺寸裁剪图片。 2943 2944**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2945 2946**系统能力:** SystemCapability.Multimedia.Image.Core 2947 2948**参数:** 2949 2950| 参数名 | 类型 | 必填 | 说明 | 2951| -------- | -------------------- | ---- | ----------------------------- | 2952| region | [Region](#region8) | 是 | 裁剪的尺寸。 | 2953 2954**错误码:** 2955 2956以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 2957 2958| 错误码ID | 错误信息 | 2959| ------- | --------------------------------------------| 2960| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 2961| 501 | Resource Unavailable | 2962 2963**示例:** 2964 2965```ts 2966import { BusinessError } from '@kit.BasicServicesKit'; 2967 2968async function CropSync() { 2969 let region : image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 2970 if (pixelMap != undefined) { 2971 pixelMap.cropSync(region); 2972 } 2973} 2974``` 2975 2976### getColorSpace<sup>10+</sup> 2977 2978getColorSpace(): colorSpaceManager.ColorSpaceManager 2979 2980获取图像广色域信息。 2981 2982**系统能力:** SystemCapability.Multimedia.Image.Core 2983 2984**返回值:** 2985 2986| 类型 | 说明 | 2987| ----------------------------------- | ---------------- | 2988| [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | 图像广色域信息。 | 2989 2990**错误码:** 2991 2992以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 2993 2994| 错误码ID | 错误信息 | 2995| ------- | --------------------------------------------| 2996| 62980101| If the image data abnormal. | 2997| 62980103| If the image data unsupport. | 2998| 62980115| If the image parameter invalid. | 2999 3000**示例:** 3001 3002```ts 3003async function GetColorSpace() { 3004 if (pixelMap != undefined) { 3005 let csm = pixelMap.getColorSpace(); 3006 } 3007} 3008``` 3009 3010### setColorSpace<sup>10+</sup> 3011 3012setColorSpace(colorSpace: colorSpaceManager.ColorSpaceManager): void 3013 3014设置图像广色域信息。 3015 3016**系统能力:** SystemCapability.Multimedia.Image.Core 3017 3018**参数:** 3019 3020| 参数名 | 类型 | 必填 | 说明 | 3021| ---------- | ----------------------------------- | ---- | --------------- | 3022| colorSpace | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | 是 | 图像广色域信息。| 3023 3024**错误码:** 3025 3026以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 3027 3028| 错误码ID | 错误信息 | 3029| ------- | --------------------------------------------| 3030| 62980111| The image source data is incomplete. | 3031| 62980115| If the image parameter invalid. | 3032 3033**示例:** 3034 3035```ts 3036import { colorSpaceManager } from '@kit.ArkGraphics2D'; 3037async function SetColorSpace() { 3038 let colorSpaceName = colorSpaceManager.ColorSpace.SRGB; 3039 let csm: colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName); 3040 if (pixelMap != undefined) { 3041 pixelMap.setColorSpace(csm); 3042 } 3043} 3044``` 3045 3046### applyColorSpace<sup>11+</sup> 3047 3048applyColorSpace(targetColorSpace: colorSpaceManager.ColorSpaceManager, callback: AsyncCallback\<void>): void 3049 3050根据输入的目标色彩空间对图像像素颜色进行色彩空间转换,使用callback形式返回。 3051 3052**系统能力:** SystemCapability.Multimedia.Image.Core 3053 3054**参数:** 3055 3056| 参数名 | 类型 | 必填 | 说明 | 3057| -------- | -------------------- | ---- | ----------------------------- | 3058| targetColorSpace | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | 是 | 目标色彩空间,支持SRGB、DCI_P3、DISPLAY_P3、ADOBE_RGB_1998。| 3059| callback | AsyncCallback\<void> | 是 | 回调函数。当对图像像素颜色进行色彩空间转换成功,err为undefined,否则为错误对象。| 3060 3061**错误码:** 3062 3063以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 3064 3065| 错误码ID | 错误信息 | 3066| ------- | ------------------------------------------| 3067| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 3068| 62980104| Failed to initialize the internal object. | 3069| 62980108| Failed to convert the color space. | 3070| 62980115| Invalid image parameter. | 3071 3072**示例:** 3073 3074```ts 3075import { colorSpaceManager } from '@kit.ArkGraphics2D'; 3076import { BusinessError } from '@kit.BasicServicesKit'; 3077 3078async function ApplyColorSpace() { 3079 let colorSpaceName = colorSpaceManager.ColorSpace.SRGB; 3080 let targetColorSpace: colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName); 3081 if (pixelMap != undefined) { 3082 pixelMap.applyColorSpace(targetColorSpace, (err: BusinessError) => { 3083 if (err) { 3084 console.error(`Failed to apply color space for pixelmap object. code is ${err.code}, message is ${err.message}`); 3085 return; 3086 } else { 3087 console.info('Succeeded in applying color space for pixelmap object.'); 3088 } 3089 }) 3090 } 3091} 3092``` 3093 3094### applyColorSpace<sup>11+</sup> 3095 3096applyColorSpace(targetColorSpace: colorSpaceManager.ColorSpaceManager): Promise\<void> 3097 3098根据输入的目标色彩空间对图像像素颜色进行色彩空间转换,使用Promise形式返回。 3099 3100**系统能力:** SystemCapability.Multimedia.Image.Core 3101 3102**参数:** 3103 3104| 参数名 | 类型 | 必填 | 说明 | 3105| ------ | ------------------ | ---- | ----------- | 3106| targetColorSpace | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | 是 | 目标色彩空间,支持SRGB、DCI_P3、DISPLAY_P3、ADOBE_RGB_1998。| 3107 3108**返回值:** 3109 3110| 类型 | 说明 | 3111| -------------- | --------------------------- | 3112| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 3113 3114**错误码:** 3115 3116以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 3117 3118| 错误码ID | 错误信息 | 3119| ------- | ------------------------------------------| 3120| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed | 3121| 62980104| Failed to initialize the internal object. | 3122| 62980108| Failed to convert the color space. | 3123| 62980115| Invalid image parameter. | 3124 3125**示例:** 3126 3127```ts 3128import { colorSpaceManager } from '@kit.ArkGraphics2D'; 3129import { BusinessError } from '@kit.BasicServicesKit'; 3130 3131async function ApplyColorSpace() { 3132 let colorSpaceName = colorSpaceManager.ColorSpace.SRGB; 3133 let targetColorSpace: colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName); 3134 if (pixelMap != undefined) { 3135 pixelMap.applyColorSpace(targetColorSpace).then(() => { 3136 console.info('Succeeded in applying color space for pixelmap object.'); 3137 }).catch((error: BusinessError) => { 3138 console.error(`Failed to apply color space for pixelmap object. code is ${error.code}, message is ${error.message}`); 3139 }) 3140 } 3141} 3142``` 3143 3144### toSdr<sup>12+<sup> 3145 3146toSdr(): Promise\<void> 3147 3148将HDR的图像内容转换为SDR的图像内容,异步使用Promise形式返回。 3149 3150**系统能力:** SystemCapability.Multimedia.Image.Core 3151 3152**返回值:** 3153 3154| 类型 | 说明 | 3155| -------------- | --------------------------- | 3156| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 3157 3158**错误码:** 3159 3160以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 3161 3162| 错误码ID | 错误信息 | 3163| ------- | --------------------------------------------| 3164| 62980137 | Invalid image operation. | 3165 3166**示例:** 3167 3168```ts 3169import image from '@ohos.multimedia.image' 3170import resourceManager from '@ohos.resourceManager' 3171import { BusinessError } from '@kit.BasicServicesKit'; 3172 3173//此处'hdr.jpg'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。 3174let img = getContext().resourceManager.getMediaContentSync($r('app.media.hdr')); 3175let imageSource = image.createImageSource(img.buffer.slice(0)); 3176let decodingOptions: image.DecodingOptions = { 3177 desiredDynamicRange: image.DecodingDynamicRange.AUTO 3178}; 3179let pixelmap = imageSource.createPixelMapSync(decodingOptions); 3180if (pixelmap != undefined) { 3181 console.info('Succeeded in creating pixelMap object.'); 3182 pixelmap.toSdr().then(() => { 3183 let imageInfo = pixelmap.getImageInfoSync(); 3184 console.info("after toSdr ,imageInfo isHdr:" + imageInfo.isHdr); 3185 }).catch((err: BusinessError) => { 3186 console.error(`Failed to set sdr. code is ${err.code}, message is ${err.message}`); 3187 }); 3188} else { 3189 console.info('Failed to create pixelMap.'); 3190} 3191``` 3192 3193### getMetadata<sup>12+</sup> 3194 3195getMetadata(key: HdrMetadataKey): HdrMetadataValue 3196 3197从PixelMap中获取元数据。 3198 3199**系统能力:** SystemCapability.Multimedia.Image.Core 3200 3201**参数:** 3202 3203| 参数名 | 类型 | 必填 | 说明 | 3204| ------------- | -------------------------------- | ---- | ---------------- | 3205| key | [HdrMetadataKey](#hdrmetadatakey12) | 是 | HDR元数据的关键字,可用于查询对应值。 | 3206 3207**返回值:** 3208 3209| 类型 | 说明 | 3210| --------------------------------- | --------------------------------- | 3211| [HdrMetadataValue](#hdrmetadatavalue12) | 返回元数据的值。 | 3212 3213**错误码:** 3214 3215以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 3216 3217| 错误码ID | 错误信息 | 3218| ------- | --------------------------------------------| 3219| 401| Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 3220| 501 | Resource unavailable. | 3221| 62980173 | The DMA memory does not exist. | 3222| 62980302 | Memory copy failed. | 3223 3224**示例:** 3225 3226```ts 3227import { BusinessError } from '@kit.BasicServicesKit'; 3228import image from '@ohos.multimedia.image' 3229 3230// 'app.media.test'需要替换为本地hdr图片。 3231let img = getContext().resourceManager.getMediaContentSync($r('app.media.test')); 3232let imageSource = image.createImageSource(img.buffer.slice(0)); 3233let decodingOptions: image.DecodingOptions = { 3234 desiredDynamicRange: image.DecodingDynamicRange.AUTO 3235}; 3236let pixelmap = imageSource.createPixelMapSync(decodingOptions); 3237if (pixelmap != undefined) { 3238 console.info('Succeeded in creating pixelMap object.'); 3239 try { 3240 let staticMetadata = pixelmap.getMetadata(image.HdrMetadataKey.HDR_STATIC_METADATA); 3241 console.info("getmetadata:" + JSON.stringify(staticMetadata)); 3242 } catch (e) { 3243 console.info('pixelmap create failed' + e); 3244 } 3245} else { 3246 console.info('Failed to create pixelMap.'); 3247} 3248``` 3249 3250### setMetadata<sup>12+</sup> 3251 3252setMetadata(key: HdrMetadataKey, value: HdrMetadataValue): Promise\<void> 3253 3254设置PixelMap元数据。 3255 3256**系统能力:** SystemCapability.Multimedia.Image.Core 3257 3258**参数:** 3259 3260| 参数名 | 类型 | 必填 | 说明 | 3261| ------------- | -------------------------------- | ---- | ---------------- | 3262| key | [HdrMetadataKey](#hdrmetadatakey12) | 是 | HDR元数据的关键字,用于设置对应值 | 3263| value | [HdrMetadataValue](#hdrmetadatavalue12) | 是 | 元数据的值 | 3264 3265**返回值:** 3266 3267| 类型 | 说明 | 3268| -------------- | --------------------- | 3269| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 3270 3271**错误码:** 3272 3273以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 3274 3275| 错误码ID | 错误信息 | 3276| ------- | --------------------------------------------| 3277| 401| Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 3278| 501 | Resource unavailable. | 3279| 62980173 | The DMA memory does not exist. | 3280| 62980302 | Memory copy failed. | 3281 3282**示例:** 3283 3284```ts 3285import image from '@ohos.multimedia.image' 3286import { BusinessError } from '@kit.BasicServicesKit'; 3287 3288let staticMetadata: image.HdrStaticMetadata = { 3289 displayPrimariesX: [1.1, 1.1, 1.1], 3290 displayPrimariesY: [1.2, 1.2, 1.2], 3291 whitePointX: 1.1, 3292 whitePointY: 1.2, 3293 maxLuminance: 2.1, 3294 minLuminance: 1.0, 3295 maxContentLightLevel: 2.1, 3296 maxFrameAverageLightLevel: 2.1, 3297} 3298const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4 3299let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 3300image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => { 3301 pixelMap.setMetadata(image.HdrMetadataKey.HDR_STATIC_METADATA, staticMetadata).then(() => { 3302 console.info('Succeeded in setting pixelMap metadata.'); 3303 }).catch((error: BusinessError) => { 3304 console.error(`Failed to set the metadata.code ${error.code},message is ${error.message}`); 3305 }) 3306}).catch((error: BusinessError) => { 3307 console.error(`Failed to create the PixelMap.code ${error.code},message is ${error.message}`); 3308}) 3309 3310``` 3311 3312### setTransferDetached<sup>12+<sup> 3313 3314setTransferDetached(detached: boolean): void 3315 3316pixelmap在跨线程传输时,断开原线程的引用。适用于需立即释放pixelmap的场景。 3317 3318**系统能力:** SystemCapability.Multimedia.Image.Core 3319 3320**参数:** 3321 3322| 参数名 | 类型 | 必填 | 说明 | 3323| ------- | ------------------ | ---- | ----------------------------- | 3324| detached | boolean | 是 | 是否断开原线程引用 | 3325 3326**错误码:** 3327 3328以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 3329 3330| 错误码ID | 错误信息 | 3331| ------- | --------------------------------------------| 3332| 501 | Resource Unavailable | 3333 3334**示例:** 3335 3336```ts 3337import { BusinessError } from '@kit.BasicServicesKit'; 3338import image from '@ohos.multimedia.image'; 3339import taskpool from '@ohos.taskpool'; 3340 3341@Concurrent 3342// 子线程方法 3343async function loadPixelMap(rawFileDescriptor: number): Promise<PixelMap> { 3344 // 创建imageSource。 3345 const imageSource = image.createImageSource(rawFileDescriptor); 3346 // 创建pixelMap。 3347 const pixelMap = imageSource.createPixelMapSync(); 3348 // 释放imageSource。 3349 imageSource.release(); 3350 // 使pixelMap在跨线程传输完成后,断开原线程的引用。 3351 pixelMap.setTransferDetached(true); 3352 // 返回pixelMap给主线程。 3353 return pixelMap; 3354} 3355 3356@Entry 3357@Component 3358struct Demo { 3359 @State pixelMap: PixelMap | undefined = undefined; 3360 // 主线程方法 3361 private loadImageFromThread(): void { 3362 const resourceMgr = getContext(this).resourceManager; 3363 // 此处‘example.jpg’仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。 3364 resourceMgr.getRawFd('example.jpg').then(rawFileDescriptor => { 3365 taskpool.execute(loadPixelMap, rawFileDescriptor).then(pixelMap => { 3366 if (pixelMap) { 3367 this.pixelMap = pixelMap as PixelMap; 3368 console.log('Succeeded in creating pixelMap.'); 3369 // 主线程释放pixelMap。由于子线程返回pixelMap时已调用setTransferDetached,所以此处能够立即释放pixelMap。 3370 this.pixelMap.release(); 3371 } else { 3372 console.error('Failed to create pixelMap.'); 3373 } 3374 }); 3375 }); 3376 } 3377 build() { 3378 // ... 3379 } 3380} 3381``` 3382 3383### marshalling<sup>10+</sup> 3384 3385marshalling(sequence: rpc.MessageSequence): void 3386 3387将PixelMap序列化后写入MessageSequence。 3388 3389**系统能力:** SystemCapability.Multimedia.Image.Core 3390 3391**参数:** 3392 3393| 参数名 | 类型 | 必填 | 说明 | 3394| ---------------------- | ------------------------------------------------------ | ---- | ---------------------------------------- | 3395| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | 是 | 新创建的MessageSequence。 | 3396 3397**错误码:** 3398 3399以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 3400 3401| 错误码ID | 错误信息 | 3402| ------- | --------------------------------------------| 3403| 62980115 | Invalid image parameter. | 3404| 62980097 | IPC error. | 3405 3406**示例:** 3407 3408```ts 3409import { image } from '@kit.ImageKit'; 3410import { rpc } from '@kit.IPCKit'; 3411 3412class MySequence implements rpc.Parcelable { 3413 pixel_map: image.PixelMap; 3414 constructor(conPixelMap : image.PixelMap) { 3415 this.pixel_map = conPixelMap; 3416 } 3417 marshalling(messageSequence : rpc.MessageSequence) { 3418 this.pixel_map.marshalling(messageSequence); 3419 console.info('marshalling'); 3420 return true; 3421 } 3422 unmarshalling(messageSequence : rpc.MessageSequence) { 3423 image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}}).then((pixelParcel: image.PixelMap) => { 3424 pixelParcel.unmarshalling(messageSequence).then(async (pixelMap: image.PixelMap) => { 3425 this.pixel_map = pixelMap; 3426 pixelMap.getImageInfo().then((imageInfo: image.ImageInfo) => { 3427 console.info("unmarshalling information h:" + imageInfo.size.height + "w:" + imageInfo.size.width); 3428 }) 3429 }) 3430 }); 3431 return true; 3432 } 3433} 3434async function Marshalling() { 3435 const color: ArrayBuffer = new ArrayBuffer(96); 3436 let bufferArr: Uint8Array = new Uint8Array(color); 3437 for (let i = 0; i < bufferArr.length; i++) { 3438 bufferArr[i] = 0x80; 3439 } 3440 let opts: image.InitializationOptions = { 3441 editable: true, 3442 pixelFormat: image.PixelMapFormat.BGRA_8888, 3443 size: { height: 4, width: 6 }, 3444 alphaType: image.AlphaType.UNPREMUL 3445 } 3446 let pixelMap: image.PixelMap | undefined = undefined; 3447 image.createPixelMap(color, opts).then((srcPixelMap: image.PixelMap) => { 3448 pixelMap = srcPixelMap; 3449 }) 3450 if (pixelMap != undefined) { 3451 // 序列化 3452 let parcelable: MySequence = new MySequence(pixelMap); 3453 let data: rpc.MessageSequence = rpc.MessageSequence.create(); 3454 data.writeParcelable(parcelable); 3455 3456 // 反序列化 rpc获取到data 3457 let ret: MySequence = new MySequence(pixelMap); 3458 data.readParcelable(ret); 3459 } 3460} 3461``` 3462 3463### unmarshalling<sup>10+</sup> 3464 3465unmarshalling(sequence: rpc.MessageSequence): Promise\<PixelMap> 3466 3467从MessageSequence中获取PixelMap, 3468如需使用同步方式创建PixelMap可使用:[createPixelMapFromParcel](#imagecreatepixelmapfromparcel11)。 3469 3470**系统能力:** SystemCapability.Multimedia.Image.Core 3471 3472**参数:** 3473 3474| 参数名 | 类型 | 必填 | 说明 | 3475| ---------------------- | ----------------------------------------------------- | ---- | ---------------------------------------- | 3476| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | 是 | 保存有PixelMap信息的MessageSequence。 | 3477 3478**返回值:** 3479 3480| 类型 | 说明 | 3481| -------------------------------- | --------------------- | 3482| Promise\<[PixelMap](#pixelmap7)> |Promise对象,返回PixelMap。 | 3483 3484**错误码:** 3485 3486以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 3487 3488| 错误码ID | 错误信息 | 3489| ------- | --------------------------------------------| 3490| 62980115 | Invalid image parameter. | 3491| 62980097 | IPC error. | 3492| 62980096 | The operation failed. | 3493 3494**示例:** 3495 3496```ts 3497import { image } from '@kit.ImageKit'; 3498import { rpc } from '@kit.IPCKit'; 3499 3500class MySequence implements rpc.Parcelable { 3501 pixel_map: image.PixelMap; 3502 constructor(conPixelMap: image.PixelMap) { 3503 this.pixel_map = conPixelMap; 3504 } 3505 marshalling(messageSequence: rpc.MessageSequence) { 3506 this.pixel_map.marshalling(messageSequence); 3507 console.info('marshalling'); 3508 return true; 3509 } 3510 unmarshalling(messageSequence: rpc.MessageSequence) { 3511 image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}}).then((pixelParcel : image.PixelMap) => { 3512 pixelParcel.unmarshalling(messageSequence).then(async (pixelMap : image.PixelMap) => { 3513 this.pixel_map = pixelMap; 3514 pixelMap.getImageInfo().then((imageInfo : image.ImageInfo) => { 3515 console.info("unmarshalling information h:" + imageInfo.size.height + "w:" + imageInfo.size.width); 3516 }) 3517 }) 3518 }); 3519 return true; 3520 } 3521} 3522async function Unmarshalling() { 3523 const color: ArrayBuffer = new ArrayBuffer(96); 3524 let bufferArr: Uint8Array = new Uint8Array(color); 3525 for (let i = 0; i < bufferArr.length; i++) { 3526 bufferArr[i] = 0x80; 3527 } 3528 let opts: image.InitializationOptions = { 3529 editable: true, 3530 pixelFormat: image.PixelMapFormat.BGRA_8888, 3531 size: { height: 4, width: 6 }, 3532 alphaType: image.AlphaType.UNPREMUL 3533 } 3534 let pixelMap: image.PixelMap | undefined = undefined; 3535 image.createPixelMap(color, opts).then((srcPixelMap : image.PixelMap) => { 3536 pixelMap = srcPixelMap; 3537 }) 3538 if (pixelMap != undefined) { 3539 // 序列化 3540 let parcelable: MySequence = new MySequence(pixelMap); 3541 let data : rpc.MessageSequence = rpc.MessageSequence.create(); 3542 data.writeParcelable(parcelable); 3543 3544 // 反序列化 rpc获取到data 3545 let ret : MySequence = new MySequence(pixelMap); 3546 data.readParcelable(ret); 3547 } 3548} 3549``` 3550 3551### release<sup>7+</sup> 3552 3553release():Promise\<void> 3554 3555释放PixelMap对象,使用Promise形式返回释放结果。 3556 3557ArkTS有内存回收机制,PixelMap对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。 3558 3559**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 3560 3561**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3562 3563**系统能力:** SystemCapability.Multimedia.Image.Core 3564 3565**返回值:** 3566 3567| 类型 | 说明 | 3568| -------------- | ------------------------------- | 3569| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 3570 3571**示例:** 3572 3573```ts 3574import { BusinessError } from '@kit.BasicServicesKit'; 3575 3576async function Release() { 3577 if (pixelMap != undefined) { 3578 pixelMap.release().then(() => { 3579 console.info('Succeeded in releasing pixelmap object.'); 3580 }).catch((error: BusinessError) => { 3581 console.error(`Failed to release pixelmap object. code is ${error.code}, message is ${error.message}`); 3582 }) 3583 } 3584} 3585``` 3586 3587### release<sup>7+</sup> 3588 3589release(callback: AsyncCallback\<void>): void 3590 3591释放PixelMap对象,使用callback形式返回释放结果。 3592 3593ArkTS有内存回收机制,PixelMap对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。 3594 3595**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 3596 3597**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3598 3599**系统能力:** SystemCapability.Multimedia.Image.Core 3600 3601**参数:** 3602 3603| 参数名 | 类型 | 必填 | 说明 | 3604| -------- | -------------------- | ---- | ------------------ | 3605| callback | AsyncCallback\<void> | 是 | 回调函数。当对PixelMap对象释放成功,err为undefined,否则为错误对象。 | 3606 3607**示例:** 3608 3609```ts 3610import { BusinessError } from '@kit.BasicServicesKit'; 3611 3612async function Release() { 3613 if (pixelMap != undefined) { 3614 pixelMap.release((err: BusinessError) => { 3615 if (err) { 3616 console.error(`Failed to release pixelmap object. code is ${err.code}, message is ${err.message}`); 3617 return; 3618 } else { 3619 console.info('Succeeded in releasing pixelmap object.'); 3620 } 3621 }) 3622 } 3623} 3624``` 3625 3626### convertPixelFormat<sup>12+</sup> 3627 3628convertPixelFormat(targetPixelFormat: PixelMapFormat): Promise\<void> 3629 3630YUV和RGB类型互转,目前仅支持NV12/NV21与RGB888/RGBA8888/RGB565/BGRA8888/RGBAF16互转,YCRCB_P010/YCBCR_P010与RGBA1010102互转。 3631 3632**系统能力:** SystemCapability.Multimedia.Image.Core 3633 3634**参数:** 3635 3636| 参数名 | 类型 | 必填 | 说明 | 3637| -------- | -------------------- | ---- | ------------------ | 3638| targetPixelFormat | [PixelMapFormat](#pixelmapformat7) | 是 | 目标像素格式,用于YUV和RGB类型互转。目前仅支持NV12/NV21与RGB888/RGBA8888/RGB565/BGRA8888/RGBAF16互转,YCRCB_P010/YCBCR_P010与RGBA1010102互转。 | 3639 3640**返回值:** 3641 3642| 类型 | 说明 | 3643| -------------- | ------------------------------- | 3644| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 3645 3646**错误码:** 3647 3648以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 3649 3650| 错误码ID | 错误信息 | 3651| ------- | --------------------------------------------| 3652| 62980111 | The image source data is incomplete. | 3653| 62980115 | Invalid input parameter. | 3654| 62980178 | Failed to create the pixelmap. | 3655| 62980274 | The conversion failed | 3656| 62980276 | The type to be converted is an unsupported target pixel format| 3657 3658**示例:** 3659 3660```ts 3661import { BusinessError } from '@kit.BasicServicesKit'; 3662 3663if (pixelMap != undefined) { 3664 // 设置目标像素格式为NV12 3665 let targetPixelFormat = image.PixelMapFormat.NV12; 3666 pixelMap.convertPixelFormat(targetPixelFormat).then(() => { 3667 // pixelMap转换成NV12格式成功 3668 console.info('PixelMapFormat convert Succeeded'); 3669 }).catch((error: BusinessError) => { 3670 // pixelMap转换成NV12格式失败 3671 console.error(`PixelMapFormat convert Failed. code is ${error.code}, message is ${error.message}`); 3672 }) 3673} 3674``` 3675 3676### setMemoryNameSync<sup>13+</sup> 3677 3678setMemoryNameSync(name: string): void 3679 3680设置PixelMap内存标识符。 3681 3682**系统能力:** SystemCapability.Multimedia.Image.Core 3683 3684**参数:** 3685 3686| 参数名 | 类型 | 必填 | 说明 | 3687| ------------- | -------------------------------- | ---- | ---------------- | 3688| name | string | 是 | pixelmap内存标识符,只允许DMA和ASHMEM内存形式的piexelmap设置,支持1-31位长度。 | 3689 3690**错误码:** 3691 3692以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 3693 3694| 错误码ID | 错误信息 | 3695| ------- | --------------------------------------------| 3696| 401 | Parameter error. Possible causes: 1.The length of the input parameter is too long. 2.Parameter verification failed. | 3697| 501 | Resource unavailable. | 3698| 62980286 | Memory format not supported. | 3699 3700**示例:** 3701 3702```ts 3703import { BusinessError } from '@ohos.base'; 3704 3705async function SetMemoryNameSync() { 3706 if (pixelMap != undefined) { 3707 try { 3708 pixelMap.setMemoryNameSync("PixelMapName Test"); 3709 } catch(e) { 3710 let error = e as BusinessError; 3711 console.error(`setMemoryNameSync error. code is ${error.code}, message is ${error.message}`); 3712 } 3713 } 3714} 3715``` 3716 3717## image.createImageSource 3718 3719createImageSource(uri: string): ImageSource 3720 3721通过传入的uri创建图片源实例。 3722 3723 3724**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3725 3726**系统能力:** SystemCapability.Multimedia.Image.ImageSource 3727 3728**参数:** 3729 3730| 参数名 | 类型 | 必填 | 说明 | 3731| ------ | ------ | ---- | ---------------------------------- | 3732| uri | string | 是 | 图片路径,当前仅支持应用沙箱路径。</br>当前支持格式有:.jpg .png .gif .bmp .webp .dng .heic<sup>12+</sup>(不同硬件设备支持情况不同) [.svg<sup>10+</sup>](#svg标签说明) .ico<sup>11+</sup>。 | 3733 3734**返回值:** 3735 3736| 类型 | 说明 | 3737| --------------------------- | -------------------------------------------- | 3738| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 | 3739 3740**示例:** 3741 3742```ts 3743const context: Context = getContext(this); 3744//此处'test.jpg'仅作示例,请开发者自行替换。否则imageSource会创建失败,导致后续无法正常执行。 3745const path: string = context.filesDir + "/test.jpg"; 3746const imageSourceApi: image.ImageSource = image.createImageSource(path); 3747``` 3748 3749## image.createImageSource<sup>9+</sup> 3750 3751createImageSource(uri: string, options: SourceOptions): ImageSource 3752 3753通过传入的uri创建图片源实例。 3754 3755**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 3756 3757**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3758 3759**系统能力:** SystemCapability.Multimedia.Image.ImageSource 3760 3761**参数:** 3762 3763| 参数名 | 类型 | 必填 | 说明 | 3764| ------- | ------------------------------- | ---- | ----------------------------------- | 3765| uri | string | 是 | 图片路径,当前仅支持应用沙箱路径。</br>当前支持格式有:.jpg .png .gif .bmp .webp .dng .heic<sup>12+</sup>(不同硬件设备支持情况不同)[.svg<sup>10+</sup>](#svg标签说明) .ico<sup>11+</sup>。 | 3766| options | [SourceOptions](#sourceoptions9) | 是 | 图片属性,包括图片像素密度、像素格式和图片尺寸。| 3767 3768**返回值:** 3769 3770| 类型 | 说明 | 3771| --------------------------- | -------------------------------------------- | 3772| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 | 3773 3774**示例:** 3775 3776```ts 3777let sourceOptions: image.SourceOptions = { sourceDensity: 120 }; 3778const context: Context = getContext(this); 3779//此处'test.png'仅作示例,请开发者自行替换。否则imageSource会创建失败,导致后续无法正常执行。 3780const path: string = context.filesDir + "/test.png"; 3781let imageSourceApi: image.ImageSource = image.createImageSource(path, sourceOptions); 3782``` 3783 3784## image.createImageSource<sup>7+</sup> 3785 3786createImageSource(fd: number): ImageSource 3787 3788通过传入文件描述符来创建图片源实例。 3789 3790**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3791 3792**系统能力:** SystemCapability.Multimedia.Image.ImageSource 3793 3794**参数:** 3795 3796| 参数名 | 类型 | 必填 | 说明 | 3797| ------ | ------ | ---- | ------------- | 3798| fd | number | 是 | 文件描述符fd。| 3799 3800**返回值:** 3801 3802| 类型 | 说明 | 3803| --------------------------- | -------------------------------------------- | 3804| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 | 3805 3806**示例:** 3807 3808```ts 3809import { fileIo as fs } from '@kit.CoreFileKit'; 3810 3811const context: Context = getContext(this); 3812//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource会创建失败导致后续无法正常执行。 3813let filePath: string = context.filesDir + "/test.jpg"; 3814let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 3815const imageSourceApi: image.ImageSource = image.createImageSource(file.fd); 3816``` 3817 3818## image.createImageSource<sup>9+</sup> 3819 3820createImageSource(fd: number, options: SourceOptions): ImageSource 3821 3822通过传入文件描述符来创建图片源实例。 3823 3824**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 3825 3826**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3827 3828**系统能力:** SystemCapability.Multimedia.Image.ImageSource 3829 3830**参数:** 3831 3832| 参数名 | 类型 | 必填 | 说明 | 3833| ------- | ------------------------------- | ---- | ----------------------------------- | 3834| fd | number | 是 | 文件描述符fd。 | 3835| options | [SourceOptions](#sourceoptions9) | 是 | 图片属性,包括图片像素密度、像素格式和图片尺寸。| 3836 3837**返回值:** 3838 3839| 类型 | 说明 | 3840| --------------------------- | -------------------------------------------- | 3841| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 | 3842 3843**示例:** 3844 3845```ts 3846import { fileIo as fs } from '@kit.CoreFileKit'; 3847 3848let sourceOptions: image.SourceOptions = { sourceDensity: 120 }; 3849const context: Context = getContext(); 3850//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。 3851const filePath: string = context.filesDir + "/test.jpg"; 3852let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 3853const imageSourceApi: image.ImageSource = image.createImageSource(file.fd, sourceOptions); 3854``` 3855 3856## image.createImageSource<sup>9+</sup> 3857 3858createImageSource(buf: ArrayBuffer): ImageSource 3859 3860通过缓冲区创建图片源实例。buf数据应该是未解码的数据,不要传入类似于RBGA,YUV的像素buffer数据,如果想通过像素buffer数据创建pixelMap,可以调用[image.createPixelMapSync](#createpixelmapsync12)这一类接口。 3861 3862**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 3863 3864**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3865 3866**系统能力:** SystemCapability.Multimedia.Image.ImageSource 3867 3868**参数:** 3869 3870| 参数名 | 类型 | 必填 | 说明 | 3871| ------ | ----------- | ---- | ---------------- | 3872| buf | ArrayBuffer | 是 | 图像缓冲区数组。 | 3873 3874**返回值:** 3875 3876| 类型 | 说明 | 3877| --------------------------- | -------------------------------------------- | 3878| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 | 3879 3880 3881**示例:** 3882 3883```ts 3884const buf: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4 3885const imageSourceApi: image.ImageSource = image.createImageSource(buf); 3886``` 3887 3888## image.createImageSource<sup>9+</sup> 3889 3890createImageSource(buf: ArrayBuffer, options: SourceOptions): ImageSource 3891 3892通过缓冲区创建图片源实例。buf数据应该是未解码的数据,不要传入类似于RBGA,YUV的像素buffer数据,如果想通过像素buffer数据创建pixelMap,可以调用[image.createPixelMapSync](#createpixelmapsync12)这一类接口。 3893 3894**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 3895 3896**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3897 3898**系统能力:** SystemCapability.Multimedia.Image.ImageSource 3899 3900**参数:** 3901 3902| 参数名 | 类型 | 必填 | 说明 | 3903| ------ | -------------------------------- | ---- | ------------------------------------ | 3904| buf | ArrayBuffer | 是 | 图像缓冲区数组。 | 3905| options | [SourceOptions](#sourceoptions9) | 是 | 图片属性,包括图片像素密度、像素格式和图片尺寸。 | 3906 3907**返回值:** 3908 3909| 类型 | 说明 | 3910| --------------------------- | -------------------------------------------- | 3911| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 | 3912 3913**示例:** 3914 3915```ts 3916const data: ArrayBuffer = new ArrayBuffer(112); 3917let sourceOptions: image.SourceOptions = { sourceDensity: 120 }; 3918const imageSourceApi: image.ImageSource = image.createImageSource(data, sourceOptions); 3919``` 3920 3921## image.createImageSource<sup>11+</sup> 3922 3923createImageSource(rawfile: resourceManager.RawFileDescriptor, options?: SourceOptions): ImageSource 3924 3925通过图像资源文件的RawFileDescriptor创建图片源实例。 3926 3927**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3928 3929**系统能力:** SystemCapability.Multimedia.Image.ImageSource 3930 3931**参数:** 3932 3933| 参数名 | 类型 | 必填 | 说明 | 3934| ------ | -------------------------------- | ---- | ------------------------------------ | 3935| rawfile | [resourceManager.RawFileDescriptor](../apis-localization-kit/js-apis-resource-manager.md#rawfiledescriptor8) | 是 | 图像资源文件的RawFileDescriptor。 | 3936| options | [SourceOptions](#sourceoptions9) | 否 | 图片属性,包括图片像素密度、像素格式和图片尺寸。 | 3937 3938**返回值:** 3939 3940| 类型 | 说明 | 3941| --------------------------- | -------------------------------------------- | 3942| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 | 3943 3944**示例:** 3945 3946```ts 3947import { resourceManager } from '@kit.LocalizationKit'; 3948 3949const context: Context = getContext(this); 3950// 获取resourceManager资源管理器 3951const resourceMgr: resourceManager.ResourceManager = context.resourceManager; 3952//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。 3953resourceMgr.getRawFd('test.jpg').then((rawFileDescriptor: resourceManager.RawFileDescriptor) => { 3954 const imageSourceApi: image.ImageSource = image.createImageSource(rawFileDescriptor); 3955}).catch((error: BusinessError) => { 3956 console.error(`Failed to get RawFileDescriptor.code is ${error.code}, message is ${error.message}`); 3957}) 3958``` 3959 3960## image.CreateIncrementalSource<sup>9+</sup> 3961 3962CreateIncrementalSource(buf: ArrayBuffer): ImageSource 3963 3964通过缓冲区以增量的方式创建图片源实例,IncrementalSource不支持读写Exif信息。 3965 3966以增量方式创建的图片源实例ImageSource,仅支持使用以下功能,同步、异步callback、异步Promise均支持。 3967- 获取图片信息:指定序号-[getImageInfo](#getimageinfo)、直接获取-[getImageInfo](#getimageinfo-1) 3968- 获取图片中给定索引处图像的指定属性键的值:[getImageProperty](#getimageproperty11) 3969- 批量获取图片中的指定属性键的值:[getImageProperties](#getimageproperties12) 3970- 更新增量数据:[updateData](#updatedata9) 3971- 创建PixelMap对象:通过图片解码参数创建-[createPixelMap](#createpixelmap7)、通过默认参数创建-[createPixelMap](#createpixelmap7-1) 、通过图片解码参数-[createPixelMap](#createpixelmap7-2) 3972- 释放图片源实例:[release](#release) 3973 3974**系统能力:** SystemCapability.Multimedia.Image.ImageSource 3975 3976**参数:** 3977 3978| 参数名 | 类型 | 必填 | 说明 | 3979| ------- | ------------| ---- | ----------| 3980| buf | ArrayBuffer | 是 | 增量数据。| 3981 3982**返回值:** 3983 3984| 类型 | 说明 | 3985| --------------------------- | --------------------------------- | 3986| [ImageSource](#imagesource) | 返回图片源,失败时返回undefined。 | 3987 3988**示例:** 3989 3990```ts 3991const context: Context = getContext(this) 3992let imageArray = context.resourceManager.getMediaContentSync($r('app.media.startIcon')) // 获取图像资源 3993// 此处'app.media.startIcon'仅作示例,请开发者自行替换,否则imageArray创建失败会导致后续无法正常执行。 3994let splitBuff1 = imageArray.slice(0, imageArray.byteLength / 2) // 分片 3995let splitBuff2 = imageArray.slice(imageArray.byteLength / 2) 3996const imageSourceIncrementalSApi: image.ImageSource = image.CreateIncrementalSource(new ArrayBuffer(imageArray.byteLength)); 3997imageSourceIncrementalSApi.updateData(splitBuff1, false, 0, splitBuff1.byteLength).then(() => { 3998 imageSourceIncrementalSApi.updateData(splitBuff2, true, 0, splitBuff2.byteLength).then(() => { 3999 let pixelMap = imageSourceIncrementalSApi.createPixelMapSync() 4000 let imageInfo = pixelMap.getImageInfoSync() 4001 console.info('Succeeded in creating pixelMap') 4002 }).catch((error : BusinessError) => { 4003 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`) 4004 }) 4005}).catch((error : BusinessError) => { 4006 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`) 4007}) 4008``` 4009 4010## image.CreateIncrementalSource<sup>9+</sup> 4011 4012CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource 4013 4014通过缓冲区以增量的方式创建图片源实例,IncrementalSource不支持读写Exif信息。 4015 4016此接口支持的功能与[CreateIncrementalSource(buf: ArrayBuffer): ImageSource](#imagecreateincrementalsource9)所生成的实例支持的功能相同 4017 4018**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4019 4020**参数:** 4021 4022| 参数名 | 类型 | 必填 | 说明 | 4023| ------- | ------------------------------- | ---- | ------------------------------------ | 4024| buf | ArrayBuffer | 是 | 增量数据。 | 4025| options | [SourceOptions](#sourceoptions9) | 否 | 图片属性,包括图片像素密度、像素格式和图片尺寸。 | 4026 4027**返回值:** 4028 4029| 类型 | 说明 | 4030| --------------------------- | --------------------------------- | 4031| [ImageSource](#imagesource) | 返回图片源,失败时返回undefined。 | 4032 4033**示例:** 4034 4035```ts 4036const context: Context = getContext(this) 4037let imageArray = context.resourceManager.getMediaContentSync($r('app.media.startIcon')) // 获取图像资源 4038// 此处'app.media.startIcon'仅作示例,请开发者自行替换,否则imageArray创建失败会导致后续无法正常执行。 4039let splitBuff1 = imageArray.slice(0, imageArray.byteLength / 2) // 分片 4040let splitBuff2 = imageArray.slice(imageArray.byteLength / 2) 4041let sourceOptions: image.SourceOptions = { sourceDensity: 120}; 4042 4043const imageSourceIncrementalSApi: image.ImageSource = image.CreateIncrementalSource(new ArrayBuffer(imageArray.byteLength), sourceOptions); 4044imageSourceIncrementalSApi.updateData(splitBuff1, false, 0, splitBuff1.byteLength).then(() => { 4045 imageSourceIncrementalSApi.updateData(splitBuff2, true, 0, splitBuff2.byteLength).then(() => { 4046 let pixelMap = imageSourceIncrementalSApi.createPixelMapSync() 4047 let imageInfo = pixelMap.getImageInfoSync() 4048 console.info('Succeeded in creating pixelMap') 4049 }).catch((error : BusinessError) => { 4050 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`) 4051 }) 4052}).catch((error : BusinessError) => { 4053 console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`) 4054}) 4055``` 4056 4057## ImageSource 4058 4059图片源类,用于获取图片相关信息。在调用ImageSource的方法前,需要先通过[createImageSource](#imagecreateimagesource)构建一个ImageSource实例。 4060 4061### 属性 4062 4063**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4064 4065| 名称 | 类型 | 可读 | 可写 | 说明 | 4066| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | 4067| supportedFormats | Array\<string> | 是 | 否 | 支持的图片格式,包括:png,jpeg,bmp,gif,webp,dng,heic<sup>12+</sup>(不同硬件设备支持情况不同)。 | 4068 4069### getImageInfo 4070 4071getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void 4072 4073获取指定序号的图片信息,使用callback形式返回图片信息。 4074 4075**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 4076 4077**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 4078 4079**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4080 4081**参数:** 4082 4083| 参数名 | 类型 | 必填 | 说明 | 4084| -------- | -------------------------------------- | ---- | ---------------------------------------- | 4085| index | number | 是 | 创建图片源时的序号。 | 4086| callback | AsyncCallback<[ImageInfo](#imageinfo)> | 是 | 回调函数。当获取图片信息成功,err为undefined,data为获取到的图片信息;否则为错误对象。 | 4087 4088**示例:** 4089 4090```ts 4091import { BusinessError } from '@kit.BasicServicesKit'; 4092 4093imageSourceApi.getImageInfo(0, (error: BusinessError, imageInfo: image.ImageInfo) => { 4094 if (error) { 4095 console.error(`Failed to obtain the image information.code is ${error.code}, message is ${error.message}`); 4096 } else { 4097 console.info('Succeeded in obtaining the image information.'); 4098 } 4099}) 4100``` 4101 4102### getImageInfo 4103 4104getImageInfo(callback: AsyncCallback\<ImageInfo>): void 4105 4106获取图片信息,使用callback形式返回图片信息。 4107 4108**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 4109 4110**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 4111 4112**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4113 4114**参数:** 4115 4116| 参数名 | 类型 | 必填 | 说明 | 4117| -------- | -------------------------------------- | ---- | ---------------------------------------- | 4118| callback | AsyncCallback<[ImageInfo](#imageinfo)> | 是 | 回调函数。当获取图片信息成功,err为undefined,data为获取到的图片信息;否则为错误对象。 | 4119 4120**示例:** 4121 4122```ts 4123import { BusinessError } from '@kit.BasicServicesKit'; 4124 4125imageSourceApi.getImageInfo((err: BusinessError, imageInfo: image.ImageInfo) => { 4126 if (err) { 4127 console.error(`Failed to obtain the image information.code is ${err.code}, message is ${err.message}`); 4128 } else { 4129 console.info('Succeeded in obtaining the image information.'); 4130 } 4131}) 4132``` 4133 4134### getImageInfo 4135 4136getImageInfo(index?: number): Promise\<ImageInfo> 4137 4138获取图片信息,使用Promise形式返回图片信息。 4139 4140**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 4141 4142**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 4143 4144**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4145 4146**参数:** 4147 4148| 参数名| 类型 | 必填 | 说明 | 4149| ----- | ------ | ---- | ------------------------------------- | 4150| index | number | 否 | 创建图片源时的序号,不选择时默认为0。 | 4151 4152**返回值:** 4153 4154| 类型 | 说明 | 4155| -------------------------------- | ---------------------- | 4156| Promise<[ImageInfo](#imageinfo)> | Promise对象,返回获取到的图片信息。 | 4157 4158**示例:** 4159 4160```ts 4161import { BusinessError } from '@kit.BasicServicesKit'; 4162 4163imageSourceApi.getImageInfo(0) 4164 .then((imageInfo: image.ImageInfo) => { 4165 console.info('Succeeded in obtaining the image information.'); 4166 }).catch((error: BusinessError) => { 4167 console.error(`Failed to obtain the image information.code is ${error.code}, message is ${error.message}`); 4168 }) 4169``` 4170 4171### getImageInfoSync<sup>12+</sup> 4172 4173getImageInfoSync(index?: number): ImageInfo 4174 4175获取指定序号的图片信息,使用同步形式返回图片信息。 4176 4177**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4178 4179**参数:** 4180 4181| 参数名| 类型 | 必填 | 说明 | 4182| ----- | ------ | ---- | ------------------------------------- | 4183| index | number | 否 | 创建图片源时的序号,不选择时默认为0。 | 4184 4185**返回值:** 4186 4187| 类型 | 说明 | 4188| -------------------------------- | ---------------------- | 4189| [ImageInfo](#imageinfo) | 同步返回获取到的图片信息。 | 4190 4191**示例:** 4192 4193```ts 4194import { image } from '@kit.ImageKit'; 4195 4196const context: Context = getContext(); 4197//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。 4198let filePath: string = context.filesDir + "/test.jpg"; 4199let imageSource = image.createImageSource(filePath); 4200let imageInfo = imageSource.getImageInfoSync(0); 4201if (imageInfo == undefined) { 4202 console.error('Failed to obtain the image information.'); 4203} else { 4204 console.info('Succeeded in obtaining the image information.'); 4205 console.info('imageInfo.size.height:' + imageInfo.size.height); 4206 console.info('imageInfo.size.width:' + imageInfo.size.width); 4207} 4208``` 4209 4210### getImageProperty<sup>11+</sup> 4211 4212getImageProperty(key:PropertyKey, options?: ImagePropertyOptions): Promise\<string> 4213 4214获取图片中给定索引处图像的指定属性键的值,用Promise形式返回结果,仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。 4215 4216**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4217 4218**参数:** 4219 4220| 参数名 | 类型 | 必填 | 说明 | 4221| ------- | ---------------------------------------------------- | ---- | ------------------------------------ | 4222| key | [PropertyKey](#propertykey7) | 是 | 图片属性名。 | 4223| options | [ImagePropertyOptions](#imagepropertyoptions11) | 否 | 图片属性,包括图片序号与默认属性值。 | 4224 4225**返回值:** 4226 4227| 类型 | 说明 | 4228| ---------------- | ----------------------------------------------------------------- | 4229| Promise\<string> | Promise对象,返回图片属性值,如获取失败则返回属性默认值。 | 4230 4231**错误码:** 4232 4233以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 4234 4235| 错误码ID | 错误信息 | 4236| ------- | --------------------------------------------| 4237| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 4238| 62980096 | The operation failed. | 4239| 62980103 | The image data is not supported. | 4240| 62980110 | The image source data is incorrect. | 4241| 62980111 | The image source data is incomplete. | 4242| 62980112 | The image format does not match. | 4243| 62980113 | Unknown image format. | 4244| 62980115 | Invalid image parameter. | 4245| 62980116| Failed to decode the image. | 4246| 62980118 | Failed to create the image plugin. | 4247| 62980122 | Failed to decode the image header. | 4248| 62980123| Images in EXIF format are not supported. | 4249| 62980135| The EXIF value is invalid. | 4250 4251**示例:** 4252 4253```ts 4254import { BusinessError } from '@kit.BasicServicesKit'; 4255 4256let options: image.ImagePropertyOptions = { index: 0, defaultValue: '9999' } 4257imageSourceApi.getImageProperty(image.PropertyKey.BITS_PER_SAMPLE, options) 4258.then((data: string) => { 4259 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 4260}).catch((error: BusinessError) => { 4261 console.error('Failed to get the value of the specified attribute key of the image.'); 4262}) 4263``` 4264 4265### getImageProperty<sup>(deprecated)</sup> 4266 4267getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\<string> 4268 4269获取图片中给定索引处图像的指定属性键的值,用Promise形式返回结果,仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。 4270 4271> **说明:** 4272> 4273> 从API version 11开始不再维护,建议使用[getImageProperty](#getimageproperty11)代替。 4274 4275**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4276 4277**参数:** 4278 4279| 参数名 | 类型 | 必填 | 说明 | 4280| ------- | ---------------------------------------------------- | ---- | ------------------------------------ | 4281| key | string | 是 | 图片属性名。 | 4282| options | [GetImagePropertyOptions](#getimagepropertyoptionsdeprecated) | 否 | 图片属性,包括图片序号与默认属性值。 | 4283 4284**返回值:** 4285 4286| 类型 | 说明 | 4287| ---------------- | ----------------------------------------------------------------- | 4288| Promise\<string> | Promise对象,返回图片属性值,如获取失败则返回属性默认值。 | 4289 4290**示例:** 4291 4292```ts 4293import { BusinessError } from '@kit.BasicServicesKit'; 4294 4295imageSourceApi.getImageProperty("BitsPerSample") 4296 .then((data: string) => { 4297 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 4298 }).catch((error: BusinessError) => { 4299 console.error('Failed to get the value of the specified attribute key of the image.'); 4300 }) 4301``` 4302 4303### getImageProperty<sup>(deprecated)</sup> 4304 4305getImageProperty(key:string, callback: AsyncCallback\<string>): void 4306 4307获取图片中给定索引处图像的指定属性键的值,用callback形式返回结果,仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。 4308 4309> **说明:** 4310> 4311> 从API version 11开始不再维护,建议使用[getImageProperty](#getimageproperty11)代替。 4312 4313**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4314 4315**参数:** 4316 4317| 参数名 | 类型 | 必填 | 说明 | 4318| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 4319| key | string | 是 | 图片属性名。 | 4320| callback | AsyncCallback\<string> | 是 | 回调函数,当获取图片属性值成功,err为undefined,data为获取到的图片属性值;否则为错误对象。 | 4321 4322**示例:** 4323 4324```ts 4325import { BusinessError } from '@kit.BasicServicesKit'; 4326 4327imageSourceApi.getImageProperty("BitsPerSample", (error: BusinessError, data: string) => { 4328 if (error) { 4329 console.error('Failed to get the value of the specified attribute key of the image.'); 4330 } else { 4331 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 4332 } 4333}) 4334``` 4335 4336### getImageProperty<sup>(deprecated)</sup> 4337 4338getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCallback\<string>): void 4339 4340获取图片指定属性键的值,callback形式返回结果,仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。 4341 4342> **说明:** 4343> 4344> 从API version 11开始不再维护,建议使用[getImageProperty](#getimageproperty11)代替。 4345 4346**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4347 4348**参数:** 4349 4350| 参数名 | 类型 | 必填 | 说明 | 4351| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------- | 4352| key | string | 是 | 图片属性名。 | 4353| options | [GetImagePropertyOptions](#getimagepropertyoptionsdeprecated) | 是 | 图片属性,包括图片序号与默认属性值。 | 4354| callback | AsyncCallback\<string> | 是 | 回调函数,当获取图片属性值成功,err为undefined,data为获取到的图片属性值;否则为错误对象。| 4355 4356**示例:** 4357 4358```ts 4359import { BusinessError } from '@kit.BasicServicesKit'; 4360 4361let property: image.GetImagePropertyOptions = { index: 0, defaultValue: '9999' } 4362imageSourceApi.getImageProperty("BitsPerSample", property, (error: BusinessError, data: string) => { 4363 if (error) { 4364 console.error('Failed to get the value of the specified attribute key of the image.'); 4365 } else { 4366 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 4367 } 4368}) 4369``` 4370 4371### getImageProperties<sup>12+</sup> 4372 4373getImageProperties(key: Array<PropertyKey>): Promise<Record<PropertyKey, string|null>> 4374 4375批量获取图片中的指定属性键的值,用Promise形式返回结果。仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。 4376 4377**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4378 4379**参数:** 4380 4381| 参数名 | 类型 | 必填 | 说明 | 4382| ------- | ---------------------------------------------------- | ---- | ------------------------------------ | 4383| key | Array\<[PropertyKey](#propertykey7)> | 是 | 图片属性名的数组。 | 4384 4385**返回值:** 4386 4387| 类型 | 说明 | 4388| ---------------- | ----------------------------------------------------------------- | 4389| Promise\<Record<[PropertyKey](#propertykey7), string \| null>> | Promise对象,返回图片属性值,如获取失败则返回null。 | 4390 4391**错误码:** 4392 4393以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 4394 4395| 错误码ID | 错误信息 | 4396| ------- | --------------------------------------------| 4397| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 4398| 62980096| The operation failed. | 4399| 62980110| The image source data is incorrect. | 4400| 62980113| Unknown image format. | 4401| 62980116| Failed to decode the image. | 4402 4403**示例:** 4404 4405```ts 4406import { image } from '@kit.ImageKit'; 4407import { BusinessError } from '@kit.BasicServicesKit'; 4408 4409let key = [image.PropertyKey.IMAGE_WIDTH, image.PropertyKey.IMAGE_LENGTH]; 4410imageSourceApi.getImageProperties(key).then((data) => { 4411 console.info(JSON.stringify(data)); 4412}).catch((err: BusinessError) => { 4413 console.error(JSON.stringify(err)); 4414}); 4415``` 4416 4417### modifyImageProperty<sup>11+</sup> 4418 4419modifyImageProperty(key: PropertyKey, value: string): Promise\<void> 4420 4421通过指定的键修改图片属性的值,使用Promise形式返回结果,仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。 4422 4423> **说明:** 4424> 4425> 调用modifyImageProperty修改属性会改变属性字节长度,使用buffer创建的ImageSource调用modifyImageProperty会导致buffer内容覆盖,目前buffer创建的ImageSource不支持调用此接口,请改用fd或path创建的ImageSource。 4426 4427**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4428 4429**参数:** 4430 4431| 参数名 | 类型 | 必填 | 说明 | 4432| ------- | ------ | ---- | ------------ | 4433| key | [PropertyKey](#propertykey7) | 是 | 图片属性名。 | 4434| value | string | 是 | 属性值。 | 4435 4436**返回值:** 4437 4438| 类型 | 说明 | 4439| -------------- | --------------------------- | 4440| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 4441 4442**错误码:** 4443 4444以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 4445 4446| 错误码ID | 错误信息 | 4447| ------- | --------------------------------------------| 4448| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; | 4449| 62980123| The image does not support EXIF decoding. | 4450| 62980133| The EXIF data is out of range. | 4451| 62980135| The EXIF value is invalid. | 4452| 62980146| The EXIF data failed to be written to the file. | 4453 4454**示例:** 4455 4456```ts 4457import { BusinessError } from '@kit.BasicServicesKit'; 4458 4459imageSourceApi.modifyImageProperty(image.PropertyKey.IMAGE_WIDTH, "120").then(() => { 4460 imageSourceApi.getImageProperty(image.PropertyKey.IMAGE_WIDTH).then((width: string) => { 4461 console.info(`ImageWidth is :${width}`); 4462 }).catch((error: BusinessError) => { 4463 console.error('Failed to get the Image Width.'); 4464 }) 4465}).catch((error: BusinessError) => { 4466 console.error('Failed to modify the Image Width'); 4467}) 4468``` 4469 4470### modifyImageProperty<sup>(deprecated)</sup> 4471 4472modifyImageProperty(key: string, value: string): Promise\<void> 4473 4474通过指定的键修改图片属性的值,使用Promise形式返回结果,仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。 4475 4476> **说明:** 4477> 4478> 调用modifyImageProperty修改属性会改变属性字节长度,使用buffer创建的ImageSource调用modifyImageProperty会导致buffer内容覆盖,目前buffer创建的ImageSource不支持调用此接口,请改用fd或path创建的ImageSource。 4479> 4480> 从API version 11开始不再维护,建议使用[modifyImageProperty](#modifyimageproperty11)代替。 4481 4482**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4483 4484**参数:** 4485 4486| 参数名 | 类型 | 必填 | 说明 | 4487| ------- | ------ | ---- | ------------ | 4488| key | string | 是 | 图片属性名。 | 4489| value | string | 是 | 属性值。 | 4490 4491**返回值:** 4492 4493| 类型 | 说明 | 4494| -------------- | --------------------------- | 4495| Promise\<void> | Promise对象。无返回结果的Promise对象。| 4496 4497**示例:** 4498 4499```ts 4500import { BusinessError } from '@kit.BasicServicesKit'; 4501 4502imageSourceApi.modifyImageProperty("ImageWidth", "120").then(() => { 4503 imageSourceApi.getImageProperty("ImageWidth").then((width: string) => { 4504 console.info(`ImageWidth is :${width}`); 4505 }).catch((error: BusinessError) => { 4506 console.error('Failed to get the Image Width.'); 4507 }) 4508}).catch((error: BusinessError) => { 4509 console.error('Failed to modify the Image Width'); 4510}) 4511``` 4512 4513### modifyImageProperty<sup>(deprecated)</sup> 4514 4515modifyImageProperty(key: string, value: string, callback: AsyncCallback\<void>): void 4516 4517通过指定的键修改图片属性的值,callback形式返回结果,仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。 4518 4519> **说明:** 4520> 4521> 调用modifyImageProperty修改属性会改变属性字节长度,使用buffer创建的ImageSource调用modifyImageProperty会导致buffer内容覆盖,目前buffer创建的ImageSource不支持调用此接口,请改用fd或path创建的ImageSource。 4522> 4523>从API version 11开始不再维护,建议使用[modifyImageProperty](#modifyimageproperty11)代替。 4524 4525**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4526 4527**参数:** 4528 4529| 参数名 | 类型 | 必填 | 说明 | 4530| -------- | ------------------- | ---- | ------------------------------ | 4531| key | string | 是 | 图片属性名。 | 4532| value | string | 是 | 属性值。 | 4533| callback | AsyncCallback\<void> | 是 | 回调函数,当修改图片属性值成功,err为undefined,否则为错误对象。 | 4534 4535**示例:** 4536 4537```ts 4538import { BusinessError } from '@kit.BasicServicesKit'; 4539 4540imageSourceApi.modifyImageProperty("ImageWidth", "120", (err: BusinessError) => { 4541 if (err) { 4542 console.error(`Failed to modify the Image Width.code is ${err.code}, message is ${err.message}`); 4543 } else { 4544 console.info('Succeeded in modifying the Image Width.'); 4545 } 4546}) 4547``` 4548 4549### modifyImageProperties<sup>12+</sup> 4550 4551modifyImageProperties(records: Record<PropertyKey, string|null>): Promise\<void> 4552 4553批量通过指定的键修改图片属性的值,使用Promise形式返回结果。仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。 4554 4555> **说明:** 4556> 4557> 调用modifyImageProperties修改属性会改变属性字节长度,使用buffer创建的ImageSource调用modifyImageProperties会导致buffer内容覆盖,目前buffer创建的ImageSource不支持调用此接口,请改用fd或path创建的ImageSource。 4558> 4559 4560**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4561 4562**参数:** 4563 4564| 参数名 | 类型 | 必填 | 说明 | 4565| ------- | ------ | ---- | ------------ | 4566| records | Record<[PropertyKey](#propertykey7), string \| null> | 是 | 包含图片属性名和属性值的数组。 | 4567 4568**返回值:** 4569 4570| 类型 | 说明 | 4571| -------------- | --------------------------- | 4572| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 4573 4574**错误码:** 4575 4576以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 4577 4578| 错误码ID | 错误信息 | 4579| ------- | --------------------------------------------| 4580| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 4581| 62980123| The image does not support EXIF decoding. | 4582| 62980133| The EXIF data is out of range. | 4583| 62980135| The EXIF value is invalid. | 4584| 62980146| The EXIF data failed to be written to the file. | 4585 4586**示例:** 4587 4588```ts 4589import { image } from '@kit.ImageKit'; 4590import { BusinessError } from '@kit.BasicServicesKit'; 4591 4592let keyValues: Record<PropertyKey, string|null> = { 4593 [image.PropertyKey.IMAGE_WIDTH] : "1024", 4594 [image.PropertyKey.IMAGE_LENGTH] : "1024" 4595}; 4596let checkKey = [image.PropertyKey.IMAGE_WIDTH, image.PropertyKey.IMAGE_LENGTH]; 4597imageSourceApi.modifyImageProperties(keyValues).then(() => { 4598 imageSourceApi.getImageProperties(checkKey).then((data) => { 4599 console.info(JSON.stringify(data)); 4600 }).catch((err: BusinessError) => { 4601 console.error(JSON.stringify(err)); 4602 }); 4603}).catch((err: BusinessError) => { 4604 console.error(JSON.stringify(err)); 4605}); 4606``` 4607 4608### updateData<sup>9+</sup> 4609 4610updateData(buf: ArrayBuffer, isFinished: boolean, offset: number, length: number): Promise\<void> 4611 4612更新增量数据,使用Promise形式返回结果。 4613 4614**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4615 4616**参数:** 4617 4618| 参数名 | 类型 | 必填 | 说明 | 4619| ---------- | ----------- | ---- | ------------ | 4620| buf | ArrayBuffer | 是 | 增量数据。 | 4621| isFinished | boolean | 是 | 是否更新完。 | 4622| offset | number | 是 | 偏移量。 | 4623| length | number | 是 | 数组长。 | 4624 4625**返回值:** 4626 4627| 类型 | 说明 | 4628| -------------- | -------------------------- | 4629| Promise\<void> | Promise对象。无返回结果的Promise对象。| 4630 4631**示例:** 4632 4633```ts 4634import { BusinessError } from '@kit.BasicServicesKit'; 4635 4636const array: ArrayBuffer = new ArrayBuffer(100); 4637imageSourceApi.updateData(array, false, 0, 10).then(() => { 4638 console.info('Succeeded in updating data.'); 4639}).catch((err: BusinessError) => { 4640 console.error(`Failed to update data.code is ${err.code},message is ${err.message}`); 4641}) 4642``` 4643 4644 4645### updateData<sup>9+</sup> 4646 4647updateData(buf: ArrayBuffer, isFinished: boolean, offset: number, length: number, callback: AsyncCallback\<void>): void 4648 4649更新增量数据,callback形式返回结果。 4650 4651**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4652 4653**参数:** 4654 4655| 参数名 | 类型 | 必填 | 说明 | 4656| ---------- | ------------------- | ---- | -------------------- | 4657| buf | ArrayBuffer | 是 | 增量数据。 | 4658| isFinished | boolean | 是 | 是否更新完。 | 4659| offset | number | 是 | 偏移量。 | 4660| length | number | 是 | 数组长。 | 4661| callback | AsyncCallback\<void> | 是 | 回调函数,当更新增量数据成功,err为undefined,否则为错误对象。 | 4662 4663**示例:** 4664 4665```ts 4666import { BusinessError } from '@kit.BasicServicesKit'; 4667 4668const array: ArrayBuffer = new ArrayBuffer(100); 4669imageSourceApi.updateData(array, false, 0, 10, (err: BusinessError) => { 4670 if (err) { 4671 console.error(`Failed to update data.code is ${err.code},message is ${err.message}`); 4672 } else { 4673 console.info('Succeeded in updating data.'); 4674 } 4675}) 4676``` 4677 4678### createPicture<sup>13+</sup> 4679 4680createPicture(options?: DecodingOptionsForPicture): Promise\<Picture> 4681 4682通过图片解码参数创建Picture对象,使用Promise形式返回。 4683 4684**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4685 4686**参数:** 4687 4688| 参数名 | 类型 | 必填 | 说明 | 4689| ------- | ------------------------------------------------------ | ---- | ---------- | 4690| options | [DecodingOptionsForPicture](#decodingoptionsforpicture13) | 否 | 解码参数。 | 4691 4692**返回值:** 4693 4694| 类型 | 说明 | 4695| ---------------------------- | -------------------------- | 4696| Promise\<[Picture](#picture13)> | Promise对象,返回Picture。 | 4697 4698**错误码:** 4699 4700以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 4701 4702| 错误码ID | 错误信息 | 4703| -------- | ------------------------------------------------------------ | 4704| 401 | Parameter error.Possible causes: 1.Mandatory parameters are left unspecified.2.Incorrect parameter types; 3.Parameter verification failed. | 4705| 7700301 | Decode failed. | 4706 4707**示例:** 4708 4709```ts 4710import { image } from '@kit.ImageKit'; 4711 4712async function CreatePicture() { 4713 let options: image.DecodingOptionsForPicture = { 4714 desiredAuxiliaryPictures: [image.AuxiliaryPictureType.GAINMAP] //GAINMAP为需要解码的辅助图类型 4715 }; 4716 let pictureObj: image.Picture = await imageSourceApi.createPicture(options); 4717 if (pictureObj != null) { 4718 console.info('Create picture succeeded'); 4719 } else { 4720 console.info('Create picture failed'); 4721 } 4722} 4723``` 4724 4725### createPixelMap<sup>7+</sup> 4726 4727createPixelMap(options?: DecodingOptions): Promise\<PixelMap> 4728 4729通过图片解码参数创建PixelMap对象。 4730 4731**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 4732 4733**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 4734 4735**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4736 4737**参数:** 4738 4739| 参数名 | 类型 | 必填 | 说明 | 4740| ------- | ------------------------------------ | ---- | ---------- | 4741| options | [DecodingOptions](#decodingoptions7) | 否 | 解码参数。 | 4742 4743**返回值:** 4744 4745| 类型 | 说明 | 4746| -------------------------------- | --------------------- | 4747| Promise\<[PixelMap](#pixelmap7)> | Promise对象,返回PixelMap。 | 4748 4749**示例:** 4750 4751```ts 4752import { BusinessError } from '@kit.BasicServicesKit'; 4753 4754imageSourceApi.createPixelMap().then((pixelMap: image.PixelMap) => { 4755 console.info('Succeeded in creating pixelMap object through image decoding parameters.'); 4756}).catch((error: BusinessError) => { 4757 console.error('Failed to create pixelMap object through image decoding parameters.'); 4758}) 4759``` 4760 4761### createPixelMap<sup>7+</sup> 4762 4763createPixelMap(callback: AsyncCallback\<PixelMap>): void 4764 4765通过默认参数创建PixelMap对象,使用callback形式返回结果。 4766 4767**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 4768 4769**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 4770 4771**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4772 4773**参数:** 4774 4775| 参数名 | 类型 | 必填 | 说明 | 4776| -------- | ------------------------------------- | ---- | -------------------------- | 4777| callback | AsyncCallback<[PixelMap](#pixelmap7)> | 是 | 回调函数,当创建PixelMap对象成功,err为undefined,data为获取到的PixelMap对象;否则为错误对象。 | 4778 4779**示例:** 4780 4781```ts 4782import { BusinessError } from '@kit.BasicServicesKit'; 4783 4784imageSourceApi.createPixelMap((err: BusinessError, pixelMap: image.PixelMap) => { 4785 if (err) { 4786 console.error(`Failed to create pixelMap.code is ${err.code},message is ${err.message}`); 4787 } else { 4788 console.info('Succeeded in creating pixelMap object.'); 4789 } 4790}) 4791``` 4792 4793### createPixelMap<sup>7+</sup> 4794 4795createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): void 4796 4797通过图片解码参数创建PixelMap对象。 4798 4799**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 4800 4801**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 4802 4803**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4804 4805**参数:** 4806 4807| 参数名 | 类型 | 必填 | 说明 | 4808| -------- | ------------------------------------- | ---- | -------------------------- | 4809| options | [DecodingOptions](#decodingoptions7) | 是 | 解码参数。 | 4810| callback | AsyncCallback<[PixelMap](#pixelmap7)> | 是 | 回调函数,当创建PixelMap对象成功,err为undefined,data为获取到的PixelMap对象;否则为错误对象。 | 4811 4812**示例:** 4813 4814```ts 4815import { BusinessError } from '@kit.BasicServicesKit'; 4816 4817let decodingOptions: image.DecodingOptions = { 4818 sampleSize: 1, 4819 editable: true, 4820 desiredSize: { width: 1, height: 2 }, 4821 rotate: 10, 4822 desiredPixelFormat: image.PixelMapFormat.RGBA_8888, 4823 desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 }, 4824 index: 0 4825}; 4826imageSourceApi.createPixelMap(decodingOptions, (err: BusinessError, pixelMap: image.PixelMap) => { 4827 if (err) { 4828 console.error(`Failed to create pixelMap.code is ${err.code},message is ${err.message}`); 4829 } else { 4830 console.info('Succeeded in creating pixelMap object.'); 4831 } 4832}) 4833``` 4834 4835### createPixelMapSync<sup>12+</sup> 4836 4837createPixelMapSync(options?: DecodingOptions): PixelMap 4838 4839通过图片解码参数同步创建PixelMap对象。 4840 4841**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4842 4843**参数:** 4844 4845| 参数名 | 类型 | 必填 | 说明 | 4846| -------- | ------------------------------------- | ---- | -------------------------- | 4847| options | [DecodingOptions](#decodingoptions7) | 否 | 解码参数。 | 4848 4849**返回值:** 4850 4851| 类型 | 说明 | 4852| -------------------------------- | --------------------- | 4853| [PixelMap](#pixelmap7) | 用于同步返回创建结果。 | 4854 4855**示例:** 4856 4857```ts 4858import { image } from '@kit.ImageKit'; 4859 4860const context: Context = getContext(); 4861//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。 4862let filePath: string = context.filesDir + "/test.jpg"; 4863let imageSource = image.createImageSource(filePath); 4864let decodingOptions: image.DecodingOptions = { 4865 sampleSize: 1, 4866 editable: true, 4867 desiredSize: { width: 1, height: 2 }, 4868 rotate: 10, 4869 desiredPixelFormat: image.PixelMapFormat.RGBA_8888, 4870 desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 }, 4871 index: 0 4872}; 4873let pixelmap = imageSource.createPixelMapSync(decodingOptions); 4874if (pixelmap != undefined) { 4875 console.info('Succeeded in creating pixelMap object.'); 4876} else { 4877 console.info('Failed to create pixelMap.'); 4878} 4879``` 4880 4881### createPixelMapList<sup>10+</sup> 4882 4883createPixelMapList(options?: DecodingOptions): Promise<Array\<PixelMap>> 4884 4885通过图片解码参数创建PixelMap数组。针对动图如Gif、Webp,此接口返回每帧图片数据;针对静态图,此接口返回唯一的一帧图片数据。 4886 4887**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4888 4889**参数:** 4890 4891| 参数名 | 类型 | 必填 | 说明 | 4892| -------- | ------------------------------------- | ---- | -------------------------- | 4893| options | [DecodingOptions](#decodingoptions7) | 否 | 解码参数。 | 4894 4895**返回值:** 4896 4897| 类型 | 说明 | 4898| -------------------------------- | --------------------- | 4899| Promise<Array<[PixelMap](#pixelmap7)>> | 异步返回PixeMap数组。 | 4900 4901**错误码:** 4902 4903以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 4904 4905| 错误码ID | 错误信息 | 4906| ------- | --------------------------------------------| 4907| 62980096| The operation failed. | 4908| 62980099 | The shared memory data is abnormal. | 4909| 62980101 | The image data is abnormal. | 4910| 62980103| The image data is not supported. | 4911| 62980106 | The image is too large. | 4912| 62980109 | Failed to crop the image. | 4913| 62980110| The image source data is incorrect. | 4914| 62980111| The image source data is incomplete. | 4915| 62980112 | The image format does not match. | 4916| 62980113 | Unknown image format. | 4917| 62980115 | Invalid image parameter. | 4918| 62980116 | Failed to decode the image. | 4919| 62980118| Failed to create the image plugin. | 4920| 62980122 | Failed to decode the image header. | 4921| 62980137 | Invalid media operation. | 4922| 62980173 | The DMA memory does not exist. | 4923| 62980174 | The DMA memory data is abnormal. | 4924 4925**示例:** 4926 4927```ts 4928import { BusinessError } from '@kit.BasicServicesKit'; 4929 4930let decodeOpts: image.DecodingOptions = { 4931 sampleSize: 1, 4932 editable: true, 4933 desiredSize: { width: 198, height: 202 }, 4934 rotate: 0, 4935 desiredPixelFormat: image.PixelMapFormat.RGBA_8888, 4936 index: 0, 4937}; 4938imageSourceApi.createPixelMapList(decodeOpts).then((pixelMapList: Array<image.PixelMap>) => { 4939 console.info('Succeeded in creating pixelMapList object.'); 4940}).catch((err: BusinessError) => { 4941 console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`); 4942}) 4943``` 4944 4945### createPixelMapList<sup>10+</sup> 4946 4947createPixelMapList(callback: AsyncCallback<Array\<PixelMap>>): void 4948 4949通过默认参数创建PixelMap数组,使用callback形式返回结果。针对动图如Gif、Webp,此接口返回每帧图片数据;针对静态图,此接口返回唯一的一帧图片数据。 4950 4951**系统能力:** SystemCapability.Multimedia.Image.ImageSource 4952 4953**参数:** 4954 4955| 参数名 | 类型 | 必填 | 说明 | 4956| -------- | ------------------------------------- | ---- | -------------------------- | 4957| callback | AsyncCallback<Array<[PixelMap](#pixelmap7)>> | 是 | 回调函数,当创建PixelMap对象数组成功,err为undefined,data为获取到的PixelMap对象数组;否则为错误对象。 | 4958 4959**错误码:** 4960 4961以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 4962 4963| 错误码ID | 错误信息 | 4964| ------- | --------------------------------------------| 4965| 62980096 | The operation failed. | 4966| 62980099 | The shared memory data is abnormal. | 4967| 62980101 | The image data is abnormal. | 4968| 62980103 | The image data is not supported. | 4969| 62980106 | The image is too large. | 4970| 62980109 | Failed to crop the image. | 4971| 62980110 | The image source data is incorrect. | 4972| 62980111 | The image source data is incomplete. | 4973| 62980112 | The image format does not match. | 4974| 62980113 | Unknown image format. | 4975| 62980115 | Invalid image parameter. | 4976| 62980116 | Failed to decode the image. | 4977| 62980118 | Failed to create the image plugin. | 4978| 62980122 | Failed to decode the image header. | 4979| 62980137 | Invalid media operation. | 4980| 62980173 | The DMA memory does not exist. | 4981| 62980174 | The DMA memory data is abnormal. | 4982 4983**示例:** 4984 4985```ts 4986import { BusinessError } from '@kit.BasicServicesKit'; 4987 4988imageSourceApi.createPixelMapList((err: BusinessError, pixelMapList: Array<image.PixelMap>) => { 4989 if (err) { 4990 console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`); 4991 } else { 4992 console.info('Succeeded in creating pixelMapList object.'); 4993 } 4994}) 4995``` 4996 4997### createPixelMapList<sup>10+</sup> 4998 4999createPixelMapList(options: DecodingOptions, callback: AsyncCallback<Array\<PixelMap>>): void 5000 5001通过图片解码参数创建PixelMap数组,使用callback形式返回结果。针对动图如Gif、Webp,此接口返回每帧图片数据;针对静态图,此接口返回唯一的一帧图片数据。 5002 5003**系统能力:** SystemCapability.Multimedia.Image.ImageSource 5004 5005**参数:** 5006 5007| 参数名 | 类型 | 必填 | 说明 | 5008| -------- | -------------------- | ---- | ---------------------------------- | 5009| options | [DecodingOptions](#decodingoptions7) | 是 | 解码参数。 | 5010| callback | AsyncCallback<Array<[PixelMap](#pixelmap7)>> | 是 | 回调函数,当创建PixelMap对象数组成功,err为undefined,data为获取到的PixelMap对象数组;否则为错误对象。 | 5011 5012**错误码:** 5013 5014以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 5015 5016| 错误码ID | 错误信息 | 5017| ------- | --------------------------------------------| 5018| 62980096 | The operation failed. | 5019| 62980099 | The shared memory data is abnormal. | 5020| 62980101 | The image data is abnormal. | 5021| 62980103 | The image data is not supported. | 5022| 62980106 | The image is too large. | 5023| 62980109 | Failed to crop the image. | 5024| 62980110 | The image source data is incorrect. | 5025| 62980111 | The image source data is incomplete. | 5026| 62980112 | The image format does not match. | 5027| 62980113 | Unknown image format. | 5028| 62980115 | Invalid image parameter. | 5029| 62980116 | Failed to decode the image. | 5030| 62980118 | Failed to create the image plugin. | 5031| 62980122 | Failed to decode the image header. | 5032| 62980137 | Invalid media operation. | 5033| 62980173 | The DMA memory does not exist. | 5034| 62980174 | The DMA memory data is abnormal. | 5035 5036**示例:** 5037 5038```ts 5039import { BusinessError } from '@kit.BasicServicesKit'; 5040 5041let decodeOpts: image.DecodingOptions = { 5042 sampleSize: 1, 5043 editable: true, 5044 desiredSize: { width: 198, height: 202 }, 5045 rotate: 0, 5046 desiredPixelFormat: image.PixelMapFormat.RGBA_8888, 5047 index: 0, 5048}; 5049imageSourceApi.createPixelMapList(decodeOpts, (err: BusinessError, pixelMapList: Array<image.PixelMap>) => { 5050 if (err) { 5051 console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`); 5052 } else { 5053 console.info('Succeeded in creating pixelMapList object.'); 5054 } 5055}) 5056``` 5057 5058### getDelayTimeList<sup>10+</sup> 5059 5060getDelayTimeList(callback: AsyncCallback<Array\<number>>): void 5061 5062获取图像延迟时间数组,使用callback形式返回结果。此接口仅用于gif图片和webp图片。 5063 5064**系统能力:** SystemCapability.Multimedia.Image.ImageSource 5065 5066**参数:** 5067 5068| 参数名 | 类型 | 必填 | 说明 | 5069| -------- | -------------------- | ---- | ---------------------------------- | 5070| callback | AsyncCallback<Array\<number>> | 是 | 回调函数,当获取图像延迟时间数组成功,err为undefined,data为获取到的图像延时时间数组;否则为错误对象。 | 5071 5072**错误码:** 5073 5074以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 5075 5076| 错误码ID | 错误信息 | 5077| ------- | --------------------------------------------| 5078| 62980096| The operation failed. | 5079| 62980110| The image source data is incorrect. | 5080| 62980111| The image source data is incomplete. | 5081| 62980112 | The image format does not match. | 5082| 62980113| Unknown image format. | 5083| 62980115 | Invalid image parameter. | 5084| 62980116| Failed to decode the image. | 5085| 62980118| Failed to create the image plugin. | 5086| 62980122| Failed to decode the image header. | 5087| 62980137 | Invalid media operation. | 5088| 62980149 | Invalid MIME type for the image source. | 5089 5090**示例:** 5091 5092```ts 5093import { BusinessError } from '@kit.BasicServicesKit'; 5094 5095imageSourceApi.getDelayTimeList((err: BusinessError, delayTimes: Array<number>) => { 5096 if (err) { 5097 console.error(`Failed to get delayTimes object.code is ${err.code},message is ${err.message}`); 5098 } else { 5099 console.info('Succeeded in getting delayTimes object.'); 5100 } 5101}) 5102``` 5103 5104### getDelayTimeList<sup>10+</sup> 5105 5106getDelayTimeList(): Promise<Array\<number>> 5107 5108获取图像延迟时间数组,使用Promise形式返回结果。此接口仅用于gif图片和webp图片。 5109 5110**系统能力:** SystemCapability.Multimedia.Image.ImageSource 5111 5112**返回值:** 5113 5114| 类型 | 说明 | 5115| -------------- | --------------------------- | 5116| Promise<Array\<number>> | Promise对象,返回延迟时间数组。 | 5117 5118**错误码:** 5119 5120以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 5121 5122| 错误码ID | 错误信息 | 5123| ------- | --------------------------------------------| 5124| 62980096 | The operation failed. | 5125| 62980110 | The image source data is incorrect. | 5126| 62980111 | The image source data is incomplete. | 5127| 62980112 | The image format does not match. | 5128| 62980113 | Unknown image format. | 5129| 62980115 | Invalid image parameter. | 5130| 62980116 | Failed to decode the image. | 5131| 62980118 | Failed to create the image plugin. | 5132| 62980122 | Failed to decode the image header. | 5133| 62980137 | Invalid media operation. | 5134| 62980149 | Invalid MIME type for the image source. | 5135 5136**示例:** 5137 5138```ts 5139import { BusinessError } from '@kit.BasicServicesKit'; 5140 5141imageSourceApi.getDelayTimeList().then((delayTimes: Array<number>) => { 5142 console.info('Succeeded in getting delayTimes object.'); 5143}).catch((err: BusinessError) => { 5144 console.error(`Failed to get delayTimes object.code is ${err.code},message is ${err.message}`); 5145}) 5146``` 5147 5148### getFrameCount<sup>10+</sup> 5149 5150getFrameCount(callback: AsyncCallback\<number>): void 5151 5152获取图像帧数,使用callback形式返回结果。 5153 5154**系统能力:** SystemCapability.Multimedia.Image.ImageSource 5155 5156**参数:** 5157 5158| 参数名 | 类型 | 必填 | 说明 | 5159| -------- | -------------------- | ---- | ---------------------------------- | 5160| callback | AsyncCallback\<number> | 是 | 回调函数,当获取图像帧数成功,err为undefined,data为获取到的图像帧数;否则为错误对象。 | 5161 5162**错误码:** 5163 5164以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 5165 5166| 错误码ID | 错误信息 | 5167| ------- | --------------------------------------------| 5168| 62980096| The operation failed. | 5169| 62980110| The image source data is incorrect. | 5170| 62980111| The image source data is incomplete. | 5171| 62980112| The image format does not match. | 5172| 62980113| Unknown image format. | 5173| 62980115| Invalid image parameter. | 5174| 62980116| Failed to decode the image. | 5175| 62980118| Failed to create the image plugin. | 5176| 62980122| Failed to decode the image header. | 5177| 62980137| Invalid media operation. | 5178 5179**示例:** 5180 5181```ts 5182import { BusinessError } from '@kit.BasicServicesKit'; 5183 5184imageSourceApi.getFrameCount((err: BusinessError, frameCount: number) => { 5185 if (err) { 5186 console.error(`Failed to get frame count.code is ${err.code},message is ${err.message}`); 5187 } else { 5188 console.info('Succeeded in getting frame count.'); 5189 } 5190}) 5191``` 5192 5193### getFrameCount<sup>10+</sup> 5194 5195getFrameCount(): Promise\<number> 5196 5197获取图像帧数,使用Promise形式返回结果。 5198 5199**系统能力:** SystemCapability.Multimedia.Image.ImageSource 5200 5201**返回值:** 5202 5203| 类型 | 说明 | 5204| -------------- | --------------------------- | 5205| Promise\<number> | Promise对象,返回图像帧数。 | 5206 5207**错误码:** 5208 5209以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 5210 5211| 错误码ID | 错误信息 | 5212| ------- | --------------------------------------------| 5213| 62980096 | The operation failed. | 5214| 62980110 | The image source data is incorrect. | 5215| 62980111 | The image source data is incomplete. | 5216| 62980112 | The image format does not match. | 5217| 62980113 | Unknown image format. | 5218| 62980115 | Invalid image parameter. | 5219| 62980116 | Failed to decode the image. | 5220| 62980118 | Failed to create the image plugin. | 5221| 62980122 | Failed to decode the image header. | 5222| 62980137 | Invalid media operation. | 5223 5224**示例:** 5225 5226```ts 5227import { BusinessError } from '@kit.BasicServicesKit'; 5228 5229imageSourceApi.getFrameCount().then((frameCount: number) => { 5230 console.info('Succeeded in getting frame count.'); 5231}).catch((err: BusinessError) => { 5232 console.error(`Failed to get frame count.code is ${err.code},message is ${err.message}`); 5233}) 5234``` 5235 5236### getDisposalTypeList<sup>12+</sup> 5237 5238getDisposalTypeList(): Promise\<Array\<number>> 5239 5240获取图像帧过渡模式数组,使用Promise形式返回结果。此接口仅用于gif图片。 5241 5242**系统能力:** SystemCapability.Multimedia.Image.ImageSource 5243 5244**返回值:** 5245 5246| 类型 | 说明 | 5247| -------------- | --------------------------- | 5248| Promise\<Array\<number>> | Promise对象,返回帧过渡模式数组。 | 5249 5250**错误码:** 5251 5252以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 5253 5254| 错误码ID | 错误信息 | 5255| ------- | --------------------------------------------| 5256| 62980096 | The operation failed. | 5257| 62980101 | The image data is abnormal. | 5258| 62980137 | Invalid media operation. | 5259| 62980149 | Invalid MIME type for the image source. | 5260 5261**示例:** 5262 5263```ts 5264import { BusinessError } from '@kit.BasicServicesKit'; 5265imageSourceApi.getDisposalTypeList().then((disposalTypes: Array<number>) => { 5266 console.info('Succeeded in getting disposalTypes object.'); 5267}).catch((err: BusinessError) => { 5268 console.error(`Failed to get disposalTypes object.code ${err.code},message is ${err.message}`); 5269}) 5270``` 5271 5272### release 5273 5274release(callback: AsyncCallback\<void>): void 5275 5276释放图片源实例,使用callback形式返回结果。 5277 5278ArkTS有内存回收机制,ImageSource对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。 5279 5280**系统能力:** SystemCapability.Multimedia.Image.ImageSource 5281 5282**参数:** 5283 5284| 参数名 | 类型 | 必填 | 说明 | 5285| -------- | -------------------- | ---- | ---------------------------------- | 5286| callback | AsyncCallback\<void> | 是 | 回调函数,当资源释放成功,err为undefined,否则为错误对象。 | 5287 5288**示例:** 5289 5290```ts 5291import { BusinessError } from '@kit.BasicServicesKit'; 5292 5293imageSourceApi.release((err: BusinessError) => { 5294 if (err) { 5295 console.error(`Failed to release the image source instance.code ${err.code},message is ${err.message}`); 5296 } else { 5297 console.info('Succeeded in releasing the image source instance.'); 5298 } 5299}) 5300``` 5301 5302### release 5303 5304release(): Promise\<void> 5305 5306释放图片源实例,使用Promise形式返回结果。 5307 5308ArkTS有内存回收机制,ImageSource对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。 5309 5310**系统能力:** SystemCapability.Multimedia.Image.ImageSource 5311 5312**返回值:** 5313 5314| 类型 | 说明 | 5315| -------------- | --------------------------- | 5316| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 5317 5318**示例:** 5319 5320```ts 5321import { BusinessError } from '@kit.BasicServicesKit'; 5322 5323imageSourceApi.release().then(() => { 5324 console.info('Succeeded in releasing the image source instance.'); 5325}).catch((error: BusinessError) => { 5326 console.error(`Failed to release the image source instance.code ${error.code},message is ${error.message}`); 5327}) 5328``` 5329 5330## image.createImagePacker 5331 5332createImagePacker(): ImagePacker 5333 5334创建ImagePacker实例。 5335 5336**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 5337 5338**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 5339 5340**返回值:** 5341 5342| 类型 | 说明 | 5343| --------------------------- | --------------------- | 5344| [ImagePacker](#imagepacker) | 返回ImagePacker实例。 | 5345 5346**示例:** 5347 5348```ts 5349const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5350``` 5351 5352## ImagePacker 5353 5354图片打包器类,用于图片压缩和打包。在调用ImagePacker的方法前,需要先通过[createImagePacker](#imagecreateimagepacker)构建一个ImagePacker实例,当前支持格式有:jpeg、webp、png、heif<sup>12+</sup>(不同硬件设备支持情况不同)。 5355 5356### 属性 5357 5358**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 5359 5360| 名称 | 类型 | 可读 | 可写 | 说明 | 5361| ---------------- | -------------- | ---- | ---- | -------------------------- | 5362| supportedFormats | Array\<string> | 是 | 否 | 图片打包支持的格式 jpeg、webp、png、heic<sup>12+</sup>(不同硬件设备支持情况不同)。 | 5363 5364### packToData<sup>13+</sup> 5365 5366packToData(source: ImageSource, options: PackingOption): Promise\<ArrayBuffer> 5367 5368图片压缩或重新打包,使用Promise形式返回结果。 5369 5370**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 5371 5372**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 5373 5374**参数:** 5375 5376| 参数名 | 类型 | 必填 | 说明 | 5377| ------ | ------------------------------- | ---- | -------------- | 5378| source | [ImageSource](#imagesource) | 是 | 打包的图片源。 | 5379| options | [PackingOption](#packingoption) | 是 | 设置打包参数。 | 5380 5381**错误码:** 5382 5383以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 5384 5385| 错误码ID | 错误信息 | 5386| ------- | --------------------------------------------| 5387| 401 | If the parameter is invalid. | 5388| 62980096| The Operation failed. | 5389| 62980101 | The image data is abnormal. | 5390| 62980106 | The image is too large. | 5391| 62980113 | Unknown image format. | 5392| 62980119 | If encoder occur error during encoding. | 5393| 62980120 | Add pixelmap out of range. | 5394| 62980172 | Failed to encode icc. | 5395| 62980252 | Failed to create surface. | 5396 5397**返回值:** 5398 5399| 类型 | 说明 | 5400| ---------------------------- | --------------------------------------------- | 5401| Promise\<ArrayBuffer> | Promise对象,返回压缩或打包后的数据。 | 5402 5403**示例:** 5404 5405```ts 5406import { BusinessError } from '@kit.BasicServicesKit'; 5407 5408const context: Context = getContext(); 5409//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource会创建失败导致后续无法正常执行。 5410let filePath: string = context.filesDir + "/test.jpg"; 5411const imageSourceApi: image.ImageSource = image.createImageSource(filePath); 5412let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 5413imagePackerApi.packToData(imageSourceApi, packOpts) 5414 .then((data: ArrayBuffer) => { 5415 console.info('Succeeded in packing the image.'); 5416 }).catch((error: BusinessError) => { 5417 console.error(`Failed to pack the image.code ${error.code},message is ${error.message}`); 5418 }) 5419``` 5420 5421### packToData<sup>13+</sup> 5422 5423packToData(source: PixelMap, options: PackingOption): Promise\<ArrayBuffer> 5424 5425图片压缩或重新打包,使用Promise形式返回结果。 5426 5427> **注意:** 5428> 接口如果返回401错误码,表明参数异常,可能是PixelMap对象被提前释放了。需要调用方排查,在该方法调用结束后再释放PixelMap对象。 5429 5430**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 5431 5432**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 5433 5434**参数:** 5435 5436| 参数名 | 类型 | 必填 | 说明 | 5437| ------ | ------------------------------- | ---- | ------------------ | 5438| source | [PixelMap](#pixelmap7) | 是 | 打包的PixelMap源。 | 5439| options | [PackingOption](#packingoption) | 是 | 设置打包参数。 | 5440 5441**返回值:** 5442 5443| 类型 | 说明 | 5444| --------------------- | -------------------------------------------- | 5445| Promise\<ArrayBuffer> | Promise对象,返回压缩或打包后的数据。| 5446 5447**错误码:** 5448 5449以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 5450 5451| 错误码ID | 错误信息 | 5452| ------- | --------------------------------------------| 5453| 401 | If the parameter is invalid. | 5454| 62980096| The Operation failed. | 5455| 62980101 | The image data is abnormal. | 5456| 62980106 | The image is too large. | 5457| 62980113 | Unknown image format. | 5458| 62980119 | If encoder occur error during encoding. | 5459| 62980120 | Add pixelmap out of range. | 5460| 62980172 | Failed to encode icc. | 5461| 62980252 | Failed to create surface. | 5462 5463**示例:** 5464 5465```ts 5466import { BusinessError } from '@kit.BasicServicesKit'; 5467 5468const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4 5469let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } 5470image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => { 5471 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 5472 imagePackerApi.packToData(pixelMap, packOpts) 5473 .then((data: ArrayBuffer) => { 5474 console.info('Succeeded in packing the image.'); 5475 }).catch((error: BusinessError) => { 5476 console.error(`Failed to pack the image.code ${error.code},message is ${error.message}`); 5477 }) 5478}).catch((error: BusinessError) => { 5479 console.error(`Failed to create PixelMap.code ${error.code},message is ${error.message}`); 5480}) 5481``` 5482 5483### packing<sup>13+</sup> 5484 5485packing(picture: Picture, options: PackingOption): Promise\<ArrayBuffer> 5486 5487将图像压缩或重新打包,使用Promise形式返回结果。 5488 5489**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 5490 5491**参数:** 5492 5493| 参数名 | 类型 | 必填 | 说明 | 5494| ---------------- | ---------------------------------------------------- | ---- | -------------------- | 5495| picture | [Picture](#picture13) | 是 | 打包的Picture对象。 | 5496| options | [PackingOption](#packingoption) | 是 | 设置打包参数。 | 5497 5498**返回值:** 5499 5500| 类型 | 说明 | 5501| --------------------- | ------------------------------------- | 5502| Promise\<ArrayBuffer> | Promise对象,返回压缩或打包后的数据。 | 5503 5504**错误码:** 5505 5506以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 5507 5508| 错误码ID | 错误信息 | 5509| -------- | ------------------------------------------------------------ | 5510| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 5511| 7800301 | Encode failed. | 5512 5513**示例:** 5514 5515```ts 5516import { BusinessError } from '@kit.BasicServicesKit'; 5517import { image } from '@kit.ImageKit'; 5518 5519async function Packing() { 5520 const context = getContext(); 5521 const resourceMgr = context.resourceManager; 5522 const rawFile = await resourceMgr.getRawFileContent("test.jpg"); 5523 let ops: image.SourceOptions = { 5524 sourceDensity: 98, 5525 } 5526 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 5527 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 5528 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 5529 5530 let funcName = "Packing"; 5531 if (imagePackerApi != null) { 5532 let opts: image.PackingOption = { 5533 format: "image/jpeg", 5534 quality: 98, 5535 bufferSize: 10, 5536 desiredDynamicRange: image.PackingDynamicRange.AUTO, 5537 needsPackProperties: true}; 5538 await imagePackerApi.packing(pictureObj, opts).then((data: ArrayBuffer) => { 5539 console.info(funcName, 'Succeeded in packing the image.'+ data); 5540 }).catch((error: BusinessError) => { 5541 console.error(funcName, 'Failed to pack the image.code ${error.code},message is ${error.message}'); 5542 }); 5543 } 5544} 5545``` 5546 5547### packing<sup>(deprecated)</sup> 5548 5549packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void 5550 5551图片压缩或重新打包,使用callback形式返回结果。 5552 5553> **说明:** 5554> 5555> 从API version 6开始支持,从API version 13开始废弃,建议使用[packToData](#packtodata13)代替。 5556 5557**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 5558 5559**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 5560 5561**参数:** 5562 5563| 参数名 | 类型 | 必填 | 说明 | 5564| -------- | ---------------------------------- | ---- | ---------------------------------- | 5565| source | [ImageSource](#imagesource) | 是 | 打包的图片源。 | 5566| option | [PackingOption](#packingoption) | 是 | 设置打包参数。 | 5567| callback | AsyncCallback\<ArrayBuffer> | 是 | 回调函数,当图片打包成功,err为undefined,data为获取到的压缩或打包数据;否则为错误对象。 | 5568 5569**示例:** 5570 5571```ts 5572import { BusinessError } from '@kit.BasicServicesKit'; 5573 5574const context: Context = getContext(); 5575//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource会创建失败导致后续无法正常执行。 5576let filePath: string = context.filesDir + "/test.jpg"; 5577const imageSourceApi: image.ImageSource = image.createImageSource(filePath); 5578let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }; 5579imagePackerApi.packing(imageSourceApi, packOpts, (err: BusinessError, data: ArrayBuffer) => { 5580 if (err) { 5581 console.error(`Failed to pack the image.code ${err.code},message is ${err.message}`); 5582 } else { 5583 console.info('Succeeded in packing the image.'); 5584 } 5585}) 5586``` 5587 5588### packing<sup>(deprecated)</sup> 5589 5590packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer> 5591 5592图片压缩或重新打包,使用Promise形式返回结果。 5593 5594> **说明:** 5595> 5596> 从API version 6开始支持,从API version 13开始废弃,建议使用[packToData](#packtodata13)代替。 5597 5598**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 5599 5600**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 5601 5602**参数:** 5603 5604| 参数名 | 类型 | 必填 | 说明 | 5605| ------ | ------------------------------- | ---- | -------------- | 5606| source | [ImageSource](#imagesource) | 是 | 打包的图片源。 | 5607| option | [PackingOption](#packingoption) | 是 | 设置打包参数。 | 5608 5609**返回值:** 5610 5611| 类型 | 说明 | 5612| ---------------------------- | --------------------------------------------- | 5613| Promise\<ArrayBuffer> | Promise对象,返回压缩或打包后的数据。 | 5614 5615**示例:** 5616 5617```ts 5618import { BusinessError } from '@kit.BasicServicesKit'; 5619 5620const context: Context = getContext(); 5621//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource会创建失败导致后续无法正常执行。 5622let filePath: string = context.filesDir + "/test.jpg"; 5623const imageSourceApi: image.ImageSource = image.createImageSource(filePath); 5624let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 5625imagePackerApi.packing(imageSourceApi, packOpts) 5626 .then((data: ArrayBuffer) => { 5627 console.info('Succeeded in packing the image.'); 5628 }).catch((error: BusinessError) => { 5629 console.error(`Failed to pack the image.code ${error.code},message is ${error.message}`); 5630 }) 5631``` 5632 5633### packing<sup>(deprecated)</sup> 5634 5635packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void 5636 5637图片压缩或重新打包,使用callback形式返回结果。 5638 5639> **说明:** 5640> 5641> 从API version 8开始支持,从API version 13开始废弃,建议使用[packToData](#packtodata13)代替。 5642 5643> **注意:** 5644> 接口如果返回"PixelMap mismatch",表明参数异常,可能是PixelMap对象被提前释放了。需要调用方排查,在该方法调用结束后再释放PixelMap对象。 5645 5646**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 5647 5648**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 5649 5650**参数:** 5651 5652| 参数名 | 类型 | 必填 | 说明 | 5653| -------- | ------------------------------- | ---- | ---------------------------------- | 5654| source | [PixelMap](#pixelmap7) | 是 | 打包的PixelMap资源。 | 5655| option | [PackingOption](#packingoption) | 是 | 设置打包参数。 | 5656| callback | AsyncCallback\<ArrayBuffer> | 是 | 回调函数,当图片打包成功,err为undefined,data为获取到的压缩或打包数据;否则为错误对象。 | 5657 5658**示例:** 5659 5660```ts 5661import { BusinessError } from '@kit.BasicServicesKit'; 5662 5663const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4 5664let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 5665image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => { 5666 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 5667 imagePackerApi.packing(pixelMap, packOpts, (err: BusinessError, data: ArrayBuffer) => { 5668 if (err) { 5669 console.error(`Failed to pack the image.code ${err.code},message is ${err.message}`); 5670 } else { 5671 console.info('Succeeded in packing the image.'); 5672 } 5673 }) 5674}).catch((error: BusinessError) => { 5675 console.error(`Failed to create the PixelMap.code ${error.code},message is ${error.message}`); 5676}) 5677``` 5678 5679### packing<sup>(deprecated)</sup> 5680 5681packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer> 5682 5683图片压缩或重新打包,使用Promise形式返回结果。 5684 5685> **说明:** 5686> 5687> 从API version 8开始支持,从API version 13开始废弃,建议使用[packToData](#packtodata13)代替。 5688 5689> **注意:** 5690> 接口如果返回"PixelMap mismatch",表明参数异常,可能是PixelMap对象被提前释放了。需要调用方排查,在该方法调用结束后再释放PixelMap对象。 5691 5692**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 5693 5694**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 5695 5696**参数:** 5697 5698| 参数名 | 类型 | 必填 | 说明 | 5699| ------ | ------------------------------- | ---- | ------------------ | 5700| source | [PixelMap](#pixelmap7) | 是 | 打包的PixelMap源。 | 5701| option | [PackingOption](#packingoption) | 是 | 设置打包参数。 | 5702 5703**返回值:** 5704 5705| 类型 | 说明 | 5706| --------------------- | -------------------------------------------- | 5707| Promise\<ArrayBuffer> | Promise对象,返回压缩或打包后的数据。| 5708 5709**示例:** 5710 5711```ts 5712import { BusinessError } from '@kit.BasicServicesKit'; 5713 5714const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4 5715let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 5716image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => { 5717 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 5718 imagePackerApi.packing(pixelMap, packOpts) 5719 .then((data: ArrayBuffer) => { 5720 console.info('Succeeded in packing the image.'); 5721 }).catch((error: BusinessError) => { 5722 console.error(`Failed to pack the image.code ${error.code},message is ${error.message}`); 5723 }) 5724}).catch((error: BusinessError) => { 5725 console.error(`Failed to create PixelMap.code ${error.code},message is ${error.message}`); 5726}) 5727``` 5728 5729### release 5730 5731release(callback: AsyncCallback\<void>): void 5732 5733释放图片打包实例,使用callback形式返回结果。 5734 5735ArkTS有内存回收机制,ImagePacker对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。 5736 5737**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 5738 5739**参数:** 5740 5741| 参数名 | 类型 | 必填 | 说明 | 5742| -------- | -------------------- | ---- | ------------------------------ | 5743| callback | AsyncCallback\<void> | 是 | 回调函数,当释放图片打包实例成功,err为undefined,否则为错误对象。 | 5744 5745**示例:** 5746 5747```ts 5748import { BusinessError } from '@kit.BasicServicesKit'; 5749 5750imagePackerApi.release((err: BusinessError)=>{ 5751 if (err) { 5752 console.error(`Failed to release image packaging.code ${err.code},message is ${err.message}`); 5753 } else { 5754 console.info('Succeeded in releasing image packaging.'); 5755 } 5756}) 5757``` 5758 5759### release 5760 5761release(): Promise\<void> 5762 5763释放图片打包实例,使用Promise形式返回释放结果。 5764 5765ArkTS有内存回收机制,ImagePacker对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。 5766 5767**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 5768 5769**返回值:** 5770 5771| 类型 | 说明 | 5772| -------------- | ------------------------------------------------------ | 5773| Promise\<void> | Promise对象。无返回结果的Promise对象。| 5774 5775**示例:** 5776 5777```ts 5778import { BusinessError } from '@kit.BasicServicesKit'; 5779 5780imagePackerApi.release().then(() => { 5781 console.info('Succeeded in releasing image packaging.'); 5782}).catch((error: BusinessError) => { 5783 console.error(`Failed to release image packaging.code ${error.code},message is ${error.message}`); 5784}) 5785``` 5786 5787### packToFile<sup>11+</sup> 5788 5789packToFile(source: ImageSource, fd: number, options: PackingOption, callback: AsyncCallback\<void>): void 5790 5791指定打包参数,将ImageSource图片源编码后直接打包进文件。使用callback形式返回结果。 5792 5793**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 5794 5795**参数:** 5796 5797| 参数名 | 类型 | 必填 | 说明 | 5798| -------- | ------------------------------- | ---- | ------------------------------ | 5799| source | [ImageSource](#imagesource) | 是 | 打包的图片源。 | 5800| fd | number | 是 | 文件描述符。 | 5801| options | [PackingOption](#packingoption) | 是 | 设置打包参数。 | 5802| callback | AsyncCallback\<void> | 是 | 回调函数,当打包进文件成功,err为undefined,否则为错误对象。 | 5803 5804**错误码:** 5805 5806以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 5807 5808| 错误码ID | 错误信息 | 5809| ------- | --------------------------------------------| 5810| 62980096| The Operation failed. | 5811| 62980101 | The image data is abnormal. | 5812| 62980106 | The image is too large. | 5813| 62980113 | Unknown image format. | 5814| 62980115 | If the parameter is invalid. | 5815| 62980119 | If encoder occur error during encoding. | 5816| 62980120 | Add pixelmap out of range. | 5817| 62980172 | Failed to encode icc. | 5818| 62980252 | Failed to create surface. | 5819 5820**示例:** 5821 5822```ts 5823import { BusinessError } from '@kit.BasicServicesKit'; 5824import { fileIo as fs } from '@kit.CoreFileKit'; 5825 5826const context: Context = getContext(this); 5827//此处'test.png'仅作示例,请开发者自行替换,否则imageSource会创建失败导致后续无法正常执行。 5828const path: string = context.filesDir + "/test.png"; 5829const imageSourceApi: image.ImageSource = image.createImageSource(path); 5830let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }; 5831const filePath: string = context.filesDir + "/image_source.jpg"; 5832let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 5833const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5834imagePackerApi.packToFile(imageSourceApi, file.fd, packOpts, (err: BusinessError) => { 5835 if (err) { 5836 console.error(`Failed to pack the image to file.code ${err.code},message is ${err.message}`); 5837 } else { 5838 console.info('Succeeded in packing the image to file.'); 5839 } 5840}) 5841``` 5842 5843### packToFile<sup>11+</sup> 5844 5845packToFile (source: ImageSource, fd: number, options: PackingOption): Promise\<void> 5846 5847指定打包参数,将ImageSource图片源编码后直接打包进文件。使用Promise形式返回结果。 5848 5849**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 5850 5851**参数:** 5852 5853| 参数名 | 类型 | 必填 | 说明 | 5854| ------ | ------------------------------- | ---- | -------------- | 5855| source | [ImageSource](#imagesource) | 是 | 打包的图片源。 | 5856| fd | number | 是 | 文件描述符。 | 5857| options | [PackingOption](#packingoption) | 是 | 设置打包参数。 | 5858 5859**返回值:** 5860 5861| 类型 | 说明 | 5862| -------------- | --------------------------------- | 5863| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 5864 5865**错误码:** 5866 5867以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 5868 5869| 错误码ID | 错误信息 | 5870| ------- | --------------------------------------------| 5871| 62980096| The Operation failed. | 5872| 62980101 | The image data is abnormal. | 5873| 62980106 | The image is too large. | 5874| 62980113 | Unknown image format. | 5875| 62980115 | If the parameter is invalid. | 5876| 62980119 | If encoder occur error during encoding. | 5877| 62980120 | Add pixelmap out of range. | 5878| 62980172 | Failed to encode icc. | 5879| 62980252 | Failed to create surface. | 5880 5881**示例:** 5882 5883```ts 5884import { BusinessError } from '@kit.BasicServicesKit'; 5885import { fileIo as fs } from '@kit.CoreFileKit'; 5886 5887const context: Context = getContext(this); 5888//此处'test.png'仅作示例,请开发者自行替换,否则imageSource会创建失败导致后续无法正常执行。 5889const path: string = context.filesDir + "/test.png"; 5890const imageSourceApi: image.ImageSource = image.createImageSource(path); 5891let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }; 5892const filePath: string = context.filesDir + "/image_source.jpg"; 5893let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 5894const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5895imagePackerApi.packToFile(imageSourceApi, file.fd, packOpts).then(() => { 5896 console.info('Succeeded in packing the image to file.'); 5897}).catch((error: BusinessError) => { 5898 console.error(`Failed to pack the image to file.code ${error.code},message is ${error.message}`); 5899}) 5900``` 5901 5902### packToFile<sup>11+</sup> 5903 5904packToFile (source: PixelMap, fd: number, options: PackingOption, callback: AsyncCallback\<void>): void; 5905 5906指定打包参数,将PixelMap图片源编码后直接打包进文件。使用callback形式返回结果。 5907 5908> **注意:** 5909> 接口如果返回62980115错误码,表明参数异常,可能是PixelMap对象被提前释放了。需要调用方排查,在该方法调用结束后再释放PixelMap对象。 5910 5911**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 5912 5913**参数:** 5914 5915| 参数名 | 类型 | 必填 | 说明 | 5916| -------- | ------------------------------- | ---- | ------------------------------ | 5917| source | [PixelMap](#pixelmap7) | 是 | 打包的PixelMap资源。 | 5918| fd | number | 是 | 文件描述符。 | 5919| options | [PackingOption](#packingoption) | 是 | 设置打包参数。 | 5920| callback | AsyncCallback\<void> | 是 | 回调函数,当打包图片进文件成功,err为undefined,否则为错误对象。 | 5921 5922**错误码:** 5923 5924以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 5925 5926| 错误码ID | 错误信息 | 5927| ------- | --------------------------------------------| 5928| 62980096| The Operation failed. | 5929| 62980101 | The image data is abnormal. | 5930| 62980106 | The image is too large. | 5931| 62980113 | Unknown image format. | 5932| 62980115 | If the parameter is invalid. | 5933| 62980119 | If encoder occur error during encoding. | 5934| 62980120 | Add pixelmap out of range. | 5935| 62980172 | Failed to encode icc. | 5936| 62980252 | Failed to create surface. | 5937 5938**示例:** 5939 5940```ts 5941import { BusinessError } from '@kit.BasicServicesKit'; 5942import { fileIo as fs } from '@kit.CoreFileKit'; 5943 5944const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4 5945let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 5946const context: Context = getContext(this); 5947const path: string = context.filesDir + "/pixel_map.jpg"; 5948image.createPixelMap(color, opts).then((pixelmap: image.PixelMap) => { 5949 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 5950 let file = fs.openSync(path, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 5951 const imagePackerApi: image.ImagePacker = image.createImagePacker(); 5952 imagePackerApi.packToFile(pixelmap, file.fd, packOpts, (err: BusinessError) => { 5953 if (err) { 5954 console.error(`Failed to pack the image to file.code ${err.code},message is ${err.message}`); 5955 } else { 5956 console.info('Succeeded in packing the image to file.'); 5957 } 5958 }) 5959}) 5960``` 5961 5962### packToFile<sup>11+</sup> 5963 5964packToFile (source: PixelMap, fd: number, options: PackingOption): Promise\<void> 5965 5966指定打包参数,将PixelMap图片源编码后直接打包进文件。使用Promise形式返回结果。 5967 5968> **注意:** 5969> 接口如果返回62980115错误码,表明参数异常,可能是PixelMap对象被提前释放了。需要调用方排查,在该方法调用结束后再释放PixelMap对象。 5970 5971**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 5972 5973**参数:** 5974 5975| 参数名 | 类型 | 必填 | 说明 | 5976| ------ | ------------------------------- | ---- | -------------------- | 5977| source | [PixelMap](#pixelmap7) | 是 | 打包的PixelMap资源。 | 5978| fd | number | 是 | 文件描述符。 | 5979| options | [PackingOption](#packingoption) | 是 | 设置打包参数。 | 5980 5981**返回值:** 5982 5983| 类型 | 说明 | 5984| -------------- | --------------------------------- | 5985| Promise\<void> | Promise对象。无返回结果的Promise对象。| 5986 5987**错误码:** 5988 5989以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 5990 5991| 错误码ID | 错误信息 | 5992| ------- | --------------------------------------------| 5993| 62980096| The Operation failed. | 5994| 62980101 | The image data is abnormal. | 5995| 62980106 | The image is too large. | 5996| 62980113 | Unknown image format. | 5997| 62980115 | If the parameter is invalid. | 5998| 62980119 | If encoder occur error during encoding. | 5999| 62980120 | Add pixelmap out of range. | 6000| 62980172 | Failed to encode icc. | 6001| 62980252 | Failed to create surface. | 6002 6003**示例:** 6004 6005```ts 6006import { BusinessError } from '@kit.BasicServicesKit'; 6007import { fileIo as fs } from '@kit.CoreFileKit'; 6008 6009const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4 6010let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } } 6011const context: Context = getContext(this); 6012const path: string = context.filesDir + "/pixel_map.jpg"; 6013image.createPixelMap(color, opts).then((pixelmap: image.PixelMap) => { 6014 let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 } 6015 let file = fs.openSync(path, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 6016 const imagePackerApi: image.ImagePacker = image.createImagePacker(); 6017 imagePackerApi.packToFile(pixelmap, file.fd, packOpts) 6018 .then(() => { 6019 console.info('Succeeded in packing the image to file.'); 6020 }).catch((error: BusinessError) => { 6021 console.error(`Failed to pack the image to file.code ${error.code},message is ${error.message}`); 6022 }) 6023}) 6024``` 6025 6026### packToFile<sup>13+</sup> 6027 6028packToFile(picture: Picture, fd: number, options: PackingOption): Promise\<void> 6029 6030指定打包参数,将Picture图片源编码后直接打包进文件。使用Promise形式返回结果。 6031 6032**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 6033 6034**参数:** 6035 6036| 参数名 | 类型 | 必填 | 说明 | 6037| ------- | ---------------------------- | ---- | -------------------- | 6038| picture | [Picture](#picture13) | 是 | 打包的Picture资源。 | 6039| fd | number | 是 | 文件描述符。 | 6040| options | [PackingOption](#packingoption) | 是 | 设置打包参数。 | 6041 6042**返回值:** 6043 6044| 类型 | 说明 | 6045| -------------- | ------------------------- | 6046| Promise\<void> | 无返回结果的Promise对象。 | 6047 6048**错误码:** 6049 6050以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 6051 6052| 错误码ID | 错误信息 | 6053| -------- | ------------------------------------------------------------ | 6054| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6055| 7800301 | Encode failed. | 6056 6057**示例:** 6058 6059```ts 6060import { BusinessError } from '@kit.BasicServicesKit'; 6061import { image } from '@kit.ImageKit'; 6062import { fileIo as fs } from '@kit.CoreFileKit'; 6063 6064async function PackToFile() { 6065 const context = getContext(); 6066 const resourceMgr = context.resourceManager; 6067 const rawFile = await resourceMgr.getRawFileContent("test.jpg"); 6068 let ops: image.SourceOptions = { 6069 sourceDensity: 98, 6070 } 6071 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6072 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6073 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6074 6075 let funcName = "PackToFile"; 6076 if (imagePackerApi != null) { 6077 const context: Context = getContext(); 6078 const filePath: string = context.filesDir + "/test.jpg"; 6079 let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 6080 let packOpts: image.PackingOption = { 6081 format: "image/jpeg", 6082 quality: 98, 6083 bufferSize: 10, 6084 desiredDynamicRange: image.PackingDynamicRange.AUTO, 6085 needsPackProperties: true}; 6086 await imagePackerApi.packToFile(pictureObj, file.fd, packOpts).then(() => { 6087 console.info(funcName, 'Succeeded in packing the image to file.'); 6088 }).catch((error: BusinessError) => { 6089 console.error(funcName, 'Failed to pack the image to file.code ${error.code},message is ${error.message}'); 6090 }); 6091 } 6092} 6093``` 6094 6095## image.createAuxiliaryPicture<sup>13+</sup> 6096 6097createAuxiliaryPicture(buffer: ArrayBuffer, size: Size, type: AuxiliaryPictureType): AuxiliaryPicture 6098 6099通过ArrayBuffer图片数据、辅助图尺寸、辅助图类型创建AuxiliaryPicture实例。 6100 6101**系统能力:** SystemCapability.Multimedia.Image.Core 6102 6103**参数:** 6104 6105| 参数名 | 类型 | 必填 | 说明 | 6106| ------ | ----------------------------------------------- | ---- | ---------------------------- | 6107| buffer | ArrayBuffer | 是 | 以buffer形式存放的图像数据。 | 6108| size | [Size](#size) | 是 | 辅助图的尺寸。 | 6109| type | [AuxiliaryPictureType](#auxiliarypicturetype13) | 是 | 辅助图类型。 | 6110 6111**返回值:** 6112 6113| 类型 | 说明 | 6114| --------------------------------------- | ------------------------------------------ | 6115| [AuxiliaryPicture](#auxiliarypicture13) | 如果操作成功,则返回AuxiliaryPicture实例。 | 6116 6117**错误码:** 6118 6119以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 6120 6121| 错误码ID | 错误信息 | 6122| -------- | ------------------------------------------------------------ | 6123| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6124 6125**示例:** 6126 6127```ts 6128import { image } from '@kit.ImageKit'; 6129 6130async function CreateAuxiliaryPicture() { 6131 let funcName = "CreateAuxiliaryPicture"; 6132 const context = getContext(); 6133 const resourceMgr = context.resourceManager; 6134 const rawFile = await resourceMgr.getRawFileContent("hdr.jpg"); //需要支持hdr的图片 6135 let auxBuffer: ArrayBuffer = rawFile.buffer as ArrayBuffer; 6136 let auxSize: Size = { 6137 height: 180, 6138 width: 240 6139 }; 6140 let auxType: image.AuxiliaryPictureType = image.AuxiliaryPictureType.GAINMAP; 6141 let auxPictureObj: image.AuxiliaryPicture | null = image.createAuxiliaryPicture(auxBuffer, auxSize, auxType); 6142 if(auxPictureObj != null) { 6143 let type: image.AuxiliaryPictureType = auxPictureObj.getType(); 6144 console.info(funcName, 'CreateAuxiliaryPicture succeeded this.Aux_picture.type.' + JSON.stringify(type)); 6145 } else { 6146 console.error(funcName, 'CreateAuxiliaryPicture failed'); 6147 } 6148} 6149``` 6150 6151## AuxiliaryPicture<sup>13+</sup> 6152 6153辅助图一般用于辅助主图进行特殊信息的展示,使图像包含更丰富的信息。辅助图图像类,用于读取或写入图像的辅助图数据以及获取图像的辅助图信息。在调用AuxiliaryPicture的方法前,需要先通过[createAuxiliaryPicture](#imagecreateauxiliarypicture13)创建一个AuxiliaryPicture实例。 6154 6155### 属性 6156 6157**系统能力:** SystemCapability.Multimedia.Image.Core 6158 6159### writePixelsFromBuffer<sup>13+</sup> 6160 6161writePixelsFromBuffer(data: ArrayBuffer): Promise\<void> 6162 6163读取ArrayBuffer中的辅助图片数据,并将数据写入AuxiliaryPicture对象,使用Promise形式返回。 6164 6165**系统能力:** SystemCapability.Multimedia.Image.Core 6166 6167**参数:** 6168 6169| 参数名 | 类型 | 必填 | 说明 | 6170| ------ | ----------- | ---- | ---------------- | 6171| data | ArrayBuffer | 是 | 辅助图像素数据。 | 6172 6173**返回值:** 6174 6175| 类型 | 说明 | 6176| -------------- | -------------------------------------- | 6177| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 6178 6179**错误码:** 6180 6181以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 6182 6183| 错误码ID | 错误信息 | 6184| -------- | ------------------------------------------------------------ | 6185| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6186| 7600301 | Memory alloc failed. | 6187| 7600302 | Memory copy failed. | 6188 6189**示例:** 6190 6191```ts 6192import { image } from '@kit.ImageKit'; 6193 6194async function WritePixelsFromBuffer() { 6195 const context = getContext(); 6196 const resourceMgr = context.resourceManager; 6197 const rawFile = await resourceMgr.getRawFileContent("hdr.jpg"); //需要支持hdr的图片 6198 let ops: image.SourceOptions = { 6199 sourceDensity: 98, 6200 } 6201 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6202 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6203 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6204 let auxPictureObj: image.AuxiliaryPicture | null = pictureObj.getAuxiliaryPicture(image.AuxiliaryPictureType.GAINMAP); 6205 if(auxPictureObj != null) { 6206 let auxBuffer: ArrayBuffer = await auxPictureObj.readPixelsToBuffer(); 6207 await auxPictureObj.writePixelsFromBuffer(auxBuffer); 6208 console.info('Write pixels from buffer success.'); 6209 } else { 6210 console.error('AuxPictureObj is null.'); 6211 } 6212} 6213``` 6214 6215### readPixelsToBuffer<sup>13+</sup> 6216 6217readPixelsToBuffer(): Promise\<ArrayBuffer> 6218 6219读取图像像素映射数据并将数据写入ArrayBuffer,使用Promise形式返回。 6220 6221**系统能力:** SystemCapability.Multimedia.Image.Core 6222 6223**返回值:** 6224 6225| 类型 | 说明 | 6226| --------------------- | --------------------------------- | 6227| Promise\<ArrayBuffer> | Promise对象。返回辅助图像素数据。 | 6228 6229**错误码:** 6230 6231以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 6232 6233| 错误码ID | 错误信息 | 6234| -------- | -------------------- | 6235| 7600301 | Memory alloc failed. | 6236| 7600302 | Memory copy failed. | 6237 6238**示例:** 6239 6240```ts 6241import { BusinessError } from '@kit.BasicServicesKit'; 6242import { image } from '@kit.ImageKit'; 6243 6244async function ReadPixelsToBuffer() { 6245 const context = getContext(); 6246 const resourceMgr = context.resourceManager; 6247 const rawFile = await resourceMgr.getRawFileContent("hdr.jpg"); //需要支持hdr的图片 6248 let ops: image.SourceOptions = { 6249 sourceDensity: 98, 6250 } 6251 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6252 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6253 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6254 let auxPictureObj: image.AuxiliaryPicture | null = pictureObj.getAuxiliaryPicture(image.AuxiliaryPictureType.GAINMAP); 6255 if(auxPictureObj != null) { 6256 await auxPictureObj.readPixelsToBuffer().then((pixelsBuffer: ArrayBuffer) => { 6257 console.info('Read pixels to buffer success.' ); 6258 }).catch((error: BusinessError) => { 6259 console.error('Read pixels to buffer failed error.code: ' + JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message)); 6260 }); 6261 } else { 6262 console.error('AuxPictureObj is null.'); 6263 } 6264} 6265``` 6266 6267### getType<sup>13+</sup> 6268 6269getType(): AuxiliaryPictureType 6270 6271获取辅助图的类型。 6272 6273**系统能力:** SystemCapability.Multimedia.Image.Core 6274 6275**返回值:** 6276 6277| 类型 | 说明 | 6278| ----------------------------------------------- | ---------------------------- | 6279| [AuxiliaryPictureType](#auxiliarypicturetype13) | 操作成功,返回辅助图的类型。 | 6280 6281**示例:** 6282 6283```ts 6284import { image } from '@kit.ImageKit'; 6285 6286async function GetAuxiliaryPictureType() { 6287 if (auxPictureObj != null) { 6288 let type: image.AuxiliaryPictureType = auxPictureObj.getType(); 6289 console.info('Success get auxiliary picture type ' + JSON.stringify(type)); 6290 } else { 6291 console.info('Failed get auxiliary picture type '); 6292 } 6293} 6294``` 6295 6296### setMetadata<sup>13+</sup> 6297 6298setMetadata(metadataType: MetadataType, metadata: Metadata): Promise\<void> 6299 6300设置辅助图元数据。 6301 6302**系统能力:** SystemCapability.Multimedia.Image.Core 6303 6304**参数:** 6305 6306| 参数名 | 类型 | 必填 | 说明 | 6307| ------------ | ------------------------------- | ---- | ------------------------------------ | 6308| metadataType | [MetadataType](#metadatatype13) | 是 | 元数据的类型,用于设置对应的元数据。 | 6309| metadata | [Metadata](#metadata13) | 是 | 元数据对象。 | 6310 6311**返回值:** 6312 6313| 类型 | 说明 | 6314| -------------- | -------------------------------------- | 6315| Promise\<void> | Promise对象,无返回结果的Promise对象。 | 6316 6317**错误码:** 6318 6319以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 6320 6321| 错误码ID | 错误信息 | 6322| -------- | ------------------------------------------------------------ | 6323| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6324| 7600202 | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. | 6325 6326**示例:** 6327 6328```ts 6329import { BusinessError } from '@kit.BasicServicesKit'; 6330import { image } from '@kit.ImageKit'; 6331 6332async function SetAuxPictureObjMetadata() { 6333 const exifContext = getContext(); 6334 const exifResourceMgr = exifContext.resourceManager; 6335 const exifRawFile = await exifResourceMgr.getRawFileContent("exif.jpg");//图片包含exif metadata 6336 let exifOps: image.SourceOptions = { 6337 sourceDensity: 98, 6338 } 6339 let exifImageSource: image.ImageSource = image.createImageSource(exifRawFile.buffer as ArrayBuffer, exifOps); 6340 let exifCommodityPixelMap: image.PixelMap = await exifImageSource.createPixelMap(); 6341 let exifPictureObj: image.Picture = image.createPicture(exifCommodityPixelMap); 6342 if (exifPictureObj != null) { 6343 console.info('Create picture succeeded'); 6344 } else { 6345 console.info('Create picture failed'); 6346 } 6347 6348 if (auxPictureObj != null) { 6349 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 6350 let exifMetaData: image.Metadata = await exifPictureObj.getMetadata(metadataType); 6351 auxPictureObj.setMetadata(metadataType, exifMetaData).then(() => { 6352 console.info('Set metadata success'); 6353 }).catch((error: BusinessError) => { 6354 console.error('Set metadata failed.error.code: ${error.code}, error.message: ${error.message}'); 6355 }); 6356 } else { 6357 console.info('AuxPictureObjMetaData is null'); 6358 } 6359} 6360``` 6361 6362### getMetadata<sup>13+</sup> 6363 6364getMetadata(metadataType: MetadataType): Promise\<Metadata> 6365 6366从辅助图中获取元数据。 6367 6368**系统能力:** SystemCapability.Multimedia.Image.Core 6369 6370**参数:** 6371 6372| 参数名 | 类型 | 必填 | 说明 | 6373| ------------ | ------------------------------- | ---- | -------------------------------------- | 6374| metadataType | [MetadataType](#metadatatype13) | 是 | 元数据类型,用于获取对应类型的元数据。 | 6375 6376**返回值:** 6377 6378| 类型 | 说明 | 6379| -------------------------------- | ---------------- | 6380| Promise<[Metadata](#metadata13)> | 返回元数据对象。 | 6381 6382**错误码:** 6383 6384以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 6385 6386| 错误码ID | 错误信息 | 6387| -------- | ------------------------------------------------------------ | 6388| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6389| 7600202 | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. | 6390 6391**示例:** 6392 6393```ts 6394import { image } from '@kit.ImageKit'; 6395 6396async function GetAuxPictureObjMetadata() { 6397 if (auxPictureObj != null) { 6398 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 6399 let auxPictureObjMetaData: image.Metadata | null = await auxPictureObj.getMetadata(metadataType); 6400 if (auxPictureObjMetaData != null) { 6401 console.info('Get auxpictureobj Metadata success' ); 6402 } else { 6403 console.info('Get auxpictureobj Metadata failed'); 6404 } 6405 } else { 6406 console.info('Get auxpictureobj is null.'); 6407 } 6408} 6409``` 6410 6411### getAuxiliaryPictureinfo<sup>13+</sup> 6412 6413getAuxiliaryPictureInfo(): AuxiliaryPictureInfo 6414 6415获取有关此辅助图的图像信息。 6416 6417**系统能力:** SystemCapability.Multimedia.Image.Core 6418 6419**返回值:** 6420 6421| 类型 | 说明 | 6422| ----------------------------------------------- | --------------------------------- | 6423| [AuxiliaryPictureInfo](#auxiliarypictureinfo13) | Promise对象,返回辅助图图像信息。 | 6424 6425**示例:** 6426 6427```ts 6428import { image } from '@kit.ImageKit'; 6429 6430async function GetAuxiliaryPictureInfo() { 6431 if(auxPictureObj != null) { 6432 let auxinfo: image.AuxiliaryPictureInfo = auxPictureObj.getAuxiliaryPictureInfo(); 6433 console.info('GetAuxiliaryPictureInfo Type: ' + auxinfo.auxiliaryPictureType + 6434 ' height: ' + auxinfo.size.height + ' width: ' + auxinfo.size.width + 6435 ' rowStride: ' + auxinfo.rowStride + ' pixelFormat: ' + auxinfo.pixelFormat + 6436 ' colorSpace: ' + auxinfo.colorSpace); 6437 } else { 6438 console.info('Get auxiliary picture information failed'); 6439 } 6440} 6441``` 6442 6443### setAuxiliaryPictureinfo<sup>13+</sup> 6444 6445setAuxiliaryPictureInfo(info: AuxiliaryPictureInfo): void 6446 6447设置辅助图的图像信息。 6448 6449**系统能力:** SystemCapability.Multimedia.Image.Core 6450 6451**参数:** 6452 6453| 参数名 | 类型 | 必填 | 说明 | 6454| ------ | ----------------------------------------------- | ---- | ------------------ | 6455| info | [AuxiliaryPictureInfo](#auxiliarypictureinfo13) | 是 | 辅助图的图像信息。 | 6456 6457**错误码:** 6458 6459以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 6460 6461| 错误码ID | 错误信息 | 6462| -------- | :----------------------------------------------------------- | 6463| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6464 6465**示例:** 6466 6467```ts 6468import { colorSpaceManager } from '@kit.ArkGraphics2D'; 6469import { image } from '@kit.ImageKit'; 6470 6471async function SetAuxiliaryPictureInfo() { 6472 if(auxPictureObj != null) { 6473 let colorSpaceName = colorSpaceManager.ColorSpace.SRGB; 6474 let info: image.AuxiliaryPictureInfo = { 6475 auxiliaryPictureType: image.AuxiliaryPictureType.GAINMAP, 6476 size: {height: 100, width: 200}, 6477 pixelFormat: image.PixelMapFormat.RGBA_8888, 6478 rowStride: 0, 6479 colorSpace: colorSpaceManager.create(colorSpaceName), 6480 }; 6481 auxPictureObj.setAuxiliaryPictureInfo(info); 6482 } 6483} 6484``` 6485 6486### release<sup>13+</sup> 6487 6488release():void 6489 6490释放辅助图对象,无返回值。 6491 6492**系统能力:** SystemCapability.Multimedia.Image.Core 6493 6494**示例:** 6495 6496```ts 6497import { image } from '@kit.ImageKit'; 6498 6499async function Release() { 6500 let funcName = "Release"; 6501 if (auxPictureObj != null) { 6502 auxPictureObj.release(); 6503 if (auxPictureObj.getType() == null) { 6504 console.info(funcName, 'Success !'); 6505 } else { 6506 console.info(funcName, 'Failed !'); 6507 } 6508 } else { 6509 console.info('PictureObj is null'); 6510 } 6511} 6512``` 6513 6514## Metadata<sup>13+</sup> 6515 6516图像元数据类,用于存储图像的元数据。目前支持的元数据类型可参考[MetadataType](#metadatatype13)。 6517 6518### 属性 6519 6520**系统能力:** SystemCapability.Multimedia.Image.Core 6521 6522### getProperties<sup>13+</sup> 6523 6524getProperties(key: Array\<string>): Promise\<Record\<string, string | null>> 6525 6526获取图像中属性的值,使用Promise形式返回。如要查询属性值信息请参考[PropertyKey](#propertykey7)和[FragmentMapPropertyKey](#fragmentmappropertykey13)。 6527 6528**系统能力:** SystemCapability.Multimedia.Image.Core 6529 6530**参数:** 6531 6532| 参数名 | 类型 | 必填 | 说明 | 6533| ------ | -------------- | ---- | ------------------------ | 6534| key | Array\<string> | 是 | 要获取其值的属性的名称。 | 6535 6536**返回值:** 6537 6538| 类型 | 说明 | 6539| ---------------------------------------- | ------------------------------------------------------------ | 6540| Promise\<Record<string, string \| null>> | Promise对象,返回元数据要获取的属性的值,如获取失败则返回错误码。 | 6541 6542**错误码:** 6543 6544以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 6545 6546| 错误码ID | 错误信息 | 6547| -------- | ------------------------------------------------------------ | 6548| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 6549| 7600202 | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. | 6550 6551**示例:** 6552 6553```ts 6554import { BusinessError } from '@kit.BasicServicesKit'; 6555import { image } from '@kit.ImageKit'; 6556 6557async function GetProperties() { 6558 const context = getContext(); 6559 const resourceMgr = context.resourceManager; 6560 const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); //图片包含exif metadata 6561 let ops: image.SourceOptions = { 6562 sourceDensity: 98, 6563 } 6564 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6565 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6566 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6567 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 6568 let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType); 6569 if (metaData != null) { 6570 await metaData.getProperties(["ImageWidth", "ImageLength"]).then((data2) => { 6571 console.info('Get properties ',JSON.stringify(data2)); 6572 }).catch((error: BusinessError) => { 6573 console.info('Get properties failed error.code: ' +JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message)); 6574 }); 6575 } else { 6576 console.info('Metadata is null.'); 6577 } 6578} 6579``` 6580 6581### setProperties<sup>13+</sup> 6582 6583setProperties(records: Record\<string, string | null>): Promise\<void> 6584 6585批量设置图片元数据中的指定属性的值,使用Promise形式返回。如要查询属性值信息请参考[PropertyKey](#propertykey7)和[FragmentMapPropertyKey](#fragmentmappropertykey13)。 6586 6587**系统能力:** SystemCapability.Multimedia.Image.Core 6588 6589**参数:** 6590 6591| 参数名 | 类型 | 必填 | 说明 | 6592| ------- | ------------------------------ | ---- | ------------------------ | 6593| records | Record<string, string \| null> | 是 | 要修改的属性和值的数组。 | 6594 6595**返回值:** 6596 6597| 类型 | 说明 | 6598| -------------- | ------------------------------------- | 6599| Promise\<void> | Promise对象,如获取失败则返回错误码。 | 6600 6601**错误码:** 6602 6603以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 6604 6605| 错误码ID | 错误信息 | 6606| -------- | ------------------------------------------------------------ | 6607| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | 6608| 7600202 | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. | 6609 6610**示例:** 6611 6612```ts 6613import { BusinessError } from '@kit.BasicServicesKit'; 6614import { image } from '@kit.ImageKit'; 6615 6616async function SetProperties() { 6617 const context = getContext(); 6618 const resourceMgr = context.resourceManager; 6619 const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); //图片包含exif metadata 6620 let ops: image.SourceOptions = { 6621 sourceDensity: 98, 6622 } 6623 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6624 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6625 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6626 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 6627 let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType); 6628 if (metaData != null) { 6629 let setkey: Record<string, string | null> = { 6630 "ImageWidth": "200", 6631 "ImageLength": "300" 6632 }; 6633 await metaData.setProperties(setkey).then(async () => { 6634 console.info('Set auxpictureobj properties success.'); 6635 }).catch((error: BusinessError) => { 6636 console.error('Failed to set metadata Properties. code is ${error.code}, message is ${error.message}'); 6637 }) 6638 } else { 6639 console.info('AuxPictureObj metadata is null. '); 6640 } 6641} 6642``` 6643 6644### getAllProperties<sup>13+</sup> 6645 6646getAllProperties(): Promise\<Record<string, string | null>> 6647 6648获取图片中所有元数据的属性和值,使用Promise形式返回。如要查询属性值信息请参考[PropertyKey](#propertykey7)和[FragmentMapPropertyKey](#fragmentmappropertykey13)。 6649 6650**系统能力:** SystemCapability.Multimedia.Image.Core 6651 6652**返回值:** 6653 6654| 类型 | 说明 | 6655| ---------------------------------------- | ------------------------------------------- | 6656| Promise\<Record<string, string \| null>> | Promise对象,返回元数据拥有的所有属性的值。 | 6657 6658**示例:** 6659 6660```ts 6661import { BusinessError } from '@kit.BasicServicesKit'; 6662import { image } from '@kit.ImageKit'; 6663 6664async function GetAllProperties() { 6665 const context = getContext(); 6666 const resourceMgr = context.resourceManager; 6667 const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); //图片包含exif metadata 6668 let ops: image.SourceOptions = { 6669 sourceDensity: 98, 6670 } 6671 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6672 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6673 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6674 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 6675 let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType); 6676 if (metaData != null) { 6677 await metaData.getAllProperties().then((data2) => { 6678 const count = Object.keys(data2).length; 6679 console.info('Metadata have ', count, ' properties'); 6680 console.info('Get metadata all properties: ', JSON.stringify(data2)); 6681 }).catch((error: BusinessError) => { 6682 console.error('Get metadata all properties failed error.code: ' +JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message)); 6683 }); 6684 } else { 6685 console.info('Metadata is null.'); 6686 } 6687} 6688``` 6689 6690### clone<sup>13+</sup> 6691 6692clone(): Promise\<Metadata> 6693 6694对元数据进行克隆,用Promise形式返回结果。 6695 6696**系统能力:** SystemCapability.Multimedia.Image.Core 6697 6698**返回值:** 6699 6700| 类型 | 说明 | 6701| --------------------------------- | --------------------------------- | 6702| Promise\<[Metadata](#metadata13)> | Promise对象,成功返回元数据实例。 | 6703 6704**错误码:** 6705 6706以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 6707 6708| 错误码ID | 错误信息 | 6709| -------- | -------------------- | 6710| 7600301 | Memory alloc failed. | 6711| 7600302 | Memory copy failed. | 6712 6713**示例:** 6714 6715```ts 6716import { BusinessError } from '@kit.BasicServicesKit'; 6717import { image } from '@kit.ImageKit'; 6718 6719async function clone() { 6720 const context = getContext(); 6721 const resourceMgr = context.resourceManager; 6722 const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); //图片包含exif metadata 6723 let ops: image.SourceOptions = { 6724 sourceDensity: 98, 6725 } 6726 let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops); 6727 let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap(); 6728 let pictureObj: image.Picture = image.createPicture(commodityPixelMap); 6729 let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA; 6730 let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType); 6731 if (metaData != null) { 6732 let new_metadata: image.Metadata = await metaData.clone(); 6733 new_metadata.getProperties(["ImageWidth"]).then((data1) => { 6734 console.info('Clone new_metadata and get Properties.', JSON.stringify(data1)); 6735 }).catch((err: BusinessError) => { 6736 console.error('Clone new_metadata failed.', JSON.stringify(err)); 6737 }); 6738 } else { 6739 console.info('Metadata is null.'); 6740 } 6741} 6742``` 6743 6744## image.createImageReceiver<sup>11+</sup> 6745 6746createImageReceiver(size: Size, format: ImageFormat, capacity: number): ImageReceiver 6747 6748通过图片大小、图片格式、容量创建ImageReceiver实例。 6749 6750**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 6751 6752**参数:** 6753 6754| 参数名 | 类型 | 必填 | 说明 | 6755| -------- | ------ | ---- | ---------------------- | 6756| size | [Size](#size) | 是 | 图像的默认大小。 | 6757| format | [ImageFormat](#imageformat9) | 是 | 图像格式,取值为[ImageFormat](#imageformat9)常量(目前仅支持 ImageFormat:JPEG,实际返回格式由生产者决定,如相机)。 | 6758| capacity | number | 是 | 同时访问的最大图像数。 | 6759 6760**返回值:** 6761 6762| 类型 | 说明 | 6763| -------------------------------- | --------------------------------------- | 6764| [ImageReceiver](#imagereceiver9) | 如果操作成功,则返回ImageReceiver实例。 | 6765 6766**错误码:** 6767 6768以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 6769 6770| 错误码ID | 错误信息 | 6771| ------- | --------------------------------------------| 6772| 401| Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; | 6773 6774**示例:** 6775 6776```ts 6777let size: image.Size = { 6778 height: 8192, 6779 width: 8 6780} 6781let receiver: image.ImageReceiver = image.createImageReceiver(size, image.ImageFormat.JPEG, 8); 6782``` 6783 6784## image.createImageReceiver<sup>(deprecated)</sup> 6785 6786createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver 6787 6788通过宽、高、图片格式、容量创建ImageReceiver实例。 6789 6790> **说明:** 6791> 6792> 从API version 11开始不再维护,建议使用[createImageReceiver](#imagecreateimagereceiver11)代替。 6793 6794**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 6795 6796**参数:** 6797 6798| 参数名 | 类型 | 必填 | 说明 | 6799| -------- | ------ | ---- | ---------------------- | 6800| width | number | 是 | 图像的默认宽度。 | 6801| height | number | 是 | 图像的默认高度。 | 6802| format | number | 是 | 图像格式,取值为[ImageFormat](#imageformat9)常量(目前仅支持 ImageFormat:JPEG,实际返回格式由生产者决定,如相机)。 | 6803| capacity | number | 是 | 同时访问的最大图像数。 | 6804 6805**返回值:** 6806 6807| 类型 | 说明 | 6808| -------------------------------- | --------------------------------------- | 6809| [ImageReceiver](#imagereceiver9) | 如果操作成功,则返回ImageReceiver实例。 | 6810 6811**示例:** 6812 6813```ts 6814let receiver: image.ImageReceiver = image.createImageReceiver(8192, 8, image.ImageFormat.JPEG, 8); 6815``` 6816 6817## ImageReceiver<sup>9+</sup> 6818 6819图像接收类,用于获取组件surface id,接收最新的图片和读取下一张图片,以及释放ImageReceiver实例。 6820 6821在调用以下方法前需要先创建ImageReceiver实例。 6822 6823### 属性 6824 6825**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 6826 6827| 名称 | 类型 | 可读 | 可写 | 说明 | 6828| -------- | ---------------------------- | ---- | ---- | ------------------ | 6829| size | [Size](#size) | 是 | 否 | 图片大小。 | 6830| capacity | number | 是 | 否 | 同时访问的图像数。 | 6831| format | [ImageFormat](#imageformat9) | 是 | 否 | 图像格式。 | 6832 6833### getReceivingSurfaceId<sup>9+</sup> 6834 6835getReceivingSurfaceId(callback: AsyncCallback\<string>): void 6836 6837用于获取一个surface id供Camera或其他组件使用。使用callback返回结果。 6838 6839**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 6840 6841**参数:** 6842 6843| 参数名 | 类型 | 必填 | 说明 | 6844| -------- | ---------------------- | ---- | -------------------------- | 6845| callback | AsyncCallback\<string> | 是 | 回调函数,当获取surface id成功,err为undefined,data为获取到的surface id;否则为错误对象。 | 6846 6847**示例:** 6848 6849```ts 6850import { BusinessError } from '@kit.BasicServicesKit'; 6851 6852receiver.getReceivingSurfaceId((err: BusinessError, id: string) => { 6853 if (err) { 6854 console.error(`Failed to get the ReceivingSurfaceId.code ${err.code},message is ${err.message}`); 6855 } else { 6856 console.info('Succeeded in getting the ReceivingSurfaceId.'); 6857 } 6858}); 6859``` 6860 6861### getReceivingSurfaceId<sup>9+</sup> 6862 6863getReceivingSurfaceId(): Promise\<string> 6864 6865用于获取一个surface id供Camera或其他组件使用。使用promise返回结果。 6866 6867**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 6868 6869**返回值:** 6870 6871| 类型 | 说明 | 6872| ---------------- | -------------------- | 6873| Promise\<string> | Promise对象,返回surface id。 | 6874 6875**示例:** 6876 6877```ts 6878import { BusinessError } from '@kit.BasicServicesKit'; 6879 6880receiver.getReceivingSurfaceId().then((id: string) => { 6881 console.info('Succeeded in getting the ReceivingSurfaceId.'); 6882}).catch((error: BusinessError) => { 6883 console.error(`Failed to get the ReceivingSurfaceId.code ${error.code},message is ${error.message}`); 6884}) 6885``` 6886 6887### readLatestImage<sup>9+</sup> 6888 6889readLatestImage(callback: AsyncCallback\<Image>): void 6890 6891从ImageReceiver读取最新的图片,并使用callback返回结果。 6892 6893**注意**:此接口需要在[on](#on9)回调触发后调用,才能正常的接收到数据。且此接口返回的[Image](#image9)对象使用完毕后需要调用[release](#release9-4)方法释放,释放后才可以继续接收新的数据。 6894 6895**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 6896 6897**参数:** 6898 6899| 参数名 | 类型 | 必填 | 说明 | 6900| -------- | ------------------------------- | ---- | ------------------------ | 6901| callback | AsyncCallback<[Image](#image9)> | 是 | 回调函数,当读取最新图片成功,err为undefined,data为获取到的最新图片;否则为错误对象。 | 6902 6903**示例:** 6904 6905```ts 6906import { BusinessError } from '@kit.BasicServicesKit'; 6907 6908receiver.readLatestImage((err: BusinessError, img: image.Image) => { 6909 if (err) { 6910 console.error(`Failed to read the latest Image.code ${err.code},message is ${err.message}`); 6911 } else { 6912 console.info('Succeeded in reading the latest Image.'); 6913 } 6914}); 6915``` 6916 6917### readLatestImage<sup>9+</sup> 6918 6919readLatestImage(): Promise\<Image> 6920 6921从ImageReceiver读取最新的图片,并使用promise返回结果。 6922 6923**注意**:此接口需要在[on](#on9)回调触发后调用,才能正常的接收到数据。且此接口返回的[Image](#image9)对象使用完毕后需要调用[release](#release9-4)方法释放,释放后才可以继续接收新的数据。 6924 6925**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 6926 6927**返回值:** 6928 6929| 类型 | 说明 | 6930| ------------------------- | ------------------ | 6931| Promise<[Image](#image9)> | Promise对象,返回最新图片。 | 6932 6933**示例:** 6934 6935```ts 6936import { BusinessError } from '@kit.BasicServicesKit'; 6937 6938receiver.readLatestImage().then((img: image.Image) => { 6939 console.info('Succeeded in reading the latest Image.'); 6940}).catch((error: BusinessError) => { 6941 console.error(`Failed to read the latest Image.code ${error.code},message is ${error.message}`); 6942}) 6943``` 6944 6945### readNextImage<sup>9+</sup> 6946 6947readNextImage(callback: AsyncCallback\<Image>): void 6948 6949从ImageReceiver读取下一张图片,并使用callback返回结果。 6950 6951**注意**:此接口需要在[on](#on9)回调触发后调用,才能正常的接收到数据。且此接口返回的[Image](#image9)对象使用完毕后需要调用[release](#release9-4)方法释放,释放后才可以继续接收新的数据。 6952 6953**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 6954 6955**参数:** 6956 6957| 参数名 | 类型 | 必填 | 说明 | 6958| -------- | ------------------------------- | ---- | -------------------------- | 6959| callback | AsyncCallback<[Image](#image9)> | 是 | 回调函数,当获取下一张图片成功,err为undefined,data为获取到的下一张图片;否则为错误对象。 | 6960 6961**示例:** 6962 6963```ts 6964import { BusinessError } from '@kit.BasicServicesKit'; 6965 6966receiver.readNextImage((err: BusinessError, img: image.Image) => { 6967 if (err) { 6968 console.error(`Failed to read the next Image.code ${err.code},message is ${err.message}`); 6969 } else { 6970 console.info('Succeeded in reading the next Image.'); 6971 } 6972}); 6973``` 6974 6975### readNextImage<sup>9+</sup> 6976 6977readNextImage(): Promise\<Image> 6978 6979从ImageReceiver读取下一张图片,并使用promise返回结果。 6980 6981**注意**:此接口需要在[on](#on9)回调触发后调用,才能正常的接收到数据。且此接口返回的[Image](#image9)对象使用完毕后需要调用[release](#release9-4)方法释放,释放后才可以继续接收新的数据。 6982 6983**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 6984 6985**返回值:** 6986 6987| 类型 | 说明 | 6988| ------------------------- | -------------------- | 6989| Promise<[Image](#image9)> | Promise对象,返回下一张图片。 | 6990 6991**示例:** 6992 6993```ts 6994import { BusinessError } from '@kit.BasicServicesKit'; 6995 6996receiver.readNextImage().then((img: image.Image) => { 6997 console.info('Succeeded in reading the next Image.'); 6998}).catch((error: BusinessError) => { 6999 console.error(`Failed to read the next Image.code ${error.code},message is ${error.message}`); 7000}) 7001``` 7002 7003### on<sup>9+</sup> 7004 7005on(type: 'imageArrival', callback: AsyncCallback\<void>): void 7006 7007接收图片时注册回调。 7008 7009**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 7010 7011**参数:** 7012 7013| 参数名 | 类型 | 必填 | 说明 | 7014| -------- | -------------------- | ---- | ------------------------------------------------------ | 7015| type | string | 是 | 注册事件的类型,固定为'imageArrival',接收图片时触发。 | 7016| callback | AsyncCallback\<void> | 是 | 回调函数,当注册事件触发成功,err为undefined,否则为错误对象。 | 7017 7018**示例:** 7019 7020```ts 7021receiver.on('imageArrival', () => { 7022 // image arrival, do something. 7023}) 7024``` 7025 7026### off<sup>13+</sup> 7027 7028off(type: 'imageArrival', callback?: AsyncCallback\<void>): void 7029 7030释放buffer时移除注册回调。 7031 7032**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 7033 7034**参数:** 7035 7036| 参数名 | 类型 | 必填 | 说明 | 7037| -------- | -------------------- |----|----------------------------------------| 7038| type | string | 是 | 注册事件的类型,固定为'imageArrival',释放buffer时触发。 | 7039| callback | AsyncCallback\<void> | 否 | 移除的回调函数。 | 7040 7041**示例:** 7042 7043```ts 7044let callbackFunc = ()=>{ 7045 // do something 7046} 7047receiver.on('imageArrival', callbackFunc) 7048receiver.off('imageArrival', callbackFunc) 7049``` 7050 7051### release<sup>9+</sup> 7052 7053release(callback: AsyncCallback\<void>): void 7054 7055释放ImageReceiver实例并使用回调返回结果。 7056 7057ArkTS有内存回收机制,ImageReceiver对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。 7058 7059**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 7060 7061**参数:** 7062 7063| 参数名 | 类型 | 必填 | 说明 | 7064| -------- | -------------------- | ---- | ------------------------ | 7065| callback | AsyncCallback\<void> | 是 | 回调函数,当释放ImageReceiver实例成功,err为undefined,否则为错误对象。 | 7066 7067**示例:** 7068 7069```ts 7070import { BusinessError } from '@kit.BasicServicesKit'; 7071 7072receiver.release((err: BusinessError) => { 7073 if (err) { 7074 console.error(`Failed to release the receiver.code ${err.code},message is ${err.message}`); 7075 } else { 7076 console.info('Succeeded in releasing the receiver.'); 7077 } 7078}) 7079``` 7080 7081### release<sup>9+</sup> 7082 7083release(): Promise\<void> 7084 7085释放ImageReceiver实例并使用promise返回结果。 7086 7087ArkTS有内存回收机制,ImageReceiver对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。 7088 7089**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 7090 7091**返回值:** 7092 7093| 类型 | 说明 | 7094| -------------- | ------------------ | 7095| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 7096 7097**示例:** 7098 7099```ts 7100import { BusinessError } from '@kit.BasicServicesKit'; 7101 7102receiver.release().then(() => { 7103 console.info('Succeeded in releasing the receiver.'); 7104}).catch((error: BusinessError) => { 7105 console.error(`Failed to release the receiver.code ${error.code},message is ${error.message}`); 7106}) 7107``` 7108 7109## image.createImageCreator<sup>11+</sup> 7110 7111createImageCreator(size: Size, format: ImageFormat, capacity: number): ImageCreator 7112 7113通过图片大小、图片格式、容量创建ImageCreator实例。 7114 7115**系统能力:** SystemCapability.Multimedia.Image.ImageCreator 7116 7117**参数:** 7118 7119| 参数名 | 类型 | 必填 | 说明 | 7120| -------- | ------ | ---- | ---------------------- | 7121| size | [Size](#size) | 是 | 图像的默认大小。 | 7122| format | [ImageFormat](#imageformat9) | 是 | 图像格式,如YCBCR_422_SP,JPEG。 | 7123| capacity | number | 是 | 同时访问的最大图像数。 | 7124 7125**返回值:** 7126 7127| 类型 | 说明 | 7128| ------------------------------ | --------------------------------------- | 7129| [ImageCreator](#imagecreator9) | 如果操作成功,则返回ImageCreator实例。 | 7130 7131 7132**错误码:** 7133 7134以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 7135 7136| 错误码ID | 错误信息 | 7137| ------- | --------------------------------------------| 7138| 401| Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; | 7139 7140**示例:** 7141 7142```ts 7143let size: image.Size = { 7144 height: 8192, 7145 width: 8 7146} 7147let creator: image.ImageCreator = image.createImageCreator(size, image.ImageFormat.JPEG, 8); 7148``` 7149 7150## image.createImageCreator<sup>(deprecated)</sup> 7151 7152createImageCreator(width: number, height: number, format: number, capacity: number): ImageCreator 7153 7154通过宽、高、图片格式、容量创建ImageCreator实例。 7155 7156> **说明:** 7157> 7158> 从API version 11开始不再维护,建议使用[createImageCreator](#imagecreateimagecreator11)代替。 7159 7160**系统能力:** SystemCapability.Multimedia.Image.ImageCreator 7161 7162**参数:** 7163 7164| 参数名 | 类型 | 必填 | 说明 | 7165| -------- | ------ | ---- | ---------------------- | 7166| width | number | 是 | 图像的默认宽度。 | 7167| height | number | 是 | 图像的默认高度。 | 7168| format | number | 是 | 图像格式,如YCBCR_422_SP,JPEG。 | 7169| capacity | number | 是 | 同时访问的最大图像数。 | 7170 7171**返回值:** 7172 7173| 类型 | 说明 | 7174| ------------------------------ | --------------------------------------- | 7175| [ImageCreator](#imagecreator9) | 如果操作成功,则返回ImageCreator实例。 | 7176 7177**示例:** 7178 7179```ts 7180let creator: image.ImageCreator = image.createImageCreator(8192, 8, image.ImageFormat.JPEG, 8); 7181``` 7182 7183## ImageCreator<sup>9+</sup> 7184 7185图像创建模块,用于请求图像原生数据区域,并开放给应用编译原生图像数据的能力。 7186在调用以下方法前需要先创建[ImageCreator](#imagecreator9)实例,ImageCreator不支持多线程。 7187 7188### 属性 7189 7190**系统能力:** SystemCapability.Multimedia.Image.ImageCreator 7191 7192| 名称 | 类型 | 可读 | 可写 | 说明 | 7193| -------- | ---------------------------- | ---- | ---- | ------------------ | 7194| capacity | number | 是 | 否 | 同时访问的图像数。 | 7195| format | [ImageFormat](#imageformat9) | 是 | 否 | 图像格式。 | 7196 7197### dequeueImage<sup>9+</sup> 7198 7199dequeueImage(callback: AsyncCallback\<Image>): void 7200 7201从空闲队列中获取buffer图片,用于绘制UI内容,并使用callback返回结果。 7202 7203**系统能力:** SystemCapability.Multimedia.Image.ImageCreator 7204 7205**参数:** 7206 7207| 参数名 | 类型 | 必填 | 说明 | 7208| ------------- | ---------------------------------------| ---- | -------------------- | 7209| callback | AsyncCallback\<[Image](#image9)> | 是 | 回调函数,当获取最新图片成功,err为undefined,data为获取到的最新图片;否则为错误对象。 | 7210 7211**示例:** 7212 7213```ts 7214import { BusinessError } from '@kit.BasicServicesKit'; 7215 7216creator.dequeueImage((err: BusinessError, img: image.Image) => { 7217 if (err) { 7218 console.error(`Failed to dequeue the Image.code ${err.code},message is ${err.message}`); 7219 } else { 7220 console.info('Succeeded in dequeuing the Image.'); 7221 } 7222}); 7223``` 7224 7225### dequeueImage<sup>9+</sup> 7226 7227dequeueImage(): Promise\<Image> 7228 7229从空闲队列中获取buffer图片,用于绘制UI内容,并使用promise返回结果。 7230 7231**系统能力:** SystemCapability.Multimedia.Image.ImageCreator 7232 7233**返回值:** 7234 7235| 类型 | 说明 | 7236| --------------- | ------------- | 7237| Promise\<[Image](#image9)> | Promise对象,返回最新图片。 | 7238 7239**示例:** 7240 7241```ts 7242import { BusinessError } from '@kit.BasicServicesKit'; 7243 7244creator.dequeueImage().then((img: image.Image) => { 7245 console.info('Succeeded in dequeuing the Image.'); 7246}).catch((error: BusinessError) => { 7247 console.error(`Failed to dequeue the Image.code ${error.code},message is ${error.message}`); 7248}) 7249``` 7250 7251### queueImage<sup>9+</sup> 7252 7253queueImage(interface: Image, callback: AsyncCallback\<void>): void 7254 7255将绘制好的图片放入Dirty队列,并使用callback返回结果。 7256 7257**系统能力:** SystemCapability.Multimedia.Image.ImageCreator 7258 7259**参数:** 7260 7261| 参数名 | 类型 | 必填 | 说明 | 7262| ------------- | -------------------------| ---- | -------------------- | 7263| interface | [Image](#image9) | 是 | 绘制好的buffer图像。 | 7264| callback | AsyncCallback\<void> | 是 | 回调函数,当将图片放入Dirty队列成功,err为undefined,否则为错误对象。 | 7265 7266**示例:** 7267 7268```ts 7269import { BusinessError } from '@kit.BasicServicesKit'; 7270 7271creator.dequeueImage().then((img: image.Image) => { 7272 //绘制图片 7273 img.getComponent(4).then((component : image.Component) => { 7274 let bufferArr: Uint8Array = new Uint8Array(component.byteBuffer); 7275 for (let i = 0; i < bufferArr.length; i += 4) { 7276 bufferArr[i] = 0; //B 7277 bufferArr[i + 1] = 0; //G 7278 bufferArr[i + 2] = 255; //R 7279 bufferArr[i + 3] = 255; //A 7280 } 7281 }) 7282 creator.queueImage(img, (err: BusinessError) => { 7283 if (err) { 7284 console.error(`Failed to queue the Image.code ${err.code},message is ${err.message}`); 7285 } else { 7286 console.info('Succeeded in queuing the Image.'); 7287 } 7288 }) 7289}) 7290 7291``` 7292 7293### queueImage<sup>9+</sup> 7294 7295queueImage(interface: Image): Promise\<void> 7296 7297将绘制好的图片放入Dirty队列,并使用promise返回结果。 7298 7299**系统能力:** SystemCapability.Multimedia.Image.ImageCreator 7300 7301**参数:** 7302 7303| 参数名 | 类型 | 必填 | 说明 | 7304| ------------- | --------| ---- | ------------------- | 7305| interface | [Image](#image9) | 是 | 绘制好的buffer图像。 | 7306 7307**返回值:** 7308 7309| 类型 | 说明 | 7310| -------------- | ------------- | 7311| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 7312 7313**示例:** 7314 7315```ts 7316import { BusinessError } from '@kit.BasicServicesKit'; 7317 7318creator.dequeueImage().then((img: image.Image) => { 7319 //绘制图片 7320 img.getComponent(4).then((component: image.Component) => { 7321 let bufferArr: Uint8Array = new Uint8Array(component.byteBuffer); 7322 for (let i = 0; i < bufferArr.length; i += 4) { 7323 bufferArr[i] = 0; //B 7324 bufferArr[i + 1] = 0; //G 7325 bufferArr[i + 2] = 255; //R 7326 bufferArr[i + 3] = 255; //A 7327 } 7328 }) 7329 creator.queueImage(img).then(() => { 7330 console.info('Succeeded in queuing the Image.'); 7331 }).catch((error: BusinessError) => { 7332 console.error(`Failed to queue the Image.code ${error.code},message is ${error.message}`); 7333 }) 7334}) 7335 7336``` 7337 7338### on<sup>9+</sup> 7339 7340on(type: 'imageRelease', callback: AsyncCallback\<void>): void 7341 7342监听imageRelease事件,并使用callback返回结果。 7343 7344**系统能力:** SystemCapability.Multimedia.Image.ImageCreator 7345 7346**参数:** 7347 7348| 参数名 | 类型 | 必填 | 说明 | 7349| ------------- | -------------------------| ---- | -------------------- | 7350| type | string | 是 | 监听事件类型,如'imageRelease'。 | 7351| callback | AsyncCallback\<void> | 是 | 回调函数,当监听事件触发成功,err为undefined,否则为错误对象。 | 7352 7353**示例:** 7354 7355```ts 7356import { BusinessError } from '@kit.BasicServicesKit'; 7357 7358creator.on('imageRelease', (err: BusinessError) => { 7359 if (err) { 7360 console.error(`Failed to get the imageRelease callback.code ${err.code},message is ${err.message}`); 7361 } else { 7362 console.info('Succeeded in getting imageRelease callback.'); 7363 } 7364}) 7365``` 7366 7367### off<sup>13+</sup> 7368 7369off(type: 'imageRelease', callback?: AsyncCallback\<void>): void 7370 7371释放buffer时,移除注册的回调函数。 7372 7373**系统能力:** SystemCapability.Multimedia.Image.ImageCreator 7374 7375**参数:** 7376 7377| 参数名 | 类型 | 必填 | 说明 | 7378| ------------- | -------------------------|----|--------------------------------------------| 7379| type | string | 是 | 监听事件类型,如'imageRelease'。 | 7380| callback | AsyncCallback\<void> | 否 | 将被移除的回调函数。 | 7381 7382**示例:** 7383 7384```ts 7385let callbackFunc = ()=>{ 7386 // do something 7387} 7388creator.on('imageRelease', callbackFunc) 7389creator.off('imageRelease', callbackFunc) 7390``` 7391 7392### release<sup>9+</sup> 7393 7394release(callback: AsyncCallback\<void>): void 7395 7396释放当前图像,并使用callback返回结果。 7397 7398ArkTS有内存回收机制,ImageCreator对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。 7399 7400**系统能力:** SystemCapability.Multimedia.Image.ImageCreator 7401 7402**参数:** 7403 7404| 参数名 | 类型 | 必填 | 说明 | 7405| ------------- | -------------------------| ---- | -------------------- | 7406| callback | AsyncCallback\<void> | 是 | 回调函数,当图像释放成功,err为undefined,否则为错误对象。 | 7407 7408**示例:** 7409 7410```ts 7411import { BusinessError } from '@kit.BasicServicesKit'; 7412 7413creator.release((err: BusinessError) => { 7414 if (err) { 7415 console.error(`Failed to release the creator.code ${err.code},message is ${err.message}`); 7416 } else { 7417 console.info('Succeeded in releasing creator.'); 7418 } 7419}); 7420``` 7421### release<sup>9+</sup> 7422 7423release(): Promise\<void> 7424 7425释放当前图像,并使用promise返回结果。 7426 7427ArkTS有内存回收机制,ImageCreator对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。 7428 7429**系统能力:** SystemCapability.Multimedia.Image.ImageCreator 7430 7431**返回值:** 7432 7433| 类型 | 说明 | 7434| -------------- | ------------- | 7435| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 7436 7437**示例:** 7438 7439```ts 7440import { BusinessError } from '@kit.BasicServicesKit'; 7441 7442creator.release().then(() => { 7443 console.info('Succeeded in releasing creator.'); 7444}).catch((error: BusinessError) => { 7445 console.error(`Failed to release the creator.code ${error.code},message is ${error.message}`); 7446}) 7447``` 7448 7449## Image<sup>9+</sup> 7450 7451提供基本的图像操作,包括获取图像信息、读写图像数据。调用[readNextImage](#readnextimage9)和[readLatestImage](#readlatestimage9)接口时会返回image。 7452 7453### 属性 7454 7455**系统能力:** SystemCapability.Multimedia.Image.Core 7456 7457| 名称 | 类型 | 可读 | 可写 | 说明 | 7458| -------- | ------------------ | ---- | ---- | -------------------------------------------------- | 7459| clipRect | [Region](#region8) | 是 | 是 | 要裁剪的图像区域。 | 7460| size | [Size](#size) | 是 | 否 | 图像大小。如果image对象所存储的是相机预览流数据,即YUV图像数据,那么获取到的size中的宽高分别对应YUV图像的宽高; 如果image对象所存储的是相机拍照流数据,即JPEG图像,由于已经是编码后的文件,size中的宽等于JPEG文件大小,高等于1。image对象所存储的数据是预览流还是拍照流,取决于应用将receiver中的surfaceId传给相机的previewOutput还是captureOutput。相机预览与拍照最佳实践请参考[双路预览(ArkTS)](../../media/camera/camera-dual-channel-preview.md)与[拍照实现方案(ArkTS)](../../media/camera/camera-shooting-case.md)。 | 7461| format | number | 是 | 否 | 图像格式,参考[OH_NativeBuffer_Format](../apis-arkgraphics2d/_o_h___native_buffer.md#oh_nativebuffer_format)。 | 7462| timestamp<sup>12+</sup> | number | 是 | 否 | 图像时间戳。时间戳以纳秒为单位,通常是单调递增的。时间戳的具体含义和基准取决于图像的生产者,在相机预览/拍照场景,生产者就是相机。来自不同生产者的图像的时间戳可能有不同的含义和基准,因此可能无法进行比较。如果要获取某张照片的生成时间,可以通过[getImageProperty](#getimageproperty11)接口读取相关的EXIF信息。| 7463 7464### getComponent<sup>9+</sup> 7465 7466getComponent(componentType: ComponentType, callback: AsyncCallback\<Component>): void 7467 7468根据图像的组件类型从图像中获取组件缓存并使用callback返回结果。 7469 7470**系统能力:** SystemCapability.Multimedia.Image.Core 7471 7472**参数:** 7473 7474| 参数名 | 类型 | 必填 | 说明 | 7475| ------------- | --------------------------------------- | ---- | -------------------- | 7476| componentType | [ComponentType](#componenttype9) | 是 | 图像的组件类型。(目前仅支持 ComponentType:JPEG,实际返回格式由生产者决定,如相机) | 7477| callback | AsyncCallback<[Component](#component9)> | 是 | 回调函数,当返回组件缓冲区成功,err为undefined,data为获取到的组件缓冲区;否则为错误对象。 | 7478 7479**示例:** 7480 7481```ts 7482import { BusinessError } from '@kit.BasicServicesKit'; 7483 7484img.getComponent(4, (err: BusinessError, component: image.Component) => { 7485 if (err) { 7486 console.error(`Failed to get the component.code ${err.code},message is ${err.message}`); 7487 } else { 7488 console.info('Succeeded in getting component.'); 7489 } 7490}) 7491``` 7492 7493### getComponent<sup>9+</sup> 7494 7495getComponent(componentType: ComponentType): Promise\<Component> 7496 7497根据图像的组件类型从图像中获取组件缓存并使用Promise方式返回结果。 7498 7499**系统能力:** SystemCapability.Multimedia.Image.Core 7500 7501**参数:** 7502 7503| 参数名 | 类型 | 必填 | 说明 | 7504| ------------- | -------------------------------- | ---- | ---------------- | 7505| componentType | [ComponentType](#componenttype9) | 是 | 图像的组件类型。(目前仅支持 ComponentType:JPEG,实际返回格式由生产者决定,如相机) | 7506 7507**返回值:** 7508 7509| 类型 | 说明 | 7510| --------------------------------- | --------------------------------- | 7511| Promise<[Component](#component9)> | Promise对象,返回组件缓冲区。 | 7512 7513**示例:** 7514 7515```ts 7516import { BusinessError } from '@kit.BasicServicesKit'; 7517 7518img.getComponent(4).then((component: image.Component) => { 7519 console.info('Succeeded in getting component.'); 7520}).catch((error: BusinessError) => { 7521 console.error(`Failed to get the component.code ${error.code},message is ${error.message}`); 7522}) 7523``` 7524 7525### release<sup>9+</sup> 7526 7527release(callback: AsyncCallback\<void>): void 7528 7529释放当前图像并使用callback返回结果。 7530 7531在接收另一个图像前必须先释放对应资源。 7532 7533ArkTS有内存回收机制,Image对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。 7534 7535**系统能力:** SystemCapability.Multimedia.Image.Core 7536 7537**参数:** 7538 7539| 参数名 | 类型 | 必填 | 说明 | 7540| -------- | -------------------- | ---- | -------------- | 7541| callback | AsyncCallback\<void> | 是 | 回调函数,当图像释放成功,err为undefined,否则为错误对象。 | 7542 7543**示例:** 7544 7545```ts 7546import { BusinessError } from '@kit.BasicServicesKit'; 7547 7548img.release((err: BusinessError) => { 7549 if (err) { 7550 console.error(`Failed to release the image instance.code ${err.code},message is ${err.message}`); 7551 } else { 7552 console.info('Succeeded in releasing the image instance.'); 7553 } 7554}) 7555``` 7556 7557### release<sup>9+</sup> 7558 7559release(): Promise\<void> 7560 7561释放当前图像并使用Promise方式返回结果。 7562 7563在接收另一个图像前必须先释放对应资源。 7564 7565ArkTS有内存回收机制,Image对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。 7566 7567**系统能力:** SystemCapability.Multimedia.Image.Core 7568 7569**返回值:** 7570 7571| 类型 | 说明 | 7572| -------------- | --------------------- | 7573| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 7574 7575**示例:** 7576 7577```ts 7578import { BusinessError } from '@kit.BasicServicesKit'; 7579 7580img.release().then(() => { 7581 console.info('Succeeded in releasing the image instance.'); 7582}).catch((error: BusinessError) => { 7583 console.error(`Failed to release the image instance.code ${error.code},message is ${error.message}`); 7584}) 7585``` 7586 7587## PositionArea<sup>7+</sup> 7588 7589表示图片指定区域内的数据。 7590 7591**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 7592 7593**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 7594 7595**系统能力:** SystemCapability.Multimedia.Image.Core 7596 7597| 名称 | 类型 | 只读| 可选| 说明 | 7598| ------ | ------------------ | ---| -----|------------------------------------------------------- | 7599| pixels | ArrayBuffer | 否 | 否 | 像素。仅支持BGRA_8888格式的图像像素数据。 | 7600| offset | number | 否 | 否 | 偏移量。 | 7601| stride | number | 否 | 否 | 跨距,内存中每行像素所占的空间。stride >= region.size.width*4。 | 7602| region | [Region](#region8) | 否 | 否 |区域,按照区域读写。写入的区域宽度加X坐标不能大于原图的宽度,写入的区域高度加Y坐标不能大于原图的高度。 | 7603 7604## ImageInfo 7605 7606表示图片信息。 7607 7608**系统能力:** SystemCapability.Multimedia.Image.Core 7609 7610| 名称 | 类型 | 只读 | 可选 | 说明 | 7611| ---- | ------------- | --- |-----|---------- | 7612| size<sup>6+</sup> | [Size](#size) | 否 | 否 |图片大小。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7613| density<sup>9+</sup> | number | 否 | 否 |像素密度,单位为ppi。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7614| stride<sup>11+</sup> | number | 否 | 否 | 跨距,内存中每行像素所占的空间。stride >= region.size.width*4 <br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7615| pixelFormat<sup>12+</sup> | [PixelMapFormat](#pixelmapformat7) | 否 | 否 | 像素格式。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7616| alphaType<sup>12+</sup> | [AlphaType](#alphatype9) | 否 | 否 |透明度。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7617| mimeType<sup>12+</sup> | string | 否 | 否 |图片真实格式(MIME type)。 | 7618| isHdr<sup>12+</sup> | boolean | 否 | 否 | 图片是否为高动态范围(HDR)。对于[ImageSource](#imagesource),代表源图片是否为HDR;对于[PixelMap](#pixelmap7),代表解码后的pixelmap是否为HDR。 | 7619 7620## Size 7621 7622表示图片尺寸。 7623 7624**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 7625 7626**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 7627 7628**系统能力:** SystemCapability.Multimedia.Image.Core 7629 7630| 名称 | 类型 | 只读 | 可选 |说明 | 7631| ------ | ------ | -- |-----| -------------- | 7632| height | number | 否 | 否 |输出图片的高,单位:像素。 | 7633| width | number | 否 | 否 | 输出图片的宽,单位:像素。 | 7634 7635## PixelMapFormat<sup>7+</sup> 7636 7637枚举,图片像素格式。 7638 7639**系统能力:** SystemCapability.Multimedia.Image.Core 7640 7641| 名称 | 值 | 说明 | 7642| ---------------------- | ------ | ----------------- | 7643| UNKNOWN | 0 | 未知格式。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7644| RGB_565 | 2 | 格式为RGB_565。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7645| RGBA_8888 | 3 | 格式为RGBA_8888。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7646| BGRA_8888<sup>9+</sup> | 4 | 格式为BGRA_8888。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7647| RGB_888<sup>9+</sup> | 5 | 格式为RGB_888。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7648| ALPHA_8<sup>9+</sup> | 6 | 格式为ALPHA_8。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7649| RGBA_F16<sup>9+</sup> | 7 | 格式为RGBA_F16。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7650| NV21<sup>9+</sup> | 8 | 格式为NV21。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7651| NV12<sup>9+</sup> | 9 | 格式为NV12。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7652| RGBA_1010102<sup>12+</sup> | 10 | 格式为RGBA_1010102 | 7653| YCBCR_P010<sup>12+</sup> | 11 | 格式为YCBCR_P010 | 7654| YCRCB_P010<sup>12+</sup> | 12 | 格式为YCRCB_P010 | 7655 7656## AlphaType<sup>9+</sup> 7657 7658枚举,图像的透明度类型。 7659 7660**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 7661 7662**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 7663 7664**系统能力:** SystemCapability.Multimedia.Image.Core 7665 7666| 名称 | 值 | 说明 | 7667| -------- | ------ | ----------------------- | 7668| UNKNOWN | 0 | 未知透明度。 | 7669| OPAQUE | 1 | 没有alpha或图片不透明。 | 7670| PREMUL | 2 | RGB预乘alpha。 | 7671| UNPREMUL | 3 | RGB非预乘alpha。 | 7672 7673## AuxiliaryPictureType<sup>13+</sup> 7674 7675枚举,辅助图的图像类型。 7676 7677**系统能力:** SystemCapability.Multimedia.Image.Core 7678 7679| 名称 | 值 | 说明 | 7680| ------------- | ---- | ------------ | 7681| GAINMAP | 1 | 增益图,代表了一种增强SDR图像以产生具有可变显示调整能力的HDR图像的机制。它是一组描述如何应用gainmap元数据的组合。 | 7682| DEPTH_MAP | 2 | 深度图,储存图像的深度数据,通过捕捉每个像素与摄像机之间的距离,提供场景的三维结构信息,通常用于3D重建和场景理解。 | 7683| UNREFOCUS_MAP | 3 | 人像未对焦的原图,提供了一种在人像拍摄中突出背景模糊效果的方式,能够帮助用户在后期处理中选择焦点区域,增加创作自由度。 | 7684| LINEAR_MAP | 4 | 线性图,用于提供额外的数据视角或补充信息,通常用于视觉效果的增强,它可以包含场景中光照、颜色或其他视觉元素的线性表示。 | 7685| FRAGMENT_MAP | 5 | 水印裁剪图,表示在原图中被水印覆盖的区域,该图像用于修复或移除水印影响,恢复图像的完整性和可视性。 | 7686 7687## AuxiliaryPictureInfo<sup>13+</sup> 7688 7689表示辅助图图像信息。 7690 7691**系统能力:** SystemCapability.Multimedia.Image.Core 7692 7693| 名称 | 类型 | 只读 | 可选 | 说明 | 7694| ------------------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ | 7695| auxiliaryPictureType | [AuxiliaryPictureType](#auxiliarypicturetype13) | 否 | 否 | 辅助图的图像类型。 | 7696| size | [Size](#size) | 否 | 否 | 图片大小。 | 7697| rowStride | number | 否 | 否 | 行距。 | 7698| pixelFormat | [PixelMapFormat](#pixelmapformat7) | 否 | 否 | 像素格式。 | 7699| colorSpace | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | 否 | 否 | 目标色彩空间。 | 7700 7701## MetadataType<sup>13+</sup> 7702 7703枚举,图片元数据类型。 7704 7705**系统能力:** SystemCapability.Multimedia.Image.Core 7706 7707| 名称 | 值 | 说明 | 7708| ----------------- | ---- | ------------------ | 7709| EXIF_METADATA | 1 | exif数据。 | 7710| FRAGMENT_METADATA | 2 | 水印裁剪图元数据。 | 7711 7712## ScaleMode<sup>9+</sup> 7713 7714枚举,图像的缩放模式。 7715 7716**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 7717 7718**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 7719 7720**系统能力:** SystemCapability.Multimedia.Image.Core 7721 7722| 名称 | 值 | 说明 | 7723| --------------- | ------ | -------------------------------------------------- | 7724| CENTER_CROP | 1 | 缩放图像以填充目标图像区域并居中裁剪区域外的效果。 | 7725| FIT_TARGET_SIZE | 0 | 图像适合目标尺寸的效果。 | 7726 7727## SourceOptions<sup>9+</sup> 7728 7729ImageSource的初始化选项。 7730 7731**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 7732 7733**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 7734 7735**系统能力:** SystemCapability.Multimedia.Image.Core 7736 7737| 名称 | 类型 | 只读 | 可选 | 说明 | 7738| ----------------- | ---------------------------------- | ---- | ---- | ------------------ | 7739| sourceDensity | number | 否 | 否 | 图片资源像素密度,单位DPI。<br>在解码参数[DecodingOptions](#decodingoptions7)未设置desiredSize的前提下,当前参数SourceOptions.sourceDensity与DecodingOptions.fitDensity非零时将对解码输出的pixelmap进行缩放。<br>缩放后宽计算公式如下(高同理):(width * fitDensity + (sourceDensity >> 1)) / sourceDensity。| 7740| sourcePixelFormat | [PixelMapFormat](#pixelmapformat7) | 否 | 是 | 图片像素格式,默认值为UNKNOWN。 | 7741| sourceSize | [Size](#size) | 否 | 是 | 图像像素大小,默认值为空。 | 7742 7743 7744## InitializationOptions<sup>8+</sup> 7745 7746PixelMap的初始化选项。 7747 7748**系统能力:** SystemCapability.Multimedia.Image.Core 7749 7750| 名称 | 类型 | 只读 |可选 | 说明 | 7751| ------------------------ | ---------------------------------- | ----| -----| -------------- | 7752| alphaType<sup>9+</sup> | [AlphaType](#alphatype9) | 否 | 是| 透明度。默认值为IMAGE_ALPHA_TYPE_PREMUL。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7753| editable | boolean | 否 | 是| 是否可编辑。默认值为false。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。| 7754| srcPixelFormat<sup>12+</sup> | [PixelMapFormat](#pixelmapformat7) | 否 | 是 | 传入的buffer数据的像素格式。默认值为BGRA_8888。| 7755| pixelFormat | [PixelMapFormat](#pixelmapformat7) | 否 | 是| 生成的pixelMap的像素格式。默认值为RGBA_8888。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7756| scaleMode<sup>9+</sup> | [ScaleMode](#scalemode9) | 否 | 是 | 缩略值。默认值为0。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7757| size | [Size](#size) | 否 | 否|创建图片大小。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7758 7759## DecodingOptions<sup>7+</sup> 7760 7761图像解码设置选项。 7762 7763**系统能力:** SystemCapability.Multimedia.Image.ImageSource 7764 7765| 名称 | 类型 | 只读 | 可选 | 说明 | 7766| ------------------ | ---------------------------------- | ---- | ---- | ---------------- | 7767| sampleSize | number | 否 | 是 | 缩略图采样大小,默认值为1。当前只能取1。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7768| rotate | number | 否 | 是 | 旋转角度。默认值为0。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7769| editable | boolean | 否 | 是 | 是否可编辑。默认值为false。当取值为false时,图片不可二次编辑,如writepixels操作将失败。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7770| desiredSize | [Size](#size) | 否 | 是 | 期望输出大小。默认值为空。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7771| desiredRegion | [Region](#region8) | 否 | 是 | 解码区域。默认值为空。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7772| desiredPixelFormat | [PixelMapFormat](#pixelmapformat7) | 否 | 是 | 解码的像素格式。默认值为RGBA_8888。仅支持设置:RGBA_8888、BGRA_8888和RGB_565。有透明通道图片格式不支持设置RGB_565,如PNG、GIF、ICO和WEBP。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7773| index | number | 否 | 是 | 解码图片序号。默认值为0。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7774| fitDensity<sup>9+</sup> | number | 否 | 是 | 图像像素密度,单位为ppi。默认值为0。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 | 7775| desiredColorSpace<sup>11+</sup> | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | 否 | 是 | 目标色彩空间。默认值为UNKNOWN。 | 7776| desiredDynamicRange<sup>12+</sup> | [DecodingDynamicRange](#decodingdynamicrange12) | 否 | 是 | 目标动态范围,默认值为SDR。<br>通过[CreateIncrementalSource](#imagecreateincrementalsource9)创建的imagesource不支持设置此属性,默认解码为SDR内容。<br>如果平台不支持HDR,设置无效,默认解码为SDR内容。 | 7777 7778## DecodingOptionsForPicture<sup>13+</sup> 7779 7780图像解码设置选项。 7781 7782**系统能力:** SystemCapability.Multimedia.Image.ImageSource 7783 7784| 名称 | 类型 | 只读 | 可选 | 说明 | 7785| ------------------------ | ------------------------------------------------------- | ---- | ---- | ------------------------------------------------------------ | 7786| desiredAuxiliaryPictures | Array\<[AuxiliaryPictureType](#auxiliarypicturetype13)> | 否 | 否 | 设置AuxiliaryPicture类型,默认解码所有AuxiliaryPicture类型。 | 7787 7788## Region<sup>8+</sup> 7789 7790表示区域信息。 7791 7792**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 7793 7794**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 7795 7796**系统能力:** SystemCapability.Multimedia.Image.Core 7797 7798| 名称 | 类型 | 只读 | 可选| 说明 | 7799| ---- | ------------- | ---- | ---- | ------------ | 7800| size<sup>7+</sup> | [Size](#size) | 否 | 否 | 区域大小。 | 7801| x<sup>7+</sup> | number | 否 | 否 | 区域横坐标。 | 7802| y<sup>7+</sup> | number | 否 | 否 | 区域纵坐标。 | 7803 7804## PackingOption 7805 7806表示图片打包选项。 7807 7808**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 7809 7810| 名称 | 类型 | 只读 | 可选 | 说明 | 7811| ------- | ------ | ---- | ---- | --------------------------------------------------- | 7812| format | string | 否 | 否 | 目标格式。</br>当前只支持"image/jpeg"、"image/webp"、"image/png"和"image/heic(或者image/heif)"<sup>12+</sup>(不同硬件设备支持情况不同)。<br>**说明:** 因为jpeg不支持透明通道,若使用带透明通道的数据编码jpeg格式,透明色将变为黑色。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 7813| quality | number | 否 | 否 | JPEG编码中设定输出图片质量的参数,取值范围为0-100。0质量最低,100质量最高,质量越高生成图片所占空间越大。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 7814| bufferSize<sup>9+</sup> | number | 否 | 是 | 接收编码数据的缓冲区大小,单位为Byte。如果不设置大小,默认为25M。如果编码图片超过25M,需要指定大小。bufferSize需大于编码后图片大小。使用[packToFile](#packtofile11)不受此参数限制。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 7815| desiredDynamicRange<sup>12+</sup> | [PackingDynamicRange](#packingdynamicrange12) | 否 | 是 | 目标动态范围。默认值为SDR。 | 7816| needsPackProperties<sup>12+</sup> | boolean | 否 | 是 | 是否需要编码图片属性信息,例如EXIF。默认值为false。 | 7817 7818## ImagePropertyOptions<sup>11+</sup> 7819 7820表示查询图片属性的索引。 7821 7822**系统能力:** SystemCapability.Multimedia.Image.ImageSource 7823 7824| 名称 | 类型 | 只读 | 可选 | 说明 | 7825| ------------ | ------ | ---- | ---- | ------------ | 7826| index | number | 是 | 是 | 图片序号。默认值为0。 | 7827| defaultValue | string | 是 | 是 | 默认属性值。默认值为空。 | 7828 7829## GetImagePropertyOptions<sup>(deprecated)</sup> 7830 7831表示查询图片属性的索引。 7832 7833> **说明:** 7834> 7835> 从API version 11开始不再维护,建议使用[ImagePropertyOptions](#imagepropertyoptions11)代替。 7836 7837**系统能力:** SystemCapability.Multimedia.Image.ImageSource 7838 7839| 名称 | 类型 | 只读 | 可选 | 说明 | 7840| ------------ | ------ | ---- | ---- | ------------ | 7841| index | number | 否 | 是 | 图片序号。默认值为0。 | 7842| defaultValue | string | 否 | 是 | 默认属性值。默认值为空。 | 7843 7844## PropertyKey<sup>7+</sup> 7845 7846枚举,Exif(Exchangeable image file format)图片信息。 7847 7848**系统能力:** SystemCapability.Multimedia.Image.Core 7849 7850| 名称 | 值 | 说明 | 7851| ----------------- | ----------------------- |---------------------------| 7852| NEW_SUBFILE_TYPE <sup>12+</sup> | "NewSubfileType" | **读写能力:** 可读写<br> 在Exif中,"NewSubfileType"字段用于标识子文件的数据类型,如全分辨率图像、缩略图或多帧图像的一部分。其值是位掩码,0代表全分辨率图像,1代表缩略图,2代表多帧图像的一部分。| 7853| SUBFILE_TYPE <sup>12+</sup> | "SubfileType" | **读写能力:** 可读写<br> 此标签指示此子文件中的数据类型。标签已弃用,请使用NewSubfileType替代。| 7854| IMAGE_WIDTH | "ImageWidth" | **读写能力:** 可读写<br> 图片宽度。| 7855| IMAGE_LENGTH | "ImageLength" | **读写能力:** 可读写<br> 图片长度。| 7856| BITS_PER_SAMPLE | "BitsPerSample" | **读写能力:** 可读写<br> 像素各分量的位数,如RGB,3分量,格式是8, 8, 8。| 7857| COMPRESSION <sup>12+</sup> | "Compression" | **读写能力:** 可读写<br> 图像压缩方案。| 7858| PHOTOMETRIC_INTERPRETATION <sup>12+</sup> | "PhotometricInterpretation" | **读写能力:** 可读写<br> 像素构成,例如 RGB 或 YCbCr。| 7859| IMAGE_DESCRIPTION<sup>10+</sup> | "ImageDescription" | **读写能力:** 可读写<br> 图像信息描述。| 7860| MAKE<sup>10+</sup> | "Make" | **读写能力:** 可读写<br> 生产商。| 7861| MODEL<sup>10+</sup> | "Model" | **读写能力:** 可读写<br> 设备型号。| 7862| STRIP_OFFSETS <sup>12+</sup> | "StripOffsets" | **读写能力:** 可读写<br> 每个strip的字节偏移量。| 7863| ORIENTATION | "Orientation" | **读写能力:** 可读写<br> 图片方向。<br/>- 1:Top-left,图像未旋转。<br/>- 2:Top-right,镜像水平翻转。<br/>- 3:Bottom-right,图像旋转180°。<br/>- 4:Bottom-left,镜像垂直翻转。<br/>- 5:Left-top,镜像水平翻转再顺时针旋转270°。<br/>- 6:Right-top,顺时针旋转90°。<br/>- 7:Right-bottom,镜像水平翻转再顺时针旋转90°。<br/>- 8:Left-bottom,顺时针旋转270°。<br/>- 未定义值返回Unknown Value。| 7864| SAMPLES_PER_PIXEL <sup>12+</sup> | "SamplesPerPixel" | **读写能力:** 可读写<br> 每个像素的分量数。由于该标准适用于 RGB 和 YCbCr 图像,因此该标签的值设置为 3。在 JPEG 压缩数据中,使用 JPEG 标记代替该标签。| 7865| ROWS_PER_STRIP <sup>12+</sup> | "RowsPerStrip" | **读写能力:** 可读写<br> 每个strip的图像数据行数。| 7866| STRIP_BYTE_COUNTS <sup>12+</sup> | "StripByteCounts" | **读写能力:** 可读写<br> 每个图像数据带的总字节数。| 7867| X_RESOLUTION <sup>12+</sup> | "XResolution" | **读写能力:** 可读写<br> 图像宽度方向的分辨率。| 7868| Y_RESOLUTION <sup>12+</sup> | "YResolution" | **读写能力:** 可读写<br> 图像高度方向的分辨率。| 7869| PLANAR_CONFIGURATION <sup>12+</sup> | "PlanarConfiguration" | **读写能力:** 可读写<br> 表示像素组件的记录格式,chunky格式或是planar格式。| 7870| RESOLUTION_UNIT <sup>12+</sup> | "ResolutionUnit" | **读写能力:** 可读写<br> 用于测量XResolution和YResolution的单位。| 7871| TRANSFER_FUNCTION <sup>12+</sup> | "TransferFunction" | **读写能力:** 可读写<br> 图像的传递函数,通常用于颜色校正。| 7872| SOFTWARE <sup>12+</sup> | "Software" | **读写能力:** 可读写<br> 用于生成图像的软件的名称和版本。| 7873| DATE_TIME<sup>10+</sup> | "DateTime" | **读写能力:** 可读写<br> 日期时间。格式如2024:01:25 05:51:34。| 7874| ARTIST <sup>12+</sup> | "Artist" | **读写能力:** 可读写<br> 创建图像的用户名称。| 7875| WHITE_POINT <sup>12+</sup> | "WhitePoint" | **读写能力:** 可读写<br> 图像的白点色度。| 7876| PRIMARY_CHROMATICITIES <sup>12+</sup> | "PrimaryChromaticities" | **读写能力:** 可读写<br> 图像的主要颜色的色度。| 7877| PHOTO_MODE<sup>10+</sup> | "PhotoMode" | **读写能力:** 可读写<br> 拍照模式。| 7878| JPEG_INTERCHANGE_FORMAT <sup>12+</sup> | "JPEGInterchangeFormat" | **读写能力:** 可读写<br> JPEG压缩缩略图数据开始字节(SOI)的偏移。| 7879| JPEG_INTERCHANGE_FORMAT_LENGTH <sup>12+</sup> | "JPEGInterchangeFormatLength" | **读写能力:** 可读写<br> JPEG压缩缩略图数据的字节数。| 7880| YCBCR_COEFFICIENTS <sup>12+</sup> | "YCbCrCoefficients" | **读写能力:** 可读写<br> 从RGB到YCbCr图像数据的转换矩阵系数。| 7881| YCBCR_SUB_SAMPLING <sup>12+</sup> | "YCbCrSubSampling" | **读写能力:** 可读写<br> 色度分量与亮度分量的采样比率。| 7882| YCBCR_POSITIONING <sup>12+</sup> | "YCbCrPositioning" | **读写能力:** 可读写<br> 色度分量相对于亮度分量的位置。| 7883| REFERENCE_BLACK_WHITE <sup>12+</sup> | "ReferenceBlackWhite" | **读写能力:** 可读写<br> 参考黑点值和参考白点值。| 7884| COPYRIGHT <sup>12+</sup> | "Copyright" | **读写能力:** 可读写<br> 图像的版权信息。| 7885| EXPOSURE_TIME<sup>9+</sup> | "ExposureTime" | **读写能力:** 可读写<br> 曝光时间,例如1/33 sec。| 7886| F_NUMBER<sup>9+</sup> | "FNumber" | **读写能力:** 可读写<br> 光圈值,例如f/1.8。| 7887| EXPOSURE_PROGRAM <sup>12+</sup> | "ExposureProgram" | **读写能力:** 可读写<br> 拍照时相机用来设置曝光的程序的类别。| 7888| SPECTRAL_SENSITIVITY <sup>12+</sup> | "SpectralSensitivity" | **读写能力:** 可读写<br> 表示所用相机的每个通道的光谱灵敏度。| 7889| GPS_VERSION_ID <sup>12+</sup> | "GPSVersionID" | **读写能力:** 可读写<br> GPSInfoIFD的版本。| 7890| GPS_LATITUDE_REF | "GPSLatitudeRef" | **读写能力:** 可读写<br> 纬度引用,例如N或S。| 7891| GPS_LATITUDE | "GPSLatitude" | **读写能力:** 可读写<br> 图片纬度。修改时应按"度,分,秒"格式传入,如"39,54,7.542"| 7892| GPS_LONGITUDE_REF | "GPSLongitudeRef" | **读写能力:** 可读写<br> 经度引用,例如W或E。| 7893| GPS_LONGITUDE | "GPSLongitude" | **读写能力:** 可读写<br> 图片经度。修改时应按"度,分,秒"格式传入,如"116,19,42.16"| 7894| GPS_ALTITUDE_REF <sup>12+</sup> | "GPSAltitudeRef" | **读写能力:** 可读写<br> 用于GPS高度的参照高度。| 7895| GPS_ALTITUDE <sup>12+</sup> | "GPSAltitude" | **读写能力:** 可读写<br> 基于GPSAltitudeRef的高度。| 7896| GPS_TIME_STAMP<sup>10+</sup> | "GPSTimeStamp" | **读写能力:** 可读写<br> GPS时间戳。| 7897| GPS_SATELLITES <sup>12+</sup> | "GPSSatellites" | **读写能力:** 可读写<br> 用于测量的GPS卫星。| 7898| GPS_STATUS <sup>12+</sup> | "GPSStatus" | **读写能力:** 可读写<br> 录制图像时GPS接收器的状态。| 7899| GPS_MEASURE_MODE <sup>12+</sup> | "GPSMeasureMode" | **读写能力:** 可读写<br> GPS测量模式。| 7900| GPS_DOP <sup>12+</sup> | "GPSDOP" | **读写能力:** 可读写<br> GPS DOP(数据精度等级)。| 7901| GPS_SPEED_REF <sup>12+</sup> | "GPSSpeedRef" | **读写能力:** 可读写<br> 用来表示GPS接收器移动速度的单位。| 7902| GPS_SPEED <sup>12+</sup> | "GPSSpeed" | **读写能力:** 可读写<br> GPS接收器的移动速度。| 7903| GPS_TRACK_REF <sup>12+</sup> | "GPSTrackRef" | **读写能力:** 可读写<br> GPS接收机移动方向的参照。| 7904| GPS_TRACK <sup>12+</sup> | "GPSTrack" | **读写能力:** 可读写<br> GPS接收机的移动方向。| 7905| GPS_IMG_DIRECTION_REF <sup>12+</sup> | "GPSImgDirectionRef" | **读写能力:** 可读写<br> 图像方向的参照。| 7906| GPS_IMG_DIRECTION <sup>12+</sup> | "GPSImgDirection" | **读写能力:** 可读写<br> 拍摄时图像的方向。| 7907| GPS_MAP_DATUM <sup>12+</sup> | "GPSMapDatum" | **读写能力:** 可读写<br> GPS接收器使用的大地测量数据。| 7908| GPS_DEST_LATITUDE_REF <sup>12+</sup> | "GPSDestLatitudeRef" | **读写能力:** 可读写<br> 目的地点的纬度参照。| 7909| GPS_DEST_LATITUDE <sup>12+</sup> | "GPSDestLatitude" | **读写能力:** 可读写<br> 目的地点的纬度。| 7910| GPS_DEST_LONGITUDE_REF <sup>12+</sup> | "GPSDestLongitudeRef" | **读写能力:** 可读写<br> 目的地点的经度参照。| 7911| GPS_DEST_LONGITUDE <sup>12+</sup> | "GPSDestLongitude" | **读写能力:** 可读写<br> 目的地点的经度。| 7912| GPS_DEST_BEARING_REF <sup>12+</sup> | "GPSDestBearingRef" | **读写能力:** 可读写<br> 指向目的地点的方位参照。| 7913| GPS_DEST_BEARING <sup>12+</sup> | "GPSDestBearing" | **读写能力:** 可读写<br> 目的地方位。| 7914| GPS_DEST_DISTANCE_REF <sup>12+</sup> | "GPSDestDistanceRef" | **读写能力:** 可读写<br> 目标点距离的测量单位。| 7915| GPS_DEST_DISTANCE <sup>12+</sup> | "GPSDestDistance" | **读写能力:** 可读写<br> 到目的地点的距离。| 7916| GPS_PROCESSING_METHOD <sup>12+</sup> | "GPSProcessingMethod" | **读写能力:** 可读写<br> 记录定位方法名的字符字符串。| 7917| GPS_AREA_INFORMATION <sup>12+</sup> | "GPSAreaInformation" | **读写能力:** 可读写<br> 记录GPS区域名的字符字符串。| 7918| GPS_DATE_STAMP<sup>10+</sup> | "GPSDateStamp" | **读写能力:** 可读写<br> GPS日期戳。| 7919| GPS_DIFFERENTIAL <sup>12+</sup> | "GPSDifferential" | **读写能力:** 可读写<br> 此字段表示GPS数据是否应用了差分校正,对于精确的位置准确性至关重要。| 7920| GPS_H_POSITIONING_ERROR <sup>12+</sup> | "GPSHPositioningError" | **读写能力:** 可读写<br> 此标签指示水平定位误差,单位为米。| 7921| ISO_SPEED_RATINGS<sup>9+</sup> | "ISOSpeedRatings" | **读写能力:** 可读写<br> ISO感光度,例如400。| 7922| PHOTOGRAPHIC_SENSITIVITY <sup>12+</sup> | "PhotographicSensitivity" | **读写能力:** 可读写<br> 此标签指示拍摄图像时相机或输入设备的灵敏度。| 7923| OECF <sup>12+</sup> | "OECF" | **读写能力:** 可读写<br> 表示ISO 14524中规定的光电转换函数(OECF)。| 7924| SENSITIVITY_TYPE<sup>10+</sup> | "SensitivityType" | **读写能力:** 可读写<br> 灵敏度类型。| 7925| STANDARD_OUTPUT_SENSITIVITY<sup>10+</sup> | "StandardOutputSensitivity" | **读写能力:** 可读写<br> 标准输出灵敏度。| 7926| RECOMMENDED_EXPOSURE_INDEX<sup>10+</sup> | "RecommendedExposureIndex" | **读写能力:** 可读写<br> 推荐曝光指数。| 7927| ISO_SPEED<sup>10+</sup> | "ISOSpeedRatings" | **读写能力:** 可读写<br> ISO速度等级。| 7928| ISO_SPEED_LATITUDE_YYY <sup>12+</sup> | "ISOSpeedLatitudeyyy" | **读写能力:** 可读写<br> 该标签指示摄像机或输入设备的ISO速度纬度yyy值,该值在ISO 12232中定义。| 7929| ISO_SPEED_LATITUDE_ZZZ <sup>12+</sup> | "ISOSpeedLatitudezzz" | **读写能力:** 可读写<br> 该标签指示摄像机或输入设备的ISO速度纬度zzz值,该值在ISO 12232中定义。| 7930| EXIF_VERSION <sup>12+</sup> | "ExifVersion" | **读写能力:** 可读写<br> 支持的Exif标准版本。| 7931| DATE_TIME_ORIGINAL<sup>9+</sup> | "DateTimeOriginal" | **读写能力:** 可读写<br> 拍摄时间,例如2022:09:06 15:48:00。| 7932| DATE_TIME_DIGITIZED <sup>12+</sup> | "DateTimeDigitized" | **读写能力:** 可读写<br> 图像作为数字数据存储的日期和时间,格式为YYYY:MM:DD HH:MM:SS| 7933| OFFSET_TIME <sup>12+</sup> | "OffsetTime" | **读写能力:** 可读写<br> 在Exif中,OffsetTime字段表示与UTC(协调世界时)的时间偏移,格式为±HH:MM,用于确定照片拍摄的本地时间。| 7934| OFFSET_TIME_ORIGINAL <sup>12+</sup> | "OffsetTimeOriginal" | **读写能力:** 可读写<br> 此标签记录原始图像创建时的UTC偏移量,对于时间敏感的应用至关重要。| 7935| OFFSET_TIME_DIGITIZED <sup>12+</sup> | "OffsetTimeDigitized" | **读写能力:** 可读写<br> 此标签记录图像数字化时的UTC偏移量,有助于准确调整时间戳。| 7936| COMPONENTS_CONFIGURATION <sup>12+</sup> | "ComponentsConfiguration" | **读写能力:** 可读写<br> 压缩数据的特定信息。| 7937| COMPRESSED_BITS_PER_PIXEL <sup>12+</sup> | "CompressedBitsPerPixel" | **读写能力:** 可读写<br> 用于压缩图像的压缩模式,单位为每像素位数。| 7938| SHUTTER_SPEED <sup>12+</sup> | "ShutterSpeedValue" | **读写能力:** 可读写<br> 快门速度,以APEX(摄影曝光的加法系统)值表示。| 7939| APERTURE_VALUE<sup>10+</sup> | "ApertureValue" | **读写能力:** 可读写<br> 光圈值。格式如4/1。| 7940| BRIGHTNESS_VALUE <sup>12+</sup> | "BrightnessValue" | **读写能力:** 可读写<br> 图像的亮度值,以APEX单位表示。| 7941| EXPOSURE_BIAS_VALUE<sup>10+</sup> | "ExposureBiasValue" | **读写能力:** 可读写<br> 曝光偏差值。| 7942| MAX_APERTURE_VALUE <sup>12+</sup> | "MaxApertureValue" | **读写能力:** 可读写<br> 最小F数镜头。| 7943| SUBJECT_DISTANCE <sup>12+</sup> | "SubjectDistance" | **读写能力:** 可读写<br> 测量单位为米的主体距离。| 7944| METERING_MODE<sup>10+</sup> | "MeteringMode" | **读写能力:** 可读写<br> 测光模式。| 7945| LIGHT_SOURCE<sup>10+</sup> | "LightSource" | **读写能力:** 可读写<br> 光源。例如Fluorescent。| 7946| FLASH <sup>10+</sup> | "Flash" | **读写能力:** 可读写<br> 闪光灯,记录闪光灯状态。| 7947| FOCAL_LENGTH <sup>10+</sup> | "FocalLength" | **读写能力:** 可读写<br> 焦距。| 7948| SUBJECT_AREA <sup>12+</sup> | "SubjectArea" | **读写能力:** 可读写<br> 该标签指示整个场景中主要主体的位置和区域。| 7949| MAKER_NOTE <sup>12+</sup> | "MakerNote" | **读写能力:** 只读<br> Exif/DCF制造商使用的标签,用于记录任何所需信息。| 7950| SCENE_POINTER <sup>12+</sup> | "HwMnoteScenePointer" | **读写能力:** 只读<br> 场景指针。| 7951| SCENE_VERSION <sup>12+</sup> | "HwMnoteSceneVersion" | **读写能力:** 只读<br> 场景算法版本信息。| 7952| SCENE_FOOD_CONF<sup>11+</sup> | "HwMnoteSceneFoodConf" | **读写能力:** 只读<br> 拍照场景:食物。| 7953| SCENE_STAGE_CONF<sup>11+</sup> | "HwMnoteSceneStageConf" | **读写能力:** 只读<br> 拍照场景:舞台。| 7954| SCENE_BLUE_SKY_CONF<sup>11+</sup> | "HwMnoteSceneBlueSkyConf" | **读写能力:** 只读<br> 拍照场景:蓝天。| 7955| SCENE_GREEN_PLANT_CONF<sup>11+</sup> | "HwMnoteSceneGreenPlantConf" | **读写能力:** 只读<br> 拍照场景:绿植。| 7956| SCENE_BEACH_CONF<sup>11+</sup> | "HwMnoteSceneBeachConf" | **读写能力:** 只读<br> 拍照场景:沙滩。| 7957| SCENE_SNOW_CONF<sup>11+</sup> | "HwMnoteSceneSnowConf" | **读写能力:** 只读<br> 拍照场景:下雪。| 7958| SCENE_SUNSET_CONF<sup>11+</sup> | "HwMnoteSceneSunsetConf" | **读写能力:** 只读<br> 拍照场景:日落。| 7959| SCENE_FLOWERS_CONF<sup>11+</sup> | "HwMnoteSceneFlowersConf" | **读写能力:** 只读<br> 拍照场景:花。| 7960| SCENE_NIGHT_CONF<sup>11+</sup> | "HwMnoteSceneNightConf" | **读写能力:** 只读<br> 拍照场景:夜晚。| 7961| SCENE_TEXT_CONF<sup>11+</sup> | "HwMnoteSceneTextConf" | **读写能力:** 只读<br> 拍照场景:文本。| 7962| FACE_POINTER <sup>12+</sup> | "HwMnoteFacePointer" | **读写能力:** 只读<br> 脸部指针。| 7963| FACE_VERSION <sup>12+</sup> | "HwMnoteFaceVersion" | **读写能力:** 只读<br> 人脸算法版本信息。| 7964| FACE_COUNT<sup>11+</sup> | "HwMnoteFaceCount" | **读写能力:** 只读<br> 人脸数量。| 7965| FACE_CONF <sup>12+</sup> | "HwMnoteFaceConf" | **读写能力:** 只读<br> 人脸置信度。| 7966| FACE_SMILE_SCORE <sup>12+</sup> | "HwMnoteFaceSmileScore" | **读写能力:** 只读<br> FaceCount张人脸的笑脸分数。| 7967| FACE_RECT <sup>12+</sup> | "HwMnoteFaceRect" | **读写能力:** 只读<br> 脸部矩形。| 7968| FACE_LEYE_CENTER <sup>12+</sup> | "HwMnoteFaceLeyeCenter" | **读写能力:** 只读<br> 左眼中心。| 7969| FACE_REYE_CENTER <sup>12+</sup> | "HwMnoteFaceReyeCenter" | **读写能力:** 只读<br> 右眼中心。| 7970| FACE_MOUTH_CENTER <sup>12+</sup> | "HwMnoteFaceMouthCenter" | **读写能力:** 只读<br> 嘴中心。| 7971| CAPTURE_MODE <sup>10+</sup> | "HwMnoteCaptureMode" | **读写能力:** 可读写<br> 捕获模式。| 7972| BURST_NUMBER <sup>12+</sup> | "HwMnoteBurstNumber" | **读写能力:** 只读<br> 连拍次数。| 7973| FRONT_CAMERA <sup>12+</sup> | "HwMnoteFrontCamera" | **读写能力:** 只读<br> 是否是前置相机自拍。| 7974| ROLL_ANGLE <sup>11+</sup> | "HwMnoteRollAngle" | **读写能力:** 只读<br> 滚动角度。| 7975| PITCH_ANGLE<sup>11+</sup> | "HwMnotePitchAngle" | **读写能力:** 只读<br> 俯仰角度。| 7976| PHYSICAL_APERTURE <sup>10+</sup> | "HwMnotePhysicalAperture" | **读写能力:** 只读<br> 物理孔径,光圈大小。| 7977| FOCUS_MODE<sup>11+</sup> | "HwMnoteFocusMode" | **读写能力:** 只读<br> 对焦模式。| 7978| USER_COMMENT <sup>10+</sup> | "UserComment" | **读写能力:** 可读写<br> 用户注释。| 7979| SUBSEC_TIME <sup>12+</sup> | "SubsecTime" | **读写能力:** 可读写<br> 用于为DateTime标签记录秒的分数的标签。| 7980| SUBSEC_TIME_ORIGINAL <sup>12+</sup> | "SubsecTimeOriginal" | **读写能力:** 可读写<br> 用于为DateTimeOriginal标签记录秒的分数的标签。| 7981| SUBSEC_TIME_DIGITIZED <sup>12+</sup> | "SubsecTimeDigitized" | **读写能力:** 可读写<br> 用于为DateTimeDigitized标签记录秒的分数的标签。| 7982| FLASHPIX_VERSION <sup>12+</sup> | "FlashpixVersion" | **读写能力:** 可读写<br> 该标签表示FPXR文件支持的Flashpix格式版本,增强了设备兼容性。| 7983| COLOR_SPACE <sup>12+</sup> | "ColorSpace" | **读写能力:** 可读写<br> 色彩空间信息标签,通常记录为色彩空间指定符。| 7984| PIXEL_X_DIMENSION <sup>10+</sup> | "PixelXDimension" | **读写能力:** 可读写<br> 像素X尺寸。| 7985| PIXEL_Y_DIMENSION<sup>10+</sup> | "PixelYDimension" | **读写能力:** 可读写<br> 像素Y尺寸。| 7986| RELATED_SOUND_FILE <sup>12+</sup> | "RelatedSoundFile" | **读写能力:** 可读写<br> 与图像数据相关的音频文件的名称。| 7987| FLASH_ENERGY <sup>12+</sup> | "FlashEnergy" | **读写能力:** 可读写<br> 图像捕获时的闪光能量,以BCPS表示。| 7988| SPATIAL_FREQUENCY_RESPONSE <sup>12+</sup> | "SpatialFrequencyResponse" | **读写能力:** 可读写<br> 相机或输入设备的空间频率表。| 7989| FOCAL_PLANE_X_RESOLUTION <sup>12+</sup> | "FocalPlaneXResolution" | **读写能力:** 可读写<br> 图像宽度中每FocalPlaneResolutionUnit的像素。| 7990| FOCAL_PLANE_Y_RESOLUTION <sup>12+</sup> | "FocalPlaneYResolution" | **读写能力:** 可读写<br> 图像高度中每FocalPlaneResolutionUnit的像素。| 7991| FOCAL_PLANE_RESOLUTION_UNIT <sup>12+</sup> | "FocalPlaneResolutionUnit" | **读写能力:** 可读写<br> 测量FocalPlaneXResolution和FocalPlaneYResolution的单位。| 7992| SUBJECT_LOCATION <sup>12+</sup> | "SubjectLocation" | **读写能力:** 可读写<br> 主要对象相对于左边缘的位置。| 7993| EXPOSURE_INDEX <sup>12+</sup> | "ExposureIndex" | **读写能力:** 可读写<br> 捕获时选定的曝光指数。| 7994| SENSING_METHOD <sup>12+</sup> | "SensingMethod" | **读写能力:** 可读写<br> 相机上的图像传感器类型。| 7995| FILE_SOURCE <sup>12+</sup> | "FileSource" | **读写能力:** 可读写<br> 表明图像来源。| 7996| SCENE_TYPE<sup>9+</sup> | "SceneType" | **读写能力:** 可读写<br> 拍摄场景模式,例如人像、风光、运动、夜景等。| 7997| CFA_PATTERN <sup>12+</sup> | "CFAPattern" | **读写能力:** 可读写<br> 图像传感器的色彩滤光片(CFA)几何图案。| 7998| CUSTOM_RENDERED <sup>12+</sup> | "CustomRendered" | **读写能力:** 可读写<br> 指示图像数据上的特殊处理。| 7999| EXPOSURE_MODE <sup>12+</sup> | "ExposureMode" | **读写能力:** 可读写<br> 拍摄时设置的曝光模式。| 8000| WHITE_BALANCE <sup>10+</sup> | "WhiteBalance" | **读写能力:** 可读写<br> 白平衡。| 8001| DIGITAL_ZOOM_RATIO <sup>12+</sup> | "DigitalZoomRatio" | **读写能力:** 可读写<br> 捕获时的数字变焦比率。| 8002| FOCAL_LENGTH_IN_35_MM_FILM <sup>10+</sup> | "FocalLengthIn35mmFilm" | **读写能力:** 可读写<br> 焦距35毫米胶片。| 8003| SCENE_CAPTURE_TYPE <sup>12+</sup> | "SceneCaptureType" | **读写能力:** 可读写<br> 捕获的场景类型。| 8004| GAIN_CONTROL <sup>12+</sup> | "GainControl" | **读写能力:** 可读写<br> 整体图像增益调整的程度。| 8005| CONTRAST <sup>12+</sup> | "Contrast" | **读写能力:** 可读写<br> 相机应用的对比度处理方向。| 8006| SATURATION <sup>12+</sup> | "Saturation" | **读写能力:** 可读写<br> 相机应用的饱和度处理方向。| 8007| SHARPNESS <sup>12+</sup> | "Sharpness" | **读写能力:** 可读写<br> 相机应用的锐度处理方向。| 8008| DEVICE_SETTING_DESCRIPTION <sup>12+</sup> | "DeviceSettingDescription" | **读写能力:** 可读写<br> 特定相机模型的拍照条件信息。| 8009| SUBJECT_DISTANCE_RANGE <sup>12+</sup> | "SubjectDistanceRange" | **读写能力:** 可读写<br> 表示主体到相机的距离范围。| 8010| IMAGE_UNIQUE_ID <sup>12+</sup> | "ImageUniqueID" | **读写能力:** 可读写<br> 为每张图片唯一分配的标识符。| 8011| CAMERA_OWNER_NAME <sup>12+</sup> | "CameraOwnerName" | **读写能力:** 可读写<br> 相机所有者的姓名。| 8012| BODY_SERIAL_NUMBER <sup>12+</sup> | "BodySerialNumber" | **读写能力:** 可读写<br> 相机机身的序列号。| 8013| LENS_SPECIFICATION <sup>12+</sup> | "LensSpecification" | **读写能力:** 可读写<br> 使用的镜头规格。| 8014| LENS_MAKE <sup>12+</sup> | "LensMake" | **读写能力:** 可读写<br> 镜头的制造商。| 8015| LENS_MODEL <sup>12+</sup> | "LensModel" | **读写能力:** 可读写<br> 镜头的型号名称。| 8016| LENS_SERIAL_NUMBER <sup>12+</sup> | "LensSerialNumber" | **读写能力:** 可读写<br> 镜头的序列号。| 8017| COMPOSITE_IMAGE <sup>12+</sup> | "CompositeImage" | **读写能力:** 可读写<br> 表示图像是否为合成图像。| 8018| SOURCE_IMAGE_NUMBER_OF_COMPOSITE_IMAGE <sup>12+</sup> | "SourceImageNumberOfCompositeImage" | **读写能力:** 可读写<br> 用于合成图像的源图像数量。| 8019| SOURCE_EXPOSURE_TIMES_OF_COMPOSITE_IMAGE <sup>12+</sup> | "SourceExposureTimesOfCompositeImage" | **读写能力:** 可读写<br> 合成图像的源图像曝光时间。| 8020| GAMMA <sup>12+</sup> | "Gamma" | **读写能力:** 可读写<br> 表示系数伽马的值。| 8021| DNG_VERSION <sup>12+</sup> | "DNGVersion" | **读写能力:** 可读写<br> DNG版本标签编码了符合DNG规范的四级版本号。| 8022| DEFAULT_CROP_SIZE <sup>12+</sup> | "DefaultCropSize" | **读写能力:** 可读写<br> DefaultCropSize指定了原始坐标中的最终图像大小,考虑了额外的边缘像素。| 8023| GIF_LOOP_COUNT <sup>12+</sup> | "GIFLoopCount" | **读写能力:** 只读<br> GIF图片循环次数。0表示无限循环,其他值表示循环次数。| 8024| IS_XMAGE_SUPPORTED <sup>12+</sup> | "HwMnoteIsXmageSupported" | **读写能力:** 可读写<br>是否支持XMAGE。 | 8025| XMAGE_MODE <sup>12+</sup> | "HwMnoteXmageMode" | **读写能力:** 可读写<br>XMAGE水印模式。 | 8026| XMAGE_LEFT <sup>12+</sup> | "HwMnoteXmageLeft" | **读写能力:** 可读写<br>水印区域X1坐标。 | 8027| XMAGE_TOP <sup>12+</sup> | "HwMnoteXmageTop" | **读写能力:** 可读写<br>水印区域Y1坐标。 | 8028| XMAGE_RIGHT <sup>12+</sup> | "HwMnoteXmageRight" | **读写能力:** 可读写<br>水印区域X2坐标。 | 8029| XMAGE_BOTTOM <sup>12+</sup> | "HwMnoteXmageBottom" | **读写能力:** 可读写<br>水印区域Y2坐标。 | 8030| CLOUD_ENHANCEMENT_MODE <sup>12+</sup> | "HwMnoteCloudEnhancementMode" | **读写能力:** 可读写<br>云增强模式。 | 8031| WIND_SNAPSHOT_MODE <sup>12+</sup> | "HwMnoteWindSnapshotMode" | **读写能力:** 只读<br>运动快拍模式。 | 8032 8033## FragmentMapPropertyKey<sup>13+</sup> 8034 8035枚举,水印裁剪图图片信息。 8036 8037**系统能力:** SystemCapability.Multimedia.Image.Core 8038 8039| 名称 | 值 | 说明 | 8040| ------------- | --------------------- | ----------------------------------- | 8041| X_IN_ORIGINAL | "XInOriginal" | 水印裁剪图左上角在原始图中的X坐标。 | 8042| Y_IN_ORIGINAL | "YInOriginal" | 水印裁剪图左上角在原始图中的Y坐标。 | 8043| WIDTH | "FragmentImageWidth" | 水印裁剪图的宽。 | 8044| HEIGHT | "FragmentImageHeight" | 水印裁剪图的高。 | 8045 8046## ImageFormat<sup>9+</sup> 8047 8048枚举,图片格式。 8049 8050**系统能力:** SystemCapability.Multimedia.Image.Core 8051 8052| 名称 | 值 | 说明 | 8053| ------------ | ------ | -------------------- | 8054| YCBCR_422_SP | 1000 | YCBCR422半平面格式。 | 8055| JPEG | 2000 | JPEG编码格式。 | 8056 8057## ComponentType<sup>9+</sup> 8058 8059枚举,图像的组件类型。 8060 8061**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 8062 8063| 名称 | 值 | 说明 | 8064| ----- | ------ | ----------- | 8065| YUV_Y | 1 | 亮度信息。 | 8066| YUV_U | 2 | 色度信息。 | 8067| YUV_V | 3 | 色度信息。 | 8068| JPEG | 4 | JPEG 类型。 | 8069 8070## Component<sup>9+</sup> 8071 8072描述图像颜色分量。 8073 8074**系统能力:** SystemCapability.Multimedia.Image.Core 8075 8076| 名称 | 类型 | 只读 | 可选 | 说明 | 8077| ------------- | -------------------------------- | ---- | ---- | ------------ | 8078| componentType | [ComponentType](#componenttype9) | 是 | 否 | 组件类型。 | 8079| rowStride | number | 是 | 否 | 行距。读取相机预览流数据时,需要考虑按stride进行读取,具体用法见[ArkTS双路预览示例](../../media/camera/camera-dual-channel-preview.md)。 | 8080| pixelStride | number | 是 | 否 | 像素间距。 | 8081| byteBuffer | ArrayBuffer | 是 | 否 | 组件缓冲区。 | 8082 8083## DecodingDynamicRange<sup>12+</sup> 8084 8085描述解码时期望的图像动态范围。 8086 8087**系统能力:** SystemCapability.Multimedia.Image.Core 8088 8089| 名称 | 值 | 说明 | 8090| ------------- | ----------| ------------ | 8091| AUTO | 0 | 自适应,根据图片信息处理。即如果图片本身为HDR图片,则会按照HDR内容解码;反之按照SDR内容解码。通过[CreateIncrementalSource](#imagecreateincrementalsource9)创建的imagesource会解码为SDR内容。 | 8092| SDR | 1 | 按照标准动态范围处理图片。 | 8093| HDR | 2 | 按照高动态范围处理图片。通过[CreateIncrementalSource](#imagecreateincrementalsource9)创建的imagesource会解码为SDR内容。 | 8094 8095## PackingDynamicRange<sup>12+</sup> 8096 8097描述编码时期望的图像动态范围。 8098 8099**系统能力:** SystemCapability.Multimedia.Image.Core 8100 8101| 名称 | 值 | 说明 | 8102| ------------- | ----------| ------------ | 8103| AUTO | 0 | 自适应,根据[pixelmap](#pixelmap7)内容处理。即如果pixelmap本身为HDR,则会按照HDR内容进行编码;反之按照SDR内容编码。 | 8104| SDR | 1 | 按照标准动态范围处理图片。 | 8105 8106## HdrMetadataKey<sup>12+</sup> 8107 8108枚举,[pixelmap](#pixelmap7)使用的HDR相关元数据信息的关键字。 8109 8110**系统能力:** SystemCapability.Multimedia.Image.Core 8111 8112| 名称 | 值 | 说明 | 8113| ------------- | ----------| ------------ | 8114| HDR_METADATA_TYPE | 0 | [pixelmap](#pixelmap7)使用的元数据类型。 | 8115| HDR_STATIC_METADATA | 1 | 静态元数据。 | 8116| HDR_DYNAMIC_METADATA | 2 | 动态元数据。 | 8117| HDR_GAINMAP_METADATA | 3 | Gainmap使用的元数据。 | 8118 8119## HdrMetadataType<sup>12+</sup> 8120 8121枚举,[HdrMetadataKey](#hdrmetadatakey12)中HDR_METADATA_TYPE关键字对应的值。 8122 8123**系统能力:** SystemCapability.Multimedia.Image.Core 8124 8125| 名称 | 值 | 说明 | 8126| ------------- | ----------| ------------ | 8127| NONE | 0 | 无元数据内容。 | 8128| BASE | 1 | 表示用于基础图的元数据。 | 8129| GAINMAP | 2 | 表示用于Gainmap图的元数据。 | 8130| ALTERNATE| 3 | 表示用于合成后HDR图的元数据。 | 8131 8132## HdrStaticMetadata<sup>12+</sup> 8133 8134静态元数据值,[HdrMetadataKey](#hdrmetadatakey12)中HDR_STATIC_METADATA关键字对应的值。 8135 8136**系统能力:** SystemCapability.Multimedia.Image.Core 8137 8138| 名称 | 类型 | 只读 | 可选 | 说明 | 8139| ------------- | ----------| -- | -- | ------------ | 8140| displayPrimariesX | Array\<number> | 否 | 否 | 归一化后显示设备三基色的X坐标,数组的长度为3,以0.00002为单位,范围[0.0, 1.0]。 | 8141| displayPrimariesY | Array\<number> | 否 | 否 | 归一化后显示设备三基色的Y坐标,数组的长度为3,以0.00002为单位,范围[0.0, 1.0]。 | 8142| whitePointX | number | 否 | 否 | 归一化后白点值的X坐标,以0.00002为单位,范围[0.0, 1.0]。 | 8143| whitePointY | number | 否 | 否 | 归一化后白点值的Y坐标,以0.00002为单位,范围[0.0, 1.0]。 | 8144| maxLuminance | number | 否 | 否 | 图像主监视器最大亮度。以1为单位,最大值为65535。 | 8145| minLuminance | number | 否 | 否 | 图像主监视器最小亮度。以0.0001为单位,最大值6.55535。 | 8146| maxContentLightLevel | number | 否 | 否 | 显示内容的最大亮度。以1为单位,最大值为65535。 | 8147| maxFrameAverageLightLevel | number | 否 | 否 | 显示内容的最大平均亮度,以1为单位,最大值为65535。 | 8148 8149## GainmapChannel<sup>12+</sup> 8150 8151Gainmap图单个通道的数据内容,参考ISO 21496-1。 8152 8153**系统能力:** SystemCapability.Multimedia.Image.Core 8154 8155| 名称 | 类型 | 只读 | 可选 | 说明 | 8156| ------------- | ----------| -- | -- | ------------ | 8157| gainmapMax | number | 否 | 否 | 增强图像的最大值,参考ISO 21496-1。 | 8158| gainmapMin | number | 否 | 否 | 增强图像的最小值,参考ISO 21496-1。 | 8159| gamma | number | 否 | 否 | gamma值,参考ISO 21496-1。 | 8160| baseOffset | number | 否 | 否 | 基础图的偏移,参考ISO 21496-1。 | 8161| alternateOffset | number | 否 | 否 | 提取的可选择图像偏移量,参考ISO 21496-1。 | 8162 8163## HdrGainmapMetadata<sup>12+</sup> 8164 8165Gainmap使用的元数据值,[HdrMetadataKey](#hdrmetadatakey12)中HDR_GAINMAP_METADATA关键字对应的值,参考ISO 21496-1。 8166 8167**系统能力:** SystemCapability.Multimedia.Image.Core 8168 8169| 名称 | 类型 | 只读 | 可选 | 说明 | 8170| ------------- | ----------| -- | -- | ------------ | 8171| writerVersion | number | 否 | 否 | 元数据编写器使用的版本。 | 8172| miniVersion | number | 否 | 否 | 元数据解析需要理解的最小版本。 | 8173| gainmapChannelCount | number | 否 | 否 | Gainmap的颜色通道数,值为3时RGB通道的元数据值不同,值为1时各通道元数据值相同,参考ISO 21496-1。 | 8174| useBaseColorFlag | boolean | 否 | 否 | 是否使用基础图的色彩空间,参考ISO 21496-1。 | 8175| baseHeadroom | number | 否 | 否 | 基础图提亮比,参考ISO 21496-1。 | 8176| alternateHeadroom | number | 否 | 否 | 提取的可选择图像提亮比,参考ISO 21496-1。 | 8177| channels | Array<[GainmapChannel](#gainmapchannel12)> | 否 | 否 | 各通道的数据,长度为3,参考ISO 21496-1。 | 8178 8179## HdrMetadataValue<sup>12+</sup> 8180 8181type HdrMetadataValue = HdrMetadataType | HdrStaticMetadata | ArrayBuffer | HdrGainmapMetadata 8182 8183PixelMap使用的HDR元数据值类型,和[HdrMetadataKey](#hdrmetadatakey12)关键字相对应。 8184 8185**系统能力:** SystemCapability.Multimedia.Image.Core 8186 8187| 类型 | 说明 | 8188| ------------------- | ----------------------------------------------- | 8189| [HdrMetadataType](#hdrmetadatatype12) | [HdrMetadataKey](#hdrmetadatakey12)中HDR_GAINMAP_METADATA关键字对应的元数据值类型。 | 8190| [HdrStaticMetadata](#hdrstaticmetadata12) | [HdrMetadataKey](#hdrmetadatakey12)中HDR_STATIC_METADATA关键字对应的元数据值类型。 | 8191| ArrayBuffer | [HdrMetadataKey](#hdrmetadatakey12)中HDR_DYNAMIC_METADATA关键字对应的元数据值类型。 | 8192| [HdrGainmapMetadata](#hdrgainmapmetadata12) | [HdrMetadataKey](#hdrmetadatakey12)中HDR_GAINMAP_METADATA关键字对应的元数据值类型。 | 8193 8194## AntiAliasingLevel<sup>12+</sup> 8195 8196缩放时的缩放算法。 8197 8198**原子化服务API**:从API version 14 开始,该接口支持在原子化服务中使用。 8199 8200**系统能力:** SystemCapability.Multimedia.Image.Core 8201 8202| 名称 | 值 | 说明 | 8203| ---------------------- | ------ | ----------------- | 8204| NONE | 0 | 最近邻插值算法。 | 8205| LOW | 1 | 双线性插值算法。 | 8206| MEDIUM | 2 | 双线性插值算法,同时开启Mipmap。缩小图片时建议使用。 | 8207| HIGH | 3 | 三次插值算法。 | 8208 8209## 补充说明 8210### SVG标签说明 8211 8212从API version 10开始支持SVG标签,使用版本为(SVG) 1.1,SVG文件需添加xml声明,应以“<?xml”开头,并且SVG标签需设置width,height。当前支持的标签列表有: 8213- a 8214- circla 8215- clipPath 8216- defs 8217- ellipse 8218- feBlend 8219- feColorMatrix 8220- feComposite 8221- feDiffuseLighting 8222- feDisplacementMap 8223- feDistantLight 8224- feFlood 8225- feGaussianBlur 8226- feImage 8227- feMorphology 8228- feOffset 8229- fePointLight 8230- feSpecularLighting 8231- feSpotLight 8232- feTurbulence 8233- filter 8234- g 8235- image 8236- line 8237- linearGradient 8238- mask 8239- path 8240- pattern 8241- polygon 8242- polyline 8243- radialGradient 8244- rect 8245- stop 8246- svg 8247- text 8248- textPath 8249- tspan 8250- use