1# @ohos.multimedia.image (图片处理) 2 3本模块提供图片处理效果,包括通过属性创建PixelMap、读取图像像素数据、读取区域内的图片数据等。 4 5> **说明:** 6> 7> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8 9## 导入模块 10 11```ts 12import image from '@ohos.multimedia.image'; 13``` 14 15## image.createPixelMap<sup>8+</sup> 16 17createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<PixelMap> 18 19通过属性创建PixelMap,默认采用BGRA_8888格式处理数据,通过Promise返回结果。 20 21**系统能力:** SystemCapability.Multimedia.Image.Core 22 23**参数:** 24 25| 参数名 | 类型 | 必填 | 说明 | 26| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- | 27| colors | ArrayBuffer | 是 | BGRA_8888格式的颜色数组。 | 28| options | [InitializationOptions](#initializationoptions8) | 是 | 创建像素的属性,包括透明度,尺寸,缩略值,像素格式和是否可编辑。 | 29 30**返回值:** 31 32| 类型 | 说明 | 33| -------------------------------- | ----------------------------------------------------------------------- | 34| Promise\<[PixelMap](#pixelmap7)> | 返回Pixelmap。<br>当创建的pixelmap大小超过原图大小时,返回原图pixelmap大小。| 35 36**示例:** 37 38```ts 39import {BusinessError} from '@ohos.base'; 40 41async function Demo() { 42 const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 43 let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } 44 image.createPixelMap(color, opts).then((pixelMap : image.PixelMap) => { 45 console.info('Succeeded in creating pixelmap.'); 46 }).catch((error : BusinessError) => { 47 console.error('Failed to create pixelmap.'); 48 }) 49} 50``` 51 52## image.createPixelMap<sup>8+</sup> 53 54createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: AsyncCallback\<PixelMap>): void 55 56通过属性创建PixelMap,默认采用BGRA_8888格式处理数据,通过回调函数返回结果。 57 58**系统能力:** SystemCapability.Multimedia.Image.Core 59 60**参数:** 61 62| 参数名 | 类型 | 必填 | 说明 | 63| -------- | ------------------------------------------------ | ---- | -------------------------- | 64| colors | ArrayBuffer | 是 | BGRA_8888格式的颜色数组。 | 65| options | [InitializationOptions](#initializationoptions8) | 是 | 属性。 | 66| callback | AsyncCallback\<[PixelMap](#pixelmap7)> | 是 | 通过回调返回PixelMap对象。 | 67 68**示例:** 69 70```ts 71import {BusinessError} from '@ohos.base'; 72 73async function Demo() { 74 const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 75 let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } 76 image.createPixelMap(color, opts, (error : BusinessError, pixelMap : image.PixelMap) => { 77 if(error) { 78 console.error('Failed to create pixelmap.'); 79 return; 80 } else { 81 console.info('Succeeded in creating pixelmap.'); 82 } 83 }) 84} 85``` 86 87## PixelMap<sup>7+</sup> 88 89图像像素类,用于读取或写入图像数据以及获取图像信息。在调用PixelMap的方法前,需要先通过[createPixelMap](#imagecreatepixelmap8)创建一个PixelMap实例。目前pixelmap序列化大小最大128MB,超过会送显失败。大小计算方式为(宽\*高\*每像素占用字节数)。 90 91从API version 11开始,PixelMap支持通过worker跨线程调用。当PixelMap通过[Worker](js-apis-worker.md)跨线程后,原线程的PixelMap的所有接口均不能调用,否则将报错501 服务器不具备完成请求的功能。 92 93在调用PixelMap的方法前,需要先通过[image.createPixelMap](#imagecreatepixelmap8)构建一个PixelMap对象。 94 95### 属性 96 97**系统能力:** SystemCapability.Multimedia.Image.Core 98 99| 名称 | 类型 | 可读 | 可写 | 说明 | 100| ---------- | ------- | ---- | ---- | -------------------------- | 101| isEditable | boolean | 是 | 否 | 设定是否图像像素可被编辑。 | 102 103### readPixelsToBuffer<sup>7+</sup> 104 105readPixelsToBuffer(dst: ArrayBuffer): Promise\<void> 106 107读取图像像素数据,结果写入ArrayBuffer里,使用Promise形式返回。指定BGRA_8888格式创建pixelmap,读取的像素数据与原数据保持一致。 108 109**系统能力:** SystemCapability.Multimedia.Image.Core 110 111**参数:** 112 113| 参数名 | 类型 | 必填 | 说明 | 114| ------ | ----------- | ---- | ----------------------------------------------------------------------------------------------------- | 115| dst | ArrayBuffer | 是 | 缓冲区,函数执行结束后获取的图像像素数据写入到该内存区域内。缓冲区大小由[getPixelBytesNumber](#getpixelbytesnumber7)接口获取。 | 116 117**返回值:** 118 119| 类型 | 说明 | 120| -------------- | ----------------------------------------------- | 121| Promise\<void> | Promise实例,用于获取结果,失败时返回错误信息。 | 122 123**示例:** 124 125```ts 126import {BusinessError} from '@ohos.base'; 127 128async function Demo() { 129 const readBuffer : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 130 pixelMap.readPixelsToBuffer(readBuffer).then(() => { 131 console.info('Succeeded in reading image pixel data.'); //符合条件则进入 132 }).catch((error : BusinessError) => { 133 console.error('Failed to read image pixel data.'); //不符合条件则进入 134 }) 135} 136``` 137 138### readPixelsToBuffer<sup>7+</sup> 139 140readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\<void>): void 141 142读取图像像素数据,结果写入ArrayBuffer里,使用callback形式返回。指定BGRA_8888格式创建pixelmap,读取的像素数据与原数据保持一致。 143 144**系统能力:** SystemCapability.Multimedia.Image.Core 145 146**参数:** 147 148| 参数名 | 类型 | 必填 | 说明 | 149| -------- | -------------------- | ---- | ----------------------------------------------------------------------------------------------------- | 150| dst | ArrayBuffer | 是 | 缓冲区,函数执行结束后获取的图像像素数据写入到该内存区域内。缓冲区大小由[getPixelBytesNumber](#getpixelbytesnumber7)接口获取。 | 151| callback | AsyncCallback\<void> | 是 | 获取回调,失败时返回错误信息。 | 152 153**示例:** 154 155```ts 156import {BusinessError} from '@ohos.base'; 157 158async function Demo() { 159 const readBuffer : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 160 pixelMap.readPixelsToBuffer(readBuffer, (err : BusinessError, res : void) => { 161 if(err) { 162 console.error('Failed to read image pixel data.'); //不符合条件则进入 163 return; 164 } else { 165 console.info('Succeeded in reading image pixel data.'); //符合条件则进入 166 } 167 }) 168} 169``` 170 171### readPixels<sup>7+</sup> 172 173readPixels(area: PositionArea): Promise\<void> 174 175读取区域内的图片数据,使用Promise形式返回。 176 177**系统能力:** SystemCapability.Multimedia.Image.Core 178 179**参数:** 180 181| 参数名 | 类型 | 必填 | 说明 | 182| ------ | ------------------------------ | ---- | ------------------------ | 183| area | [PositionArea](#positionarea7) | 是 | 区域大小,根据区域读取。 | 184 185**返回值:** 186 187| 类型 | 说明 | 188| :------------- | :-------------------------------------------------- | 189| Promise\<void> | Promise实例,用于获取读取结果,失败时返回错误信息。 | 190 191**示例:** 192 193```ts 194import {BusinessError} from '@ohos.base'; 195 196async function Demo() { 197 const area : image.PositionArea = { 198 pixels: new ArrayBuffer(8), 199 offset: 0, 200 stride: 8, 201 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 202 }; 203 pixelMap.readPixels(area).then(() => { 204 console.info('Succeeded in reading the image data in the area.'); //符合条件则进入 205 }).catch((error : BusinessError) => { 206 console.error('Failed to read the image data in the area.'); //不符合条件则进入 207 }) 208} 209``` 210 211### readPixels<sup>7+</sup> 212 213readPixels(area: PositionArea, callback: AsyncCallback\<void>): void 214 215读取区域内的图片数据,使用callback形式返回读取结果。 216 217**系统能力:** SystemCapability.Multimedia.Image.Core 218 219**参数:** 220 221| 参数名 | 类型 | 必填 | 说明 | 222| -------- | ------------------------------ | ---- | ------------------------------ | 223| area | [PositionArea](#positionarea7) | 是 | 区域大小,根据区域读取。 | 224| callback | AsyncCallback\<void> | 是 | 获取回调,失败时返回错误信息。 | 225 226**示例:** 227 228```ts 229import {BusinessError} from '@ohos.base'; 230 231async function Demo() { 232 const area : image.PositionArea = { 233 pixels: new ArrayBuffer(8), 234 offset: 0, 235 stride: 8, 236 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 237 }; 238 pixelMap.readPixels(area, (err : BusinessError) => { 239 if (err != undefined) { 240 console.error('Failed to read pixelmap from the specified area.'); 241 return; 242 } else { 243 console.info('Succeeded to read pixelmap from the specified area.'); 244 } 245 }) 246} 247``` 248 249### writePixels<sup>7+</sup> 250 251writePixels(area: PositionArea): Promise\<void> 252 253将PixelMap写入指定区域内,使用Promise形式返回写入结果。 254 255**系统能力:** SystemCapability.Multimedia.Image.Core 256 257**参数:** 258 259| 参数名 | 类型 | 必填 | 说明 | 260| ------ | ------------------------------ | ---- | -------------------- | 261| area | [PositionArea](#positionarea7) | 是 | 区域,根据区域写入。 | 262 263**返回值:** 264 265| 类型 | 说明 | 266| :------------- | :-------------------------------------------------- | 267| Promise\<void> | Promise实例,用于获取写入结果,失败时返回错误信息。 | 268 269**示例:** 270 271```ts 272import {BusinessError} from '@ohos.base'; 273 274async function Demo() { 275 const area : image.PositionArea = { 276 pixels: new ArrayBuffer(8), 277 offset: 0, 278 stride: 8, 279 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 280 }; 281 let bufferArr : Uint8Array = new Uint8Array(area.pixels); 282 for (let i = 0; i < bufferArr.length; i++) { 283 bufferArr[i] = i + 1; 284 } 285 pixelMap.writePixels(area).then(() => { 286 console.info('Succeeded to write pixelmap into the specified area.'); 287 }).catch((error : BusinessError) => { 288 console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`); 289 }) 290} 291``` 292 293### writePixels<sup>7+</sup> 294 295writePixels(area: PositionArea, callback: AsyncCallback\<void>): void 296 297将PixelMap写入指定区域内,使用callback形式返回写入结果。 298 299**系统能力:** SystemCapability.Multimedia.Image.Core 300 301**参数:** 302 303| 参数名 | 类型 | 必填 | 说明 | 304| --------- | ------------------------------ | ---- | ------------------------------ | 305| area | [PositionArea](#positionarea7) | 是 | 区域,根据区域写入。 | 306| callback | AsyncCallback\<void> | 是 | 获取回调,失败时返回错误信息。 | 307 308**示例:** 309 310```ts 311import {BusinessError} from '@ohos.base'; 312 313async function Demo() { 314 const area : image.PositionArea = { pixels: new ArrayBuffer(8), 315 offset: 0, 316 stride: 8, 317 region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 318 }; 319 let bufferArr : Uint8Array = new Uint8Array(area.pixels); 320 for (let i = 0; i < bufferArr.length; i++) { 321 bufferArr[i] = i + 1; 322 } 323 pixelMap.writePixels(area, (error : BusinessError) => { 324 if (error != undefined) { 325 console.error('Failed to write pixelmap into the specified area.'); 326 return; 327 } else { 328 console.info('Succeeded to write pixelmap into the specified area.'); 329 } 330 }) 331} 332``` 333 334### writeBufferToPixels<sup>7+</sup> 335 336writeBufferToPixels(src: ArrayBuffer): Promise\<void> 337 338读取缓冲区中的图片数据,结果写入PixelMap中,使用Promise形式返回。 339 340**系统能力:** SystemCapability.Multimedia.Image.Core 341 342**参数:** 343 344| 参数名 | 类型 | 必填 | 说明 | 345| ------ | ----------- | ---- | -------------- | 346| src | ArrayBuffer | 是 | 图像像素数据。 | 347 348**返回值:** 349 350| 类型 | 说明 | 351| -------------- | ----------------------------------------------- | 352| Promise\<void> | Promise实例,用于获取结果,失败时返回错误信息。 | 353 354**示例:** 355 356```ts 357import {BusinessError} from '@ohos.base'; 358 359async function Demo() { 360 const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 361 let bufferArr : Uint8Array = new Uint8Array(color); 362 for (let i = 0; i < bufferArr.length; i++) { 363 bufferArr[i] = i + 1; 364 } 365 pixelMap.writeBufferToPixels(color).then(() => { 366 console.info("Succeeded in writing data from a buffer to a PixelMap."); 367 }).catch((error : BusinessError) => { 368 console.error("Failed to write data from a buffer to a PixelMap."); 369 }) 370} 371``` 372 373### writeBufferToPixels<sup>7+</sup> 374 375writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\<void>): void 376 377读取缓冲区中的图片数据,结果写入PixelMap中,使用callback形式返回。 378 379**系统能力:** SystemCapability.Multimedia.Image.Core 380 381**参数:** 382 383| 参数名 | 类型 | 必填 | 说明 | 384| -------- | -------------------- | ---- | ------------------------------ | 385| src | ArrayBuffer | 是 | 图像像素数据。 | 386| callback | AsyncCallback\<void> | 是 | 获取回调,失败时返回错误信息。 | 387 388**示例:** 389 390```ts 391import {BusinessError} from '@ohos.base'; 392 393async function Demo() { 394 const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 395 let bufferArr : Uint8Array = new Uint8Array(color); 396 for (let i = 0; i < bufferArr.length; i++) { 397 bufferArr[i] = i + 1; 398 } 399 pixelMap.writeBufferToPixels(color, (err : BusinessError) => { 400 if (err != undefined) { 401 console.error("Failed to write data from a buffer to a PixelMap."); 402 return; 403 } else { 404 console.info("Succeeded in writing data from a buffer to a PixelMap."); 405 } 406 }) 407} 408``` 409 410### getImageInfo<sup>7+</sup> 411 412getImageInfo(): Promise\<ImageInfo> 413 414获取图像像素信息,使用Promise形式返回获取的图像像素信息。 415 416**系统能力:** SystemCapability.Multimedia.Image.Core 417 418**返回值:** 419 420| 类型 | 说明 | 421| --------------------------------- | ----------------------------------------------------------- | 422| Promise\<[ImageInfo](#imageinfo)> | Promise实例,用于异步获取图像像素信息,失败时返回错误信息。 | 423 424**示例:** 425 426```ts 427async function Demo() { 428 pixelMap.getImageInfo().then((imageInfo : image.ImageInfo) => { 429 if (imageInfo == undefined) { 430 console.error("Failed to obtain the image pixel map information."); 431 } 432 if (imageInfo.size.height == 4 && imageInfo.size.width == 6) { 433 console.info("Succeeded in obtaining the image pixel map information."); 434 } 435 }) 436} 437``` 438 439### getImageInfo<sup>7+</sup> 440 441getImageInfo(callback: AsyncCallback\<ImageInfo>): void 442 443获取图像像素信息,使用callback形式返回获取的图像像素信息。 444 445**系统能力:** SystemCapability.Multimedia.Image.Core 446 447**参数:** 448 449| 参数名 | 类型 | 必填 | 说明 | 450| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | 451| callback | AsyncCallback\<[ImageInfo](#imageinfo)> | 是 | 获取图像像素信息回调,异步返回图像像素信息,失败时返回错误信息。 | 452 453**示例:** 454 455```ts 456import {BusinessError} from '@ohos.base'; 457 458async function Demo() { 459 pixelMap.getImageInfo((err : BusinessError, imageInfo : image.ImageInfo) => { 460 if (imageInfo == undefined) { 461 console.error("Failed to obtain the image pixel map information."); 462 return; 463 } 464 if (imageInfo.size.height == 4 && imageInfo.size.width == 6) { 465 console.info("Succeeded in obtaining the image pixel map information."); 466 } 467 }) 468} 469``` 470 471### getBytesNumberPerRow<sup>7+</sup> 472 473getBytesNumberPerRow(): number 474 475获取图像像素每行字节数。 476 477**系统能力:** SystemCapability.Multimedia.Image.Core 478 479**返回值:** 480 481| 类型 | 说明 | 482| ------ | -------------------- | 483| number | 图像像素的行字节数。 | 484 485**示例:** 486 487```ts 488let rowCount : number = pixelMap.getBytesNumberPerRow(); 489``` 490 491### getPixelBytesNumber<sup>7+</sup> 492 493getPixelBytesNumber(): number 494 495获取图像像素的总字节数。 496 497**系统能力:** SystemCapability.Multimedia.Image.Core 498 499**返回值:** 500 501| 类型 | 说明 | 502| ------ | -------------------- | 503| number | 图像像素的总字节数。 | 504 505**示例:** 506 507```ts 508let pixelBytesNumber : number = pixelMap.getPixelBytesNumber(); 509``` 510 511### getDensity<sup>9+</sup> 512 513getDensity():number 514 515获取当前图像像素的密度。 516 517**系统能力:** SystemCapability.Multimedia.Image.Core 518 519**返回值:** 520 521| 类型 | 说明 | 522| ------ | --------------- | 523| number | 图像像素的密度。| 524 525**示例:** 526 527```ts 528let getDensity : number = pixelMap.getDensity(); 529``` 530 531### opacity<sup>9+</sup> 532 533opacity(rate: number, callback: AsyncCallback\<void>): void 534 535通过设置透明比率来让PixelMap达到对应的透明效果,使用callback形式返回。 536 537**系统能力:** SystemCapability.Multimedia.Image.Core 538 539**参数:** 540 541| 参数名 | 类型 | 必填 | 说明 | 542| -------- | -------------------- | ---- | ------------------------------ | 543| rate | number | 是 | 透明比率的值。 | 544| callback | AsyncCallback\<void> | 是 | 获取回调,失败时返回错误信息。 | 545 546**示例:** 547 548```ts 549import {BusinessError} from '@ohos.base'; 550 551async function Demo() { 552 let rate : number = 0.5; 553 pixelMap.opacity(rate, (err : BusinessError) => { 554 if (err) { 555 console.error("Failed to set opacity."); 556 return; 557 } else { 558 console.info("Succeeded in setting opacity."); 559 } 560 }) 561} 562``` 563 564### opacity<sup>9+</sup> 565 566opacity(rate: number): Promise\<void> 567 568通过设置透明比率来让PixelMap达到对应的透明效果,使用Promise形式返回。 569 570**系统能力:** SystemCapability.Multimedia.Image.Core 571 572**参数:** 573 574| 参数名 | 类型 | 必填 | 说明 | 575| ------ | ------ | ---- | --------------------------- | 576| rate | number | 是 | 透明比率的值。| 577 578**返回值:** 579 580| 类型 | 说明 | 581| -------------- | ----------------------------------------------- | 582| Promise\<void> | Promise实例,用于获取结果,失败时返回错误信息。 | 583 584**示例:** 585 586```ts 587import {BusinessError} from '@ohos.base'; 588 589async function Demo() { 590 let rate : number = 0.5; 591 await pixelMap.opacity(rate).then(() => { 592 console.info('Sucessed in setting opacity.'); 593 }).catch((err : BusinessError) => { 594 console.error('Failed to set opacity.'); 595 }) 596} 597``` 598 599### createAlphaPixelmap<sup>9+</sup> 600 601createAlphaPixelmap(): Promise\<PixelMap> 602 603根据Alpha通道的信息,来生成一个仅包含Alpha通道信息的pixelmap,可用于阴影效果,使用Promise形式返回。 604 605**系统能力:** SystemCapability.Multimedia.Image.Core 606 607**返回值:** 608 609| 类型 | 说明 | 610| -------------------------------- | --------------------------- | 611| Promise\<[PixelMap](#pixelmap7)> | Promise实例,返回pixelmap。 | 612 613**示例:** 614 615```ts 616import {BusinessError} from '@ohos.base'; 617 618async function Demo() { 619 await pixelMap.createAlphaPixelmap().then((alphaPixelMap : image.PixelMap) => { 620 console.info('Succeeded in creating alpha pixelmap.'); 621 }).catch((error : BusinessError) => { 622 console.error('Failed to create alpha pixelmap.'); 623 }) 624} 625``` 626 627### createAlphaPixelmap<sup>9+</sup> 628 629createAlphaPixelmap(callback: AsyncCallback\<PixelMap>): void 630 631根据Alpha通道的信息,来生成一个仅包含Alpha通道信息的pixelmap,可用于阴影效果,使用callback形式返回。 632 633**系统能力:** SystemCapability.Multimedia.Image.Core 634 635**参数:** 636 637| 参数名 | 类型 | 必填 | 说明 | 638| -------- | ------------------------ | ---- | ------------------------ | 639| callback | AsyncCallback\<[PixelMap](#pixelmap7)> | 是 | 获取回调,异步返回结果。 | 640 641**示例:** 642 643```ts 644import {BusinessError} from '@ohos.base'; 645 646async function Demo() { 647 pixelMap.createAlphaPixelmap((err : BusinessError, alphaPixelMap : image.PixelMap) => { 648 if (alphaPixelMap == undefined) { 649 console.error('Failed to obtain new pixel map.'); 650 return; 651 } else { 652 console.info('Succeed in obtaining new pixel map.'); 653 } 654 }) 655} 656``` 657 658### scale<sup>9+</sup> 659 660scale(x: number, y: number, callback: AsyncCallback\<void>): void 661 662根据输入的宽高对图片进行缩放,使用callback形式返回。 663 664**系统能力:** SystemCapability.Multimedia.Image.Core 665 666**参数:** 667 668| 参数名 | 类型 | 必填 | 说明 | 669| -------- | -------------------- | ---- | ------------------------------- | 670| x | number | 是 | 宽度的缩放倍数。| 671| y | number | 是 | 高度的缩放倍数。| 672| callback | AsyncCallback\<void> | 是 | 获取回调,失败时返回错误信息。 | 673 674**示例:** 675 676```ts 677import {BusinessError} from '@ohos.base'; 678 679async function Demo() { 680 let scaleX : number = 2.0; 681 let scaleY : number = 1.0; 682 pixelMap.scale(scaleX, scaleY, (err : BusinessError) => { 683 if (err) { 684 console.error("Failed to scale pixelmap."); 685 return; 686 } else { 687 console.info("Succeeded in scaling pixelmap."); 688 } 689 }) 690} 691``` 692 693### scale<sup>9+</sup> 694 695scale(x: number, y: number): Promise\<void> 696 697根据输入的宽高对图片进行缩放,使用Promise形式返回。 698 699**系统能力:** SystemCapability.Multimedia.Image.Core 700 701**参数:** 702 703| 参数名 | 类型 | 必填 | 说明 | 704| ------ | ------ | ---- | ------------------------------- | 705| x | number | 是 | 宽度的缩放倍数。| 706| y | number | 是 | 高度的缩放倍数。| 707 708**返回值:** 709 710| 类型 | 说明 | 711| -------------- | --------------------------- | 712| Promise\<void> | Promise实例,异步返回结果。 | 713 714**示例:** 715 716```ts 717import {BusinessError} from '@ohos.base'; 718 719async function Demo() { 720 let scaleX : number = 2.0; 721 let scaleY : number = 1.0; 722 await pixelMap.scale(scaleX, scaleY).then(() => { 723 console.info('Sucessed in scaling pixelmap.'); 724 }).catch((err : BusinessError) => { 725 console.error('Failed to scale pixelmap.'); 726 }) 727} 728``` 729 730### translate<sup>9+</sup> 731 732translate(x: number, y: number, callback: AsyncCallback\<void>): void 733 734根据输入的坐标对图片进行位置变换,使用callback形式返回。 735 736**系统能力:** SystemCapability.Multimedia.Image.Core 737 738**参数:** 739 740| 参数名 | 类型 | 必填 | 说明 | 741| -------- | -------------------- | ---- | ----------------------------- | 742| x | number | 是 | 区域横坐标。 | 743| y | number | 是 | 区域纵坐标。 | 744| callback | AsyncCallback\<void> | 是 | 获取回调,失败时返回错误信息。| 745 746**示例:** 747 748```ts 749import {BusinessError} from '@ohos.base'; 750 751async function Demo() { 752 let translateX : number = 50.0; 753 let translateY : number = 10.0; 754 pixelMap.translate(translateX, translateY, (err : BusinessError) => { 755 if (err) { 756 console.error("Failed to translate pixelmap."); 757 return; 758 } else { 759 console.info("Succeeded in translating pixelmap."); 760 } 761 }) 762} 763``` 764 765### translate<sup>9+</sup> 766 767translate(x: number, y: number): Promise\<void> 768 769根据输入的坐标对图片进行位置变换,使用Promise形式返回。 770 771**系统能力:** SystemCapability.Multimedia.Image.Core 772 773**参数:** 774 775| 参数名 | 类型 | 必填 | 说明 | 776| ------ | ------ | ---- | ----------- | 777| x | number | 是 | 区域横坐标。| 778| y | number | 是 | 区域纵坐标。| 779 780**返回值:** 781 782| 类型 | 说明 | 783| -------------- | --------------------------- | 784| Promise\<void> | Promise实例,异步返回结果。 | 785 786**示例:** 787 788```ts 789import {BusinessError} from '@ohos.base'; 790 791async function Demo() { 792 let translateX : number = 50.0; 793 let translateY : number = 10.0; 794 await pixelMap.translate(translateX, translateY).then(() => { 795 console.info('Sucessed in translating pixelmap.'); 796 }).catch((err : BusinessError) => { 797 console.error('Failed to translate pixelmap.'); 798 }) 799} 800``` 801 802### rotate<sup>9+</sup> 803 804rotate(angle: number, callback: AsyncCallback\<void>): void 805 806根据输入的角度对图片进行旋转,使用callback形式返回。 807 808**系统能力:** SystemCapability.Multimedia.Image.Core 809 810**参数:** 811 812| 参数名 | 类型 | 必填 | 说明 | 813| -------- | -------------------- | ---- | ----------------------------- | 814| angle | number | 是 | 图片旋转的角度。 | 815| callback | AsyncCallback\<void> | 是 | 获取回调,失败时返回错误信息。| 816 817**示例:** 818 819```ts 820import {BusinessError} from '@ohos.base'; 821 822async function Demo() { 823 let angle : number = 90.0; 824 pixelMap.rotate(angle, (err : BusinessError) => { 825 if (err != undefined) { 826 console.error("Failed to rotate pixelmap."); 827 return; 828 } else { 829 console.info("Succeeded in rotating pixelmap."); 830 } 831 }) 832} 833``` 834 835### rotate<sup>9+</sup> 836 837rotate(angle: number): Promise\<void> 838 839根据输入的角度对图片进行旋转,使用Promise形式返回。 840 841**系统能力:** SystemCapability.Multimedia.Image.Core 842 843**参数:** 844 845| 参数名 | 类型 | 必填 | 说明 | 846| ------ | ------ | ---- | ----------------------------- | 847| angle | number | 是 | 图片旋转的角度。 | 848 849**返回值:** 850 851| 类型 | 说明 | 852| -------------- | --------------------------- | 853| Promise\<void> | Promise实例,异步返回结果。 | 854 855**示例:** 856 857```ts 858import {BusinessError} from '@ohos.base'; 859 860async function Demo() { 861 let angle : number = 90.0; 862 await pixelMap.rotate(angle).then(() => { 863 console.info('Sucessed in rotating pixelmap.'); 864 }).catch((err : BusinessError) => { 865 console.error('Failed to rotate pixelmap.'); 866 }) 867} 868``` 869 870### flip<sup>9+</sup> 871 872flip(horizontal: boolean, vertical: boolean, callback: AsyncCallback\<void>): void 873 874根据输入的条件对图片进行翻转,使用callback形式返回。 875 876**系统能力:** SystemCapability.Multimedia.Image.Core 877 878**参数:** 879 880| 参数名 | 类型 | 必填 | 说明 | 881| ---------- | -------------------- | ---- | ----------------------------- | 882| horizontal | boolean | 是 | 水平翻转。 | 883| vertical | boolean | 是 | 垂直翻转。 | 884| callback | AsyncCallback\<void> | 是 | 获取回调,失败时返回错误信息。| 885 886**示例:** 887 888```ts 889import {BusinessError} from '@ohos.base'; 890 891async function Demo() { 892 let horizontal : boolean = true; 893 let vertical : boolean = false; 894 pixelMap.flip(horizontal, vertical, (err : BusinessError) => { 895 if (err != undefined) { 896 console.error("Failed to flip pixelmap."); 897 return; 898 } else { 899 console.info("Succeeded in flipping pixelmap."); 900 } 901 }) 902} 903``` 904 905### flip<sup>9+</sup> 906 907flip(horizontal: boolean, vertical: boolean): Promise\<void> 908 909根据输入的条件对图片进行翻转,使用Promise形式返回。 910 911**系统能力:** SystemCapability.Multimedia.Image.Core 912 913**参数:** 914 915| 参数名 | 类型 | 必填 | 说明 | 916| ---------- | ------- | ---- | --------- | 917| horizontal | boolean | 是 | 水平翻转。| 918| vertical | boolean | 是 | 垂直翻转。| 919 920**返回值:** 921 922| 类型 | 说明 | 923| -------------- | --------------------------- | 924| Promise\<void> | Promise实例,异步返回结果。 | 925 926**示例:** 927 928```ts 929import {BusinessError} from '@ohos.base'; 930 931async function Demo() { 932 let horizontal : boolean = true; 933 let vertical : boolean = false; 934 await pixelMap.flip(horizontal, vertical).then(() => { 935 console.info('Sucessed in flipping pixelmap.'); 936 }).catch((err : BusinessError) => { 937 console.error('Failed to flip pixelmap.'); 938 }) 939} 940``` 941 942### crop<sup>9+</sup> 943 944crop(region: Region, callback: AsyncCallback\<void>): void 945 946根据输入的尺寸对图片进行裁剪,使用callback形式返回。 947 948**系统能力:** SystemCapability.Multimedia.Image.Core 949 950**参数:** 951 952| 参数名 | 类型 | 必填 | 说明 | 953| -------- | -------------------- | ---- | ----------------------------- | 954| region | [Region](#region7) | 是 | 裁剪的尺寸。 | 955| callback | AsyncCallback\<void> | 是 | 获取回调,失败时返回错误信息。| 956 957**示例:** 958 959```ts 960import {BusinessError} from '@ohos.base'; 961 962async function Demo() { 963 let region : image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 964 pixelMap.crop(region, (err : BusinessError) => { 965 if (err != undefined) { 966 console.error("Failed to crop pixelmap."); 967 return; 968 } else { 969 console.info("Succeeded in cropping pixelmap."); 970 } 971 }) 972} 973``` 974 975### crop<sup>9+</sup> 976 977crop(region: Region): Promise\<void> 978 979根据输入的尺寸对图片进行裁剪,使用Promise形式返回。 980 981**系统能力:** SystemCapability.Multimedia.Image.Core 982 983**参数:** 984 985| 参数名 | 类型 | 必填 | 说明 | 986| ------ | ------------------ | ---- | ----------- | 987| region | [Region](#region7) | 是 | 裁剪的尺寸。| 988 989**返回值:** 990 991| 类型 | 说明 | 992| -------------- | --------------------------- | 993| Promise\<void> | Promise实例,异步返回结果。 | 994 995**示例:** 996 997```ts 998import {BusinessError} from '@ohos.base'; 999 1000async function Demo() { 1001 let region : image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } }; 1002 await pixelMap.crop(region).then(() => { 1003 console.info('Sucessed in cropping pixelmap.'); 1004 }).catch((err : BusinessError) => { 1005 console.error('Failed to crop pixelmap.'); 1006 }); 1007} 1008``` 1009 1010### getColorSpace<sup>10+</sup> 1011 1012getColorSpace(): colorSpaceManager.ColorSpaceManager 1013 1014获取图像广色域信息。 1015 1016**系统能力:** SystemCapability.Multimedia.Image.Core 1017 1018**返回值:** 1019 1020| 类型 | 说明 | 1021| ----------------------------------- | ---------------- | 1022| [colorSpaceManager.ColorSpaceManager](js-apis-colorSpaceManager.md#colorspacemanager) | 图像广色域信息。 | 1023 1024**错误码:** 1025 1026以下错误码的详细介绍请参见[Image错误码](../errorcodes/errorcode-image.md)。 1027 1028| 错误码ID | 错误信息 | 1029| ------- | --------------------------------------------| 1030| 62980101| If the image data abnormal | 1031| 62980103| If the image data unsupport | 1032| 62980115| If the image parameter invalid | 1033 1034**示例:** 1035 1036```ts 1037async function Demo() { 1038 let csm = pixelMap.getColorSpace(); 1039} 1040``` 1041 1042### setColorSpace<sup>10+</sup> 1043 1044setColorSpace(colorSpace: colorSpaceManager.ColorSpaceManager): void 1045 1046设置图像广色域信息。 1047 1048**系统能力:** SystemCapability.Multimedia.Image.Core 1049 1050**参数:** 1051 1052| 参数名 | 类型 | 必填 | 说明 | 1053| ---------- | ----------------------------------- | ---- | --------------- | 1054| colorSpace | [colorSpaceManager.ColorSpaceManager](js-apis-colorSpaceManager.md#colorspacemanager) | 是 | 图像广色域信息。| 1055 1056**错误码:** 1057 1058以下错误码的详细介绍请参见[Image错误码](../errorcodes/errorcode-image.md)。 1059 1060| 错误码ID | 错误信息 | 1061| ------- | --------------------------------------------| 1062| 62980111| If the operation invalid | 1063| 62980115| If the image parameter invalid | 1064 1065**示例:** 1066 1067```ts 1068import colorSpaceManager from '@ohos.graphics.colorSpaceManager'; 1069async function Demo() { 1070 let colorSpaceName = colorSpaceManager.ColorSpace.SRGB; 1071 let csm : colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName); 1072 pixelMap.setColorSpace(csm); 1073} 1074``` 1075 1076### marshalling<sup>10+</sup> 1077 1078marshalling(sequence: rpc.MessageSequence): void 1079 1080将PixelMap序列化后写入MessageSequence。 1081 1082**系统能力:** SystemCapability.Multimedia.Image.Core 1083 1084**参数:** 1085 1086| 参数名 | 类型 | 必填 | 说明 | 1087| ---------------------- | ------------------------------------------------------ | ---- | ---------------------------------------- | 1088| sequence | [rpc.MessageSequence](js-apis-rpc.md#messagesequence9) | 是 | 新创建的MessageSequence。 | 1089 1090**错误码:** 1091 1092以下错误码的详细介绍请参见[Image错误码](../errorcodes/errorcode-image.md)。 1093 1094| 错误码ID | 错误信息 | 1095| ------- | --------------------------------------------| 1096| 62980115 | If the input parameter invalid | 1097| 62980097 | If the ipc error | 1098 1099**示例:** 1100 1101```ts 1102import image from '@ohos.multimedia.image'; 1103import rpc from '@ohos.rpc'; 1104 1105class MySequence implements rpc.Parcelable { 1106 pixel_map : image.PixelMap; 1107 constructor(conPixelMap : image.PixelMap) { 1108 this.pixel_map = conPixelMap; 1109 } 1110 marshalling(messageSequence : rpc.MessageSequence) { 1111 this.pixel_map.marshalling(messageSequence); 1112 console.info('marshalling'); 1113 return true; 1114 } 1115 unmarshalling(messageSequence : rpc.MessageSequence) { 1116 image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}}).then((pixelParcel : image.PixelMap) => { 1117 pixelParcel.unmarshalling(messageSequence).then(async (pixelMap : image.PixelMap) => { 1118 this.pixel_map = pixelMap; 1119 await pixelMap.getImageInfo().then((imageInfo : image.ImageInfo) => { 1120 console.info("unmarshalling information h:" + imageInfo.size.height + "w:" + imageInfo.size.width); 1121 }) 1122 }) 1123 }); 1124 return true; 1125 } 1126} 1127async function Demo() { 1128 const color : ArrayBuffer = new ArrayBuffer(96); 1129 let bufferArr : Uint8Array = new Uint8Array(color); 1130 for (let i = 0; i < bufferArr.length; i++) { 1131 bufferArr[i] = 0x80; 1132 } 1133 let opts : image.InitializationOptions = { 1134 editable: true, 1135 pixelFormat: 4, 1136 size: { height: 4, width: 6 }, 1137 alphaType: 3 1138 } 1139 let pixelMap : image.PixelMap | undefined = undefined; 1140 await image.createPixelMap(color, opts).then((srcPixelMap : image.PixelMap) => { 1141 pixelMap = srcPixelMap; 1142 }) 1143 if (pixelMap != undefined) { 1144 // 序列化 1145 let parcelable : MySequence = new MySequence(pixelMap); 1146 let data : rpc.MessageSequence = rpc.MessageSequence.create(); 1147 data.writeParcelable(parcelable); 1148 1149 1150 // 反序列化 rpc获取到data 1151 let ret : MySequence = new MySequence(pixelMap); 1152 data.readParcelable(ret); 1153 } 1154} 1155``` 1156 1157### unmarshalling<sup>10+</sup> 1158 1159unmarshalling(sequence: rpc.MessageSequence): Promise\<PixelMap> 1160 1161从MessageSequence中获取PixelMap。 1162 1163**系统能力:** SystemCapability.Multimedia.Image.Core 1164 1165**参数:** 1166 1167| 参数名 | 类型 | 必填 | 说明 | 1168| ---------------------- | ----------------------------------------------------- | ---- | ---------------------------------------- | 1169| sequence | [rpc.MessageSequence](js-apis-rpc.md#messagesequence9) | 是 | 保存有PixelMap信息的MessageSequence。 | 1170 1171**返回值:** 1172 1173| 类型 | 说明 | 1174| -------------------------------- | --------------------- | 1175| Promise\<[PixelMap](#pixelmap7)> | Promise实例,用于异步获取结果,失败时返回错误信息。 | 1176 1177**错误码:** 1178 1179以下错误码的详细介绍请参见[Image错误码](../errorcodes/errorcode-image.md)。 1180 1181| 错误码ID | 错误信息 | 1182| ------- | --------------------------------------------| 1183| 62980115 | If the input parameter invalid | 1184| 62980097 | If the ipc error | 1185| 62980096 | If fail to create async work | 1186 1187**示例:** 1188 1189```ts 1190import image from '@ohos.multimedia.image'; 1191import rpc from '@ohos.rpc'; 1192 1193class MySequence implements rpc.Parcelable { 1194 pixel_map : image.PixelMap; 1195 constructor(conPixelMap : image.PixelMap) { 1196 this.pixel_map = conPixelMap; 1197 } 1198 marshalling(messageSequence : rpc.MessageSequence) { 1199 this.pixel_map.marshalling(messageSequence); 1200 console.info('marshalling'); 1201 return true; 1202 } 1203 unmarshalling(messageSequence : rpc.MessageSequence) { 1204 image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}}).then((pixelParcel : image.PixelMap) => { 1205 pixelParcel.unmarshalling(messageSequence).then(async (pixelMap : image.PixelMap) => { 1206 this.pixel_map = pixelMap; 1207 await pixelMap.getImageInfo().then((imageInfo : image.ImageInfo) => { 1208 console.info("unmarshalling information h:" + imageInfo.size.height + "w:" + imageInfo.size.width); 1209 }) 1210 }) 1211 }); 1212 return true; 1213 } 1214} 1215async function Demo() { 1216 const color : ArrayBuffer = new ArrayBuffer(96); 1217 let bufferArr : Uint8Array = new Uint8Array(color); 1218 for (let i = 0; i < bufferArr.length; i++) { 1219 bufferArr[i] = 0x80; 1220 } 1221 let opts : image.InitializationOptions = { 1222 editable: true, 1223 pixelFormat: 4, 1224 size: { height: 4, width: 6 }, 1225 alphaType: 3 1226 } 1227 let pixelMap : image.PixelMap | undefined = undefined; 1228 await image.createPixelMap(color, opts).then((srcPixelMap : image.PixelMap) => { 1229 pixelMap = srcPixelMap; 1230 }) 1231 if (pixelMap != undefined) { 1232 // 序列化 1233 let parcelable : MySequence = new MySequence(pixelMap); 1234 let data : rpc.MessageSequence = rpc.MessageSequence.create(); 1235 data.writeParcelable(parcelable); 1236 1237 1238 // 反序列化 rpc获取到data 1239 let ret : MySequence = new MySequence(pixelMap); 1240 data.readParcelable(ret); 1241 } 1242} 1243``` 1244 1245### release<sup>7+</sup> 1246 1247release():Promise\<void> 1248 1249释放PixelMap对象,使用Promise形式返回释放结果。 1250 1251**系统能力:** SystemCapability.Multimedia.Image.Core 1252 1253**返回值:** 1254 1255| 类型 | 说明 | 1256| -------------- | ------------------------------- | 1257| Promise\<void> | Promise实例,异步返回释放结果。 | 1258 1259**示例:** 1260 1261```ts 1262import {BusinessError} from '@ohos.base'; 1263 1264async function Demo() { 1265 pixelMap.release().then(() => { 1266 console.info('Succeeded in releasing pixelmap object.'); 1267 }).catch((error : BusinessError) => { 1268 console.error('Failed to release pixelmap object.'); 1269 }) 1270} 1271``` 1272 1273### release<sup>7+</sup> 1274 1275release(callback: AsyncCallback\<void>): void 1276 1277释放PixelMap对象,使用callback形式返回释放结果。 1278 1279**系统能力:** SystemCapability.Multimedia.Image.Core 1280 1281**参数:** 1282 1283| 参数名 | 类型 | 必填 | 说明 | 1284| -------- | -------------------- | ---- | ------------------ | 1285| callback | AsyncCallback\<void> | 是 | 异步返回释放结果。 | 1286 1287**示例:** 1288 1289```ts 1290import {BusinessError} from '@ohos.base'; 1291 1292async function Demo() { 1293 pixelMap.release((err : BusinessError) => { 1294 if (err != undefined) { 1295 console.error('Failed to release pixelmap object.'); 1296 return; 1297 } else { 1298 console.info('Succeeded in releasing pixelmap object.'); 1299 } 1300 }) 1301} 1302``` 1303 1304## image.createImageSource 1305 1306createImageSource(uri: string): ImageSource 1307 1308通过传入的uri创建图片源实例。 1309 1310**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1311 1312**参数:** 1313 1314| 参数名 | 类型 | 必填 | 说明 | 1315| ------ | ------ | ---- | ---------------------------------- | 1316| uri | string | 是 | 图片路径,当前仅支持应用沙箱路径。</br>当前支持格式有:.jpg .png .gif .bmp .webp RAW [SVG<sup>10+</sup>](#svg标签说明)。 | 1317 1318**返回值:** 1319 1320| 类型 | 说明 | 1321| --------------------------- | -------------------------------------------- | 1322| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 | 1323 1324**示例:** 1325 1326```ts 1327//Stage模型 1328const context : Context = getContext(this); 1329const path : string = context.cacheDir + "/test.jpg"; 1330const imageSourceApi : image.ImageSource = image.createImageSource(path); 1331``` 1332 1333```ts 1334//FA模型 1335import featureAbility from '@ohos.ability.featureAbility'; 1336 1337const context : featureAbility.Context = featureAbility.getContext(); 1338const path : string = context.getCacheDir() + "/test.jpg"; 1339const imageSourceApi : image.ImageSource = image.createImageSource(path); 1340``` 1341 1342## image.createImageSource<sup>9+</sup> 1343 1344createImageSource(uri: string, options: SourceOptions): ImageSource 1345 1346通过传入的uri创建图片源实例。 1347 1348**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1349 1350**参数:** 1351 1352| 参数名 | 类型 | 必填 | 说明 | 1353| ------- | ------------------------------- | ---- | ----------------------------------- | 1354| uri | string | 是 | 图片路径,当前仅支持应用沙箱路径。</br>当前支持格式有:.jpg .png .gif .bmp .webp RAW [SVG<sup>10+</sup>](#svg标签说明)。 | 1355| options | [SourceOptions](#sourceoptions9) | 是 | 图片属性,包括图片序号与默认属性值。| 1356 1357**返回值:** 1358 1359| 类型 | 说明 | 1360| --------------------------- | -------------------------------------------- | 1361| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 | 1362 1363**示例:** 1364 1365```ts 1366let sourceOptions : image.SourceOptions = { sourceDensity: 120 }; 1367let imageSource : image.ImageSource = image.createImageSource('test.png', sourceOptions); 1368``` 1369 1370## image.createImageSource<sup>7+</sup> 1371 1372createImageSource(fd: number): ImageSource 1373 1374通过传入文件描述符来创建图片源实例。 1375 1376**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1377 1378**参数:** 1379 1380| 参数名 | 类型 | 必填 | 说明 | 1381| ------ | ------ | ---- | ------------- | 1382| fd | number | 是 | 文件描述符fd。| 1383 1384**返回值:** 1385 1386| 类型 | 说明 | 1387| --------------------------- | -------------------------------------------- | 1388| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 | 1389 1390**示例:** 1391 1392```ts 1393const imageSourceApi : image.ImageSource = image.createImageSource(0); 1394``` 1395 1396## image.createImageSource<sup>9+</sup> 1397 1398createImageSource(fd: number, options: SourceOptions): ImageSource 1399 1400通过传入文件描述符来创建图片源实例。 1401 1402**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1403 1404**参数:** 1405 1406| 参数名 | 类型 | 必填 | 说明 | 1407| ------- | ------------------------------- | ---- | ----------------------------------- | 1408| fd | number | 是 | 文件描述符fd。 | 1409| options | [SourceOptions](#sourceoptions9) | 是 | 图片属性,包括图片序号与默认属性值。| 1410 1411**返回值:** 1412 1413| 类型 | 说明 | 1414| --------------------------- | -------------------------------------------- | 1415| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 | 1416 1417**示例:** 1418 1419```ts 1420let sourceOptions : image.SourceOptions = { sourceDensity: 120 }; 1421const imageSourceApi : image.ImageSource = image.createImageSource(0, sourceOptions); 1422``` 1423 1424## image.createImageSource<sup>9+</sup> 1425 1426createImageSource(buf: ArrayBuffer): ImageSource 1427 1428通过缓冲区创建图片源实例。 1429 1430**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1431 1432**参数:** 1433 1434| 参数名 | 类型 | 必填 | 说明 | 1435| ------ | ----------- | ---- | ---------------- | 1436| buf | ArrayBuffer | 是 | 图像缓冲区数组。 | 1437 1438**返回值:** 1439 1440| 类型 | 说明 | 1441| --------------------------- | -------------------------------------------- | 1442| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 | 1443 1444 1445**示例:** 1446 1447```ts 1448const buf : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 1449const imageSourceApi : image.ImageSource = image.createImageSource(buf); 1450``` 1451 1452## image.createImageSource<sup>9+</sup> 1453 1454createImageSource(buf: ArrayBuffer, options: SourceOptions): ImageSource 1455 1456通过缓冲区创建图片源实例。 1457 1458**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1459 1460**参数:** 1461 1462| 参数名 | 类型 | 必填 | 说明 | 1463| ------ | -------------------------------- | ---- | ------------------------------------ | 1464| buf | ArrayBuffer | 是 | 图像缓冲区数组。 | 1465| options | [SourceOptions](#sourceoptions9) | 是 | 图片属性,包括图片序号与默认属性值。 | 1466 1467**返回值:** 1468 1469| 类型 | 说明 | 1470| --------------------------- | -------------------------------------------- | 1471| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 | 1472 1473**示例:** 1474 1475```ts 1476const data : ArrayBuffer= new ArrayBuffer(112); 1477let sourceOptions : image.SourceOptions = { sourceDensity: 120 }; 1478const imageSourceApi : image.ImageSource = image.createImageSource(data, sourceOptions); 1479``` 1480 1481## image.CreateIncrementalSource<sup>9+</sup> 1482 1483CreateIncrementalSource(buf: ArrayBuffer): ImageSource 1484 1485通过缓冲区以增量的方式创建图片源实例。 1486 1487**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1488 1489**参数:** 1490 1491| 参数名 | 类型 | 必填 | 说明 | 1492| ------- | ------------| ---- | ----------| 1493| buf | ArrayBuffer | 是 | 增量数据。| 1494 1495**返回值:** 1496 1497| 类型 | 说明 | 1498| --------------------------- | --------------------------------- | 1499| [ImageSource](#imagesource) | 返回图片源,失败时返回undefined。 | 1500 1501**示例:** 1502 1503```ts 1504const buf : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 1505const imageSourceIncrementalSApi : image.ImageSource = image.CreateIncrementalSource(buf); 1506``` 1507 1508## image.CreateIncrementalSource<sup>9+</sup> 1509 1510CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource 1511 1512通过缓冲区以增量的方式创建图片源实例。 1513 1514**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1515 1516**参数:** 1517 1518| 参数名 | 类型 | 必填 | 说明 | 1519| ------- | ------------------------------- | ---- | ------------------------------------ | 1520| buf | ArrayBuffer | 是 | 增量数据。 | 1521| options | [SourceOptions](#sourceoptions9) | 否 | 图片属性,包括图片序号与默认属性值。 | 1522 1523**返回值:** 1524 1525| 类型 | 说明 | 1526| --------------------------- | --------------------------------- | 1527| [ImageSource](#imagesource) | 返回图片源,失败时返回undefined。 | 1528 1529**示例:** 1530 1531```ts 1532const buf : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 1533let sourceOptions : image.SourceOptions = { sourceDensity: 120 }; 1534const imageSourceIncrementalSApi : image.ImageSource = image.CreateIncrementalSource(buf, sourceOptions); 1535``` 1536 1537## ImageSource 1538 1539图片源类,用于获取图片相关信息。在调用ImageSource的方法前,需要先通过[createImageSource](#imagecreateimagesource)构建一个ImageSource实例。 1540 1541### 属性 1542 1543**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1544 1545| 名称 | 类型 | 可读 | 可写 | 说明 | 1546| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | 1547| supportedFormats | Array\<string> | 是 | 否 | 支持的图片格式,包括:png,jpeg,bmp,gif,webp,RAW。 | 1548 1549### getImageInfo 1550 1551getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void 1552 1553获取指定序号的图片信息,使用callback形式返回图片信息。 1554 1555**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1556 1557**参数:** 1558 1559| 参数名 | 类型 | 必填 | 说明 | 1560| -------- | -------------------------------------- | ---- | ---------------------------------------- | 1561| index | number | 是 | 创建图片源时的序号。 | 1562| callback | AsyncCallback<[ImageInfo](#imageinfo)> | 是 | 获取图片信息回调,异步返回图片信息对象。 | 1563 1564**示例:** 1565 1566```ts 1567import {BusinessError} from '@ohos.base'; 1568 1569imageSourceApi.getImageInfo(0,(error : BusinessError, imageInfo : image.ImageInfo) => { 1570 if(error) { 1571 console.error('getImageInfo failed.'); 1572 } else { 1573 console.info('getImageInfo succeeded.'); 1574 } 1575}) 1576``` 1577 1578### getImageInfo 1579 1580getImageInfo(callback: AsyncCallback\<ImageInfo>): void 1581 1582获取图片信息,使用callback形式返回图片信息。 1583 1584**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1585 1586**参数:** 1587 1588| 参数名 | 类型 | 必填 | 说明 | 1589| -------- | -------------------------------------- | ---- | ---------------------------------------- | 1590| callback | AsyncCallback<[ImageInfo](#imageinfo)> | 是 | 获取图片信息回调,异步返回图片信息对象。 | 1591 1592**示例:** 1593 1594```ts 1595import {BusinessError} from '@ohos.base'; 1596 1597imageSourceApi.getImageInfo((err : BusinessError, imageInfo : image.ImageInfo) => { 1598 if (err != undefined) { 1599 console.error(`Failed to obtaining the image information.code is ${err.code}, message is ${err.message}`); 1600 } else { 1601 console.info('Succeeded in obtaining the image information.'); 1602 } 1603}) 1604``` 1605 1606### getImageInfo 1607 1608getImageInfo(index?: number): Promise\<ImageInfo> 1609 1610获取图片信息,使用Promise形式返回图片信息。 1611 1612**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1613 1614**参数:** 1615 1616| 参数名| 类型 | 必填 | 说明 | 1617| ----- | ------ | ---- | ------------------------------------- | 1618| index | number | 否 | 创建图片源时的序号,不选择时默认为0。 | 1619 1620**返回值:** 1621 1622| 类型 | 说明 | 1623| -------------------------------- | ---------------------- | 1624| Promise<[ImageInfo](#imageinfo)> | Promise实例,用于异步返回获取到的图片信息。 | 1625 1626**示例:** 1627 1628```ts 1629import {BusinessError} from '@ohos.base'; 1630 1631imageSourceApi.getImageInfo(0) 1632 .then((imageInfo : image.ImageInfo) => { 1633 console.info('Succeeded in obtaining the image information.'); 1634 }).catch((error : BusinessError) => { 1635 console.error('Failed to obtain the image information.'); 1636 }) 1637``` 1638 1639### getImageProperty<sup>7+</sup> 1640 1641getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\<string> 1642 1643获取图片中给定索引处图像的指定属性键的值,用Promise形式返回结果,仅支持JPEG文件,且需要包含exif信息。 1644 1645**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1646 1647**参数:** 1648 1649| 参数名 | 类型 | 必填 | 说明 | 1650| ------- | ---------------------------------------------------- | ---- | ------------------------------------ | 1651| key | string | 是 | 图片属性名。 | 1652| options | [GetImagePropertyOptions](#getimagepropertyoptions7) | 否 | 图片属性,包括图片序号与默认属性值。 | 1653 1654**返回值:** 1655 1656| 类型 | 说明 | 1657| ---------------- | ----------------------------------------------------------------- | 1658| Promise\<string> | Promise实例,用于异步获取图片属性值,如获取失败则返回属性默认值。 | 1659 1660**示例:** 1661 1662```ts 1663import {BusinessError} from '@ohos.base'; 1664 1665imageSourceApi.getImageProperty("BitsPerSample") 1666 .then((data : string) => { 1667 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 1668 }).catch((error : BusinessError) => { 1669 console.error('Failed to get the value of the specified attribute key of the image.'); 1670 }) 1671``` 1672 1673### getImageProperty<sup>7+</sup> 1674 1675getImageProperty(key:string, callback: AsyncCallback\<string>): void 1676 1677获取图片中给定索引处图像的指定属性键的值,用callback形式返回结果,仅支持JPEG文件,且需要包含exif信息。 1678 1679**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1680 1681**参数:** 1682 1683| 参数名 | 类型 | 必填 | 说明 | 1684| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 1685| key | string | 是 | 图片属性名。 | 1686| callback | AsyncCallback\<string> | 是 | 获取图片属性回调,返回图片属性值,如获取失败则返回属性默认值。 | 1687 1688**示例:** 1689 1690```ts 1691import {BusinessError} from '@ohos.base'; 1692 1693imageSourceApi.getImageProperty("BitsPerSample",(error : BusinessError, data : string) => { 1694 if(error) { 1695 console.error('Failed to get the value of the specified attribute key of the image.'); 1696 } else { 1697 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 1698 } 1699}) 1700``` 1701 1702### getImageProperty<sup>7+</sup> 1703 1704getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCallback\<string>): void 1705 1706获取图片指定属性键的值,callback形式返回结果,仅支持JPEG文件,且需要包含exif信息。 1707 1708**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1709 1710**参数:** 1711 1712| 参数名 | 类型 | 必填 | 说明 | 1713| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------- | 1714| key | string | 是 | 图片属性名。 | 1715| options | [GetImagePropertyOptions](#getimagepropertyoptions7) | 是 | 图片属性,包括图片序号与默认属性值。 | 1716| callback | AsyncCallback\<string> | 是 | 获取图片属性回调,返回图片属性值,如获取失败则返回属性默认值。| 1717 1718**示例:** 1719 1720```ts 1721import {BusinessError} from '@ohos.base'; 1722 1723let property : image.GetImagePropertyOptions = { index: 0, defaultValue: '9999' } 1724imageSourceApi.getImageProperty("BitsPerSample",property,(error : BusinessError, data : string) => { 1725 if(error) { 1726 console.error('Failed to get the value of the specified attribute key of the image.'); 1727 } else { 1728 console.info('Succeeded in getting the value of the specified attribute key of the image.'); 1729 } 1730}) 1731``` 1732 1733### modifyImageProperty<sup>9+</sup> 1734 1735modifyImageProperty(key: string, value: string): Promise\<void> 1736 1737通过指定的键修改图片属性的值,使用Promise形式返回结果,仅支持JPEG文件,且需要包含exif信息。 1738 1739**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1740 1741**参数:** 1742 1743| 参数名 | 类型 | 必填 | 说明 | 1744| ------- | ------ | ---- | ------------ | 1745| key | string | 是 | 图片属性名。 | 1746| value | string | 是 | 属性值。 | 1747 1748**返回值:** 1749 1750| 类型 | 说明 | 1751| -------------- | --------------------------- | 1752| Promise\<void> | Promise实例,异步返回结果。 | 1753 1754**示例:** 1755 1756```ts 1757import {BusinessError} from '@ohos.base'; 1758 1759imageSourceApi.modifyImageProperty("ImageWidth", "120").then(() => { 1760 imageSourceApi.getImageProperty("ImageWidth").then((width : string) => { 1761 console.info(`ImageWidth is :${width}`); 1762 }).catch((error : BusinessError) => { 1763 console.error('Failed to get the Image Width.'); 1764 }) 1765}).catch((error : BusinessError) => { 1766 console.error('Failed to modify the Image Width'); 1767}) 1768``` 1769 1770### modifyImageProperty<sup>9+</sup> 1771 1772modifyImageProperty(key: string, value: string, callback: AsyncCallback\<void>): void 1773 1774通过指定的键修改图片属性的值,callback形式返回结果,仅支持JPEG文件,且需要包含exif信息。 1775 1776**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1777 1778**参数:** 1779 1780| 参数名 | 类型 | 必填 | 说明 | 1781| -------- | ------------------- | ---- | ------------------------------ | 1782| key | string | 是 | 图片属性名。 | 1783| value | string | 是 | 属性值。 | 1784| callback | AsyncCallback\<void> | 是 | 修改属性值,callback返回结果。 | 1785 1786**示例:** 1787 1788```ts 1789import {BusinessError} from '@ohos.base'; 1790 1791imageSourceApi.modifyImageProperty("ImageWidth", "120",(err : BusinessError) => { 1792 if (err != undefined) { 1793 console.error('modifyImageProperty Failed'); 1794 } else { 1795 console.info('modifyImageProperty Succeeded'); 1796 } 1797}) 1798``` 1799 1800### updateData<sup>9+</sup> 1801 1802updateData(buf: ArrayBuffer, isFinished: boolean, value: number, length: number): Promise\<void> 1803 1804更新增量数据,使用Promise形式返回结果。 1805 1806**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1807 1808**参数:** 1809 1810| 参数名 | 类型 | 必填 | 说明 | 1811| ---------- | ----------- | ---- | ------------ | 1812| buf | ArrayBuffer | 是 | 增量数据。 | 1813| isFinished | boolean | 是 | 是否更新完。 | 1814| value | number | 是 | 偏移量。 | 1815| length | number | 是 | 数组长。 | 1816 1817**返回值:** 1818 1819| 类型 | 说明 | 1820| -------------- | -------------------------- | 1821| Promise\<void> | Promise实例,异步返回结果。| 1822 1823**示例:** 1824 1825```ts 1826import {BusinessError} from '@ohos.base'; 1827 1828const array : ArrayBuffer = new ArrayBuffer(100); 1829imageSourceApi.updateData(array, false, 0, 10).then(() => { 1830 console.info('Succeeded in updating data.'); 1831}).catch((err: BusinessError) => { 1832 console.error(`Failed to update data.code is ${err.code},message is ${err.message}`); 1833}) 1834``` 1835 1836 1837### updateData<sup>9+</sup> 1838 1839updateData(buf: ArrayBuffer, isFinished: boolean, value: number, length: number, callback: AsyncCallback\<void>): void 1840 1841更新增量数据,callback形式返回结果。 1842 1843**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1844 1845**参数:** 1846 1847| 参数名 | 类型 | 必填 | 说明 | 1848| ---------- | ------------------- | ---- | -------------------- | 1849| buf | ArrayBuffer | 是 | 增量数据。 | 1850| isFinished | boolean | 是 | 是否更新完。 | 1851| value | number | 是 | 偏移量。 | 1852| length | number | 是 | 数组长。 | 1853| callback | AsyncCallback\<void> | 是 | 回调表示成功或失败。 | 1854 1855**示例:** 1856 1857```ts 1858import {BusinessError} from '@ohos.base'; 1859 1860const array : ArrayBuffer = new ArrayBuffer(100); 1861imageSourceApi.updateData(array, false, 0, 10, (err: BusinessError) => { 1862 if (err != undefined) { 1863 console.error(`Failed to update data.code is ${err.code},message is ${err.message}`); 1864 } else { 1865 console.info('Succeeded in updating data.'); 1866 } 1867}) 1868``` 1869 1870### createPixelMap<sup>7+</sup> 1871 1872createPixelMap(options?: DecodingOptions): Promise\<PixelMap> 1873 1874通过图片解码参数创建PixelMap对象。 1875 1876**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1877 1878**参数:** 1879 1880| 参数名 | 类型 | 必填 | 说明 | 1881| ------- | ------------------------------------ | ---- | ---------- | 1882| options | [DecodingOptions](#decodingoptions7) | 否 | 解码参数。 | 1883 1884**返回值:** 1885 1886| 类型 | 说明 | 1887| -------------------------------- | --------------------- | 1888| Promise\<[PixelMap](#pixelmap7)> | Promise实例,用于异步返回创建结果。 | 1889 1890**示例:** 1891 1892```ts 1893import {BusinessError} from '@ohos.base'; 1894 1895imageSourceApi.createPixelMap().then((pixelMap : image.PixelMap) => { 1896 console.info('Succeeded in creating pixelMap object through image decoding parameters.'); 1897}).catch((error : BusinessError) => { 1898 console.error('Failed to create pixelMap object through image decoding parameters.'); 1899}) 1900``` 1901 1902### createPixelMap<sup>7+</sup> 1903 1904createPixelMap(callback: AsyncCallback\<PixelMap>): void 1905 1906通过默认参数创建PixelMap对象,使用callback形式返回结果。 1907 1908**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1909 1910**参数:** 1911 1912| 参数名 | 类型 | 必填 | 说明 | 1913| -------- | ------------------------------------- | ---- | -------------------------- | 1914| callback | AsyncCallback<[PixelMap](#pixelmap7)> | 是 | 通过回调返回PixelMap对象。 | 1915 1916**示例:** 1917 1918```ts 1919import {BusinessError} from '@ohos.base'; 1920 1921imageSourceApi.createPixelMap((err : BusinessError, pixelMap : image.PixelMap) => { 1922 if (err != undefined) { 1923 console.error(`Failed to create pixelMap.code is ${err.code},message is ${err.message}`); 1924 } else { 1925 console.info('Succeeded in creating pixelMap object.'); 1926 } 1927}) 1928``` 1929 1930### createPixelMap<sup>7+</sup> 1931 1932createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): void 1933 1934通过图片解码参数创建PixelMap对象。 1935 1936**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1937 1938**参数:** 1939 1940| 参数名 | 类型 | 必填 | 说明 | 1941| -------- | ------------------------------------- | ---- | -------------------------- | 1942| options | [DecodingOptions](#decodingoptions7) | 是 | 解码参数。 | 1943| callback | AsyncCallback<[PixelMap](#pixelmap7)> | 是 | 通过回调返回PixelMap对象。 | 1944 1945**示例:** 1946 1947```ts 1948import {BusinessError} from '@ohos.base'; 1949 1950let decodingOptions : image.DecodingOptions = { 1951 sampleSize: 1, 1952 editable: true, 1953 desiredSize: { width: 1, height: 2 }, 1954 rotate: 10, 1955 desiredPixelFormat: 3, 1956 desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 }, 1957 index: 0 1958}; 1959imageSourceApi.createPixelMap(decodingOptions, (err : BusinessError, pixelMap : image.PixelMap) => { 1960 if (err != undefined) { 1961 console.error(`Failed to create pixelMap.code is ${err.code},message is ${err.message}`); 1962 } else { 1963 console.info('Succeeded in creating pixelMap object.'); 1964 } 1965}) 1966``` 1967 1968### createPixelMapList<sup>10+</sup> 1969 1970createPixelMapList(options?: DecodingOptions): Promise<Array\<PixelMap>> 1971 1972通过图片解码参数创建PixelMap数组。 1973 1974**系统能力:** SystemCapability.Multimedia.Image.ImageSource 1975 1976**参数:** 1977 1978| 参数名 | 类型 | 必填 | 说明 | 1979| -------- | ------------------------------------- | ---- | -------------------------- | 1980| options | [DecodingOptions](#decodingoptions7) | 否 | 解码参数。 | 1981 1982**返回值:** 1983 1984| 类型 | 说明 | 1985| -------------------------------- | --------------------- | 1986| Promise<Array<[PixelMap](#pixelmap7)>> | 异步返回PixeMap数组。 | 1987 1988**错误码:** 1989 1990以下错误码的详细介绍请参见[Image错误码](../errorcodes/errorcode-image.md)。 1991 1992| 错误码ID | 错误信息 | 1993| ------- | --------------------------------------------| 1994| 62980096| If the operation failed | 1995| 62980103| If the image data unsupport | 1996| 62980110| If the image source data error | 1997| 62980111| If the image source data incomplete | 1998| 62980118| If the image plugin create failed | 1999 2000**示例:** 2001 2002```ts 2003import {BusinessError} from '@ohos.base'; 2004 2005let decodeOpts: image.DecodingOptions = { 2006 sampleSize: 1, 2007 editable: true, 2008 desiredSize: { width: 198, height: 202 }, 2009 rotate: 0, 2010 desiredPixelFormat: 3, 2011 index: 0, 2012}; 2013imageSourceApi.createPixelMapList(decodeOpts).then((pixelMapList: Array<image.PixelMap>) => { 2014 console.info('Succeeded in creating pixelMapList object.'); 2015}).catch((err: BusinessError) => { 2016 console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`); 2017}) 2018``` 2019 2020### createPixelMapList<sup>10+</sup> 2021 2022createPixelMapList(callback: AsyncCallback<Array\<PixelMap>>): void 2023 2024通过默认参数创建PixelMap数组,使用callback形式返回结果。 2025 2026**系统能力:** SystemCapability.Multimedia.Image.ImageSource 2027 2028**参数:** 2029 2030| 参数名 | 类型 | 必填 | 说明 | 2031| -------- | ------------------------------------- | ---- | -------------------------- | 2032| callback | AsyncCallback<Array<[PixelMap](#pixelmap7)>> | 是 | 通过回调返回PixelMap数组。 | 2033 2034**错误码:** 2035 2036以下错误码的详细介绍请参见[Image错误码](../errorcodes/errorcode-image.md)。 2037 2038| 错误码ID | 错误信息 | 2039| ------- | --------------------------------------------| 2040| 62980096| If the operation failed | 2041| 62980103| If the image data unsupport | 2042| 62980110| If the image source data error | 2043| 62980111| If the image source data incomplete | 2044| 62980118| If the image plugin create failed | 2045 2046**示例:** 2047 2048```ts 2049import {BusinessError} from '@ohos.base'; 2050 2051imageSourceApi.createPixelMapList((err: BusinessError, pixelMapList: Array<image.PixelMap>) => { 2052 if (err != undefined) { 2053 console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`); 2054 } else { 2055 console.info('Succeeded in creating pixelMapList object.'); 2056 } 2057}) 2058``` 2059 2060### createPixelMapList<sup>10+</sup> 2061 2062createPixelMapList(options: DecodingOptions, callback: AsyncCallback<Array\<PixelMap>>): void 2063 2064通过图片解码参数创建PixelMap数组,使用callback形式返回结果。 2065 2066**系统能力:** SystemCapability.Multimedia.Image.ImageSource 2067 2068**参数:** 2069 2070| 参数名 | 类型 | 必填 | 说明 | 2071| -------- | -------------------- | ---- | ---------------------------------- | 2072| options | [DecodingOptions](#decodingoptions7) | 是 | 解码参数。 | 2073| callback | AsyncCallback<Array<[PixelMap](#pixelmap7)>> | 是 | 通过回调返回PixelMap数组。 | 2074 2075**错误码:** 2076 2077以下错误码的详细介绍请参见[Image错误码](../errorcodes/errorcode-image.md)。 2078 2079| 错误码ID | 错误信息 | 2080| ------- | --------------------------------------------| 2081| 62980096| If the operation failed | 2082| 62980103| If the image data unsupport | 2083| 62980110| If the image source data error | 2084| 62980111| If the image source data incomplete | 2085| 62980118| If the image plugin create failed | 2086 2087**示例:** 2088 2089```ts 2090import {BusinessError} from '@ohos.base'; 2091 2092let decodeOpts : image.DecodingOptions = { 2093 sampleSize: 1, 2094 editable: true, 2095 desiredSize: { width: 198, height: 202 }, 2096 rotate: 0, 2097 desiredPixelFormat: 3, 2098 index: 0, 2099}; 2100imageSourceApi.createPixelMapList(decodeOpts, (err: BusinessError, pixelMapList: Array<image.PixelMap>) => { 2101 if (err != undefined) { 2102 console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`); 2103 } else { 2104 console.info('Succeeded in creating pixelMapList object.'); 2105 } 2106}) 2107``` 2108 2109### getDelayTimeList<sup>10+</sup> 2110 2111getDelayTimeList(callback: AsyncCallback<Array\<number>>): void 2112 2113获取图像延迟时间数组,使用callback形式返回结果。 2114 2115**系统能力:** SystemCapability.Multimedia.Image.ImageSource 2116 2117**参数:** 2118 2119| 参数名 | 类型 | 必填 | 说明 | 2120| -------- | -------------------- | ---- | ---------------------------------- | 2121| callback | AsyncCallback<Array\<number>> | 是 | 通过回调返回延迟时间数组。 | 2122 2123**错误码:** 2124 2125以下错误码的详细介绍请参见[Image错误码](../errorcodes/errorcode-image.md)。 2126 2127| 错误码ID | 错误信息 | 2128| ------- | --------------------------------------------| 2129| 62980096| If the operation failed | 2130| 62980110| If the image source data error | 2131| 62980111| If the image source data incomplete | 2132| 62980113| If the image format unknown | 2133| 62980116| If the image decode failed | 2134| 62980118| If the image plugin create failed | 2135| 62980122| If the image decode head abnormal | 2136 2137**示例:** 2138 2139```ts 2140import {BusinessError} from '@ohos.base'; 2141 2142imageSourceApi.getDelayTimeList((err: BusinessError, delayTimes: Array<number>) => { 2143 if (err != undefined) { 2144 console.error(`Failed to get delayTimes object.code is ${err.code},message is ${err.message}`); 2145 } else { 2146 console.info('Succeeded in delayTimes object.'); 2147 } 2148}) 2149``` 2150 2151### getDelayTimeList<sup>10+</sup> 2152 2153getDelayTimeList(): Promise<Array\<number>> 2154 2155获取图像延迟时间数组,使用Promise形式返回结果。 2156 2157**系统能力:** SystemCapability.Multimedia.Image.ImageSource 2158 2159**返回值:** 2160 2161| 类型 | 说明 | 2162| -------------- | --------------------------- | 2163| Promise<Array\<number>> | Promise实例,异步返回延迟时间数组。 | 2164 2165**错误码:** 2166 2167以下错误码的详细介绍请参见[Image错误码](../errorcodes/errorcode-image.md)。 2168 2169| 错误码ID | 错误信息 | 2170| ------- | --------------------------------------------| 2171| 62980096| If the operation failed | 2172| 62980110| If the image source data error | 2173| 62980111| If the image source data incomplete | 2174| 62980113| If the image format unknown | 2175| 62980116| If the image decode failed | 2176| 62980118| If the image plugin create failed | 2177| 62980122| If the image decode head abnormal | 2178 2179**示例:** 2180 2181```ts 2182import {BusinessError} from '@ohos.base'; 2183 2184imageSourceApi.getDelayTimeList().then((delayTimes : Array<number>) => { 2185 console.info('Succeeded in delayTimes object.'); 2186}).catch((err: BusinessError) => { 2187 console.error(`Failed to get delayTimes object.code is ${err.code},message is ${err.message}`); 2188}) 2189``` 2190 2191### getFrameCount<sup>10+</sup> 2192 2193getFrameCount(callback: AsyncCallback\<number>): void 2194 2195获取图像帧数,使用callback形式返回结果。 2196 2197**系统能力:** SystemCapability.Multimedia.Image.ImageSource 2198 2199**参数:** 2200 2201| 参数名 | 类型 | 必填 | 说明 | 2202| -------- | -------------------- | ---- | ---------------------------------- | 2203| callback | AsyncCallback\<number> | 是 | 通过回调返回图像帧数。 | 2204 2205**错误码:** 2206 2207以下错误码的详细介绍请参见[Image错误码](../errorcodes/errorcode-image.md)。 2208 2209| 错误码ID | 错误信息 | 2210| ------- | --------------------------------------------| 2211| 62980096| If the operation failed | 2212| 62980110| If the image source data error | 2213| 62980111| If the image source data incomplete | 2214| 62980113| If the image format unknown | 2215| 62980116| If the image decode failed | 2216| 62980118| If the image plugin create failed | 2217| 62980122| If the image decode head abnormal | 2218 2219**示例:** 2220 2221```ts 2222import {BusinessError} from '@ohos.base'; 2223 2224imageSourceApi.getFrameCount((err: BusinessError, frameCount: number) => { 2225 if (err != undefined) { 2226 console.error(`Failed to get frame count.code is ${err.code},message is ${err.message}`); 2227 } else { 2228 console.info('Succeeded in getting frame count.'); 2229 } 2230}) 2231``` 2232 2233### getFrameCount<sup>10+</sup> 2234 2235getFrameCount(): Promise\<number> 2236 2237获取图像帧数,使用Promise形式返回结果。 2238 2239**系统能力:** SystemCapability.Multimedia.Image.ImageSource 2240 2241**返回值:** 2242 2243| 类型 | 说明 | 2244| -------------- | --------------------------- | 2245| Promise\<number> | Promise实例,异步返回图像帧数。 | 2246 2247**错误码:** 2248 2249以下错误码的详细介绍请参见[Image错误码](../errorcodes/errorcode-image.md)。 2250 2251| 错误码ID | 错误信息 | 2252| ------- | --------------------------------------------| 2253| 62980096| If the operation failed | 2254| 62980110| If the image source data error | 2255| 62980111| If the image source data incomplete | 2256| 62980113| If the image format unknown | 2257| 62980116| If the image decode failed | 2258| 62980118| If the image plugin create failed | 2259| 62980122| If the image decode head abnormal | 2260 2261**示例:** 2262 2263```ts 2264import {BusinessError} from '@ohos.base'; 2265 2266imageSourceApi.getFrameCount().then((frameCount: number) => { 2267 console.info('Succeeded in getting frame count.'); 2268}).catch((err : BusinessError) => { 2269 console.error(`Failed to get frame count.code is ${err.code},message is ${err.message}`); 2270}) 2271``` 2272 2273### release 2274 2275release(callback: AsyncCallback\<void>): void 2276 2277释放图片源实例,使用callback形式返回结果。 2278 2279**系统能力:** SystemCapability.Multimedia.Image.ImageSource 2280 2281**参数:** 2282 2283| 参数名 | 类型 | 必填 | 说明 | 2284| -------- | -------------------- | ---- | ---------------------------------- | 2285| callback | AsyncCallback\<void> | 是 | 资源释放回调,失败时返回错误信息。 | 2286 2287**示例:** 2288 2289```ts 2290import {BusinessError} from '@ohos.base'; 2291 2292imageSourceApi.release((err : BusinessError) => { 2293 if (err != undefined) { 2294 console.error('Failed to release the image source instance.'); 2295 } else { 2296 console.info('Succeeded in releasing the image source instance.'); 2297 } 2298}) 2299``` 2300 2301### release 2302 2303release(): Promise\<void> 2304 2305释放图片源实例,使用Promise形式返回结果。 2306 2307**系统能力:** SystemCapability.Multimedia.Image.ImageSource 2308 2309**返回值:** 2310 2311| 类型 | 说明 | 2312| -------------- | --------------------------- | 2313| Promise\<void> | Promise实例,异步返回结果。 | 2314 2315**示例:** 2316 2317```ts 2318import {BusinessError} from '@ohos.base'; 2319 2320imageSourceApi.release().then(()=>{ 2321 console.info('Succeeded in releasing the image source instance.'); 2322}).catch((error : BusinessError) => { 2323 console.error('Failed to release the image source instance.'); 2324}) 2325``` 2326 2327## image.createImagePacker 2328 2329createImagePacker(): ImagePacker 2330 2331创建ImagePacker实例。 2332 2333**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 2334 2335**返回值:** 2336 2337| 类型 | 说明 | 2338| --------------------------- | --------------------- | 2339| [ImagePacker](#imagepacker) | 返回ImagePacker实例。 | 2340 2341**示例:** 2342 2343```ts 2344const imagePackerApi : image.ImagePacker = image.createImagePacker(); 2345``` 2346 2347## ImagePacker 2348 2349图片打包器类,用于图片压缩和打包。在调用ImagePacker的方法前,需要先通过[createImagePacker](#imagecreateimagepacker)构建一个ImagePacker实例,当前支持格式有:jpeg、webp、png。 2350 2351### 属性 2352 2353**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 2354 2355| 名称 | 类型 | 可读 | 可写 | 说明 | 2356| ---------------- | -------------- | ---- | ---- | -------------------------- | 2357| supportedFormats | Array\<string> | 是 | 否 | 图片打包支持的格式 jpeg、webp、png。 | 2358 2359### packing 2360 2361packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void 2362 2363图片压缩或重新打包,使用callback形式返回结果。 2364 2365**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 2366 2367**参数:** 2368 2369| 参数名 | 类型 | 必填 | 说明 | 2370| -------- | ---------------------------------- | ---- | ---------------------------------- | 2371| source | [ImageSource](#imagesource) | 是 | 打包的图片源。 | 2372| option | [PackingOption](#packingoption) | 是 | 设置打包参数。 | 2373| callback | AsyncCallback\<ArrayBuffer> | 是 | 获取图片打包回调,返回打包后数据。 | 2374 2375**示例:** 2376 2377```ts 2378import {BusinessError} from '@ohos.base'; 2379 2380const imageSourceApi : image.ImageSource = image.createImageSource(0); 2381let packOpts : image.PackingOption = { format:"image/jpeg", quality:98 }; 2382imagePackerApi.packing(imageSourceApi, packOpts, (err : BusinessError, data : ArrayBuffer) => { 2383 if(err) { 2384 console.error('packing failed.'); 2385 } else { 2386 console.info('packing succeeded.'); 2387 } 2388}) 2389``` 2390 2391### packing 2392 2393packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer> 2394 2395图片压缩或重新打包,使用Promise形式返回结果。 2396 2397**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 2398 2399**参数:** 2400 2401| 参数名 | 类型 | 必填 | 说明 | 2402| ------ | ------------------------------- | ---- | -------------- | 2403| source | [ImageSource](#imagesource) | 是 | 打包的图片源。 | 2404| option | [PackingOption](#packingoption) | 是 | 设置打包参数。 | 2405 2406**返回值:** 2407 2408| 类型 | 说明 | 2409| ---------------------------- | --------------------------------------------- | 2410| Promise\<ArrayBuffer> | Promise实例,用于异步获取压缩或打包后的数据。 | 2411 2412**示例:** 2413 2414```ts 2415import {BusinessError} from '@ohos.base'; 2416 2417const imageSourceApi : image.ImageSource = image.createImageSource(0); 2418let packOpts : image.PackingOption = { format:"image/jpeg", quality:98 } 2419imagePackerApi.packing(imageSourceApi, packOpts) 2420 .then( (data : ArrayBuffer) => { 2421 console.info('packing succeeded.'); 2422 }).catch((error : BusinessError) => { 2423 console.error('packing failed.'); 2424 }) 2425``` 2426 2427### packing<sup>8+</sup> 2428 2429packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void 2430 2431图片压缩或重新打包,使用callback形式返回结果。 2432 2433**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 2434 2435**参数:** 2436 2437| 参数名 | 类型 | 必填 | 说明 | 2438| -------- | ------------------------------- | ---- | ---------------------------------- | 2439| source | [PixelMap](#pixelmap7) | 是 | 打包的PixelMap资源。 | 2440| option | [PackingOption](#packingoption) | 是 | 设置打包参数。 | 2441| callback | AsyncCallback\<ArrayBuffer> | 是 | 获取图片打包回调,返回打包后数据。 | 2442 2443**示例:** 2444 2445```ts 2446import {BusinessError} from '@ohos.base'; 2447 2448const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 2449let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } 2450image.createPixelMap(color, opts).then((pixelMap : image.PixelMap) => { 2451 let packOpts : image.PackingOption = { format:"image/jpeg", quality:98 } 2452 imagePackerApi.packing(pixelMap, packOpts, (err : BusinessError, data : ArrayBuffer) => { 2453 console.info('Succeeded in packing the image.'); 2454 }) 2455}).catch((error : BusinessError) => { 2456 console.error('createPixelMap failed.'); 2457}) 2458``` 2459 2460### packing<sup>8+</sup> 2461 2462packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer> 2463 2464图片压缩或重新打包,使用Promise形式返回结果。 2465 2466**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 2467 2468**参数:** 2469 2470| 参数名 | 类型 | 必填 | 说明 | 2471| ------ | ------------------------------- | ---- | ------------------ | 2472| source | [PixelMap](#pixelmap7) | 是 | 打包的PixelMap源。 | 2473| option | [PackingOption](#packingoption) | 是 | 设置打包参数。 | 2474 2475**返回值:** 2476 2477| 类型 | 说明 | 2478| --------------------- | -------------------------------------------- | 2479| Promise\<ArrayBuffer> | Promise实例,用于异步获取压缩或打包后的数据。| 2480 2481**示例:** 2482 2483```ts 2484import {BusinessError} from '@ohos.base'; 2485 2486const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 2487let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } 2488image.createPixelMap(color, opts).then((pixelMap : image.PixelMap) => { 2489 let packOpts : image.PackingOption = { format:"image/jpeg", quality:98 } 2490 imagePackerApi.packing(pixelMap, packOpts) 2491 .then( (data : ArrayBuffer) => { 2492 console.info('Succeeded in packing the image.'); 2493 }).catch((error : BusinessError) => { 2494 console.error('Failed to pack the image..'); 2495 }) 2496}).catch((error : BusinessError) => { 2497 console.error('createPixelMap failed.'); 2498}) 2499``` 2500 2501### release 2502 2503release(callback: AsyncCallback\<void>): void 2504 2505释放图片打包实例,使用callback形式返回结果。 2506 2507**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 2508 2509**参数:** 2510 2511| 参数名 | 类型 | 必填 | 说明 | 2512| -------- | -------------------- | ---- | ------------------------------ | 2513| callback | AsyncCallback\<void> | 是 | 释放回调,失败时返回错误信息。 | 2514 2515**示例:** 2516 2517```ts 2518import {BusinessError} from '@ohos.base'; 2519 2520imagePackerApi.release((err : BusinessError)=>{ 2521 if (err != undefined) { 2522 console.error('Failed to release image packaging.'); 2523 } else { 2524 console.info('Succeeded in releasing image packaging.'); 2525 } 2526}) 2527``` 2528 2529### release 2530 2531release(): Promise\<void> 2532 2533释放图片打包实例,使用Promise形式返回释放结果。 2534 2535**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 2536 2537**返回值:** 2538 2539| 类型 | 说明 | 2540| -------------- | ------------------------------------------------------ | 2541| Promise\<void> | Promise实例,用于异步获取释放结果,失败时返回错误信息。| 2542 2543**示例:** 2544 2545```ts 2546import {BusinessError} from '@ohos.base'; 2547 2548imagePackerApi.release().then(()=>{ 2549 console.info('Succeeded in releasing image packaging.'); 2550}).catch((error : BusinessError)=>{ 2551 console.error('Failed to release image packaging.'); 2552}) 2553``` 2554 2555## image.createImageReceiver<sup>9+</sup> 2556 2557createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver 2558 2559通过宽、高、图片格式、容量创建ImageReceiver实例。 2560 2561**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 2562 2563**参数:** 2564 2565| 参数名 | 类型 | 必填 | 说明 | 2566| -------- | ------ | ---- | ---------------------- | 2567| width | number | 是 | 图像的默认宽度。 | 2568| height | number | 是 | 图像的默认高度。 | 2569| format | number | 是 | 图像格式,取值为[ImageFormat](#imageformat9)常量(目前仅支持 ImageFormat:JPEG)。 | 2570| capacity | number | 是 | 同时访问的最大图像数。 | 2571 2572**返回值:** 2573 2574| 类型 | 说明 | 2575| -------------------------------- | --------------------------------------- | 2576| [ImageReceiver](#imagereceiver9) | 如果操作成功,则返回ImageReceiver实例。 | 2577 2578**示例:** 2579 2580```ts 2581let receiver : image.ImageReceiver = image.createImageReceiver(8192, 8, image.ImageFormat.JPEG, 8); 2582``` 2583 2584## ImageReceiver<sup>9+</sup> 2585 2586图像接收类,用于获取组件surface id,接收最新的图片和读取下一张图片,以及释放ImageReceiver实例。 2587 2588在调用以下方法前需要先创建ImageReceiver实例。 2589 2590### 属性 2591 2592**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 2593 2594| 名称 | 类型 | 可读 | 可写 | 说明 | 2595| -------- | ---------------------------- | ---- | ---- | ------------------ | 2596| size | [Size](#size) | 是 | 否 | 图片大小。 | 2597| capacity | number | 是 | 否 | 同时访问的图像数。 | 2598| format | [ImageFormat](#imageformat9) | 是 | 否 | 图像格式。 | 2599 2600### getReceivingSurfaceId<sup>9+</sup> 2601 2602getReceivingSurfaceId(callback: AsyncCallback\<string>): void 2603 2604用于获取一个surface id供Camera或其他组件使用。使用callback返回结果。 2605 2606**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 2607 2608**参数:** 2609 2610| 参数名 | 类型 | 必填 | 说明 | 2611| -------- | ---------------------- | ---- | -------------------------- | 2612| callback | AsyncCallback\<string> | 是 | 回调函数,返回surface id。 | 2613 2614**示例:** 2615 2616```ts 2617import {BusinessError} from '@ohos.base'; 2618 2619receiver.getReceivingSurfaceId((err : BusinessError, id : string) => { 2620 if(err) { 2621 console.error('getReceivingSurfaceId failed.'); 2622 } else { 2623 console.info('getReceivingSurfaceId succeeded.'); 2624 } 2625}); 2626``` 2627 2628### getReceivingSurfaceId<sup>9+</sup> 2629 2630getReceivingSurfaceId(): Promise\<string> 2631 2632用于获取一个surface id供Camera或其他组件使用。使用promise返回结果。 2633 2634**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 2635 2636**返回值:** 2637 2638| 类型 | 说明 | 2639| ---------------- | -------------------- | 2640| Promise\<string> | 异步返回surface id。 | 2641 2642**示例:** 2643 2644```ts 2645import {BusinessError} from '@ohos.base'; 2646 2647receiver.getReceivingSurfaceId().then( (id : string) => { 2648 console.info('getReceivingSurfaceId succeeded.'); 2649}).catch((error : BusinessError) => { 2650 console.error('getReceivingSurfaceId failed.'); 2651}) 2652``` 2653 2654### readLatestImage<sup>9+</sup> 2655 2656readLatestImage(callback: AsyncCallback\<Image>): void 2657 2658从ImageReceiver读取最新的图片,并使用callback返回结果。 2659 2660**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 2661 2662**参数:** 2663 2664| 参数名 | 类型 | 必填 | 说明 | 2665| -------- | ------------------------------- | ---- | ------------------------ | 2666| callback | AsyncCallback<[Image](#image9)> | 是 | 回调函数,返回最新图像。 | 2667 2668**示例:** 2669 2670```ts 2671import {BusinessError} from '@ohos.base'; 2672 2673receiver.readLatestImage((err : BusinessError, img : image.Image) => { 2674 if(err) { 2675 console.error('readLatestImage failed.'); 2676 } else { 2677 console.info('readLatestImage succeeded.'); 2678 } 2679}); 2680``` 2681 2682### readLatestImage<sup>9+</sup> 2683 2684readLatestImage(): Promise\<Image> 2685 2686从ImageReceiver读取最新的图片,并使用promise返回结果。 2687 2688**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 2689 2690**返回值:** 2691 2692| 类型 | 说明 | 2693| ------------------------- | ------------------ | 2694| Promise<[Image](#image9)> | 异步返回最新图片。 | 2695 2696**示例:** 2697 2698```ts 2699import {BusinessError} from '@ohos.base'; 2700 2701receiver.readLatestImage().then((img : image.Image) => { 2702 console.info('readLatestImage succeeded.'); 2703}).catch((error : BusinessError) => { 2704 console.error('readLatestImage failed.'); 2705}) 2706``` 2707 2708### readNextImage<sup>9+</sup> 2709 2710readNextImage(callback: AsyncCallback\<Image>): void 2711 2712从ImageReceiver读取下一张图片,并使用callback返回结果。 2713 2714**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 2715 2716**参数:** 2717 2718| 参数名 | 类型 | 必填 | 说明 | 2719| -------- | ------------------------------- | ---- | -------------------------- | 2720| callback | AsyncCallback<[Image](#image9)> | 是 | 回调函数,返回下一张图片。 | 2721 2722**示例:** 2723 2724```ts 2725import {BusinessError} from '@ohos.base'; 2726 2727receiver.readNextImage((err : BusinessError, img : image.Image) => { 2728 if(err) { 2729 console.error('readNextImage failed.'); 2730 } else { 2731 console.info('readNextImage succeeded.'); 2732 } 2733}); 2734``` 2735 2736### readNextImage<sup>9+</sup> 2737 2738readNextImage(): Promise\<Image> 2739 2740从ImageReceiver读取下一张图片,并使用promise返回结果。 2741 2742**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 2743 2744**返回值:** 2745 2746| 类型 | 说明 | 2747| ------------------------- | -------------------- | 2748| Promise<[Image](#image9)> | 异步返回下一张图片。 | 2749 2750**示例:** 2751 2752```ts 2753import {BusinessError} from '@ohos.base'; 2754 2755receiver.readNextImage().then((img : image.Image) => { 2756 console.info('readNextImage succeeded.'); 2757}).catch((error : BusinessError) => { 2758 console.error('readNextImage failed.'); 2759}) 2760``` 2761 2762### on<sup>9+</sup> 2763 2764on(type: 'imageArrival', callback: AsyncCallback\<void>): void 2765 2766接收图片时注册回调。 2767 2768**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 2769 2770**参数:** 2771 2772| 参数名 | 类型 | 必填 | 说明 | 2773| -------- | -------------------- | ---- | ------------------------------------------------------ | 2774| type | string | 是 | 注册事件的类型,固定为'imageArrival',接收图片时触发。 | 2775| callback | AsyncCallback\<void> | 是 | 注册的事件回调。 | 2776 2777**示例:** 2778 2779```ts 2780receiver.on('imageArrival', () => { 2781 // image arrival, do something. 2782}) 2783``` 2784 2785### release<sup>9+</sup> 2786 2787release(callback: AsyncCallback\<void>): void 2788 2789释放ImageReceiver实例并使用回调返回结果。 2790 2791**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 2792 2793**参数:** 2794 2795| 参数名 | 类型 | 必填 | 说明 | 2796| -------- | -------------------- | ---- | ------------------------ | 2797| callback | AsyncCallback\<void> | 是 | 回调函数,返回操作结果。 | 2798 2799**示例:** 2800 2801```ts 2802import {BusinessError} from '@ohos.base' 2803 2804receiver.release((err : BusinessError) => { 2805 if(err) { 2806 console.error('release ImageReceiver failed.'); 2807 } else { 2808 console.info('release ImageReceiver succeeded.'); 2809 } 2810}) 2811``` 2812 2813### release<sup>9+</sup> 2814 2815release(): Promise\<void> 2816 2817释放ImageReceiver实例并使用promise返回结果。 2818 2819**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 2820 2821**返回值:** 2822 2823| 类型 | 说明 | 2824| -------------- | ------------------ | 2825| Promise\<void> | 异步返回操作结果。 | 2826 2827**示例:** 2828 2829```ts 2830import {BusinessError} from '@ohos.base'; 2831 2832receiver.release().then(() => { 2833 console.info('release succeeded.'); 2834}).catch((error : BusinessError) => { 2835 console.error('release failed.'); 2836}) 2837``` 2838 2839## image.createImageCreator<sup>9+</sup> 2840 2841createImageCreator(width: number, height: number, format: number, capacity: number): ImageCreator 2842 2843通过宽、高、图片格式、容量创建ImageCreator实例。 2844 2845**系统能力:** SystemCapability.Multimedia.Image.ImageCreator 2846 2847**参数:** 2848 2849| 参数名 | 类型 | 必填 | 说明 | 2850| -------- | ------ | ---- | ---------------------- | 2851| width | number | 是 | 图像的默认宽度。 | 2852| height | number | 是 | 图像的默认高度。 | 2853| format | number | 是 | 图像格式,如YCBCR_422_SP,JPEG。 | 2854| capacity | number | 是 | 同时访问的最大图像数。 | 2855 2856**返回值:** 2857 2858| 类型 | 说明 | 2859| ------------------------------ | --------------------------------------- | 2860| [ImageCreator](#imagecreator9) | 如果操作成功,则返回ImageCreator实例。 | 2861 2862**示例:** 2863 2864```ts 2865let creator : image.ImageCreator = image.createImageCreator(8192, 8, image.ImageFormat.JPEG, 8); 2866``` 2867 2868## ImageCreator<sup>9+</sup> 2869 2870图像创建模块,用于请求图像原生数据区域,并开放给应用编译原生图像数据的能力。 2871在调用以下方法前需要先创建[ImageCreator](#imagecreator9)实例,ImageCreator不支持多线程。 2872 2873### 属性 2874 2875**系统能力:** SystemCapability.Multimedia.Image.ImageCreator 2876 2877| 名称 | 类型 | 可读 | 可写 | 说明 | 2878| -------- | ---------------------------- | ---- | ---- | ------------------ | 2879| capacity | number | 是 | 否 | 同时访问的图像数。 | 2880| format | [ImageFormat](#imageformat9) | 是 | 否 | 图像格式。 | 2881 2882### dequeueImage<sup>9+</sup> 2883 2884dequeueImage(callback: AsyncCallback\<Image>): void 2885 2886从空闲队列中获取buffer图片,用于绘制UI内容,并使用callback返回结果。 2887 2888**系统能力:** SystemCapability.Multimedia.Image.ImageCreator 2889 2890**参数:** 2891 2892| 参数名 | 类型 | 必填 | 说明 | 2893| ------------- | ---------------------------------------| ---- | -------------------- | 2894| callback | AsyncCallback\<[Image](#image9)> | 是 | 回调函数,返回最新图片。 | 2895 2896**示例:** 2897 2898```ts 2899import {BusinessError} from '@ohos.base'; 2900 2901creator.dequeueImage((err : BusinessError, img : image.Image) => { 2902 if (err) { 2903 console.error('dequeueImage failed.'); 2904 } else { 2905 console.info('dequeueImage succeeded.'); 2906 } 2907}); 2908``` 2909 2910### dequeueImage<sup>9+</sup> 2911 2912dequeueImage(): Promise\<Image> 2913 2914从空闲队列中获取buffer图片,用于绘制UI内容,并使用promise返回结果。 2915 2916**系统能力:** SystemCapability.Multimedia.Image.ImageCreator 2917 2918**返回值:** 2919 2920| 类型 | 说明 | 2921| --------------- | ------------- | 2922| Promise\<[Image](#image9)> | Promise实例,用于返回最新图片。 | 2923 2924**示例:** 2925 2926```ts 2927import {BusinessError} from '@ohos.base'; 2928 2929creator.dequeueImage().then((img : image.Image) => { 2930 console.info('dequeueImage succeeded.'); 2931}).catch((error : BusinessError) => { 2932 console.error('dequeueImage failed: ' + error); 2933}) 2934``` 2935 2936### queueImage<sup>9+</sup> 2937 2938queueImage(interface: Image, callback: AsyncCallback\<void>): void 2939 2940将绘制好的图片放入Dirty队列,并使用callback返回结果。 2941 2942**系统能力:** SystemCapability.Multimedia.Image.ImageCreator 2943 2944**参数:** 2945 2946| 参数名 | 类型 | 必填 | 说明 | 2947| ------------- | -------------------------| ---- | -------------------- | 2948| interface | [Image](#image9) | 是 | 绘制好的buffer图像。 | 2949| callback | AsyncCallback\<void> | 是 | 获取回调,失败时返回错误信息。 | 2950 2951**示例:** 2952 2953```ts 2954import {BusinessError} from '@ohos.base'; 2955 2956creator.dequeueImage().then((img : image.Image) => { 2957 //绘制图片 2958 img.getComponent(4).then( (component : image.Component) => { 2959 let bufferArr : Uint8Array = new Uint8Array(component.byteBuffer); 2960 for (let i = 0; i < bufferArr.length; i += 4) { 2961 bufferArr[i] = 0; //B 2962 bufferArr[i + 1] = 0; //G 2963 bufferArr[i + 2] = 255; //R 2964 bufferArr[i + 3] = 255; //A 2965 } 2966 }) 2967 creator.queueImage(img, (err : BusinessError) => { 2968 if (err) { 2969 console.error('queueImage failed: ' + err); 2970 } else { 2971 console.info('queueImage succeeded'); 2972 } 2973 }) 2974}) 2975 2976``` 2977 2978### queueImage<sup>9+</sup> 2979 2980queueImage(interface: Image): Promise\<void> 2981 2982将绘制好的图片放入Dirty队列,并使用promise返回结果。 2983 2984**系统能力:** SystemCapability.Multimedia.Image.ImageCreator 2985 2986**参数:** 2987 2988| 参数名 | 类型 | 必填 | 说明 | 2989| ------------- | --------| ---- | ------------------- | 2990| interface | [Image](#image9) | 是 | 绘制好的buffer图像。 | 2991 2992**返回值:** 2993 2994| 类型 | 说明 | 2995| -------------- | ------------- | 2996| Promise\<void> | 获取回调,失败时返回错误信息。 | 2997 2998**示例:** 2999 3000```ts 3001import {BusinessError} from '@ohos.base'; 3002 3003creator.dequeueImage().then((img : image.Image) => { 3004 //绘制图片 3005 img.getComponent(4).then((component : image.Component) => { 3006 let bufferArr : Uint8Array = new Uint8Array(component.byteBuffer); 3007 for (let i = 0; i < bufferArr.length; i += 4) { 3008 bufferArr[i] = 0; //B 3009 bufferArr[i + 1] = 0; //G 3010 bufferArr[i + 2] = 255; //R 3011 bufferArr[i + 3] = 255; //A 3012 } 3013 }) 3014 creator.queueImage(img).then(() => { 3015 console.info('queueImage succeeded.'); 3016 }).catch((error : BusinessError) => { 3017 console.error('queueImage failed: ' + error); 3018 }) 3019}) 3020 3021``` 3022 3023### on<sup>9+</sup> 3024 3025on(type: 'imageRelease', callback: AsyncCallback\<void>): void 3026 3027监听imageRelease事件,并使用callback返回结果。 3028 3029**系统能力:** SystemCapability.Multimedia.Image.ImageCreator 3030 3031**参数:** 3032 3033| 参数名 | 类型 | 必填 | 说明 | 3034| ------------- | -------------------------| ---- | -------------------- | 3035| type | string | 是 | 监听事件类型,如'imageRelease'。 | 3036| callback | AsyncCallback\<void> | 是 | 获取回调,失败时返回错误信息。 | 3037 3038**示例:** 3039 3040```ts 3041import {BusinessError} from '@ohos.base'; 3042 3043creator.on('imageRelease', (err : BusinessError) => { 3044 if (err) { 3045 console.error('on faild' + err); 3046 } else { 3047 console.info('on succeeded'); 3048 } 3049}) 3050``` 3051 3052### release<sup>9+</sup> 3053 3054release(callback: AsyncCallback\<void>): void 3055 3056释放当前图像,并使用callback返回结果。 3057 3058**系统能力:** SystemCapability.Multimedia.Image.ImageCreator 3059 3060**参数:** 3061 3062| 参数名 | 类型 | 必填 | 说明 | 3063| ------------- | -------------------------| ---- | -------------------- | 3064| callback | AsyncCallback\<void> | 是 | 获取回调,失败时返回错误信息。 | 3065 3066**示例:** 3067 3068```ts 3069import {BusinessError} from '@ohos.base'; 3070 3071creator.release((err : BusinessError) => { 3072 if (err) { 3073 console.error('release failed: ' + err); 3074 } else { 3075 console.info('release succeeded'); 3076 } 3077}); 3078``` 3079### release<sup>9+</sup> 3080 3081release(): Promise\<void> 3082 3083释放当前图像,并使用promise返回结果。 3084 3085**系统能力:** SystemCapability.Multimedia.Image.ImageCreator 3086 3087**返回值:** 3088 3089| 类型 | 说明 | 3090| -------------- | ------------- | 3091| Promise\<void> | 获取回调,失败时返回错误信息。 | 3092 3093**示例:** 3094 3095```ts 3096import {BusinessError} from '@ohos.base'; 3097 3098creator.release().then(() => { 3099 console.info('release succeeded'); 3100}).catch((error : BusinessError) => { 3101 console.error('release failed'); 3102}) 3103``` 3104 3105## Image<sup>9+</sup> 3106 3107提供基本的图像操作,包括获取图像信息、读写图像数据。调用[readNextImage](#readnextimage9)和[readLatestImage](#readlatestimage9)接口时会返回image。 3108 3109### 属性 3110 3111**系统能力:** SystemCapability.Multimedia.Image.Core 3112 3113| 名称 | 类型 | 可读 | 可写 | 说明 | 3114| -------- | ------------------ | ---- | ---- | -------------------------------------------------- | 3115| clipRect | [Region](#region7) | 是 | 是 | 要裁剪的图像区域。 | 3116| size | [Size](#size) | 是 | 否 | 图像大小。 | 3117| format | number | 是 | 否 | 图像格式,参考[PixelMapFormat](#pixelmapformat7)。 | 3118 3119### getComponent<sup>9+</sup> 3120 3121getComponent(componentType: ComponentType, callback: AsyncCallback\<Component>): void 3122 3123根据图像的组件类型从图像中获取组件缓存并使用callback返回结果。 3124 3125**系统能力:** SystemCapability.Multimedia.Image.Core 3126 3127**参数:** 3128 3129| 参数名 | 类型 | 必填 | 说明 | 3130| ------------- | --------------------------------------- | ---- | -------------------- | 3131| componentType | [ComponentType](#componenttype9) | 是 | 图像的组件类型。 | 3132| callback | AsyncCallback<[Component](#component9)> | 是 | 用于返回组件缓冲区。 | 3133 3134**示例:** 3135 3136```ts 3137import {BusinessError} from '@ohos.base'; 3138 3139img.getComponent(4, (err : BusinessError, component : image.Component) => { 3140 if(err) { 3141 console.error('getComponent failed.'); 3142 } else { 3143 console.info('getComponent succeeded.'); 3144 } 3145}) 3146``` 3147 3148### getComponent<sup>9+</sup> 3149 3150getComponent(componentType: ComponentType): Promise\<Component> 3151 3152根据图像的组件类型从图像中获取组件缓存并使用Promise方式返回结果。 3153 3154**系统能力:** SystemCapability.Multimedia.Image.Core 3155 3156**参数:** 3157 3158| 参数名 | 类型 | 必填 | 说明 | 3159| ------------- | -------------------------------- | ---- | ---------------- | 3160| componentType | [ComponentType](#componenttype9) | 是 | 图像的组件类型。 | 3161 3162**返回值:** 3163 3164| 类型 | 说明 | 3165| --------------------------------- | --------------------------------- | 3166| Promise<[Component](#component9)> | Promise实例,用于异步返回组件缓冲区。 | 3167 3168**示例:** 3169 3170```ts 3171import {BusinessError} from '@ohos.base'; 3172 3173img.getComponent(4).then((component : image.Component) => { 3174 console.info('getComponent succeeded.'); 3175}).catch((error : BusinessError) => { 3176 console.error('getComponent failed'); 3177}) 3178``` 3179 3180### release<sup>9+</sup> 3181 3182release(callback: AsyncCallback\<void>): void 3183 3184释放当前图像并使用callback返回结果。 3185 3186在接收另一个图像前必须先释放对应资源。 3187 3188**系统能力:** SystemCapability.Multimedia.Image.Core 3189 3190**参数:** 3191 3192| 参数名 | 类型 | 必填 | 说明 | 3193| -------- | -------------------- | ---- | -------------- | 3194| callback | AsyncCallback\<void> | 是 | 返回操作结果。 | 3195 3196**示例:** 3197 3198```ts 3199import {BusinessError} from '@ohos.base'; 3200 3201img.release((err : BusinessError) =>{ 3202 if (err != undefined) { 3203 console.error('Failed to release the image source instance.'); 3204 } else { 3205 console.info('Succeeded in releasing the image source instance.'); 3206 } 3207}) 3208``` 3209 3210### release<sup>9+</sup> 3211 3212release(): Promise\<void> 3213 3214释放当前图像并使用Promise方式返回结果。 3215 3216在接收另一个图像前必须先释放对应资源。 3217 3218**系统能力:** SystemCapability.Multimedia.Image.Core 3219 3220**返回值:** 3221 3222| 类型 | 说明 | 3223| -------------- | --------------------- | 3224| Promise\<void> | promise返回操作结果。 | 3225 3226**示例:** 3227 3228```ts 3229import {BusinessError} from '@ohos.base'; 3230 3231img.release().then(() =>{ 3232 console.info('release succeeded.'); 3233}).catch((error : BusinessError) => { 3234 console.error('release failed.'); 3235}) 3236``` 3237 3238## PositionArea<sup>7+</sup> 3239 3240表示图片指定区域内的数据。 3241 3242**系统能力:** SystemCapability.Multimedia.Image.Core 3243 3244| 名称 | 类型 | 可读 | 可写 | 说明 | 3245| ------ | ------------------ | ---- | ---- | ------------------------------------------------------------ | 3246| pixels | ArrayBuffer | 是 | 否 | 像素。 | 3247| offset | number | 是 | 否 | 偏移量。 | 3248| stride | number | 是 | 否 | 跨距,内存中每行像素所占的空间。stride >= region.size.width*4。 | 3249| region | [Region](#region7) | 是 | 否 | 区域,按照区域读写。写入的区域宽度加X坐标不能大于原图的宽度,写入的区域高度加Y坐标不能大于原图的高度。 | 3250 3251## ImageInfo 3252 3253表示图片信息。 3254 3255**系统能力:** SystemCapability.Multimedia.Image.Core 3256 3257| 名称 | 类型 | 可读 | 可写 | 说明 | 3258| ---- | ------------- | ---- | ---- | ---------- | 3259| size | [Size](#size) | 是 | 是 | 图片大小。 | 3260| density<sup>9+</sup> | number | 是 | 是 | 像素密度,单位为ppi。 | 3261 3262## Size 3263 3264表示图片尺寸。 3265 3266**系统能力:** SystemCapability.Multimedia.Image.Core 3267 3268| 名称 | 类型 | 可读 | 可写 | 说明 | 3269| ------ | ------ | ---- | ---- | -------------- | 3270| height | number | 是 | 是 | 输出图片的高。 | 3271| width | number | 是 | 是 | 输出图片的宽。 | 3272 3273## PixelMapFormat<sup>7+</sup> 3274 3275枚举,图片像素格式。 3276 3277**系统能力:** SystemCapability.Multimedia.Image.Core 3278 3279| 名称 | 值 | 说明 | 3280| ---------------------- | ------ | ----------------- | 3281| UNKNOWN | 0 | 未知格式。 | 3282| RGB_565 | 2 | 格式为RGB_565 | 3283| RGBA_8888 | 3 | 格式为RGBA_8888 | 3284| BGRA_8888<sup>9+</sup> | 4 | 格式为BGRA_8888 | 3285| RGB_888<sup>9+</sup> | 5 | 格式为RGB_888 | 3286| ALPHA_8<sup>9+</sup> | 6 | 格式为ALPHA_8 | 3287| RGBA_F16<sup>9+</sup> | 7 | 格式为RGBA_F16 | 3288| NV21<sup>9+</sup> | 8 | 格式为NV21 | 3289| NV12<sup>9+</sup> | 9 | 格式为NV12 | 3290 3291## AlphaType<sup>9+</sup> 3292 3293枚举,图像的透明度类型。 3294 3295**系统能力:** SystemCapability.Multimedia.Image.Core 3296 3297| 名称 | 值 | 说明 | 3298| -------- | ------ | ----------------------- | 3299| UNKNOWN | 0 | 未知透明度。 | 3300| OPAQUE | 1 | 没有alpha或图片不透明。 | 3301| PREMUL | 2 | RGB前乘alpha。 | 3302| UNPREMUL | 3 | RGB不前乘alpha。 | 3303 3304## ScaleMode<sup>9+</sup> 3305 3306枚举,图像的缩放模式。 3307 3308**系统能力:** SystemCapability.Multimedia.Image.Core 3309 3310| 名称 | 值 | 说明 | 3311| --------------- | ------ | -------------------------------------------------- | 3312| CENTER_CROP | 1 | 缩放图像以填充目标图像区域并居中裁剪区域外的效果。 | 3313| FIT_TARGET_SIZE | 0 | 图像适合目标尺寸的效果。 | 3314 3315## SourceOptions<sup>9+</sup> 3316 3317ImageSource的初始化选项。 3318 3319**系统能力:** SystemCapability.Multimedia.Image.Core 3320 3321| 名称 | 类型 | 可读 | 可写 | 说明 | 3322| ----------------- | ---------------------------------- | ---- | ---- | ------------------ | 3323| sourceDensity | number | 是 | 是 | ImageSource的密度。| 3324| sourcePixelFormat | [PixelMapFormat](#pixelmapformat7) | 是 | 是 | 图片像素格式。 | 3325| sourceSize | [Size](#size) | 是 | 是 | 图像像素大小。 | 3326 3327 3328## InitializationOptions<sup>8+</sup> 3329 3330PixelMap的初始化选项。 3331 3332**系统能力:** SystemCapability.Multimedia.Image.Core 3333 3334| 名称 | 类型 | 可读 | 可写 | 说明 | 3335| ------------------------ | ---------------------------------- | ---- | ---- | -------------- | 3336| alphaType<sup>9+</sup> | [AlphaType](#alphatype9) | 是 | 是 | 透明度。 | 3337| editable | boolean | 是 | 是 | 是否可编辑。 | 3338| pixelFormat | [PixelMapFormat](#pixelmapformat7) | 是 | 是 | 像素格式。 | 3339| scaleMode<sup>9+</sup> | [ScaleMode](#scalemode9) | 是 | 是 | 缩略值。 | 3340| size | [Size](#size) | 是 | 是 | 创建图片大小。 | 3341 3342## DecodingOptions<sup>7+</sup> 3343 3344图像解码设置选项。 3345 3346**系统能力:** SystemCapability.Multimedia.Image.ImageSource 3347 3348| 名称 | 类型 | 可读 | 可写 | 说明 | 3349| ------------------ | ---------------------------------- | ---- | ---- | ---------------- | 3350| sampleSize | number | 是 | 是 | 缩略图采样大小,当前只能取1。 | 3351| rotate | number | 是 | 是 | 旋转角度。 | 3352| editable | boolean | 是 | 是 | 是否可编辑。当取值为false时,图片不可二次编辑,如crop等操作将失败。 | 3353| desiredSize | [Size](#size) | 是 | 是 | 期望输出大小。 | 3354| desiredRegion | [Region](#region7) | 是 | 是 | 解码区域。 | 3355| desiredPixelFormat | [PixelMapFormat](#pixelmapformat7) | 是 | 是 | 解码的像素格式。 | 3356| index | number | 是 | 是 | 解码图片序号。 | 3357| fitDensity<sup>9+</sup> | number | 是 | 是 | 图像像素密度,单位为ppi。 | 3358 3359## Region<sup>7+</sup> 3360 3361表示区域信息。 3362 3363**系统能力:** SystemCapability.Multimedia.Image.Core 3364 3365| 名称 | 类型 | 可读 | 可写 | 说明 | 3366| ---- | ------------- | ---- | ---- | ------------ | 3367| size | [Size](#size) | 是 | 是 | 区域大小。 | 3368| x | number | 是 | 是 | 区域横坐标。 | 3369| y | number | 是 | 是 | 区域纵坐标。 | 3370 3371## PackingOption 3372 3373表示图片打包选项。 3374 3375**系统能力:** SystemCapability.Multimedia.Image.ImagePacker 3376 3377| 名称 | 类型 | 可读 | 可写 | 说明 | 3378| ------- | ------ | ---- | ---- | --------------------------------------------------- | 3379| format | string | 是 | 是 | 目标格式。</br>当前只支持jpg、webp 和 png。 | 3380| quality | number | 是 | 是 | JPEG编码中设定输出图片质量的参数,取值范围为1-100。 | 3381| bufferSize<sup>9+</sup> | number | 是 | 是 | 接收编码数据的缓冲区大小,单位为Byte。默认为10MB。bufferSize需大于编码后图片大小。 | 3382 3383## GetImagePropertyOptions<sup>7+</sup> 3384 3385表示查询图片属性的索引。 3386 3387**系统能力:** SystemCapability.Multimedia.Image.ImageSource 3388 3389| 名称 | 类型 | 可读 | 可写 | 说明 | 3390| ------------ | ------ | ---- | ---- | ------------ | 3391| index | number | 是 | 是 | 图片序号。 | 3392| defaultValue | string | 是 | 是 | 默认属性值。 | 3393 3394## PropertyKey<sup>7+</sup> 3395 3396枚举,Exif(Exchangeable image file format)图片信息。 3397 3398**系统能力:** SystemCapability.Multimedia.Image.Core 3399 3400| 名称 | 值 | 说明 | 3401| ----------------- | ----------------------- | ------------------------ | 3402| BITS_PER_SAMPLE | "BitsPerSample" | 每个像素比特数。 | 3403| ORIENTATION | "Orientation" | 图片方向。 | 3404| IMAGE_LENGTH | "ImageLength" | 图片长度。 | 3405| IMAGE_WIDTH | "ImageWidth" | 图片宽度。 | 3406| GPS_LATITUDE | "GPSLatitude" | 图片纬度。 | 3407| GPS_LONGITUDE | "GPSLongitude" | 图片经度。 | 3408| GPS_LATITUDE_REF | "GPSLatitudeRef" | 纬度引用,例如N或S。 | 3409| GPS_LONGITUDE_REF | "GPSLongitudeRef" | 经度引用,例如W或E。 | 3410| DATE_TIME_ORIGINAL<sup>9+</sup> | "DateTimeOriginal" | 拍摄时间,例如2022:09:06 15:48:00。当前为只读属性。 | 3411| EXPOSURE_TIME<sup>9+</sup> | "ExposureTime" | 曝光时间,例如1/33 sec。当前为只读属性。 | 3412| SCENE_TYPE<sup>9+</sup> | "SceneType" | 拍摄场景模式,例如人像、风光、运动、夜景等。当前为只读属性。 | 3413| ISO_SPEED_RATINGS<sup>9+</sup> | "ISOSpeedRatings" | ISO感光度,例如400。当前为只读属性。 | 3414| F_NUMBER<sup>9+</sup> | "FNumber" | 光圈值,例如f/1.8。当前为只读属性。 | 3415| DATE_TIME<sup>10+</sup> | "DateTime" | 日期时间,当前为只读属性。 | 3416| GPS_TIME_STAMP<sup>10+</sup> | "GPSTimeStamp" | GPS时间戳,当前为只读属性。 | 3417| GPS_DATE_STAMP<sup>10+</sup> | "GPSDateStamp" | GPS日期戳,当前为只读属性。 | 3418| IMAGE_DESCRIPTION<sup>10+</sup> | "ImageDescription" | 图像信息描述,当前为只读属性。 | 3419| MAKE<sup>10+</sup> | "Make" | 生产商,当前为只读属性。 | 3420| MODEL<sup>10+</sup> | "Model" | 设备型号,当前为只读属性。 | 3421| PHOTO_MODE<sup>10+</sup> | "PhotoMode " | 拍照模式,当前为只读属性。 | 3422| SENSITIVITY_TYPE<sup>10+</sup> | "SensitivityType" | 灵敏度类型,当前为只读属性。 | 3423| STANDARD_OUTPUT_SENSITIVITY<sup>10+</sup> | "StandardOutputSensitivity" | 标准输出灵敏度,当前为只读属性。 | 3424| RECOMMENDED_EXPOSURE_INDEX<sup>10+</sup> | "RecommendedExposureIndex" | 推荐曝光指数,当前为只读属性。 | 3425| ISO_SPEED<sup>10+</sup> | "ISOSpeedRatings" | ISO速度等级,当前为只读属性。 | 3426| APERTURE_VALUE<sup>10+</sup> | "ApertureValue" | 光圈值,当前为只读属性。 | 3427| EXPOSURE_BIAS_VALUE<sup>10+</sup> | "ExposureBiasValue" | 曝光偏差值,当前为只读属性。 | 3428| METERING_MODE<sup>10+</sup> | "MeteringMode" | 测光模式,当前为只读属性。 | 3429| LIGHT_SOURCE<sup>10+</sup> | "LightSource" | 光源,当前为只读属性。 | 3430| FLASH <sup>10+</sup> | "Flash" | 闪光灯,记录闪光灯状态,当前为只读属性。 | 3431| FOCAL_LENGTH <sup>10+</sup> | "FocalLength" | 焦距,当前为只读属性。 | 3432| USER_COMMENT <sup>10+</sup> | "UserComment" | 用户注释,当前为只读属性。 | 3433| PIXEL_X_DIMENSION <sup>10+</sup> | "PixelXDimension" | 像素X尺寸,当前为只读属性。 | 3434| PIXEL_Y_DIMENSION<sup>10+</sup> | "PixelYDimension" | 像素Y尺寸,当前为只读属性。 | 3435| WHITE_BALANCE <sup>10+</sup> | "WhiteBalance" | 白平衡,当前为只读属性。 | 3436| FOCAL_LENGTH_IN_35_MM_FILM <sup>10+</sup> | "FocalLengthIn35mmFilm" | 焦距35毫米胶片,当前为只读属性。 | 3437| CAPTURE_MODE <sup>10+</sup> | "HwMnoteCaptureMode" | 捕获模式,当前为只读属性。 | 3438| PHYSICAL_APERTURE <sup>10+</sup> | "HwMnotePhysicalAperture" | 物理孔径,光圈大小,当前为只读属性。 | 3439 3440## ImageFormat<sup>9+</sup> 3441 3442枚举,图片格式。 3443 3444**系统能力:** SystemCapability.Multimedia.Image.Core 3445 3446| 名称 | 值 | 说明 | 3447| ------------ | ------ | -------------------- | 3448| YCBCR_422_SP | 1000 | YCBCR422半平面格式。 | 3449| JPEG | 2000 | JPEG编码格式。 | 3450 3451## ComponentType<sup>9+</sup> 3452 3453枚举,图像的组件类型。 3454 3455**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver 3456 3457| 名称 | 值 | 说明 | 3458| ----- | ------ | ----------- | 3459| YUV_Y | 1 | 亮度信息。 | 3460| YUV_U | 2 | 色度信息。 | 3461| YUV_V | 3 | 色度信息。 | 3462| JPEG | 4 | JPEG 类型。 | 3463 3464## Component<sup>9+</sup> 3465 3466描述图像颜色分量。 3467 3468**系统能力:** SystemCapability.Multimedia.Image.Core 3469 3470| 名称 | 类型 | 可读 | 可写 | 说明 | 3471| ------------- | -------------------------------- | ---- | ---- | ------------ | 3472| componentType | [ComponentType](#componenttype9) | 是 | 否 | 组件类型。 | 3473| rowStride | number | 是 | 否 | 行距。 | 3474| pixelStride | number | 是 | 否 | 像素间距。 | 3475| byteBuffer | ArrayBuffer | 是 | 否 | 组件缓冲区。 | 3476 3477## 补充说明 3478### SVG标签说明 3479 3480从API version 10开始支持SVG标签,使用版本为(SVG) 1.1,当前支持的标签列表有: 3481- a 3482- circla 3483- clipPath 3484- defs 3485- ellipse 3486- feBlend 3487- feColorMatrix 3488- feComposite 3489- feDiffuseLighting 3490- feDisplacementMap 3491- feDistantLight 3492- feFlood 3493- feGaussianBlur 3494- feImage 3495- feMorphology 3496- feOffset 3497- fePointLight 3498- feSpecularLighting 3499- feSpotLight 3500- feTurbulence 3501- filter 3502- g 3503- image 3504- line 3505- linearGradient 3506- mask 3507- path 3508- pattern 3509- polygon 3510- polyline 3511- radialGradient 3512- rect 3513- stop 3514- svg 3515- text 3516- textPath 3517- tspan 3518- use 3519