1# @ohos.multimedia.image (图片处理)
2
3本模块提供图片处理效果,包括通过属性创建PixelMap、读取图像像素数据、读取区域内的图片数据等。
4
5> **说明:**
6>
7> - 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8>
9> - 从API version 12开始,本模块接口支持在ArkTS卡片中使用。
10
11## 导入模块
12
13```ts
14import { image } from '@kit.ImageKit';
15```
16
17## image.createPicture<sup>13+</sup>
18
19createPicture(mainPixelmap : PixelMap): Picture
20
21通过主图的pixelmap创建一个Picture对象。
22
23**系统能力:** SystemCapability.Multimedia.Image.Core
24
25**参数:**
26
27| 参数名       | 类型                | 必填 | 说明             |
28| ------------ | ------------------- | ---- | ---------------- |
29| mainPixelmap | [PixelMap](#pixelmap7) | 是   | 主图的pixelmap。 |
30
31**返回值:**
32
33| 类型               | 说明              |
34| ------------------ | ----------------- |
35| [Picture](#picture13) | 返回Picture对象。 |
36
37**错误码:**
38
39以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
40
41| 错误码ID | 错误信息                                                     |
42| -------- | ------------------------------------------------------------ |
43| 401      | Parameter error.Possible causes:1.Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
44
45**示例:**
46
47```ts
48import { image } from '@kit.ImageKit';
49
50async function CreatePicture() {
51  const context = getContext();
52  const resourceMgr = context.resourceManager;
53  const rawFile = await resourceMgr.getRawFileContent("test.jpg");
54  let ops: image.SourceOptions = {
55    sourceDensity: 98,
56  }
57  let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops);
58  let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap();
59  let pictureObj: image.Picture = image.createPicture(commodityPixelMap);
60  if (pictureObj != null) {
61    console.info('Create picture succeeded');
62  } else {
63    console.info('Create picture failed');
64  }
65}
66```
67
68## image.createPictureFromParcel<sup>13+</sup>
69
70createPictureFromParcel(sequence: rpc.MessageSequence): Picture
71
72从MessageSequence中获取Picture。
73
74**系统能力:** SystemCapability.Multimedia.Image.Core
75
76**参数:**
77
78| 参数名   | 类型                                                                | 必填 | 说明                                 |
79| -------- | ------------------------------------------------------------------- | ---- | ------------------------------------ |
80| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | 是   | 保存有Picture信息的MessageSequence。 |
81
82**返回值:**
83
84| 类型               | 说明              |
85| ------------------ | ----------------- |
86| [Picture](#picture13) | 返回Picture对象。 |
87
88**错误码:**
89
90以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
91
92| 错误码ID | 错误信息                                                     |
93| -------- | ------------------------------------------------------------ |
94| 401      | Parameter error.Possible causes:1.Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
95| 62980097 | IPC error.                                                   |
96
97**示例:**
98
99```ts
100import { rpc } from '@kit.IPCKit';
101import { BusinessError } from '@kit.BasicServicesKit';
102import { image } from '@kit.ImageKit';
103
104class MySequence implements rpc.Parcelable {
105  picture: image.Picture | null = null;
106  constructor(conPicture: image.Picture) {
107    this.picture = conPicture;
108  }
109  marshalling(messageSequence: rpc.MessageSequence) {
110    if(this.picture != null) {
111      this.picture.marshalling(messageSequence);
112      console.info('Marshalling success !');
113      return true;
114    } else {
115      console.info('Marshalling failed !');
116      return false;
117    }
118  }
119  unmarshalling(messageSequence : rpc.MessageSequence) {
120    this.picture = image.createPictureFromParcel(messageSequence);
121    this.picture.getMainPixelmap().getImageInfo().then((imageInfo : image.ImageInfo) => {
122      console.info('Unmarshalling to get mainPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width);
123    }).catch((error: BusinessError) => {
124      console.error('Unmarshalling failed error.code: ${error.code} ,error.message: ${error.message}');
125    });
126    return true;
127  }
128}
129
130async function Marshalling_UnMarshalling() {
131  const context = getContext();
132  const resourceMgr = context.resourceManager;
133  const rawFile = await resourceMgr.getRawFileContent("test.jpg");
134  let ops: image.SourceOptions = {
135    sourceDensity: 98,
136  }
137  let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops);
138  let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap();
139  let pictureObj: image.Picture = image.createPicture(commodityPixelMap);
140  if (pictureObj != null) {
141    let parcelable: MySequence = new MySequence(pictureObj);
142    let data: rpc.MessageSequence = rpc.MessageSequence.create();
143    // marshalling
144    data.writeParcelable(parcelable);
145    let ret: MySequence = new MySequence(pictureObj);
146    // unmarshalling
147    data.readParcelable(ret);
148  } else {
149    console.info('PictureObj is null');
150  }
151}
152```
153
154## image.createPixelMap<sup>8+</sup>
155
156createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<PixelMap>
157
158通过属性创建PixelMap,默认采用BGRA_8888格式处理数据,通过Promise返回结果。
159
160**系统能力:** SystemCapability.Multimedia.Image.Core
161
162**参数:**
163
164| 参数名  | 类型                                             | 必填 | 说明                                                             |
165| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- |
166| colors  | ArrayBuffer                                      | 是   | 图像像素数据的缓冲区,用于初始化PixelMap的像素。初始化前,缓冲区中的像素格式需要由[InitializationOptions](#initializationoptions8).srcPixelFormat指定。 |
167| options | [InitializationOptions](#initializationoptions8) | 是   | 创建像素的属性,包括透明度,尺寸,缩略值,像素格式和是否可编辑。 |
168
169**返回值:**
170
171| 类型                             | 说明                                                                    |
172| -------------------------------- | ----------------------------------------------------------------------- |
173| Promise\<[PixelMap](#pixelmap7)> | Promise对象,返回PixelMap。<br>当创建的pixelMap大小超过原图大小时,返回原图pixelMap大小。|
174
175**示例:**
176
177```ts
178import { BusinessError } from '@kit.BasicServicesKit';
179
180async function Demo() {
181  const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
182  let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
183  image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => {
184    console.info('Succeeded in creating pixelmap.');
185  }).catch((error: BusinessError) => {
186    console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`);
187  })
188}
189```
190
191## image.createPixelMap<sup>8+</sup>
192
193createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: AsyncCallback\<PixelMap>): void
194
195通过属性创建PixelMap,默认采用BGRA_8888格式处理数据,通过回调函数返回结果。
196
197**系统能力:** SystemCapability.Multimedia.Image.Core
198
199**参数:**
200
201| 参数名   | 类型                                             | 必填 | 说明                       |
202| -------- | ------------------------------------------------ | ---- | -------------------------- |
203| colors   | ArrayBuffer                                      | 是   | 图像像素数据的缓冲区,用于初始化PixelMap的像素。初始化前,缓冲区中的像素格式需要由[InitializationOptions](#initializationoptions8).srcPixelFormat指定。 |
204| options  | [InitializationOptions](#initializationoptions8) | 是   | 创建像素的属性,包括透明度,尺寸,缩略值,像素格式和是否可编辑。 |
205| callback | AsyncCallback\<[PixelMap](#pixelmap7)>           | 是   | 回调函数,当创建PixelMap成功,err为undefined,data为获取到的PixelMap对象;否则为错误对象。 |
206
207**示例:**
208
209```ts
210import { BusinessError } from '@kit.BasicServicesKit';
211
212async function Demo() {
213  const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
214  let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
215  image.createPixelMap(color, opts, (error: BusinessError, pixelMap: image.PixelMap) => {
216    if(error) {
217      console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`);
218      return;
219    } else {
220      console.info('Succeeded in creating pixelmap.');
221    }
222  })
223}
224```
225
226## image.createPixelMapFromParcel<sup>11+</sup>
227
228createPixelMapFromParcel(sequence: rpc.MessageSequence): PixelMap
229
230从MessageSequence中获取PixelMap。
231
232**系统能力:** SystemCapability.Multimedia.Image.Core
233
234**参数:**
235
236| 参数名                 | 类型                                                  | 必填 | 说明                                     |
237| ---------------------- | ----------------------------------------------------- | ---- | ---------------------------------------- |
238| sequence               | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | 是   | 保存有PixelMap信息的MessageSequence。      |
239
240**返回值:**
241
242| 类型                             | 说明                  |
243| -------------------------------- | --------------------- |
244| [PixelMap](#pixelmap7) | 成功同步返回PixelMap对象,失败抛出异常。 |
245
246**错误码:**
247
248以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
249
250| 错误码ID | 错误信息 |
251| ------- | --------------------------------------------|
252| 62980096 | Operation failed|
253| 62980097 | IPC error.|
254| 62980115 | Invalid input parameter|
255| 62980105 | Failed to get the data|
256| 62980177 | Abnormal API environment|
257| 62980178 | Failed to create the PixelMap|
258| 62980179 | Abnormal buffer size|
259| 62980180 | FD mapping failed|
260| 62980246 | Failed to read the PixelMap|
261
262**示例:**
263
264```ts
265import { image } from '@kit.ImageKit';
266import { rpc } from '@kit.IPCKit';
267import { BusinessError } from '@kit.BasicServicesKit';
268
269class MySequence implements rpc.Parcelable {
270  pixel_map: image.PixelMap;
271  constructor(conPixelmap: image.PixelMap) {
272    this.pixel_map = conPixelmap;
273  }
274  marshalling(messageSequence: rpc.MessageSequence) {
275    this.pixel_map.marshalling(messageSequence);
276    return true;
277  }
278  unmarshalling(messageSequence: rpc.MessageSequence) {
279    try {
280      this.pixel_map = image.createPixelMapFromParcel(messageSequence);
281    } catch(e) {
282      let error = e as BusinessError;
283      console.error(`createPixelMapFromParcel error. code is ${error.code}, message is ${error.message}`);
284      return false;
285    }
286    return true;
287  }
288}
289async function Demo() {
290  const color: ArrayBuffer = new ArrayBuffer(96);
291  let bufferArr: Uint8Array = new Uint8Array(color);
292  for (let i = 0; i < bufferArr.length; i++) {
293    bufferArr[i] = 0x80;
294  }
295  let opts: image.InitializationOptions = {
296    editable: true,
297    pixelFormat: 4,
298    size: { height: 4, width: 6 },
299    alphaType: 3
300  }
301  let pixelMap: image.PixelMap | undefined = undefined;
302  image.createPixelMap(color, opts).then((srcPixelMap: image.PixelMap) => {
303    pixelMap = srcPixelMap;
304  })
305  if (pixelMap != undefined) {
306    // 序列化
307    let parcelable: MySequence = new MySequence(pixelMap);
308    let data: rpc.MessageSequence = rpc.MessageSequence.create();
309    data.writeParcelable(parcelable);
310
311    // 反序列化 rpc获取到data
312    let ret: MySequence = new MySequence(pixelMap);
313    data.readParcelable(ret);
314
315    // 获取到pixelmap
316    let unmarshPixelmap = ret.pixel_map;
317  }
318}
319```
320
321## image.createPixelMapFromSurface<sup>11+</sup>
322
323createPixelMapFromSurface(surfaceId: string, region: Region): Promise\<PixelMap>
324
325根据Surface id和区域信息,创建一个PixelMap对象。该区域的大小由[Region](#region8).size指定。使用Promise形式返回。
326
327> **说明:**
328> 1. [Region](#region8).size的宽高需和[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)组件的宽高保持一致。
329> 2. 当开发设备为折叠屏,折叠状态切换时,需自行调整[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)组件的宽高。
330
331**系统能力:** SystemCapability.Multimedia.Image.Core
332
333**参数:**
334
335| 参数名                 | 类型                 | 必填 | 说明                                     |
336| ---------------------- | -------------       | ---- | ---------------------------------------- |
337| surfaceId              | string              | 是   | 从[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)组件获取的surfaceId。|
338| region                 | [Region](#region8)  | 是   | 区域信息。 |
339
340**返回值:**
341| 类型                             | 说明                  |
342| -------------------------------- | --------------------- |
343| Promise\<[PixelMap](#pixelmap7)> | Promise对象,返回PixelMap。 |
344
345**错误码:**
346
347以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
348
349| 错误码ID | 错误信息 |
350| ------- | --------------------------------------------|
351| 62980115 | If the image parameter invalid.|
352| 62980105 | Failed to get the data|
353| 62980178 | Failed to create the PixelMap|
354
355**示例:**
356
357```ts
358import { BusinessError } from '@kit.BasicServicesKit';
359
360async function Demo(surfaceId: string) {
361  let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } };
362  image.createPixelMapFromSurface(surfaceId, region).then(() => {
363    console.info('Succeeded in creating pixelmap from Surface');
364  }).catch((error: BusinessError) => {
365    console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`);
366  });
367} 
368```
369
370## image.createPixelMapFromSurfaceSync<sup>12+</sup>
371
372createPixelMapFromSurfaceSync(surfaceId: string, region: Region): PixelMap
373
374以同步方式,根据Surface id和区域信息,创建一个PixelMap对象。该区域的大小由[Region](#region8).size指定。
375
376> **说明:**
377> 1. [Region](#region8).size的宽高需和[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)组件的宽高保持一致。
378> 2. 当开发设备为折叠屏,折叠状态切换时,需自行调整[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)组件的宽高。
379
380**系统能力:** SystemCapability.Multimedia.Image.Core
381
382**参数:**
383
384| 参数名                 | 类型                 | 必填 | 说明                                     |
385| ---------------------- | -------------       | ---- | ---------------------------------------- |
386| surfaceId              | string              | 是   | 从[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)组件获取的surfaceId。|
387| region                 | [Region](#region8)  | 是   | 区域信息。 |
388
389**返回值:**
390| 类型                             | 说明                  |
391| -------------------------------- | --------------------- |
392| [PixelMap](#pixelmap7) | 成功同步返回PixelMap对象,失败抛出异常。 |
393
394**错误码:**
395
396以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
397
398| 错误码ID | 错误信息 |
399| ------- | --------------------------------------------|
400|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed|
401| 62980105 | Failed to get the data|
402| 62980178 | Failed to create the PixelMap|
403
404**示例:**
405
406```ts
407import { BusinessError } from '@kit.BasicServicesKit';
408
409async function Demo(surfaceId: string) {
410  let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } };
411  let pixelMap : image.PixelMap = image.createPixelMapFromSurfaceSync(surfaceId, region);
412  return pixelMap;
413}
414```
415
416## image.createPixelMapSync<sup>12+</sup>
417
418createPixelMapSync(colors: ArrayBuffer, options: InitializationOptions): PixelMap
419
420通过属性创建PixelMap,同步返回PixelMap结果。
421
422**系统能力:** SystemCapability.Multimedia.Image.Core
423
424**参数:**
425
426| 参数名  | 类型                                             | 必填 | 说明                                                             |
427| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- |
428| colors  | ArrayBuffer                                      | 是   | 图像像素数据的缓冲区,用于初始化PixelMap的像素。初始化前,缓冲区中的像素格式需要由[InitializationOptions](#initializationoptions8).srcPixelFormat指定。 |
429| options | [InitializationOptions](#initializationoptions8) | 是   | 创建像素的属性,包括透明度,尺寸,缩略值,像素格式和是否可编辑。 |
430
431**返回值:**
432| 类型                             | 说明                  |
433| -------------------------------- | --------------------- |
434| [PixelMap](#pixelmap7) | 成功同步返回PixelMap对象,失败抛出异常。 |
435
436**错误码:**
437
438以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
439
440| 错误码ID | 错误信息 |
441| ------- | --------------------------------------------|
442|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed|
443
444**示例:**
445
446```ts
447import { BusinessError } from '@kit.BasicServicesKit';
448
449async function Demo() {
450  const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
451  let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
452  let pixelMap : image.PixelMap = image.createPixelMapSync(color, opts);
453  return pixelMap;
454}
455```
456
457## image.createPixelMapSync<sup>12+</sup>
458
459createPixelMapSync(options: InitializationOptions): PixelMap
460
461通过属性创建PixelMap,同步返回PixelMap结果。
462
463**系统能力:** SystemCapability.Multimedia.Image.Core
464
465**参数:**
466
467| 参数名  | 类型                                             | 必填 | 说明                                                             |
468| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- |
469| options | [InitializationOptions](#initializationoptions8) | 是   | 创建像素的属性,包括透明度,尺寸,缩略值,像素格式和是否可编辑。 |
470
471**返回值:**
472| 类型                             | 说明                  |
473| -------------------------------- | --------------------- |
474| [PixelMap](#pixelmap7) | 成功同步返回PixelMap对象,失败抛出异常。 |
475
476**错误码:**
477
478以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
479
480| 错误码ID | 错误信息 |
481| ------- | --------------------------------------------|
482|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed|
483
484**示例:**
485
486```ts
487import { BusinessError } from '@kit.BasicServicesKit';
488
489async function Demo() {
490  let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
491  let pixelMap : image.PixelMap = image.createPixelMapSync(opts);
492  return pixelMap;
493}
494```
495
496## image.createPremultipliedPixelMap<sup>12+</sup>
497
498createPremultipliedPixelMap(src: PixelMap, dst: PixelMap, callback: AsyncCallback\<void>): void
499
500将PixelMap的透明通道非预乘模式转变为预乘模式,转换后的数据存入目标PixelMap,通过回调函数返回结果。
501
502**系统能力:** SystemCapability.Multimedia.Image.Core
503
504**参数:**
505
506| 参数名   | 类型                                             | 必填 | 说明                       |
507| -------- | ------------------------------------------------ | ---- | -------------------------- |
508| src | [PixelMap](#pixelmap7) | 是   | 源PixelMap对象。 |
509| dst | [PixelMap](#pixelmap7) | 是   | 目标PixelMap对象。 |
510|callback | AsyncCallback\<void> | 是   | 回调函数,当创建PixelMap成功,err为undefined,否则为错误对象。 |
511
512**错误码:**
513
514以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
515
516| 错误码ID | 错误信息 |
517| ------- | --------------------------------------------|
518|  401          | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed|
519|  62980103     | The image data is not supported |
520|  62980246      | Failed to read the pixelMap |
521|  62980248     | Pixelmap not allow modify |
522
523**示例:**
524
525```ts
526import { BusinessError } from '@kit.BasicServicesKit';
527
528async function Demo() {
529  const color: ArrayBuffer = new ArrayBuffer(16); // 16为需要创建的像素buffer大小,取值为:height * width *4
530  let bufferArr = new Uint8Array(color);
531  for (let i = 0; i < bufferArr.length; i += 4) {
532    bufferArr[i] = 255;
533    bufferArr[i+1] = 255;
534    bufferArr[i+2] = 122;
535    bufferArr[i+3] = 122;
536  }
537  let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 2, width: 2 } , alphaType: 3}
538  let srcPixelmap = image.createPixelMapSync(color, optsForUnpre);
539  let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 2, width: 2 } , alphaType: 2}
540  let dstPixelMap = image.createPixelMapSync(optsForPre);
541  image.createPremultipliedPixelMap(srcPixelmap, dstPixelMap, (error: BusinessError) => {
542    if(error) {
543      console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`);
544      return;
545    } else {
546      console.info('Succeeded in converting pixelmap.');
547    }
548  })
549}
550```
551
552## image.createPremultipliedPixelMap<sup>12+</sup>
553
554createPremultipliedPixelMap(src: PixelMap, dst: PixelMap): Promise\<void>
555
556将PixelMap数据按照透明度非预乘格式转为预乘格式,转换后的数据存入另一个PixelMap,通过Promise返回结果。
557
558**系统能力:** SystemCapability.Multimedia.Image.Core
559
560**参数:**
561
562| 参数名   | 类型                                             | 必填 | 说明                       |
563| -------- | ------------------------------------------------ | ---- | -------------------------- |
564| src | [PixelMap](#pixelmap7) | 是   | 源PixelMap对象 |
565| dst | [PixelMap](#pixelmap7) | 是   | 目标PixelMap对象 |
566
567**返回值:**
568
569| 类型                             | 说明                                                                    |
570| -------------------------------- | ----------------------------------------------------------------------- |
571| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
572
573**错误码:**
574
575以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
576
577| 错误码ID | 错误信息 |
578| ------- | --------------------------------------------|
579|  401          | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed|
580|  62980103     | The image data is not supported |
581|  62980246      | Failed to read the pixelMap |
582|  62980248     | Pixelmap not allow modify |
583
584**示例:**
585
586```ts
587import { BusinessError } from '@kit.BasicServicesKit';
588
589async function Demo() {
590  const color: ArrayBuffer = new ArrayBuffer(16); // 16为需要创建的像素buffer大小,取值为:height * width *4
591  let bufferArr = new Uint8Array(color);
592  for (let i = 0; i < bufferArr.length; i += 4) {
593    bufferArr[i] = 255;
594    bufferArr[i+1] = 255;
595    bufferArr[i+2] = 122;
596    bufferArr[i+3] = 122;
597  }
598  let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 2, width: 2 } , alphaType: 3}
599  let srcPixelmap = image.createPixelMapSync(color, optsForUnpre);
600  let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 2, width: 2 } , alphaType: 2}
601  let dstPixelMap = image.createPixelMapSync(optsForPre);
602  image.createPremultipliedPixelMap(srcPixelmap, dstPixelMap).then(() => {
603    console.info('Succeeded in converting pixelmap.');
604  }).catch((error: BusinessError) => {
605    console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`);
606  })
607}
608```
609
610## image.createUnpremultipliedPixelMap<sup>12+</sup>
611
612createUnpremultipliedPixelMap(src: PixelMap, dst: PixelMap, callback: AsyncCallback\<void>): void
613
614将PixelMap的透明通道预乘模式转变为非预乘模式,转换后的数据存入目标PixelMap,通过回调函数返回结果。
615
616**系统能力:** SystemCapability.Multimedia.Image.Core
617
618**参数:**
619
620| 参数名   | 类型                                             | 必填 | 说明                       |
621| -------- | ------------------------------------------------ | ---- | -------------------------- |
622| src | [PixelMap](#pixelmap7) | 是   | 源PixelMap对象。 |
623| dst | [PixelMap](#pixelmap7) | 是   | 目标PixelMap对象。|
624|callback | AsyncCallback\<void> | 是   | 回调函数,当创建PixelMap成功,err为undefined,否则为错误对象。|
625
626**错误码:**
627
628以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
629
630| 错误码ID | 错误信息 |
631| ------- | --------------------------------------------|
632|  401          | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed|
633|  62980103     | The image data is not supported |
634|  62980246      | Failed to read the pixelMap |
635|  62980248     | Pixelmap not allow modify |
636
637**示例:**
638
639```ts
640import { BusinessError } from '@kit.BasicServicesKit';
641
642async function Demo() {
643  const color: ArrayBuffer = new ArrayBuffer(16); // 16为需要创建的像素buffer大小,取值为:height * width *4
644  let bufferArr = new Uint8Array(color);
645  for (let i = 0; i < bufferArr.length; i += 4) {
646    bufferArr[i] = 255;
647    bufferArr[i+1] = 255;
648    bufferArr[i+2] = 122;
649    bufferArr[i+3] = 122;
650  }
651  let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 2, width: 2 } , alphaType: 2}
652  let srcPixelmap = image.createPixelMapSync(color, optsForPre);
653  let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 2, width: 2 } , alphaType: 3}
654  let dstPixelMap = image.createPixelMapSync(optsForUnpre);
655  image.createUnpremultipliedPixelMap(srcPixelmap, dstPixelMap, (error: BusinessError) => {
656    if(error) {
657      console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`);
658      return;
659    } else {
660      console.info('Succeeded in converting pixelmap.');
661    }
662  })
663}
664```
665
666## image.createUnpremultipliedPixelMap<sup>12+</sup>
667
668createUnpremultipliedPixelMap(src: PixelMap, dst: PixelMap): Promise\<void>
669
670将PixelMap的透明通道预乘模式转变为非预乘模式,转换后的数据存入目标PixelMap,通过Promise返回结果。
671
672**系统能力:** SystemCapability.Multimedia.Image.Core
673
674**参数:**
675
676| 参数名  | 类型                                             | 必填 | 说明                                                             |
677| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- |
678| src | [PixelMap](#pixelmap7) | 是   | 源PixelMap对象。 |
679| dst | [PixelMap](#pixelmap7) | 是   | 目标PixelMap对象。 |
680
681**返回值:**
682
683| 类型                             | 说明                                                                    |
684| -------------------------------- | ----------------------------------------------------------------------- |
685| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
686
687**错误码:**
688
689以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
690
691| 错误码ID | 错误信息 |
692| ------- | --------------------------------------------|
693|  401          | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed|
694|  62980103    | The image data is not supported |
695|  62980246    | Failed to read the pixelMap. |
696|  62980248    | Pixelmap not allow modify. |
697
698**示例:**
699
700```ts
701import { BusinessError } from '@kit.BasicServicesKit';
702
703async function Demo() {
704  const color: ArrayBuffer = new ArrayBuffer(16); // 16为需要创建的像素buffer大小,取值为:height * width *4
705  let bufferArr = new Uint8Array(color);
706  for (let i = 0; i < bufferArr.length; i += 4) {
707    bufferArr[i] = 255;
708    bufferArr[i+1] = 255;
709    bufferArr[i+2] = 122;
710    bufferArr[i+3] = 122;
711  }
712  let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 2, width: 2 } , alphaType: 2}
713  let srcPixelmap = image.createPixelMapSync(color, optsForPre);
714  let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 2, width: 2 } , alphaType: 3}
715  let dstPixelMap = image.createPixelMapSync(optsForUnpre);
716  image.createUnpremultipliedPixelMap(srcPixelmap, dstPixelMap).then(() => {
717    console.info('Succeeded in converting pixelmap.');
718  }).catch((error: BusinessError) => {
719    console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`);
720  })
721}
722```
723
724
725## Picture<sup>13+</sup>
726
727一些包含特殊信息的图片可以解码为多图对象,多图对象一般包含主图、辅助图和元数据。其中主图包含图像的大部分信息,主要用于显示图像内容;辅助图用于存储与主图相关但不同的数据,展示图像更丰富的信息;元数据一般用来存储关于图像文件的信息。多图对象类用于读取或写入多图对象。在调用Picture的方法前,需要先通过[createPicture](#imagecreatepicture13)创建一个Picture实例。
728
729### 属性
730
731**系统能力:** SystemCapability.Multimedia.Image.Core
732
733### getMainPixelmap<sup>13+</sup>
734
735getMainPixelmap(): PixelMap
736
737获取主图的pixelmap。
738
739**系统能力:** SystemCapability.Multimedia.Image.Core
740
741**返回值:**
742
743| 类型                | 说明                   |
744| ------------------- | ---------------------- |
745| [PixelMap](#pixelmap7) | 同步返回PixelMap对象。 |
746
747**示例:**
748
749```ts
750import { BusinessError } from '@kit.BasicServicesKit';
751import { image } from '@kit.ImageKit';
752
753async function GetMainPixelmap() {
754  let funcName = "getMainPixelmap";
755  if (pictureObj != null) {
756    let mainPixelmap: image.PixelMap = pictureObj.getMainPixelmap();
757    if (mainPixelmap != null) {
758      mainPixelmap.getImageInfo().then((imageInfo: image.ImageInfo) => {
759        if (imageInfo != null) {
760          console.info('GetMainPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width);
761        }
762      }).catch((error: BusinessError) => {
763        console.error(funcName, 'Failed error.code: ${error.code} ,error.message: ${error.message}');
764      });
765    }
766  } else {
767    console.info('PictureObj is null');
768  }
769}
770```
771
772### getHdrComposedPixelmap<sup>13+</sup>
773
774getHdrComposedPixelmap(): Promise\<PixelMap>
775
776合成hdr图并获取hdr图的pixelmap,使用Promise形式返回结果。
777
778**系统能力:** SystemCapability.Multimedia.Image.Core
779
780**返回值:**
781
782| 类型                          | 说明                        |
783| ----------------------------- | --------------------------- |
784| Promise\<[PixelMap](#pixelmap7)> | Promise对象,返回PixelMap。 |
785
786**错误码:**
787
788以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
789
790| 错误码ID | 错误信息               |
791| -------- | ---------------------- |
792| 7600901  | Unknown error.         |
793| 7600201  | Unsupported operation. |
794
795**示例:**
796
797```ts
798import { BusinessError } from '@kit.BasicServicesKit';
799import { image } from '@kit.ImageKit';
800
801async function GetHdrComposedPixelmap() {
802  let funcName = "getHdrComposedPixelmap";
803  if (pictureObj != null) { //图片包含Hdr图
804    let hdrComposedPixelmap: image.PixelMap = await pictureObj.getHdrComposedPixelmap();
805    if (hdrComposedPixelmap != null) {
806      hdrComposedPixelmap.getImageInfo().then((imageInfo: image.ImageInfo) => {
807        if (imageInfo != null) {
808          console.info('GetHdrComposedPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width);
809        }
810      }).catch((error: BusinessError) => {
811        console.error(funcName, 'Failed error.code: ${error.code} ,error.message: ${error.message}');
812      });
813    }
814  } else {
815    console.info('PictureObj is null');
816  }
817}
818```
819
820### getGainmapPixelmap<sup>13+</sup>
821
822getGainmapPixelmap(): PixelMap | null
823
824获取增益图的pixelmap。
825
826**系统能力:** SystemCapability.Multimedia.Image.Core
827
828**返回值:**
829
830| 类型                      | 说明                                   |
831| ------------------------- | -------------------------------------- |
832| [PixelMap](#pixelmap7) \| null | 返回Pixelmap对象,如果没有则返回null。 |
833
834**示例:**
835
836```ts
837import { BusinessError } from '@kit.BasicServicesKit';
838import { image } from '@kit.ImageKit';
839
840async function GetGainmapPixelmap() {
841  let funcName = "getGainmapPixelmap";
842  if (pictureObj != null) { //图片包含增益图
843    let gainPixelmap: image.PixelMap | null = pictureObj.getGainmapPixelmap();
844    if (gainPixelmap != null) {
845      gainPixelmap.getImageInfo().then((imageInfo: image.ImageInfo) => {
846        if (imageInfo != null) {
847          console.info('GetGainmapPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width);
848        } else {
849          console.info('GainPixelmap is null');
850        }
851      }).catch((error: BusinessError) => {
852        console.error(funcName, 'Failed error.code: ${error.code} ,error.message: ${error.message}');
853      });
854    } else {
855      console.info('GainPixelmap is null');
856    }
857  } else {
858    console.info('PictureObj is null');
859  }
860}
861```
862
863### setAuxiliaryPicture<sup>13+</sup>
864
865setAuxiliaryPicture(type: AuxiliaryPictureType, auxiliaryPicture: AuxiliaryPicture): void
866
867设置辅助图。
868
869**系统能力:** SystemCapability.Multimedia.Image.Core
870
871**参数:**
872
873| 参数名           | 类型                 | 必填 | 说明         |
874| ---------------- | -------------------- | ---- | ------------ |
875| type             | [AuxiliaryPictureType](#auxiliarypicturetype13) | 是   | 辅助图类型。 |
876| auxiliaryPicture | [AuxiliaryPicture](#auxiliarypicture13)     | 是   | 辅助图对象。 |
877
878**错误码:**
879
880以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
881
882| 错误码ID | 错误信息                                                     |
883| -------- | ------------------------------------------------------------ |
884| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
885
886**示例:**
887
888```ts
889import { image } from '@kit.ImageKit';
890
891async function SetAuxiliaryPicture() {
892  const context = getContext();
893  const resourceMgr = context.resourceManager;
894  const rawFile = await resourceMgr.getRawFileContent("hdr.jpg");//需要支持hdr的图片
895  let ops: image.SourceOptions = {
896    sourceDensity: 98,
897  }
898  let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops);
899  let pixelMap: image.PixelMap = await imageSource.createPixelMap();
900  let auxPicture: image.Picture = image.createPicture(pixelMap);
901  if (auxPicture != null) {
902    console.info('Create picture succeeded');
903  } else {
904    console.info('Create picture failed');
905  }
906
907  if (pictureObj != null) {
908    let type: image.AuxiliaryPictureType = image.AuxiliaryPictureType.GAINMAP;
909    let auxPictureObj: image.AuxiliaryPicture | null = await auxPicture.getAuxiliaryPicture(type);
910    if (auxPictureObj != null) {
911      pictureObj.setAuxiliaryPicture(type, auxPictureObj);
912    }
913  }
914}
915```
916
917### getAuxiliaryPicture<sup>13+</sup>
918
919getAuxiliaryPicture(type: AuxiliaryPictureType): AuxiliaryPicture | null
920
921根据类型获取辅助图。
922
923**系统能力:** SystemCapability.Multimedia.Image.Core
924
925**参数:**
926
927| 参数名 | 类型                 | 必填 | 说明         |
928| ------ | -------------------- | ---- | ------------ |
929| type   | [AuxiliaryPictureType](#auxiliarypicturetype13) | 是   | 辅助图类型。 |
930
931**返回值:**
932
933| 类型                   | 说明                                           |
934| ---------------------- | ---------------------------------------------- |
935| [AuxiliaryPicture](#auxiliarypicture13) \| null | 返回AuxiliaryPicture对象,如果没有则返回null。 |
936
937**错误码:**
938
939以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
940
941| 错误码ID | 错误信息                                                     |
942| -------- | ------------------------------------------------------------ |
943| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
944
945**示例:**
946
947```ts
948import { image } from '@kit.ImageKit';
949
950async function GetAuxiliaryPicture() {
951  if (pictureObj != null) {
952    let type: image.AuxiliaryPictureType = image.AuxiliaryPictureType.GAINMAP;
953    let auxPictureObj: image.AuxiliaryPicture | null = pictureObj.getAuxiliaryPicture(type);
954  }
955}
956```
957
958### setMetadata<sup>13+</sup>
959
960setMetadata(metadataType: MetadataType, metadata: Metadata): Promise\<void>
961
962设置主图的元数据。
963
964**系统能力:** SystemCapability.Multimedia.Image.Core
965
966**参数:**
967
968| 参数名       | 类型         | 必填 | 说明         |
969| ------------ | ------------ | ---- | ------------ |
970| metadataType | [MetadataType](#metadatatype13) | 是   | 元数据类型。 |
971| metadata     | [Metadata](#metadata13)     | 是   | 元数据对象。 |
972
973**返回值:**
974
975| 类型           | 说明                                   |
976| -------------- | -------------------------------------- |
977| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
978
979**错误码:**
980
981以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
982
983| 错误码ID | 错误信息                                                     |
984| -------- | ------------------------------------------------------------ |
985| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
986| 7600202  | Unsupported metadata. Possible causes: Unsupported metadata type. |
987
988**示例:**
989
990```ts
991import { BusinessError } from '@kit.BasicServicesKit';
992import { image } from '@kit.ImageKit';
993
994async function SetPictureObjMetadata() {
995  const exifContext = getContext();
996  const exifResourceMgr = exifContext.resourceManager;
997  const exifRawFile = await exifResourceMgr.getRawFileContent("exif.jpg");//含有exif metadata的图片
998  let exifOps: image.SourceOptions = {
999    sourceDensity: 98,
1000  }
1001  let exifImageSource: image.ImageSource = image.createImageSource(exifRawFile.buffer as ArrayBuffer, exifOps);
1002  let exifCommodityPixelMap: image.PixelMap = await exifImageSource.createPixelMap();
1003  let exifPictureObj: image.Picture = image.createPicture(exifCommodityPixelMap);
1004  if (exifPictureObj != null) {
1005    console.info('Create picture succeeded');
1006  } else {
1007    console.info('Create picture failed');
1008  }
1009
1010  if (pictureObj != null) {
1011    let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA;
1012    let exifMetaData: image.Metadata = await exifPictureObj.getMetadata(metadataType);
1013    pictureObj.setMetadata(metadataType, exifMetaData).then(() => {
1014      console.info('Set metadata success');
1015    }).catch((error: BusinessError) => {
1016      console.error('Failed to set metadata. error.code: ' +JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message));
1017    });
1018  } else {
1019    console.info('PictureObj is null');
1020  }
1021}
1022```
1023
1024### getMetadata<sup>13+</sup>
1025
1026getMetadata(metadataType: MetadataType): Promise\<Metadata>
1027
1028获取主图的元数据。
1029
1030**系统能力:** SystemCapability.Multimedia.Image.Core
1031
1032**参数:**
1033
1034| 参数名       | 类型         | 必填 | 说明         |
1035| ------------ | ------------ | ---- | ------------ |
1036| metadataType | [MetadataType](#metadatatype13) | 是   | 元数据类型。 |
1037
1038**返回值:**
1039
1040| 类型               | 说明                      |
1041| ------------------ | ------------------------- |
1042| Promise\<[Metadata](#metadata13)> | Promise对象。返回元数据。 |
1043
1044**错误码:**
1045
1046以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
1047
1048| 错误码ID | 错误信息                                                     |
1049| -------- | ------------------------------------------------------------ |
1050| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
1051| 7600202  | Unsupported metadata. Possible causes: Unsupported metadata type. |
1052
1053**示例:**
1054
1055```ts
1056import { image } from '@kit.ImageKit';
1057
1058async function GetPictureObjMetadataProperties() {
1059  if (pictureObj != null) {
1060    let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA;
1061    let pictureObjMetaData: image.Metadata = await pictureObj.getMetadata(metadataType);
1062    if (pictureObjMetaData != null) {
1063      console.info('get picture metadata success');
1064    } else {
1065      console.info('get picture metadata is failed');
1066    }
1067  } else {
1068    console.info(" pictureObj is null");
1069  }
1070}
1071```
1072
1073### marshalling<sup>13+</sup>
1074
1075marshalling(sequence: rpc.MessageSequence): void
1076
1077将picture序列化后写入MessageSequence。
1078
1079**系统能力:** SystemCapability.Multimedia.Image.Core
1080
1081**参数:**
1082
1083| 参数名   | 类型                                                                | 必填 | 说明                      |
1084| -------- | ------------------------------------------------------------------- | ---- | ------------------------- |
1085| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | 是   | 新创建的MessageSequence。 |
1086
1087**错误码:**
1088
1089以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
1090
1091| 错误码ID | 错误信息                                                     |
1092| -------- | ------------------------------------------------------------ |
1093| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
1094| 62980097 | IPC error.                                                   |
1095
1096**示例:**
1097
1098```ts
1099import { BusinessError } from '@kit.BasicServicesKit';
1100import { image } from '@kit.ImageKit';
1101import { rpc } from '@kit.IPCKit';
1102
1103class MySequence implements rpc.Parcelable {
1104  picture: image.Picture | null = null;
1105  constructor(conPicture: image.Picture) {
1106    this.picture = conPicture;
1107  }
1108  marshalling(messageSequence: rpc.MessageSequence) {
1109    if(this.picture != null) {
1110      this.picture.marshalling(messageSequence);
1111      console.info('Marshalling success !');
1112      return true;
1113    } else {
1114      console.info('Marshalling failed !');
1115      return false;
1116    }
1117  }
1118  unmarshalling(messageSequence : rpc.MessageSequence) {
1119    this.picture = image.createPictureFromParcel(messageSequence);
1120    this.picture.getMainPixelmap().getImageInfo().then((imageInfo : image.ImageInfo) => {
1121      console.info('Unmarshalling to get mainPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width);
1122    }).catch((error: BusinessError) => {
1123      console.error('Unmarshalling failed error.code: ${error.code} ,error.message: ${error.message}');
1124    });
1125    return true;
1126  }
1127}
1128
1129async function Marshalling_UnMarshalling() {
1130  if (pictureObj != null) {
1131    let parcelable: MySequence = new MySequence(pictureObj);
1132    let data: rpc.MessageSequence = rpc.MessageSequence.create();
1133    // marshalling
1134    data.writeParcelable(parcelable);
1135    let ret: MySequence = new MySequence(pictureObj);
1136    // unmarshalling
1137    data.readParcelable(ret);
1138  } else {
1139    console.info('PictureObj is null');
1140  }
1141}
1142```
1143
1144### release<sup>13+</sup>
1145
1146release(): void
1147
1148释放picture对象。
1149
1150**系统能力:** SystemCapability.Multimedia.Image.Core
1151
1152**示例:**
1153
1154```ts
1155import { image } from '@kit.ImageKit';
1156
1157async function Release() {
1158  let funcName = "Release";
1159  if (pictureObj != null) {
1160    pictureObj.release();
1161    if (pictureObj.getMainPixelmap() == null) {
1162      console.info(funcName, 'Success !');
1163    } else {
1164      console.info(funcName, 'Failed !');
1165    }
1166  } else {
1167    console.info('PictureObj is null');
1168  }
1169}
1170```
1171
1172## PixelMap<sup>7+</sup>
1173
1174图像像素类,用于读取或写入图像数据以及获取图像信息。在调用PixelMap的方法前,需要先通过[createPixelMap](#imagecreatepixelmap8)创建一个PixelMap实例。目前pixelmap序列化大小最大128MB,超过会送显失败。大小计算方式为(宽\*高\*每像素占用字节数)。
1175
1176从API version 11开始,PixelMap支持通过worker跨线程调用。当PixelMap通过[Worker](../apis-arkts/js-apis-worker.md)跨线程后,原线程的PixelMap的所有接口均不能调用,否则将报错501 服务器不具备完成请求的功能。  
1177
1178在调用PixelMap的方法前,需要先通过[image.createPixelMap](#imagecreatepixelmap8)构建一个PixelMap对象。
1179
1180### 属性
1181
1182**系统能力:** SystemCapability.Multimedia.Image.Core
1183
1184| 名称              | 类型    | 可读 | 可写 | 说明                       |
1185| -----------------| ------- | ---- | ---- | -------------------------- |
1186| isEditable        | boolean | 是   | 否   | 设定是否图像像素可被编辑。 <br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 |
1187| isStrideAlignment<sup>11+</sup> | boolean | 是   | 否   | 设定图像内存是否为DMA内存。 |
1188
1189### readPixelsToBuffer<sup>7+</sup>
1190
1191readPixelsToBuffer(dst: ArrayBuffer): Promise\<void>
1192
1193读取图像像素数据,并按照PixelMap的像素格式写入缓冲区中,使用Promise形式返回。
1194
1195**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1196
1197**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1198
1199**系统能力:** SystemCapability.Multimedia.Image.Core
1200
1201**参数:**
1202
1203| 参数名 | 类型        | 必填 | 说明                                                                                                  |
1204| ------ | ----------- | ---- | ----------------------------------------------------------------------------------------------------- |
1205| dst    | ArrayBuffer | 是   | 缓冲区,函数执行结束后获取的图像像素数据写入到该内存区域内。缓冲区大小由[getPixelBytesNumber](#getpixelbytesnumber7)接口获取。 |
1206
1207**返回值:**
1208
1209| 类型           | 说明                                            |
1210| -------------- | ----------------------------------------------- |
1211| Promise\<void> | Promise对象。无返回结果的Promise对象。  |
1212
1213**示例:**
1214
1215```ts
1216import { BusinessError } from '@kit.BasicServicesKit';
1217
1218async function Demo() {
1219  const readBuffer: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
1220  if (pixelMap != undefined) {
1221    pixelMap.readPixelsToBuffer(readBuffer).then(() => {
1222      console.info('Succeeded in reading image pixel data.'); // 符合条件则进入 
1223    }).catch((error: BusinessError) => {
1224      console.error(`Failed to read image pixel data. code is ${error.code}, message is ${error.message}`);// 不符合条件则进入
1225    })
1226  }
1227}
1228```
1229
1230### readPixelsToBuffer<sup>7+</sup>
1231
1232readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\<void>): void
1233
1234读取图像像素数据,并按照PixelMap的像素格式写入缓冲区中,使用callback形式返回。
1235
1236**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1237
1238**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1239
1240**系统能力:** SystemCapability.Multimedia.Image.Core
1241
1242**参数:**
1243
1244| 参数名   | 类型                 | 必填 | 说明                                                                                                  |
1245| -------- | -------------------- | ---- | ----------------------------------------------------------------------------------------------------- |
1246| dst      | ArrayBuffer          | 是   | 缓冲区,函数执行结束后获取的图像像素数据写入到该内存区域内。缓冲区大小由[getPixelBytesNumber](#getpixelbytesnumber7)接口获取。 |
1247| callback | AsyncCallback\<void> | 是   | 回调函数。当读取像素数据到ArrayBuffer成功,err为undefined,否则为错误对象。  |
1248
1249**示例:**
1250
1251```ts
1252import { BusinessError } from '@kit.BasicServicesKit';
1253
1254async function Demo() {
1255  const readBuffer: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
1256  if (pixelMap != undefined) {
1257    pixelMap.readPixelsToBuffer(readBuffer, (error: BusinessError, res: void) => {
1258      if(error) {
1259        console.error(`Failed to read image pixel data. code is ${error.code}, message is ${error.message}`);// 不符合条件则进入
1260        return;
1261      } else {
1262        console.info('Succeeded in reading image pixel data.');  //符合条件则进入
1263      }
1264    })
1265  }
1266}
1267```
1268
1269### readPixelsToBufferSync<sup>12+</sup>
1270
1271readPixelsToBufferSync(dst: ArrayBuffer): void
1272
1273以同步方式读取图像像素数据,并按照PixelMap的像素格式写入缓冲区中。
1274
1275**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1276
1277**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1278
1279**系统能力:** SystemCapability.Multimedia.Image.Core
1280
1281**参数:**
1282
1283| 参数名   | 类型                 | 必填 | 说明                                                                                                  |
1284| -------- | -------------------- | ---- | ----------------------------------------------------------------------------------------------------- |
1285| dst      | ArrayBuffer          | 是   | 缓冲区,函数执行结束后获取的图像像素数据写入到该内存区域内。缓冲区大小由[getPixelBytesNumber](#getpixelbytesnumber7)接口获取。 |
1286
1287**错误码:**
1288
1289以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
1290
1291| 错误码ID | 错误信息 |
1292| ------- | --------------------------------------------|
1293|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
1294|  501    | Resource Unavailable |
1295
1296**示例:**
1297
1298```ts
1299import { BusinessError } from '@kit.BasicServicesKit';
1300
1301async function Demo() {
1302  const readBuffer: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
1303  if (pixelMap != undefined) {
1304    pixelMap.readPixelsToBufferSync(readBuffer);
1305  }
1306}
1307```
1308
1309### readPixels<sup>7+</sup>
1310
1311readPixels(area: PositionArea): Promise\<void>
1312
1313读取PixelMap指定区域内的图像像素数据,并写入[PositionArea](#positionarea7).pixels缓冲区中,该区域由[PositionArea](#positionarea7).region指定。
1314当PixelMap的像素格式为RGB类型时,固定按照BGRA_8888格式从PixelMap读取。使用Promise形式返回。
1315
1316可用公式计算PositionArea需要申请的内存大小。
1317
1318YUV的区域计算公式:读取区域(region.size{width * height})* 1.5 (1倍的Y分量+0.25倍U分量+0.25倍V分量)
1319
1320RGBA的区域计算公式:读取区域(region.size{width * height})* 4 (1倍的R分量+1倍G分量+1倍B分量+1倍A分量)
1321
1322**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1323
1324**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1325
1326**系统能力:** SystemCapability.Multimedia.Image.Core
1327
1328**参数:**
1329
1330| 参数名 | 类型                           | 必填 | 说明                     |
1331| ------ | ------------------------------ | ---- | ------------------------ |
1332| area   | [PositionArea](#positionarea7) | 是   | 区域大小,根据区域读取。 |
1333
1334**返回值:**
1335
1336| 类型           | 说明                                                |
1337| :------------- | :-------------------------------------------------- |
1338| Promise\<void> | Promise对象。无返回结果的Promise对象。  |
1339
1340**示例:**
1341
1342```ts
1343import { BusinessError } from '@kit.BasicServicesKit';
1344
1345async function Demo() {
1346  const area: image.PositionArea = {
1347    pixels: new ArrayBuffer(8), // 8为需要创建的像素buffer大小,取值为:height * width *4
1348    offset: 0,
1349    stride: 8,
1350    region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
1351  };
1352  if (pixelMap != undefined) {
1353    pixelMap.readPixels(area).then(() => {
1354      console.info('Succeeded in reading the image data in the area.'); //符合条件则进入
1355    }).catch((error: BusinessError) => {
1356      console.error(`Failed to read the image data in the area. code is ${error.code}, message is ${error.message}`);// 不符合条件则进入
1357    })
1358  }
1359}
1360
1361async function Demo() {
1362  const area: image.PositionArea = {
1363    pixels: new ArrayBuffer(6),  // 6为需要创建的像素buffer大小,取值为:height * width *1.5
1364    offset: 0,
1365    stride: 8,
1366    region: { size: { height: 2, width: 2 }, x: 0, y: 0 }
1367  };
1368  if (pixelMap != undefined) {
1369    pixelMap.readPixels(area).then(() => {
1370      console.info('Succeeded in reading the image data in the area.'); //符合条件则进入
1371    }).catch((error: BusinessError) => {
1372      console.error(`Failed to read the image data in the area. code is ${error.code}, message is ${error.message}`);// 不符合条件则进入
1373    })
1374  }
1375}
1376```
1377
1378### readPixels<sup>7+</sup>
1379
1380readPixels(area: PositionArea, callback: AsyncCallback\<void>): void
1381
1382读取PixelMap指定区域内的图像像素数据,并写入[PositionArea](#positionarea7).pixels缓冲区中,该区域由[PositionArea](#positionarea7).region指定。
1383当像素格式为RGBA 类型时,固定按照BGRA_8888格式从PixelMap读取。使用callback形式返回。
1384
1385可用公式计算PositionArea需要申请的内存大小。
1386
1387YUV的区域计算公式:读取区域(region.size{width * height})* 1.5 (1倍的Y分量+0.25倍U分量+0.25倍V分量)
1388
1389RGBA的区域计算公式:读取区域(region.size{width * height})* 4 (1倍的R分量+1倍G分量+1倍B分量+1倍A分量)
1390
1391**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1392
1393**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1394
1395**系统能力:** SystemCapability.Multimedia.Image.Core
1396
1397**参数:**
1398
1399| 参数名   | 类型                           | 必填 | 说明                           |
1400| -------- | ------------------------------ | ---- | ------------------------------ |
1401| area     | [PositionArea](#positionarea7) | 是   | 区域大小,根据区域读取。       |
1402| callback | AsyncCallback\<void>           | 是   |  回调函数。当读取区域内的图片数据成功,err为undefined,否则为错误对象。 |
1403
1404**示例:**
1405
1406```ts
1407import { BusinessError } from '@kit.BasicServicesKit';
1408
1409async function Demo() {
1410  const area: image.PositionArea = {
1411    pixels: new ArrayBuffer(8), // 8为需要创建的像素buffer大小,取值为:height * width *4
1412    offset: 0,
1413    stride: 8,
1414    region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
1415  };
1416  if (pixelMap != undefined) {
1417    pixelMap.readPixels(area, (error: BusinessError) => {
1418      if (error) {
1419        console.error(`Failed to read pixelmap from the specified area. code is ${error.code}, message is ${error.message}`);
1420        return;
1421      } else {
1422        console.info('Succeeded in reading pixelmap from the specified area.');
1423      }
1424    })
1425  }
1426}
1427
1428async function Demo() {
1429  const area: image.PositionArea = {
1430    pixels: new ArrayBuffer(6), // 6为需要创建的像素buffer大小,取值为:height * width *1.5
1431    offset: 0,
1432    stride: 8,
1433    region: { size: { height: 2, width: 2 }, x: 0, y: 0 }
1434  };
1435  if (pixelMap != undefined) {
1436    pixelMap.readPixels(area, (error: BusinessError) => {
1437      if (error) {
1438        console.error(`Failed to read pixelmap from the specified area. code is ${error.code}, message is ${error.message}`);
1439        return;
1440      } else {
1441        console.info('Succeeded in reading pixelmap from the specified area.');
1442      }
1443    })
1444  }
1445}
1446```
1447
1448### readPixelsSync<sup>12+</sup>
1449
1450readPixelsSync(area: PositionArea): void
1451
1452以同步方式读取PixelMap指定区域内的图像像素数据,并写入[PositionArea](#positionarea7).pixels缓冲区中,该区域由[PositionArea](#positionarea7).region指定。
1453当PixelMap的像素格式为RGB类型时,固定按照BGRA_8888格式从PixelMap读取。
1454
1455**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1456
1457**系统能力:** SystemCapability.Multimedia.Image.Core
1458
1459**参数:**
1460
1461| 参数名 | 类型                           | 必填 | 说明                     |
1462| ------ | ------------------------------ | ---- | ------------------------ |
1463| area   | [PositionArea](#positionarea7) | 是   | 区域大小,根据区域读取。 |
1464
1465**错误码:**
1466
1467以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
1468
1469| 错误码ID | 错误信息 |
1470| ------- | --------------------------------------------|
1471|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
1472|  501    | Resource Unavailable |
1473
1474**示例:**
1475
1476```ts
1477import { BusinessError } from '@kit.BasicServicesKit';
1478
1479async function Demo() {
1480  const area : image.PositionArea = {
1481    pixels: new ArrayBuffer(8),
1482    offset: 0,
1483    stride: 8,
1484    region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
1485  };
1486  if (pixelMap != undefined) {
1487    pixelMap.readPixelsSync(area);
1488  }
1489}
1490```
1491
1492### writePixels<sup>7+</sup>
1493
1494writePixels(area: PositionArea): Promise\<void>
1495
1496读取[PositionArea](#positionarea7).pixels缓冲区中的图像像素数据,并写入PixelMap指定区域内,该区域由[PositionArea](#positionarea7).region指定。
1497当PixelMap的像素格式为RGB类型时,固定按照BGRA_8888格式写入PixelMap。使用Promise形式返回。
1498
1499可用公式计算PositionArea需要申请的内存大小。
1500
1501YUV的区域计算公式:读取区域(region.size{width * height})* 1.5 (1倍的Y分量+0.25倍U分量+0.25倍V分量)
1502
1503RGBA的区域计算公式:读取区域(region.size{width * height})* 4 (1倍的R分量+1倍G分量+1倍B分量+1倍A分量)
1504
1505**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1506
1507**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1508
1509**系统能力:** SystemCapability.Multimedia.Image.Core
1510
1511**参数:**
1512
1513| 参数名 | 类型                           | 必填 | 说明                 |
1514| ------ | ------------------------------ | ---- | -------------------- |
1515| area   | [PositionArea](#positionarea7) | 是   | 区域,根据区域写入。 |
1516
1517**返回值:**
1518
1519| 类型           | 说明                                                |
1520| :------------- | :-------------------------------------------------- |
1521| Promise\<void> | Promise对象。无返回结果的Promise对象。  |
1522
1523**示例:**
1524
1525```ts
1526import { BusinessError } from '@kit.BasicServicesKit';
1527
1528async function Demo() {
1529  const area: image.PositionArea = {
1530    pixels: new ArrayBuffer(8), // 8为需要创建的像素buffer大小,取值为:height * width *4
1531    offset: 0,
1532    stride: 8,
1533    region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
1534  };
1535  let bufferArr: Uint8Array = new Uint8Array(area.pixels);
1536  for (let i = 0; i < bufferArr.length; i++) {
1537    bufferArr[i] = i + 1;
1538  }
1539  if (pixelMap != undefined) {
1540    pixelMap.writePixels(area).then(() => {
1541      console.info('Succeeded in writing pixelmap into the specified area.');
1542    }).catch((error: BusinessError) => {
1543      console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`);
1544    })
1545  }
1546}
1547
1548async function Demo() {
1549  const area: image.PositionArea = {
1550    pixels: new ArrayBuffer(6), // 6为需要创建的像素buffer大小,取值为:height * width *1.5
1551    offset: 0,
1552    stride: 8,
1553    region: { size: { height: 2, width: 2 }, x: 0, y: 0 }
1554  };
1555  let bufferArr: Uint8Array = new Uint8Array(area.pixels);
1556  for (let i = 0; i < bufferArr.length; i++) {
1557    bufferArr[i] = i + 1;
1558  }
1559  if (pixelMap != undefined) {
1560    pixelMap.writePixels(area).then(() => {
1561      console.info('Succeeded in writing pixelmap into the specified area.');
1562    }).catch((error: BusinessError) => {
1563      console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`);
1564    })
1565  }
1566}
1567```
1568
1569### writePixels<sup>7+</sup>
1570
1571writePixels(area: PositionArea, callback: AsyncCallback\<void>): void
1572
1573读取[PositionArea](#positionarea7).pixels缓冲区中的图像像素数据,并写入PixelMap指定区域内,该区域由[PositionArea](#positionarea7).region指定。
1574当PixelMap的像素格式为RGB类型时,固定按照BGRA_8888格式写入PixelMap。使用callback形式返回。
1575
1576可用公式计算PositionArea需要申请的内存大小。
1577
1578YUV的区域计算公式:读取区域(region.size{width * height})* 1.5 (1倍的Y分量+0.25倍U分量+0.25倍V分量)
1579
1580RGBA的区域计算公式:读取区域(region.size{width * height})* 4 (1倍的R分量+1倍G分量+1倍B分量+1倍A分量)
1581
1582**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1583
1584**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1585
1586**系统能力:** SystemCapability.Multimedia.Image.Core
1587
1588**参数:**
1589
1590| 参数名    | 类型                           | 必填 | 说明                           |
1591| --------- | ------------------------------ | ---- | ------------------------------ |
1592| area      | [PositionArea](#positionarea7) | 是   | 区域,根据区域写入。           |
1593| callback  | AsyncCallback\<void>           | 是   | 回调函数,当写入成功,err为undefined,否则为错误对象。 |
1594
1595**示例:**
1596
1597```ts
1598import { BusinessError } from '@kit.BasicServicesKit';
1599
1600async function Demo() {
1601  const area: image.PositionArea = { pixels: new ArrayBuffer(8), // 8为需要创建的像素buffer大小,取值为:height * width *4
1602    offset: 0,
1603    stride: 8,
1604    region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
1605  };
1606  let bufferArr: Uint8Array = new Uint8Array(area.pixels);
1607  for (let i = 0; i < bufferArr.length; i++) {
1608    bufferArr[i] = i + 1;
1609  }
1610  if (pixelMap != undefined) {
1611    pixelMap.writePixels(area, (error : BusinessError) => {
1612      if (error) {
1613        console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`);
1614        return;
1615      } else {
1616        console.info('Succeeded in writing pixelmap into the specified area.');
1617      }
1618    })
1619  }
1620}
1621
1622async function Demo() {
1623  const area: image.PositionArea = { pixels: new ArrayBuffer(6), // 6为需要创建的像素buffer大小,取值为:height * width *1.5
1624    offset: 0,
1625    stride: 8,
1626    region: { size: { height: 2, width: 2 }, x: 0, y: 0 }
1627  };
1628  let bufferArr: Uint8Array = new Uint8Array(area.pixels);
1629  for (let i = 0; i < bufferArr.length; i++) {
1630    bufferArr[i] = i + 1;
1631  }
1632  if (pixelMap != undefined) {
1633    pixelMap.writePixels(area, (error : BusinessError) => {
1634      if (error) {
1635        console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`);
1636        return;
1637      } else {
1638        console.info('Succeeded in writing pixelmap into the specified area.');
1639      }
1640    })
1641  }
1642}
1643```
1644
1645### writePixelsSync<sup>12+</sup>
1646
1647writePixelsSync(area: PositionArea): void
1648
1649以同步方式读取[PositionArea](#positionarea7).pixels缓冲区中的图像像素数据,并写入PixelMap指定区域内,该区域由[PositionArea](#positionarea7).region指定。
1650当PixelMap的像素格式为RGB类型时,固定按照BGRA_8888格式写入PixelMap。
1651
1652**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1653
1654**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1655
1656**系统能力:** SystemCapability.Multimedia.Image.Core
1657
1658**参数:**
1659
1660| 参数名 | 类型                           | 必填 | 说明                 |
1661| ------ | ------------------------------ | ---- | -------------------- |
1662| area   | [PositionArea](#positionarea7) | 是   | 区域,根据区域写入。 |
1663
1664**错误码:**
1665
1666以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
1667
1668| 错误码ID | 错误信息 |
1669| ------- | --------------------------------------------|
1670|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
1671|  501    | Resource Unavailable |
1672
1673**示例:**
1674
1675```ts
1676import { BusinessError } from '@kit.BasicServicesKit';
1677
1678async function Demo() {
1679  const area: image.PositionArea = {
1680    pixels: new ArrayBuffer(8),
1681    offset: 0,
1682    stride: 8,
1683    region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
1684  };
1685  let bufferArr: Uint8Array = new Uint8Array(area.pixels);
1686  for (let i = 0; i < bufferArr.length; i++) {
1687    bufferArr[i] = i + 1;
1688  }
1689  if (pixelMap != undefined) {
1690    pixelMap.writePixelsSync(area);
1691  }
1692}
1693```
1694
1695### writeBufferToPixels<sup>7+</sup>
1696
1697writeBufferToPixels(src: ArrayBuffer): Promise\<void>
1698
1699读取缓冲区中的图像像素数据,并按照PixelMap的像素格式将结果写入PixelMap,使用Promise形式返回。
1700
1701**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1702
1703**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1704
1705**系统能力:** SystemCapability.Multimedia.Image.Core
1706
1707**参数:**
1708
1709| 参数名 | 类型        | 必填 | 说明           |
1710| ------ | ----------- | ---- | -------------- |
1711| src    | ArrayBuffer | 是   | 缓冲区,函数执行时会将该缓冲区中的图像像素数据写入到PixelMap。缓冲区大小由[getPixelBytesNumber](#getpixelbytesnumber7)接口获取。 |
1712
1713**返回值:**
1714
1715| 类型           | 说明                                            |
1716| -------------- | ----------------------------------------------- |
1717| Promise\<void> | Promise对象。无返回结果的Promise对象。  |
1718
1719**示例:**
1720
1721```ts
1722import { BusinessError } from '@kit.BasicServicesKit';
1723
1724async function Demo() {
1725  const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
1726  let bufferArr: Uint8Array = new Uint8Array(color);
1727  for (let i = 0; i < bufferArr.length; i++) {
1728    bufferArr[i] = i + 1;
1729  }
1730  if (pixelMap != undefined) {
1731    pixelMap.writeBufferToPixels(color).then(() => {
1732      console.info("Succeeded in writing data from a buffer to a PixelMap.");
1733    }).catch((error: BusinessError) => {
1734      console.error(`Failed to write data from a buffer to a PixelMap. code is ${error.code}, message is ${error.message}`);
1735    })
1736  }
1737}
1738```
1739
1740### writeBufferToPixels<sup>7+</sup>
1741
1742writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\<void>): void
1743
1744读取缓冲区中的图像像素数据,并按照PixelMap的像素格式将结果写入PixelMap,通过回调函数形式返回。
1745
1746**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1747
1748**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1749
1750**系统能力:** SystemCapability.Multimedia.Image.Core
1751
1752**参数:**
1753
1754| 参数名   | 类型                 | 必填 | 说明                           |
1755| -------- | -------------------- | ---- | ------------------------------ |
1756| src      | ArrayBuffer          | 是   | 缓冲区,函数执行时会将该缓冲区中的图像像素数据写入到PixelMap。缓冲区大小由[getPixelBytesNumber](#getpixelbytesnumber7)接口获取。 |
1757| callback | AsyncCallback\<void> | 是   | 回调函数。当缓冲区中的图像像素数据写入PixelMap成功,err为undefined,否则为错误对象。 |
1758
1759**示例:**
1760
1761```ts
1762import { BusinessError } from '@kit.BasicServicesKit';
1763
1764async function Demo() {
1765  const color: ArrayBuffer = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
1766  let bufferArr: Uint8Array = new Uint8Array(color);
1767  for (let i = 0; i < bufferArr.length; i++) {
1768    bufferArr[i] = i + 1;
1769  }
1770  if (pixelMap != undefined) {
1771    pixelMap.writeBufferToPixels(color, (error: BusinessError) => {
1772      if (error) {
1773        console.error(`Failed to write data from a buffer to a PixelMap. code is ${error.code}, message is ${error.message}`);
1774        return;
1775      } else {
1776        console.info("Succeeded in writing data from a buffer to a PixelMap.");
1777      }
1778    })
1779  }
1780}
1781```
1782
1783### writeBufferToPixelsSync<sup>12+</sup>
1784
1785writeBufferToPixelsSync(src: ArrayBuffer): void
1786
1787读取缓冲区中的图像像素数据,按照PixelMap的像素格式将结果写入PixelMap并同步返回结果。
1788
1789**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1790
1791**系统能力:** SystemCapability.Multimedia.Image.Core
1792
1793**参数:**
1794
1795| 参数名 | 类型        | 必填 | 说明           |
1796| ------ | ----------- | ---- | -------------- |
1797| src    | ArrayBuffer | 是   | 缓冲区,函数执行时会将该缓冲区中的图像像素数据写入到PixelMap。缓冲区大小由[getPixelBytesNumber](#getpixelbytesnumber7)接口获取。 |
1798
1799**错误码:**
1800
1801以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
1802
1803| 错误码ID | 错误信息 |
1804| ------- | --------------------------------------------|
1805|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
1806|  501    | Resource Unavailable |
1807
1808**示例:**
1809
1810```ts
1811import { BusinessError } from '@kit.BasicServicesKit';
1812
1813async function Demo() {
1814  const color : ArrayBuffer = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
1815  let bufferArr : Uint8Array = new Uint8Array(color);
1816  for (let i = 0; i < bufferArr.length; i++) {
1817    bufferArr[i] = i + 1;
1818  }
1819  if (pixelMap != undefined) {
1820    pixelMap.writeBufferToPixelsSync(color);
1821  }
1822}
1823```
1824
1825
1826### getImageInfo<sup>7+</sup>
1827
1828getImageInfo(): Promise\<ImageInfo>
1829
1830获取图像像素信息,使用Promise形式返回获取的图像像素信息。
1831
1832**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1833
1834**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1835
1836**系统能力:** SystemCapability.Multimedia.Image.Core
1837
1838**返回值:**
1839
1840| 类型                              | 说明                                                        |
1841| --------------------------------- | ----------------------------------------------------------- |
1842| Promise\<[ImageInfo](#imageinfo)> | Promise对象,返回图像像素信息。 |
1843
1844**示例:**
1845
1846```ts
1847import { BusinessError } from '@kit.BasicServicesKit';
1848
1849async function Demo() {
1850  if (pixelMap != undefined) {
1851    pixelMap.getImageInfo().then((imageInfo: image.ImageInfo) => {
1852      if (imageInfo != undefined) {
1853        console.info("Succeeded in obtaining the image pixel map information."+ imageInfo.size.height);
1854      }
1855    }).catch((error: BusinessError) => {
1856      console.error(`Failed to obtain the image pixel map information. code is ${error.code}, message is ${error.message}`);
1857    })
1858  }
1859}
1860```
1861
1862### getImageInfo<sup>7+</sup>
1863
1864getImageInfo(callback: AsyncCallback\<ImageInfo>): void
1865
1866获取图像像素信息,使用callback形式返回获取的图像像素信息。
1867
1868**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1869
1870**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1871
1872**系统能力:** SystemCapability.Multimedia.Image.Core
1873
1874**参数:**
1875
1876| 参数名   | 类型                                    | 必填 | 说明                                                         |
1877| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
1878| callback | AsyncCallback\<[ImageInfo](#imageinfo)> | 是   | 回调函数。当获取图像像素信息成功,err为undefined,data为获取到的图像像素信息;否则为错误对象。 |
1879
1880**示例:**
1881
1882```ts
1883import { BusinessError } from '@kit.BasicServicesKit';
1884
1885async function Demo() {
1886  if (pixelMap != undefined) {
1887    pixelMap.getImageInfo((error: BusinessError, imageInfo: image.ImageInfo) => {
1888      if (error) {
1889        console.error(`Failed to obtain the image pixel map information. code is ${error.code}, message is ${error.message}`);
1890        return;
1891      } else {
1892        console.info("Succeeded in obtaining the image pixel map information."+ imageInfo.size.height);
1893      }
1894    })
1895  }
1896}
1897```
1898
1899### getImageInfoSync<sup>12+</sup>
1900
1901getImageInfoSync(): ImageInfo
1902
1903以同步方法获取图像像素信息。
1904
1905**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1906
1907**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1908
1909**系统能力:** SystemCapability.Multimedia.Image.ImageSource
1910
1911**返回值:**
1912
1913| 类型                              | 说明                                                        |
1914| --------------------------------- | ----------------------------------------------------------- |
1915| [ImageInfo](#imageinfo)           | 图像像素信息                                                |
1916
1917**错误码:**
1918
1919以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
1920
1921| 错误码ID | 错误信息 |
1922| ------- | --------------------------------------------|
1923|  501    | Resource Unavailable |
1924
1925**示例:**
1926
1927```ts
1928import { BusinessError } from '@kit.BasicServicesKit';
1929
1930async function Demo() {
1931  if (pixelMap != undefined) {
1932    let imageInfo : image.ImageInfo = pixelMap.getImageInfoSync();
1933    return imageInfo;
1934  }
1935  return undefined;
1936}
1937```
1938
1939### getBytesNumberPerRow<sup>7+</sup>
1940
1941getBytesNumberPerRow(): number
1942
1943获取图像像素每行字节数。
1944
1945**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1946
1947**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1948
1949**系统能力:** SystemCapability.Multimedia.Image.Core
1950
1951**返回值:**
1952
1953| 类型   | 说明                 |
1954| ------ | -------------------- |
1955| number | 图像像素的行字节数。 |
1956
1957**示例:**
1958
1959```ts
1960let rowCount: number = pixelMap.getBytesNumberPerRow();
1961```
1962
1963### getPixelBytesNumber<sup>7+</sup>
1964
1965getPixelBytesNumber(): number
1966
1967获取图像像素的总字节数。
1968
1969**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1970
1971**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1972
1973**系统能力:** SystemCapability.Multimedia.Image.Core
1974
1975**返回值:**
1976
1977| 类型   | 说明                 |
1978| ------ | -------------------- |
1979| number | 图像像素的总字节数。 |
1980
1981**示例:**
1982
1983```ts
1984let pixelBytesNumber: number = pixelMap.getPixelBytesNumber();
1985```
1986
1987### getDensity<sup>9+</sup>
1988
1989getDensity():number
1990
1991获取当前图像像素的密度。
1992
1993**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1994
1995**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1996
1997**系统能力:** SystemCapability.Multimedia.Image.Core
1998
1999**返回值:**
2000
2001| 类型   | 说明            |
2002| ------ | --------------- |
2003| number | 图像像素的密度。|
2004
2005**示例:**
2006
2007```ts
2008let getDensity: number = pixelMap.getDensity();
2009```
2010
2011### opacity<sup>9+</sup>
2012
2013opacity(rate: number, callback: AsyncCallback\<void>): void
2014
2015通过设置透明比率来让PixelMap达到对应的透明效果,yuv图片不支持设置透明度,使用callback形式返回。
2016
2017**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2018
2019**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2020
2021**系统能力:** SystemCapability.Multimedia.Image.Core
2022
2023**参数:**
2024
2025| 参数名   | 类型                 | 必填 | 说明                           |
2026| -------- | -------------------- | ---- | ------------------------------ |
2027| rate     | number               | 是   | 透明比率的值。   |
2028| callback | AsyncCallback\<void> | 是   | 回调函数。当设置透明比率成功,err为undefined,否则为错误对象。 |
2029
2030**示例:**
2031
2032```ts
2033import { BusinessError } from '@kit.BasicServicesKit';
2034
2035async function Demo() {
2036  let rate: number = 0.5;
2037  if (pixelMap != undefined) {
2038    pixelMap.opacity(rate, (err: BusinessError) => {
2039      if (err) {
2040        console.error(`Failed to set opacity. code is ${err.code}, message is ${err.message}`);
2041        return;
2042      } else {
2043        console.info("Succeeded in setting opacity.");
2044      }
2045    })
2046  }
2047}
2048```
2049
2050### opacity<sup>9+</sup>
2051
2052opacity(rate: number): Promise\<void>
2053
2054通过设置透明比率来让PixelMap达到对应的透明效果,yuv图片不支持设置透明度,使用Promise形式返回。
2055
2056**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2057
2058**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2059
2060**系统能力:** SystemCapability.Multimedia.Image.Core
2061
2062**参数:**
2063
2064| 参数名 | 类型   | 必填 | 说明                        |
2065| ------ | ------ | ---- | --------------------------- |
2066| rate   | number | 是   | 透明比率的值。|
2067
2068**返回值:**
2069
2070| 类型           | 说明                                            |
2071| -------------- | ----------------------------------------------- |
2072| Promise\<void> | Promise对象。无返回结果的Promise对象。  |
2073
2074**示例:**
2075
2076```ts
2077import { BusinessError } from '@kit.BasicServicesKit';
2078
2079async function Demo() {
2080  let rate: number = 0.5;
2081  if (pixelMap != undefined) {
2082    pixelMap.opacity(rate).then(() => {
2083      console.info('Succeeded in setting opacity.');
2084    }).catch((err: BusinessError) => {
2085      console.error(`Failed to set opacity. code is ${err.code}, message is ${err.message}`);
2086    })
2087  }
2088}
2089```
2090
2091### opacitySync<sup>12+</sup>
2092
2093opacitySync(rate: number): void
2094
2095设置PixelMap的透明比率,yuv图片不支持设置透明度,初始化PixelMap并同步返回结果。
2096
2097**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2098
2099**系统能力:** SystemCapability.Multimedia.Image.Core
2100
2101**参数:**
2102
2103| 参数名   | 类型                 | 必填 | 说明                           |
2104| -------- | -------------------- | ---- | ------------------------------ |
2105| rate     | number               | 是   | 透明比率的值。   |
2106
2107**错误码:**
2108
2109以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
2110
2111| 错误码ID | 错误信息 |
2112| ------- | --------------------------------------------|
2113|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
2114|  501    | Resource Unavailable |
2115
2116**示例:**
2117
2118```ts
2119import { BusinessError } from '@kit.BasicServicesKit';
2120
2121async function Demo() {
2122  let rate : number = 0.5;
2123  if (pixelMap != undefined) {
2124    pixelMap.opacitySync(rate);
2125  }
2126}
2127```
2128
2129### createAlphaPixelmap<sup>9+</sup>
2130
2131createAlphaPixelmap(): Promise\<PixelMap>
2132
2133根据Alpha通道的信息,来生成一个仅包含Alpha通道信息的pixelmap,可用于阴影效果,yuv格式不支持此接口,使用Promise形式返回。
2134
2135**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2136
2137**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2138
2139**系统能力:** SystemCapability.Multimedia.Image.Core
2140
2141**返回值:**
2142
2143| 类型                             | 说明                        |
2144| -------------------------------- | --------------------------- |
2145| Promise\<[PixelMap](#pixelmap7)> | Promise对象,返回PixelMap。 |
2146
2147**示例:**
2148
2149```ts
2150import { BusinessError } from '@kit.BasicServicesKit';
2151
2152async function Demo() {
2153  if (pixelMap != undefined) {
2154    pixelMap.createAlphaPixelmap().then((alphaPixelMap: image.PixelMap) => {
2155      console.info('Succeeded in creating alpha pixelmap.');
2156    }).catch((error: BusinessError) => {
2157      console.error(`Failed to create alpha pixelmap. code is ${error.code}, message is ${error.message}`);
2158    })
2159  }
2160}
2161```
2162
2163### createAlphaPixelmap<sup>9+</sup>
2164
2165createAlphaPixelmap(callback: AsyncCallback\<PixelMap>): void
2166
2167根据Alpha通道的信息,来生成一个仅包含Alpha通道信息的pixelmap,可用于阴影效果,yuv格式不支持此接口,使用callback形式返回。
2168
2169**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2170
2171**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2172
2173**系统能力:** SystemCapability.Multimedia.Image.Core
2174
2175**参数:**
2176
2177| 参数名   | 类型                     | 必填 | 说明                     |
2178| -------- | ------------------------ | ---- | ------------------------ |
2179| callback | AsyncCallback\<[PixelMap](#pixelmap7)> | 是   |  回调函数,当创建PixelMap成功,err为undefined,data为获取到的PixelMap对象;否则为错误对象。 |
2180
2181**示例:**
2182
2183```ts
2184import { BusinessError } from '@kit.BasicServicesKit';
2185
2186async function Demo() {
2187  if (pixelMap != undefined) {
2188    pixelMap.createAlphaPixelmap((err: BusinessError, alphaPixelMap: image.PixelMap) => {
2189      if (alphaPixelMap == undefined) {
2190        console.error(`Failed to obtain new pixel map. code is ${err.code}, message is ${err.message}`);
2191        return;
2192      } else {
2193        console.info('Succeeded in obtaining new pixel map.');
2194      }
2195    })
2196  }
2197}
2198```
2199
2200### createAlphaPixelmapSync<sup>12+</sup>
2201
2202createAlphaPixelmapSync(): PixelMap
2203
2204根据Alpha通道的信息,生成一个仅包含Alpha通道信息的PixelMap,可用于阴影效果,yuv格式不支持此接口,同步返回PixelMap类型的结果。
2205
2206**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2207
2208**系统能力:** SystemCapability.Multimedia.Image.Core
2209
2210**返回值:**
2211
2212| 类型                             | 说明                  |
2213| -------------------------------- | --------------------- |
2214| [PixelMap](#pixelmap7) | 成功同步返回PixelMap对象,失败抛出异常。 |
2215
2216**错误码:**
2217
2218以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
2219
2220| 错误码ID | 错误信息 |
2221| ------- | --------------------------------------------|
2222|  401    | Parameter error. Possible causes: 1.Parameter verification failed |
2223|  501    | Resource Unavailable |
2224
2225**示例:**
2226
2227```ts
2228import { BusinessError } from '@kit.BasicServicesKit';
2229
2230async function Demo() {
2231  if (pixelMap != undefined) {
2232    let pixelmap : image.PixelMap = pixelMap.createAlphaPixelmapSync();
2233    return pixelmap;
2234  }
2235  return undefined;
2236}
2237```
2238
2239### scale<sup>9+</sup>
2240
2241scale(x: number, y: number, callback: AsyncCallback\<void>): void
2242
2243根据输入的宽高对图片进行缩放,使用callback形式返回。
2244
2245**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2246
2247**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2248
2249**系统能力:** SystemCapability.Multimedia.Image.Core
2250
2251**参数:**
2252
2253| 参数名   | 类型                 | 必填 | 说明                            |
2254| -------- | -------------------- | ---- | ------------------------------- |
2255| x        | number               | 是   | 宽度的缩放倍数。|
2256| y        | number               | 是   | 高度的缩放倍数。|
2257| callback | AsyncCallback\<void> | 是   | 回调函数。当对图片进行缩放成功,err为undefined,否则为错误对象。 |
2258
2259**示例:**
2260
2261```ts
2262import { BusinessError } from '@kit.BasicServicesKit';
2263
2264async function Demo() {
2265  let scaleX: number = 2.0;
2266  let scaleY: number = 1.0;
2267  if (pixelMap != undefined) {
2268    pixelMap.scale(scaleX, scaleY, (err: BusinessError) => {
2269      if (err) {
2270        console.error(`Failed to scale pixelmap. code is ${err.code}, message is ${err.message}`);
2271        return;
2272      } else {
2273        console.info("Succeeded in scaling pixelmap.");
2274      }
2275    })
2276  }
2277}
2278```
2279
2280### scale<sup>9+</sup>
2281
2282scale(x: number, y: number): Promise\<void>
2283
2284根据输入的宽高对图片进行缩放,使用Promise形式返回。
2285
2286**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2287
2288**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2289
2290**系统能力:** SystemCapability.Multimedia.Image.Core
2291
2292**参数:**
2293
2294| 参数名 | 类型   | 必填 | 说明                            |
2295| ------ | ------ | ---- | ------------------------------- |
2296| x      | number | 是   | 宽度的缩放倍数。|
2297| y      | number | 是   | 高度的缩放倍数。|
2298
2299**返回值:**
2300
2301| 类型           | 说明                        |
2302| -------------- | --------------------------- |
2303| Promise\<void> |  Promise对象。无返回结果的Promise对象。|
2304
2305**示例:**
2306
2307```ts
2308import { BusinessError } from '@kit.BasicServicesKit';
2309
2310async function Demo() {
2311  let scaleX: number = 2.0;
2312  let scaleY: number = 1.0;
2313  if (pixelMap != undefined) {
2314    pixelMap.scale(scaleX, scaleY).then(() => {
2315      console.info('Succeeded in scaling pixelmap.');
2316    }).catch((err: BusinessError) => {
2317      console.error(`Failed to scale pixelmap. code is ${err.code}, message is ${err.message}`);
2318
2319    })
2320  }
2321}
2322```
2323
2324### scaleSync<sup>12+</sup>
2325
2326scaleSync(x: number, y: number): void
2327
2328以同步方法根据输入的宽高对图片进行缩放。
2329
2330**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2331
2332**系统能力:** SystemCapability.Multimedia.Image.Core
2333
2334**参数:**
2335
2336| 参数名 | 类型   | 必填 | 说明                            |
2337| ------ | ------ | ---- | ------------------------------- |
2338| x      | number | 是   | 宽度的缩放倍数。|
2339| y      | number | 是   | 高度的缩放倍数。|
2340
2341**错误码:**
2342
2343以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
2344
2345| 错误码ID | 错误信息 |
2346| ------- | --------------------------------------------|
2347|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
2348|  501    | Resource Unavailable |
2349
2350**示例:**
2351
2352```ts
2353import { BusinessError } from '@kit.BasicServicesKit';
2354
2355async function Demo() {
2356  let scaleX: number = 2.0;
2357  let scaleY: number = 1.0;
2358  if (pixelMap != undefined) {
2359    pixelMap.scaleSync(scaleX, scaleY);
2360  }
2361}
2362```
2363
2364### scale<sup>12+</sup>
2365
2366scale(x: number, y: number, level: AntiAliasingLevel): Promise\<void>
2367
2368根据输入的宽高对图片进行缩放,使用Promise形式返回。
2369
2370**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2371
2372**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2373
2374**系统能力:** SystemCapability.Multimedia.Image.Core
2375
2376**参数:**
2377
2378| 参数名 | 类型   | 必填 | 说明                            |
2379| ------ | ------ | ---- | ------------------------------- |
2380| x      | number | 是   | 宽度的缩放倍数。|
2381| y      | number | 是   | 高度的缩放倍数。|
2382| level  | [AntiAliasingLevel](#antialiasinglevel12) | 是   | 采用的缩放算法。|
2383
2384**返回值:**
2385
2386| 类型           | 说明                        |
2387| -------------- | --------------------------- |
2388| Promise\<void> |  Promise对象。无返回结果的Promise对象。|
2389
2390**错误码:**
2391
2392以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
2393
2394| 错误码ID | 错误信息 |
2395| ------- | --------------------------------------------|
2396|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
2397|  501    | Resource Unavailable |
2398
2399**示例:**
2400
2401```ts
2402import { BusinessError } from '@kit.BasicServicesKit';
2403
2404async function Demo() {
2405  let scaleX: number = 2.0;
2406  let scaleY: number = 1.0;
2407  if (pixelMap != undefined) {
2408    pixelMap.scale(scaleX, scaleY, image.AntiAliasingLevel.LOW).then(() => {
2409      console.info('Succeeded in scaling pixelmap.');
2410    }).catch((err: BusinessError) => {
2411      console.error(`Failed to scale pixelmap. code is ${err.code}, message is ${err.message}`);
2412
2413    })
2414  }
2415}
2416```
2417
2418### scaleSync<sup>12+</sup>
2419
2420scaleSync(x: number, y: number, level: AntiAliasingLevel): void
2421
2422以同步方法根据输入的宽高对图片进行缩放。
2423
2424**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2425
2426**系统能力:** SystemCapability.Multimedia.Image.Core
2427
2428**参数:**
2429
2430| 参数名 | 类型   | 必填 | 说明                            |
2431| ------ | ------ | ---- | ------------------------------- |
2432| x      | number | 是   | 宽度的缩放倍数。|
2433| y      | number | 是   | 高度的缩放倍数。|
2434| level  | [AntiAliasingLevel](#antialiasinglevel12) | 是   | 采用的缩放算法。|
2435
2436**错误码:**
2437
2438以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
2439
2440| 错误码ID | 错误信息 |
2441| ------- | --------------------------------------------|
2442|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
2443|  501    | Resource Unavailable |
2444
2445**示例:**
2446
2447```ts
2448import { BusinessError } from '@kit.BasicServicesKit';
2449
2450async function Demo() {
2451  let scaleX: number = 2.0;
2452  let scaleY: number = 1.0;
2453  if (pixelMap != undefined) {
2454    pixelMap.scaleSync(scaleX, scaleY, image.AntiAliasingLevel.LOW);
2455  }
2456}
2457```
2458
2459### translate<sup>9+</sup>
2460
2461translate(x: number, y: number, callback: AsyncCallback\<void>): void
2462
2463根据输入的坐标对图片进行位置变换,translate后的图片尺寸:width+X ,height+Y,使用callback形式返回。
2464
2465**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2466
2467**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2468
2469**系统能力:** SystemCapability.Multimedia.Image.Core
2470
2471**参数:**
2472
2473| 参数名   | 类型                 | 必填 | 说明                          |
2474| -------- | -------------------- | ---- | ----------------------------- |
2475| x        | number               | 是   | 区域横坐标。                  |
2476| y        | number               | 是   | 区域纵坐标。                  |
2477| callback | AsyncCallback\<void> | 是   | 回调函数。当对图片进行位置变换成功,err为undefined,否则为错误对象。|
2478
2479**示例:**
2480
2481```ts
2482import { BusinessError } from '@kit.BasicServicesKit';
2483
2484async function Demo() {
2485  let translateX: number = 50.0;
2486  let translateY: number = 10.0;
2487  if (pixelMap != undefined) {
2488    pixelMap.translate(translateX, translateY, (err: BusinessError) => {
2489      if (err) {
2490        console.error(`Failed to translate pixelmap. code is ${err.code}, message is ${err.message}`);
2491        return;
2492      } else {
2493        console.info("Succeeded in translating pixelmap.");
2494      }
2495    })
2496  }
2497}
2498```
2499
2500### translate<sup>9+</sup>
2501
2502translate(x: number, y: number): Promise\<void>
2503
2504根据输入的坐标对图片进行位置变换,translate后的图片尺寸:width+X ,height+Y,使用Promise形式返回。
2505
2506**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2507
2508**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2509
2510**系统能力:** SystemCapability.Multimedia.Image.Core
2511
2512**参数:**
2513
2514| 参数名 | 类型   | 必填 | 说明        |
2515| ------ | ------ | ---- | ----------- |
2516| x      | number | 是   | 区域横坐标。|
2517| y      | number | 是   | 区域纵坐标。|
2518
2519**返回值:**
2520
2521| 类型           | 说明                        |
2522| -------------- | --------------------------- |
2523| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
2524
2525**示例:**
2526
2527```ts
2528import { BusinessError } from '@kit.BasicServicesKit';
2529
2530async function Demo() {
2531  let translateX: number = 50.0;
2532  let translateY: number = 10.0;
2533  if (pixelMap != undefined) {
2534    pixelMap.translate(translateX, translateY).then(() => {
2535      console.info('Succeeded in translating pixelmap.');
2536    }).catch((err: BusinessError) => {
2537      console.error(`Failed to translate pixelmap. code is ${err.code}, message is ${err.message}`);
2538    })
2539  }
2540}
2541```
2542
2543### translateSync<sup>12+</sup>
2544
2545translateSync(x: number, y: number): void
2546
2547根据输入的坐标对图片进行位置变换并同步返回结果。
2548
2549**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2550
2551**系统能力:** SystemCapability.Multimedia.Image.Core
2552
2553**参数:**
2554
2555| 参数名   | 类型                 | 必填 | 说明                            |
2556| -------- | -------------------- | ---- | ------------------------------- |
2557| x        | number               | 是   | 宽度的缩放倍数。|
2558| y        | number               | 是   | 高度的缩放倍数。|
2559
2560**错误码:**
2561
2562以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
2563
2564| 错误码ID | 错误信息 |
2565| ------- | --------------------------------------------|
2566|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
2567|  501    | Resource Unavailable |
2568
2569**示例:**
2570
2571```ts
2572import { BusinessError } from '@kit.BasicServicesKit';
2573
2574async function Demo() {
2575  let translateX : number = 50.0;
2576  let translateY : number = 10.0;
2577  if (pixelMap != undefined) {
2578    pixelMap.translateSync(translateX, translateY);
2579  }
2580}
2581```
2582
2583### rotate<sup>9+</sup>
2584
2585rotate(angle: number, callback: AsyncCallback\<void>): void
2586
2587根据输入的角度对图片进行旋转,使用callback形式返回。
2588
2589**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2590
2591**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2592
2593**系统能力:** SystemCapability.Multimedia.Image.Core
2594
2595**参数:**
2596
2597| 参数名   | 类型                 | 必填 | 说明                          |
2598| -------- | -------------------- | ---- | ----------------------------- |
2599| angle    | number               | 是   | 图片旋转的角度。              |
2600| callback | AsyncCallback\<void> | 是   | 回调函数。当对图片进行旋转成功,err为undefined,否则为错误对象。|
2601
2602**示例:**
2603
2604```ts
2605import { BusinessError } from '@kit.BasicServicesKit';
2606
2607async function Demo() {
2608  let angle: number = 90.0;
2609  if (pixelMap != undefined) {
2610    pixelMap.rotate(angle, (err: BusinessError) => {
2611      if (err) {
2612        console.error(`Failed to rotate pixelmap. code is ${err.code}, message is ${err.message}`);
2613        return;
2614      } else {
2615        console.info("Succeeded in rotating pixelmap.");
2616      }
2617    })
2618  }
2619}
2620```
2621
2622### rotate<sup>9+</sup>
2623
2624rotate(angle: number): Promise\<void>
2625
2626根据输入的角度对图片进行旋转,使用Promise形式返回。
2627
2628**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2629
2630**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2631
2632**系统能力:** SystemCapability.Multimedia.Image.Core
2633
2634**参数:**
2635
2636| 参数名 | 类型   | 必填 | 说明                          |
2637| ------ | ------ | ---- | ----------------------------- |
2638| angle  | number | 是   | 图片旋转的角度。              |
2639
2640**返回值:**
2641
2642| 类型           | 说明                        |
2643| -------------- | --------------------------- |
2644| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
2645
2646**示例:**
2647
2648```ts
2649import { BusinessError } from '@kit.BasicServicesKit';
2650
2651async function Demo() {
2652  let angle: number = 90.0;
2653  if (pixelMap != undefined) {
2654    pixelMap.rotate(angle).then(() => {
2655      console.info('Succeeded in rotating pixelmap.');
2656    }).catch((err: BusinessError) => {
2657      console.error(`Failed to rotate pixelmap. code is ${err.code}, message is ${err.message}`);
2658    })
2659  }
2660}
2661```
2662
2663### rotateSync<sup>12+</sup>
2664
2665rotateSync(angle: number): void
2666
2667根据输入的角度对图片进行旋转并同步返回结果。
2668
2669**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2670
2671**系统能力:** SystemCapability.Multimedia.Image.Core
2672
2673**参数:**
2674
2675| 参数名   | 类型                 | 必填 | 说明                          |
2676| -------- | -------------------- | ---- | ----------------------------- |
2677| angle    | number               | 是   | 图片旋转的角度。              |
2678
2679**错误码:**
2680
2681以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
2682
2683| 错误码ID | 错误信息 |
2684| ------- | --------------------------------------------|
2685|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
2686|  501    | Resource Unavailable |
2687
2688**示例:**
2689
2690```ts
2691import { BusinessError } from '@kit.BasicServicesKit';
2692
2693async function Demo() {
2694  let angle : number = 90.0;
2695  if (pixelMap != undefined) {
2696    pixelMap.rotateSync(angle);
2697  }
2698}
2699```
2700
2701### flip<sup>9+</sup>
2702
2703flip(horizontal: boolean, vertical: boolean, callback: AsyncCallback\<void>): void
2704
2705根据输入的条件对图片进行翻转,使用callback形式返回。
2706
2707**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2708
2709**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2710
2711**系统能力:** SystemCapability.Multimedia.Image.Core
2712
2713**参数:**
2714
2715| 参数名     | 类型                 | 必填 | 说明                          |
2716| ---------- | -------------------- | ---- | ----------------------------- |
2717| horizontal | boolean              | 是   | 水平翻转。                    |
2718| vertical   | boolean              | 是   | 垂直翻转。                    |
2719| callback   | AsyncCallback\<void> | 是   | 回调函数,当对图片翻转成功,err为undefined,否则为错误对象。|
2720
2721**示例:**
2722
2723```ts
2724import { BusinessError } from '@kit.BasicServicesKit';
2725
2726async function Demo() {
2727  let horizontal: boolean = true;
2728  let vertical: boolean = false;
2729  if (pixelMap != undefined) {
2730    pixelMap.flip(horizontal, vertical, (err: BusinessError) => {
2731      if (err) {
2732        console.error(`Failed to flip pixelmap. code is ${err.code}, message is ${err.message}`);
2733        return;
2734      } else {
2735        console.info("Succeeded in flipping pixelmap.");
2736      }
2737    })
2738  }
2739}
2740```
2741
2742### flip<sup>9+</sup>
2743
2744flip(horizontal: boolean, vertical: boolean): Promise\<void>
2745
2746根据输入的条件对图片进行翻转,使用Promise形式返回。
2747
2748**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2749
2750**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2751
2752**系统能力:** SystemCapability.Multimedia.Image.Core
2753
2754**参数:**
2755
2756| 参数名     | 类型    | 必填 | 说明      |
2757| ---------- | ------- | ---- | --------- |
2758| horizontal | boolean | 是   | 水平翻转。|
2759| vertical   | boolean | 是   | 垂直翻转。|
2760
2761**返回值:**
2762
2763| 类型           | 说明                        |
2764| -------------- | --------------------------- |
2765| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
2766
2767**示例:**
2768
2769```ts
2770import { BusinessError } from '@kit.BasicServicesKit';
2771
2772async function Demo() {
2773  let horizontal: boolean = true;
2774  let vertical: boolean = false;
2775  if (pixelMap != undefined) {
2776    pixelMap.flip(horizontal, vertical).then(() => {
2777      console.info('Succeeded in flipping pixelmap.');
2778    }).catch((err: BusinessError) => {
2779      console.error(`Failed to flip pixelmap. code is ${err.code}, message is ${err.message}`);
2780    })
2781  }
2782}
2783```
2784
2785### flipSync<sup>12+</sup>
2786
2787flipSync(horizontal: boolean, vertical: boolean): void
2788
2789根据输入的条件对图片进行翻转并同步返回结果。
2790
2791**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2792
2793**系统能力:** SystemCapability.Multimedia.Image.Core
2794
2795**参数:**
2796
2797| 参数名     | 类型                 | 必填 | 说明                          |
2798| ---------- | -------------------- | ---- | ----------------------------- |
2799| horizontal | boolean              | 是   | 水平翻转。                    |
2800| vertical   | boolean              | 是   | 垂直翻转。                    |
2801
2802**错误码:**
2803
2804以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
2805
2806| 错误码ID | 错误信息 |
2807| ------- | --------------------------------------------|
2808|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
2809|  501    | Resource Unavailable |
2810
2811**示例:**
2812
2813```ts
2814import { BusinessError } from '@kit.BasicServicesKit';
2815
2816async function Demo() {
2817  let horizontal : boolean = true;
2818  let vertical : boolean = false;
2819  if (pixelMap != undefined) {
2820    pixelMap.flipSync(horizontal, vertical);
2821  }
2822}
2823```
2824
2825### crop<sup>9+</sup>
2826
2827crop(region: Region, callback: AsyncCallback\<void>): void
2828
2829根据输入的尺寸对图片进行裁剪,使用callback形式返回。
2830
2831**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2832
2833**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2834
2835**系统能力:** SystemCapability.Multimedia.Image.Core
2836
2837**参数:**
2838
2839| 参数名   | 类型                 | 必填 | 说明                          |
2840| -------- | -------------------- | ---- | ----------------------------- |
2841| region   | [Region](#region8)   | 是   | 裁剪的尺寸。                  |
2842| callback | AsyncCallback\<void> | 是   |  回调函数。当对图片进行裁剪成功,err为undefined,否则为错误对象。|
2843
2844**示例:**
2845
2846```ts
2847import { BusinessError } from '@kit.BasicServicesKit';
2848
2849async function Demo() {
2850  let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } };
2851  if (pixelMap != undefined) {
2852    pixelMap.crop(region, (err: BusinessError) => {
2853      if (err) {
2854        console.error(`Failed to crop pixelmap. code is ${err.code}, message is ${err.message}`);
2855        return;
2856      } else {
2857        console.info("Succeeded in cropping pixelmap.");
2858      }
2859    })
2860  }
2861}
2862```
2863
2864### crop<sup>9+</sup>
2865
2866crop(region: Region): Promise\<void>
2867
2868根据输入的尺寸对图片进行裁剪,使用Promise形式返回。
2869
2870**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2871
2872**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2873
2874**系统能力:** SystemCapability.Multimedia.Image.Core
2875
2876**参数:**
2877
2878| 参数名 | 类型               | 必填 | 说明        |
2879| ------ | ------------------ | ---- | ----------- |
2880| region | [Region](#region8) | 是   | 裁剪的尺寸。|
2881
2882**返回值:**
2883
2884| 类型           | 说明                        |
2885| -------------- | --------------------------- |
2886| Promise\<void> |  Promise对象。无返回结果的Promise对象。|
2887
2888**示例:**
2889
2890```ts
2891import { BusinessError } from '@kit.BasicServicesKit';
2892
2893async function Demo() {
2894  let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } };
2895  if (pixelMap != undefined) {
2896    pixelMap.crop(region).then(() => {
2897      console.info('Succeeded in cropping pixelmap.');
2898    }).catch((err: BusinessError) => {
2899      console.error(`Failed to crop pixelmap. code is ${err.code}, message is ${err.message}`);
2900
2901    });
2902  }
2903}
2904```
2905
2906### cropSync<sup>12+</sup>
2907
2908cropSync(region: Region): void
2909
2910根据输入的尺寸裁剪图片。
2911
2912**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2913
2914**系统能力:** SystemCapability.Multimedia.Image.Core
2915
2916**参数:**
2917
2918| 参数名   | 类型                 | 必填 | 说明                          |
2919| -------- | -------------------- | ---- | ----------------------------- |
2920| region   | [Region](#region8)   | 是   | 裁剪的尺寸。                  |
2921
2922**错误码:**
2923
2924以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
2925
2926| 错误码ID | 错误信息 |
2927| ------- | --------------------------------------------|
2928|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
2929|  501    | Resource Unavailable |
2930
2931**示例:**
2932
2933```ts
2934import { BusinessError } from '@kit.BasicServicesKit';
2935
2936async function Demo() {
2937  let region : image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } };
2938  if (pixelMap != undefined) {
2939    pixelMap.cropSync(region);
2940  }
2941}
2942```
2943
2944### getColorSpace<sup>10+</sup>
2945
2946getColorSpace(): colorSpaceManager.ColorSpaceManager
2947
2948获取图像广色域信息。
2949
2950**系统能力:** SystemCapability.Multimedia.Image.Core
2951
2952**返回值:**
2953
2954| 类型                                | 说明             |
2955| ----------------------------------- | ---------------- |
2956| [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | 图像广色域信息。 |
2957
2958**错误码:**
2959
2960以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
2961
2962| 错误码ID | 错误信息 |
2963| ------- | --------------------------------------------|
2964| 62980101| If the image data abnormal.            |
2965| 62980103| If the image data unsupport.             |
2966| 62980115| If the image parameter invalid.            |
2967
2968**示例:**
2969
2970```ts
2971async function Demo() {
2972  if (pixelMap != undefined) {
2973    let csm = pixelMap.getColorSpace();
2974  }
2975}
2976```
2977
2978### setColorSpace<sup>10+</sup>
2979
2980setColorSpace(colorSpace: colorSpaceManager.ColorSpaceManager): void
2981
2982设置图像广色域信息。
2983
2984**系统能力:** SystemCapability.Multimedia.Image.Core
2985
2986**参数:**
2987
2988| 参数名     | 类型                                | 必填 | 说明            |
2989| ---------- | ----------------------------------- | ---- | --------------- |
2990| colorSpace | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | 是   | 图像广色域信息。|
2991
2992**错误码:**
2993
2994以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
2995
2996| 错误码ID | 错误信息 |
2997| ------- | --------------------------------------------|
2998| 62980111| The image source data is incomplete.        |
2999| 62980115| If the image parameter invalid.             |
3000
3001**示例:**
3002
3003```ts
3004import { colorSpaceManager } from '@kit.ArkGraphics2D';
3005async function Demo() {
3006  let colorSpaceName = colorSpaceManager.ColorSpace.SRGB;
3007  let csm: colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName);
3008  if (pixelMap != undefined) {
3009    pixelMap.setColorSpace(csm);
3010  }
3011}
3012```
3013
3014### applyColorSpace<sup>11+</sup>
3015
3016applyColorSpace(targetColorSpace: colorSpaceManager.ColorSpaceManager, callback: AsyncCallback\<void>): void
3017
3018根据输入的目标色彩空间对图像像素颜色进行色彩空间转换,使用callback形式返回。
3019
3020**系统能力:** SystemCapability.Multimedia.Image.Core
3021
3022**参数:**
3023
3024| 参数名   | 类型                 | 必填 | 说明                          |
3025| -------- | -------------------- | ---- | ----------------------------- |
3026| targetColorSpace | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | 是   | 目标色彩空间,支持SRGB、DCI_P3、DISPLAY_P3、ADOBE_RGB_1998。|
3027| callback | AsyncCallback\<void> | 是   | 回调函数。当对图像像素颜色进行色彩空间转换成功,err为undefined,否则为错误对象。|
3028
3029**错误码:**
3030
3031以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
3032
3033| 错误码ID | 错误信息 |
3034| ------- | ------------------------------------------|
3035| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
3036| 62980104| Failed to initialize the internal object. |
3037| 62980108| Failed to convert the color space.       |
3038| 62980115| Invalid image parameter.            |
3039
3040**示例:**
3041
3042```ts
3043import { colorSpaceManager } from '@kit.ArkGraphics2D';
3044import { BusinessError } from '@kit.BasicServicesKit';
3045
3046async function Demo() {
3047  let colorSpaceName = colorSpaceManager.ColorSpace.SRGB;
3048  let targetColorSpace: colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName);
3049  if (pixelMap != undefined) {
3050    pixelMap.applyColorSpace(targetColorSpace, (err: BusinessError) => {
3051      if (err) {
3052        console.error(`Failed to apply color space for pixelmap object. code is ${err.code}, message is ${err.message}`);
3053        return;
3054      } else {
3055        console.info('Succeeded in applying color space for pixelmap object.');
3056      }
3057    })
3058  }
3059}
3060```
3061
3062### applyColorSpace<sup>11+</sup>
3063
3064applyColorSpace(targetColorSpace: colorSpaceManager.ColorSpaceManager): Promise\<void>
3065
3066根据输入的目标色彩空间对图像像素颜色进行色彩空间转换,使用Promise形式返回。
3067
3068**系统能力:** SystemCapability.Multimedia.Image.Core
3069
3070**参数:**
3071
3072| 参数名 | 类型               | 必填 | 说明        |
3073| ------ | ------------------ | ---- | ----------- |
3074| targetColorSpace | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | 是   | 目标色彩空间,支持SRGB、DCI_P3、DISPLAY_P3、ADOBE_RGB_1998。|
3075
3076**返回值:**
3077
3078| 类型           | 说明                        |
3079| -------------- | --------------------------- |
3080| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
3081
3082**错误码:**
3083
3084以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
3085
3086| 错误码ID | 错误信息 |
3087| ------- | ------------------------------------------|
3088| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
3089| 62980104| Failed to initialize the internal object. |
3090| 62980108| Failed to convert the color space.       |
3091| 62980115| Invalid image parameter.            |
3092
3093**示例:**
3094
3095```ts
3096import { colorSpaceManager } from '@kit.ArkGraphics2D';
3097import { BusinessError } from '@kit.BasicServicesKit';
3098
3099async function Demo() {
3100  let colorSpaceName = colorSpaceManager.ColorSpace.SRGB;
3101  let targetColorSpace: colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName);
3102  if (pixelMap != undefined) {
3103    pixelMap.applyColorSpace(targetColorSpace).then(() => {
3104      console.info('Succeeded in applying color space for pixelmap object.');
3105    }).catch((error: BusinessError) => {
3106      console.error(`Failed to apply color space for pixelmap object. code is ${error.code}, message is ${error.message}`);
3107    })
3108  }
3109}
3110```
3111
3112### toSdr<sup>12+<sup>
3113
3114toSdr(): Promise\<void>
3115
3116将HDR的图像内容转换为SDR的图像内容,异步使用Promise形式返回。
3117
3118**系统能力:** SystemCapability.Multimedia.Image.Core
3119
3120**返回值:**
3121
3122| 类型           | 说明                        |
3123| -------------- | --------------------------- |
3124| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
3125
3126**错误码:**
3127
3128以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
3129
3130| 错误码ID | 错误信息 |
3131| ------- | --------------------------------------------|
3132| 62980137 | Invalid image operation.              |
3133
3134**示例:**
3135
3136```ts
3137import image from '@ohos.multimedia.image'
3138import resourceManager from '@ohos.resourceManager'
3139import { BusinessError } from '@kit.BasicServicesKit';
3140
3141//此处'hdr.jpg'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。
3142let img = getContext().resourceManager.getMediaContentSync($r('app.media.hdr'));
3143let imageSource = image.createImageSource(img.buffer.slice(0));
3144let decodingOptions: image.DecodingOptions = {
3145  desiredDynamicRange: image.DecodingDynamicRange.AUTO
3146};
3147let pixelmap = imageSource.createPixelMapSync(decodingOptions);
3148if (pixelmap != undefined) {
3149  console.info('Succeeded in creating pixelMap object.');
3150  pixelmap.toSdr().then(() => {
3151    let imageInfo = pixelmap.getImageInfoSync();
3152    console.info("after toSdr ,imageInfo isHdr:" + imageInfo.isHdr);
3153  }).catch((err: BusinessError) => {
3154    console.error(`Failed to set sdr. code is ${err.code}, message is ${err.message}`);
3155  });
3156} else {
3157  console.info('Failed to create pixelMap.');
3158}
3159```
3160
3161### getMetadata<sup>12+</sup>
3162
3163getMetadata(key: HdrMetadataKey): HdrMetadataValue
3164
3165从PixelMap中获取元数据。
3166
3167**系统能力:** SystemCapability.Multimedia.Image.Core
3168
3169**参数:**
3170
3171| 参数名        | 类型                             | 必填 | 说明             |
3172| ------------- | -------------------------------- | ---- | ---------------- |
3173| key | [HdrMetadataKey](#hdrmetadatakey12) | 是   | HDR元数据的关键字,可用于查询对应值。 |
3174
3175**返回值:**
3176
3177| 类型                              | 说明                              |
3178| --------------------------------- | --------------------------------- |
3179| [HdrMetadataValue](#hdrmetadatavalue12) | 返回元数据的值。 |
3180
3181**错误码:**
3182
3183以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
3184
3185| 错误码ID | 错误信息 |
3186| ------- | --------------------------------------------|
3187| 401| Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.          |
3188| 501 | Resource unavailable.          |
3189| 62980173 | The DMA memory does not exist.          |
3190| 62980302 | Memory copy failed.          |
3191
3192**示例:**
3193
3194```ts
3195import { BusinessError } from '@kit.BasicServicesKit';
3196import image from '@ohos.multimedia.image'
3197
3198// 'app.media.test'需要替换为本地hdr图片。
3199let img = getContext().resourceManager.getMediaContentSync($r('app.media.test'));
3200let imageSource = image.createImageSource(img.buffer.slice(0));
3201let decodingOptions: image.DecodingOptions = {
3202  desiredDynamicRange: image.DecodingDynamicRange.AUTO
3203};
3204let pixelmap = imageSource.createPixelMapSync(decodingOptions);
3205if (pixelmap != undefined) {
3206  console.info('Succeeded in creating pixelMap object.');
3207  try {
3208    let staticMetadata = pixelmap.getMetadata(image.HdrMetadataKey.HDR_STATIC_METADATA);
3209    console.info("getmetadata:" + JSON.stringify(staticMetadata));
3210  } catch (e) {
3211    console.info('pixelmap create failed' + e);
3212  }
3213} else {
3214  console.info('Failed to create pixelMap.');
3215}
3216```
3217
3218### setMetadata<sup>12+</sup>
3219
3220setMetadata(key: HdrMetadataKey, value: HdrMetadataValue): Promise\<void>
3221
3222设置PixelMap元数据。
3223
3224**系统能力:** SystemCapability.Multimedia.Image.Core
3225
3226**参数:**
3227
3228| 参数名        | 类型                             | 必填 | 说明             |
3229| ------------- | -------------------------------- | ---- | ---------------- |
3230| key | [HdrMetadataKey](#hdrmetadatakey12) | 是   | HDR元数据的关键字,用于设置对应值 |
3231| value | [HdrMetadataValue](#hdrmetadatavalue12) | 是   | 元数据的值 |
3232
3233**返回值:**
3234
3235| 类型           | 说明                  |
3236| -------------- | --------------------- |
3237| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
3238
3239**错误码:**
3240
3241以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
3242
3243| 错误码ID | 错误信息 |
3244| ------- | --------------------------------------------|
3245| 401|  Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.         |
3246| 501 | Resource unavailable.          |
3247| 62980173 | The DMA memory does not exist.          |
3248| 62980302 | Memory copy failed.          |
3249
3250**示例:**
3251
3252```ts
3253import image from '@ohos.multimedia.image'
3254import { BusinessError } from '@kit.BasicServicesKit';
3255
3256let staticMetadata: image.HdrStaticMetadata = {
3257  displayPrimariesX: [1.1, 1.1, 1.1],
3258  displayPrimariesY: [1.2, 1.2, 1.2],
3259  whitePointX: 1.1,
3260  whitePointY: 1.2,
3261  maxLuminance: 2.1,
3262  minLuminance: 1.0,
3263  maxContentLightLevel: 2.1,
3264  maxFrameAverageLightLevel: 2.1,
3265}
3266const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
3267let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
3268image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => {
3269  pixelMap.setMetadata(image.HdrMetadataKey.HDR_STATIC_METADATA, staticMetadata).then((pixelMap: image.PixelMap) => {
3270    console.info('Succeeded in setting pixelMap metadata.');
3271  }).catch((error: BusinessError) => {
3272    console.error(`Failed to set the metadata.code ${error.code},message is ${error.message}`);
3273  })
3274}).catch((error: BusinessError) => {
3275  console.error(`Failed to create the PixelMap.code ${error.code},message is ${error.message}`);
3276})
3277
3278```
3279
3280### setTransferDetached<sup>12+<sup>
3281
3282setTransferDetached(detached: boolean): void
3283
3284pixelmap在跨线程传输时,断开原线程的引用。适用于需立即释放pixelmap的场景。
3285
3286**系统能力:** SystemCapability.Multimedia.Image.Core
3287
3288**参数:**
3289
3290| 参数名   | 类型               | 必填 | 说明                          |
3291| ------- | ------------------ | ---- | ----------------------------- |
3292| detached | boolean   | 是   | 是否断开原线程引用                  |
3293
3294**错误码:**
3295
3296以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
3297
3298| 错误码ID | 错误信息 |
3299| ------- | --------------------------------------------|
3300|  501    | Resource Unavailable |
3301
3302**示例:**
3303
3304```ts
3305import { BusinessError } from '@kit.BasicServicesKit';
3306import image from '@ohos.multimedia.image';
3307import taskpool from '@ohos.taskpool';
3308
3309@Concurrent
3310// 子线程方法
3311async function loadPixelMap(rawFileDescriptor: number): Promise<PixelMap> {
3312  // 创建imageSource。
3313  const imageSource = image.createImageSource(rawFileDescriptor);
3314  // 创建pixelMap。
3315  const pixelMap = imageSource.createPixelMapSync();
3316  // 释放imageSource。
3317  imageSource.release();
3318  // 使pixelMap在跨线程传输完成后,断开原线程的引用。
3319  pixelMap.setTransferDetached(true);
3320  // 返回pixelMap给主线程。
3321  return pixelMap;
3322}
3323
3324@Entry
3325@Component
3326struct Demo {
3327  @State pixelMap: PixelMap | undefined = undefined;
3328  // 主线程方法
3329  private loadImageFromThread(): void {
3330    const resourceMgr = getContext(this).resourceManager;
3331    // 此处‘example.jpg’仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。
3332    resourceMgr.getRawFd('example.jpg').then(rawFileDescriptor => {
3333      taskpool.execute(loadPixelMap, rawFileDescriptor).then(pixelMap => {
3334        if (pixelMap) {
3335          this.pixelMap = pixelMap as PixelMap;
3336          console.log('Succeeded in creating pixelMap.');
3337          // 主线程释放pixelMap。由于子线程返回pixelMap时已调用setTransferDetached,所以此处能够立即释放pixelMap。
3338          this.pixelMap.release();
3339        } else {
3340          console.error('Failed to create pixelMap.');
3341        }
3342      });
3343    });
3344  }
3345}
3346```
3347
3348### marshalling<sup>10+</sup>
3349
3350marshalling(sequence: rpc.MessageSequence): void
3351
3352将PixelMap序列化后写入MessageSequence。
3353
3354**系统能力:** SystemCapability.Multimedia.Image.Core
3355
3356**参数:**
3357
3358| 参数名                 | 类型                                                  | 必填 | 说明                                     |
3359| ---------------------- | ------------------------------------------------------ | ---- | ---------------------------------------- |
3360| sequence               | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9)  | 是   | 新创建的MessageSequence。                 |
3361
3362**错误码:**
3363
3364以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
3365
3366| 错误码ID | 错误信息 |
3367| ------- | --------------------------------------------|
3368| 62980115 | Invalid image parameter.              |
3369| 62980097 | IPC error.             |
3370
3371**示例:**
3372
3373```ts
3374import { image } from '@kit.ImageKit';
3375import { rpc } from '@kit.IPCKit';
3376
3377class MySequence implements rpc.Parcelable {
3378  pixel_map: image.PixelMap;
3379  constructor(conPixelMap : image.PixelMap) {
3380    this.pixel_map = conPixelMap;
3381  }
3382  marshalling(messageSequence : rpc.MessageSequence) {
3383    this.pixel_map.marshalling(messageSequence);
3384    console.info('marshalling');
3385    return true;
3386  }
3387  unmarshalling(messageSequence : rpc.MessageSequence) {
3388    image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}}).then((pixelParcel: image.PixelMap) => {
3389      pixelParcel.unmarshalling(messageSequence).then(async (pixelMap: image.PixelMap) => {
3390        this.pixel_map = pixelMap;
3391        pixelMap.getImageInfo().then((imageInfo: image.ImageInfo) => {
3392          console.info("unmarshalling information h:" + imageInfo.size.height + "w:" + imageInfo.size.width);
3393        })
3394      })
3395    });
3396    return true;
3397  }
3398}
3399async function Demo() {
3400  const color: ArrayBuffer = new ArrayBuffer(96);
3401  let bufferArr: Uint8Array = new Uint8Array(color);
3402  for (let i = 0; i < bufferArr.length; i++) {
3403    bufferArr[i] = 0x80;
3404  }
3405  let opts: image.InitializationOptions = {
3406    editable: true,
3407    pixelFormat: 4,
3408    size: { height: 4, width: 6 },
3409    alphaType: 3
3410  }
3411  let pixelMap: image.PixelMap | undefined = undefined;
3412  image.createPixelMap(color, opts).then((srcPixelMap: image.PixelMap) => {
3413    pixelMap = srcPixelMap;
3414  })
3415  if (pixelMap != undefined) {
3416    // 序列化
3417    let parcelable: MySequence = new MySequence(pixelMap);
3418    let data: rpc.MessageSequence = rpc.MessageSequence.create();
3419    data.writeParcelable(parcelable);
3420
3421    // 反序列化 rpc获取到data
3422    let ret: MySequence = new MySequence(pixelMap);
3423    data.readParcelable(ret);
3424  }
3425}
3426```
3427
3428### unmarshalling<sup>10+</sup>
3429
3430unmarshalling(sequence: rpc.MessageSequence): Promise\<PixelMap>
3431
3432从MessageSequence中获取PixelMap,
3433如需使用同步方式创建PixelMap可使用:[createPixelMapFromParcel](#imagecreatepixelmapfromparcel11)。
3434
3435**系统能力:** SystemCapability.Multimedia.Image.Core
3436
3437**参数:**
3438
3439| 参数名                 | 类型                                                  | 必填 | 说明                                     |
3440| ---------------------- | ----------------------------------------------------- | ---- | ---------------------------------------- |
3441| sequence               | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | 是   | 保存有PixelMap信息的MessageSequence。      |
3442
3443**返回值:**
3444
3445| 类型                             | 说明                  |
3446| -------------------------------- | --------------------- |
3447| Promise\<[PixelMap](#pixelmap7)> |Promise对象,返回PixelMap。 |
3448
3449**错误码:**
3450
3451以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
3452
3453| 错误码ID | 错误信息 |
3454| ------- | --------------------------------------------|
3455| 62980115 | Invalid image parameter.              |
3456| 62980097 | IPC error.              |
3457| 62980096 | The operation failed.         |
3458
3459**示例:**
3460
3461```ts
3462import { image } from '@kit.ImageKit';
3463import { rpc } from '@kit.IPCKit';
3464
3465class MySequence implements rpc.Parcelable {
3466  pixel_map: image.PixelMap;
3467  constructor(conPixelMap: image.PixelMap) {
3468    this.pixel_map = conPixelMap;
3469  }
3470  marshalling(messageSequence: rpc.MessageSequence) {
3471    this.pixel_map.marshalling(messageSequence);
3472    console.info('marshalling');
3473    return true;
3474  }
3475  unmarshalling(messageSequence: rpc.MessageSequence) {
3476    image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}}).then((pixelParcel : image.PixelMap) => {
3477      pixelParcel.unmarshalling(messageSequence).then(async (pixelMap : image.PixelMap) => {
3478        this.pixel_map = pixelMap;
3479        pixelMap.getImageInfo().then((imageInfo : image.ImageInfo) => {
3480          console.info("unmarshalling information h:" + imageInfo.size.height + "w:" + imageInfo.size.width);
3481        })
3482      })
3483    });
3484    return true;
3485  }
3486}
3487async function Demo() {
3488  const color: ArrayBuffer = new ArrayBuffer(96);
3489  let bufferArr: Uint8Array = new Uint8Array(color);
3490  for (let i = 0; i < bufferArr.length; i++) {
3491    bufferArr[i] = 0x80;
3492  }
3493  let opts: image.InitializationOptions = {
3494    editable: true,
3495    pixelFormat: 4,
3496    size: { height: 4, width: 6 },
3497    alphaType: 3
3498  }
3499  let pixelMap: image.PixelMap | undefined = undefined;
3500  image.createPixelMap(color, opts).then((srcPixelMap : image.PixelMap) => {
3501    pixelMap = srcPixelMap;
3502  })
3503  if (pixelMap != undefined) {
3504    // 序列化
3505    let parcelable: MySequence = new MySequence(pixelMap);
3506    let data : rpc.MessageSequence = rpc.MessageSequence.create();
3507    data.writeParcelable(parcelable);
3508
3509    // 反序列化 rpc获取到data
3510    let ret : MySequence = new MySequence(pixelMap);
3511    data.readParcelable(ret);
3512  }
3513}
3514```
3515
3516### release<sup>7+</sup>
3517
3518release():Promise\<void>
3519
3520释放PixelMap对象,使用Promise形式返回释放结果。
3521
3522ArkTS有内存回收机制,PixelMap对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
3523
3524**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
3525
3526**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3527
3528**系统能力:** SystemCapability.Multimedia.Image.Core
3529
3530**返回值:**
3531
3532| 类型           | 说明                            |
3533| -------------- | ------------------------------- |
3534| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
3535
3536**示例:**
3537
3538```ts
3539import { BusinessError } from '@kit.BasicServicesKit';
3540
3541async function Demo() {
3542  if (pixelMap != undefined) {
3543    pixelMap.release().then(() => {
3544      console.info('Succeeded in releasing pixelmap object.');
3545    }).catch((error: BusinessError) => {
3546      console.error(`Failed to release pixelmap object. code is ${error.code}, message is ${error.message}`);
3547    })
3548  }
3549}
3550```
3551
3552### release<sup>7+</sup>
3553
3554release(callback: AsyncCallback\<void>): void
3555
3556释放PixelMap对象,使用callback形式返回释放结果。
3557
3558ArkTS有内存回收机制,PixelMap对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
3559
3560**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
3561
3562**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3563
3564**系统能力:** SystemCapability.Multimedia.Image.Core
3565
3566**参数:**
3567
3568| 参数名   | 类型                 | 必填 | 说明               |
3569| -------- | -------------------- | ---- | ------------------ |
3570| callback | AsyncCallback\<void> | 是   | 回调函数。当对PixelMap对象释放成功,err为undefined,否则为错误对象。 |
3571
3572**示例:**
3573
3574```ts
3575import { BusinessError } from '@kit.BasicServicesKit';
3576
3577async function Demo() {
3578  if (pixelMap != undefined) {
3579    pixelMap.release((err: BusinessError) => {
3580      if (err) {
3581        console.error(`Failed to release pixelmap object. code is ${err.code}, message is ${err.message}`);
3582        return;
3583      } else {
3584        console.info('Succeeded in releasing pixelmap object.');
3585      }
3586    })
3587  }
3588}
3589```
3590
3591### convertPixelFormat<sup>12+</sup>
3592
3593convertPixelFormat(targetPixelFormat: PixelMapFormat): Promise\<void>
3594
3595YUV和RGB类型互转,目前仅支持NV12/NV21RGB888/RGBA8888/RGB565/BGRA8888/RGBAF16互转,YCRCB_P010/YCBCR_P010与RGBA1010102互转。
3596
3597**系统能力:** SystemCapability.Multimedia.Image.Core
3598
3599**参数:**
3600
3601| 参数名   | 类型                 | 必填 | 说明               |
3602| -------- | -------------------- | ---- | ------------------ |
3603| targetPixelFormat | [PixelMapFormat](#pixelmapformat7) | 是   | 目标像素格式,用于YUV和RGB类型互转。目前仅支持NV12/NV21RGB888/RGBA8888/RGB565/BGRA8888/RGBAF16互转,YCRCB_P010/YCBCR_P010与RGBA1010102互转。 |
3604
3605**返回值:**
3606
3607| 类型           | 说明                            |
3608| -------------- | ------------------------------- |
3609| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
3610
3611**错误码:**
3612
3613以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
3614
3615| 错误码ID | 错误信息 |
3616| ------- | --------------------------------------------|
3617| 62980111 | The image source data is incomplete. |
3618| 62980115 | Invalid input parameter.              |
3619| 62980178 | Failed to create the pixelmap. |
3620| 62980274 | The conversion failed |
3621| 62980276 | The type to be converted is an unsupported target pixel format|
3622
3623**示例:**
3624
3625```ts
3626import { BusinessError } from '@kit.BasicServicesKit';
3627
3628if (pixelMap != undefined) {
3629  // 设置目标像素格式为NV12
3630  let targetPixelFormat = image.PixelMapFormat.NV12;
3631  pixelMap.convertPixelFormat(targetPixelFormat).then(() => {
3632    // pixelMap转换成NV12格式成功
3633    console.info('PixelMapFormat convert Succeeded');
3634  }).catch((error: BusinessError) => {
3635    // pixelMap转换成NV12格式失败
3636    console.error(`PixelMapFormat convert Failed. code is ${error.code}, message is ${error.message}`);
3637  })
3638}
3639```
3640
3641### setMemoryNameSync<sup>13+</sup>
3642
3643setMemoryNameSync(name: string): void
3644
3645设置PixelMap内存标识符。
3646
3647**系统能力:** SystemCapability.Multimedia.Image.Core
3648
3649**参数:**
3650
3651| 参数名        | 类型                             | 必填 | 说明             |
3652| ------------- | -------------------------------- | ---- | ---------------- |
3653| name | string | 是   | pixelmap内存标识符,只允许DMA和ASHMEM内存形式的piexelmap设置,支持1-31位长度。 |
3654
3655**错误码:**
3656
3657以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
3658
3659| 错误码ID | 错误信息 |
3660| ------- | --------------------------------------------|
3661| 401 | Parameter error. Possible causes: 1.The length of the input parameter is too long. 2.Parameter verification failed. |
3662| 501 | Resource unavailable. |
3663| 62980286 | Memory format not supported. |
3664
3665**示例:**
3666
3667```ts
3668import { BusinessError } from '@ohos.base';
3669
3670async Demo() {
3671  if (pixelMap != undefined) {
3672    try {
3673      pixelMap.setMemoryNameSync("PixelMapName Test");
3674    } catch(e) {
3675      let error = e as BusinessError;
3676      console.error(`setMemoryNameSync error. code is ${error.code}, message is ${error.message}`);
3677    }
3678  }
3679}
3680```
3681
3682## image.createImageSource
3683
3684createImageSource(uri: string): ImageSource
3685
3686通过传入的uri创建图片源实例。
3687
3688
3689**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3690
3691**系统能力:** SystemCapability.Multimedia.Image.ImageSource
3692
3693**参数:**
3694
3695| 参数名 | 类型   | 必填 | 说明                               |
3696| ------ | ------ | ---- | ---------------------------------- |
3697| uri    | string | 是   | 图片路径,当前仅支持应用沙箱路径。</br>当前支持格式有:.jpg .png .gif .bmp .webp .dng .heic<sup>12+</sup>(不同硬件设备支持情况不同) [.svg<sup>10+</sup>](#svg标签说明) .ico<sup>11+</sup>。 |
3698
3699**返回值:**
3700
3701| 类型                        | 说明                                         |
3702| --------------------------- | -------------------------------------------- |
3703| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |
3704
3705**示例:**
3706
3707```ts
3708const context: Context = getContext(this);
3709//此处'test.jpg'仅作示例,请开发者自行替换。否则imageSource会创建失败,导致后续无法正常执行。
3710const path: string = context.filesDir + "/test.jpg";
3711const imageSourceApi: image.ImageSource = image.createImageSource(path);
3712```
3713
3714## image.createImageSource<sup>9+</sup>
3715
3716createImageSource(uri: string, options: SourceOptions): ImageSource
3717
3718通过传入的uri创建图片源实例。
3719
3720**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
3721
3722**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3723
3724**系统能力:** SystemCapability.Multimedia.Image.ImageSource
3725
3726**参数:**
3727
3728| 参数名  | 类型                            | 必填 | 说明                                |
3729| ------- | ------------------------------- | ---- | ----------------------------------- |
3730| uri     | string                          | 是   | 图片路径,当前仅支持应用沙箱路径。</br>当前支持格式有:.jpg .png .gif .bmp .webp .dng .heic<sup>12+</sup>(不同硬件设备支持情况不同)[.svg<sup>10+</sup>](#svg标签说明) .ico<sup>11+</sup>。 |
3731| options | [SourceOptions](#sourceoptions9) | 是   | 图片属性,包括图片像素密度、像素格式和图片尺寸。|
3732
3733**返回值:**
3734
3735| 类型                        | 说明                                         |
3736| --------------------------- | -------------------------------------------- |
3737| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |
3738
3739**示例:**
3740
3741```ts
3742let sourceOptions: image.SourceOptions = { sourceDensity: 120 };
3743const context: Context = getContext(this);
3744//此处'test.png'仅作示例,请开发者自行替换。否则imageSource会创建失败,导致后续无法正常执行。
3745const path: string = context.filesDir + "/test.png";
3746let imageSourceApi: image.ImageSource = image.createImageSource(path, sourceOptions);
3747```
3748
3749## image.createImageSource<sup>7+</sup>
3750
3751createImageSource(fd: number): ImageSource
3752
3753通过传入文件描述符来创建图片源实例。
3754
3755**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3756
3757**系统能力:** SystemCapability.Multimedia.Image.ImageSource
3758
3759**参数:**
3760
3761| 参数名 | 类型   | 必填 | 说明          |
3762| ------ | ------ | ---- | ------------- |
3763| fd     | number | 是   | 文件描述符fd。|
3764
3765**返回值:**
3766
3767| 类型                        | 说明                                         |
3768| --------------------------- | -------------------------------------------- |
3769| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |
3770
3771**示例:**
3772
3773```ts
3774import { fileIo as fs } from '@kit.CoreFileKit';
3775
3776const context: Context = getContext(this);
3777//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource会创建失败导致后续无法正常执行。
3778let filePath: string = context.filesDir + "/test.jpg";
3779let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
3780const imageSourceApi: image.ImageSource = image.createImageSource(file.fd);
3781```
3782
3783## image.createImageSource<sup>9+</sup>
3784
3785createImageSource(fd: number, options: SourceOptions): ImageSource
3786
3787通过传入文件描述符来创建图片源实例。
3788
3789**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
3790
3791**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3792
3793**系统能力:** SystemCapability.Multimedia.Image.ImageSource
3794
3795**参数:**
3796
3797| 参数名  | 类型                            | 必填 | 说明                                |
3798| ------- | ------------------------------- | ---- | ----------------------------------- |
3799| fd      | number                          | 是   | 文件描述符fd。                      |
3800| options | [SourceOptions](#sourceoptions9) | 是   | 图片属性,包括图片像素密度、像素格式和图片尺寸。|
3801
3802**返回值:**
3803
3804| 类型                        | 说明                                         |
3805| --------------------------- | -------------------------------------------- |
3806| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |
3807
3808**示例:**
3809
3810```ts
3811import { fileIo as fs } from '@kit.CoreFileKit';
3812
3813let sourceOptions: image.SourceOptions = { sourceDensity: 120 };
3814const context: Context = getContext();
3815//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。
3816const filePath: string = context.filesDir + "/test.jpg";
3817let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
3818const imageSourceApi: image.ImageSource = image.createImageSource(file.fd, sourceOptions);
3819```
3820
3821## image.createImageSource<sup>9+</sup>
3822
3823createImageSource(buf: ArrayBuffer): ImageSource
3824
3825通过缓冲区创建图片源实例。buf数据应该是未解码的数据,不要传入类似于RBGA,YUV的像素buffer数据,如果想通过像素buffer数据创建pixelMap,可以调用[image.createPixelMapSync](#createpixelmapsync12)这一类接口。
3826
3827**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
3828
3829**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3830
3831**系统能力:** SystemCapability.Multimedia.Image.ImageSource
3832
3833**参数:**
3834
3835| 参数名 | 类型        | 必填 | 说明             |
3836| ------ | ----------- | ---- | ---------------- |
3837| buf    | ArrayBuffer | 是   | 图像缓冲区数组。 |
3838
3839**返回值:**
3840
3841| 类型                        | 说明                                         |
3842| --------------------------- | -------------------------------------------- |
3843| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |
3844
3845
3846**示例:**
3847
3848```ts
3849const buf: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
3850const imageSourceApi: image.ImageSource = image.createImageSource(buf);
3851```
3852
3853## image.createImageSource<sup>9+</sup>
3854
3855createImageSource(buf: ArrayBuffer, options: SourceOptions): ImageSource
3856
3857通过缓冲区创建图片源实例。buf数据应该是未解码的数据,不要传入类似于RBGA,YUV的像素buffer数据,如果想通过像素buffer数据创建pixelMap,可以调用[image.createPixelMapSync](#createpixelmapsync12)这一类接口。
3858
3859**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
3860
3861**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3862
3863**系统能力:** SystemCapability.Multimedia.Image.ImageSource
3864
3865**参数:**
3866
3867| 参数名 | 类型                             | 必填 | 说明                                 |
3868| ------ | -------------------------------- | ---- | ------------------------------------ |
3869| buf    | ArrayBuffer                      | 是   | 图像缓冲区数组。                     |
3870| options | [SourceOptions](#sourceoptions9) | 是   | 图片属性,包括图片像素密度、像素格式和图片尺寸。 |
3871
3872**返回值:**
3873
3874| 类型                        | 说明                                         |
3875| --------------------------- | -------------------------------------------- |
3876| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |
3877
3878**示例:**
3879
3880```ts
3881const data: ArrayBuffer = new ArrayBuffer(112);
3882let sourceOptions: image.SourceOptions = { sourceDensity: 120 };
3883const imageSourceApi: image.ImageSource = image.createImageSource(data, sourceOptions);
3884```
3885
3886## image.createImageSource<sup>11+</sup>
3887
3888createImageSource(rawfile: resourceManager.RawFileDescriptor, options?: SourceOptions): ImageSource
3889
3890通过图像资源文件的RawFileDescriptor创建图片源实例。
3891
3892**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3893
3894**系统能力:** SystemCapability.Multimedia.Image.ImageSource
3895
3896**参数:**
3897
3898| 参数名 | 类型                             | 必填 | 说明                                 |
3899| ------ | -------------------------------- | ---- | ------------------------------------ |
3900| rawfile | [resourceManager.RawFileDescriptor](../apis-localization-kit/js-apis-resource-manager.md#rawfiledescriptor8) | 是 | 图像资源文件的RawFileDescriptor。 |
3901| options | [SourceOptions](#sourceoptions9) | 否 | 图片属性,包括图片像素密度、像素格式和图片尺寸。 |
3902
3903**返回值:**
3904
3905| 类型                        | 说明                                         |
3906| --------------------------- | -------------------------------------------- |
3907| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |
3908
3909**示例:**
3910
3911```ts
3912import { resourceManager } from '@kit.LocalizationKit';
3913
3914const context: Context = getContext(this);
3915// 获取resourceManager资源管理器
3916const resourceMgr: resourceManager.ResourceManager = context.resourceManager;
3917//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。
3918resourceMgr.getRawFd('test.jpg').then((rawFileDescriptor: resourceManager.RawFileDescriptor) => {
3919  const imageSourceApi: image.ImageSource = image.createImageSource(rawFileDescriptor);
3920}).catch((error: BusinessError) => {
3921  console.error(`Failed to get RawFileDescriptor.code is ${error.code}, message is ${error.message}`);
3922})
3923```
3924
3925## image.CreateIncrementalSource<sup>9+</sup>
3926
3927CreateIncrementalSource(buf: ArrayBuffer): ImageSource
3928
3929通过缓冲区以增量的方式创建图片源实例,IncrementalSource不支持读写Exif信息。
3930
3931以增量方式创建的图片源实例ImageSource,仅支持使用以下功能,同步、异步callback、异步Promise均支持。
3932- 获取图片信息:指定序号-[getImageInfo](#getimageinfo)、直接获取-[getImageInfo](#getimageinfo-1)
3933- 获取图片中给定索引处图像的指定属性键的值:[getImageProperty](#getimageproperty11)
3934- 批量获取图片中的指定属性键的值:[getImageProperties](#getimageproperties12)
3935- 更新增量数据:[updateData](#updatedata9)
3936- 创建PixelMap对象:通过图片解码参数创建-[createPixelMap](#createpixelmap7)、通过默认参数创建-[createPixelMap](#createpixelmap7-1) 、通过图片解码参数-[createPixelMap](#createpixelmap7-2)
3937- 释放图片源实例:[release](#release)
3938
3939**系统能力:** SystemCapability.Multimedia.Image.ImageSource
3940
3941**参数:**
3942
3943| 参数名  | 类型        | 必填 | 说明      |
3944| ------- | ------------| ---- | ----------|
3945| buf     | ArrayBuffer | 是   | 增量数据。|
3946
3947**返回值:**
3948
3949| 类型                        | 说明                              |
3950| --------------------------- | --------------------------------- |
3951| [ImageSource](#imagesource) | 返回图片源,失败时返回undefined。 |
3952
3953**示例:**
3954
3955```ts
3956const context: Context = getContext(this)
3957let imageArray = context.resourceManager.getMediaContentSync($r('app.media.startIcon')) // 获取图像资源
3958// 此处'app.media.startIcon'仅作示例,请开发者自行替换,否则imageArray创建失败会导致后续无法正常执行。
3959let splitBuff1 = imageArray.slice(0, imageArray.byteLength / 2)  // 分片
3960let splitBuff2 = imageArray.slice(imageArray.byteLength / 2)
3961const imageSourceIncrementalSApi: image.ImageSource = image.CreateIncrementalSource(new ArrayBuffer(imageArray.byteLength));
3962imageSourceIncrementalSApi.updateData(splitBuff1, false, 0, splitBuff1.byteLength).then(() => {
3963  imageSourceIncrementalSApi.updateData(splitBuff2, true, 0, splitBuff2.byteLength).then(() => {
3964    let pixelMap = imageSourceIncrementalSApi.createPixelMapSync()
3965    let imageInfo = pixelMap.getImageInfoSync()
3966    console.info('Succeeded in creating pixelMap')
3967  }).catch((error : BusinessError) => {
3968    console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`)
3969  })
3970}).catch((error : BusinessError) => {
3971  console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`)
3972})
3973```
3974
3975## image.CreateIncrementalSource<sup>9+</sup>
3976
3977CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource
3978
3979通过缓冲区以增量的方式创建图片源实例,IncrementalSource不支持读写Exif信息。
3980
3981此接口支持的功能与[CreateIncrementalSource(buf: ArrayBuffer): ImageSource](#imagecreateincrementalsource9)所生成的实例支持的功能相同
3982
3983**系统能力:** SystemCapability.Multimedia.Image.ImageSource
3984
3985**参数:**
3986
3987| 参数名  | 类型                            | 必填 | 说明                                 |
3988| ------- | ------------------------------- | ---- | ------------------------------------ |
3989| buf     | ArrayBuffer                     | 是   | 增量数据。                           |
3990| options | [SourceOptions](#sourceoptions9) | 否   | 图片属性,包括图片像素密度、像素格式和图片尺寸。 |
3991
3992**返回值:**
3993
3994| 类型                        | 说明                              |
3995| --------------------------- | --------------------------------- |
3996| [ImageSource](#imagesource) | 返回图片源,失败时返回undefined。 |
3997
3998**示例:**
3999
4000```ts
4001const context: Context = getContext(this)
4002let imageArray = context.resourceManager.getMediaContentSync($r('app.media.startIcon')) // 获取图像资源
4003// 此处'app.media.startIcon'仅作示例,请开发者自行替换,否则imageArray创建失败会导致后续无法正常执行。
4004let splitBuff1 = imageArray.slice(0, imageArray.byteLength / 2)  // 分片
4005let splitBuff2 = imageArray.slice(imageArray.byteLength / 2)
4006let sourceOptions: image.SourceOptions = { sourceDensity: 120};
4007
4008const imageSourceIncrementalSApi: image.ImageSource = image.CreateIncrementalSource(new ArrayBuffer(imageArray.byteLength), sourceOptions);
4009imageSourceIncrementalSApi.updateData(splitBuff1, false, 0, splitBuff1.byteLength).then(() => {
4010  imageSourceIncrementalSApi.updateData(splitBuff2, true, 0, splitBuff2.byteLength).then(() => {
4011    let pixelMap = imageSourceIncrementalSApi.createPixelMapSync()
4012    let imageInfo = pixelMap.getImageInfoSync()
4013    console.info('Succeeded in creating pixelMap')
4014  }).catch((error : BusinessError) => {
4015    console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`)
4016  })
4017}).catch((error : BusinessError) => {
4018  console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`)
4019})
4020```
4021
4022## ImageSource
4023
4024图片源类,用于获取图片相关信息。在调用ImageSource的方法前,需要先通过[createImageSource](#imagecreateimagesource)构建一个ImageSource实例。
4025
4026### 属性
4027
4028**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4029
4030| 名称             | 类型           | 可读 | 可写 | 说明                                                         |
4031| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
4032| supportedFormats | Array\<string> | 是   | 否   | 支持的图片格式,包括:png,jpeg,bmp,gif,webp,dng,heif<sup>12+</sup>(不同硬件设备支持情况不同)。 |
4033
4034### getImageInfo
4035
4036getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void
4037
4038获取指定序号的图片信息,使用callback形式返回图片信息。
4039
4040**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
4041
4042**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4043
4044**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4045
4046**参数:**
4047
4048| 参数名   | 类型                                   | 必填 | 说明                                     |
4049| -------- | -------------------------------------- | ---- | ---------------------------------------- |
4050| index    | number                                 | 是   | 创建图片源时的序号。                     |
4051| callback | AsyncCallback<[ImageInfo](#imageinfo)> | 是   | 回调函数。当获取图片信息成功,err为undefined,data为获取到的图片信息;否则为错误对象。 |
4052
4053**示例:**
4054
4055```ts
4056import { BusinessError } from '@kit.BasicServicesKit';
4057
4058imageSourceApi.getImageInfo(0, (error: BusinessError, imageInfo: image.ImageInfo) => {
4059  if (error) {
4060    console.error(`Failed to obtain the image information.code is ${error.code}, message is ${error.message}`);
4061  } else {
4062    console.info('Succeeded in obtaining the image information.');
4063  }
4064})
4065```
4066
4067### getImageInfo
4068
4069getImageInfo(callback: AsyncCallback\<ImageInfo>): void
4070
4071获取图片信息,使用callback形式返回图片信息。
4072
4073**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
4074
4075**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4076
4077**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4078
4079**参数:**
4080
4081| 参数名   | 类型                                   | 必填 | 说明                                     |
4082| -------- | -------------------------------------- | ---- | ---------------------------------------- |
4083| callback | AsyncCallback<[ImageInfo](#imageinfo)> | 是   | 回调函数。当获取图片信息成功,err为undefined,data为获取到的图片信息;否则为错误对象。 |
4084
4085**示例:**
4086
4087```ts
4088import { BusinessError } from '@kit.BasicServicesKit';
4089
4090imageSourceApi.getImageInfo((err: BusinessError, imageInfo: image.ImageInfo) => {
4091  if (err) {
4092    console.error(`Failed to obtain the image information.code is ${err.code}, message is ${err.message}`);
4093  } else {
4094    console.info('Succeeded in obtaining the image information.');
4095  }
4096})
4097```
4098
4099### getImageInfo
4100
4101getImageInfo(index?: number): Promise\<ImageInfo>
4102
4103获取图片信息,使用Promise形式返回图片信息。
4104
4105**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
4106
4107**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4108
4109**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4110
4111**参数:**
4112
4113| 参数名| 类型   | 必填 | 说明                                  |
4114| ----- | ------ | ---- | ------------------------------------- |
4115| index | number | 否   | 创建图片源时的序号,不选择时默认为0。 |
4116
4117**返回值:**
4118
4119| 类型                             | 说明                   |
4120| -------------------------------- | ---------------------- |
4121| Promise<[ImageInfo](#imageinfo)> | Promise对象,返回获取到的图片信息。 |
4122
4123**示例:**
4124
4125```ts
4126import { BusinessError } from '@kit.BasicServicesKit';
4127
4128imageSourceApi.getImageInfo(0)
4129  .then((imageInfo: image.ImageInfo) => {
4130    console.info('Succeeded in obtaining the image information.');
4131  }).catch((error: BusinessError) => {
4132    console.error(`Failed to obtain the image information.code is ${error.code}, message is ${error.message}`);
4133  })
4134```
4135
4136### getImageInfoSync<sup>12+</sup>
4137
4138getImageInfoSync(index?: number): ImageInfo
4139
4140获取指定序号的图片信息,使用同步形式返回图片信息。
4141
4142**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4143
4144**参数:**
4145
4146| 参数名| 类型   | 必填 | 说明                                  |
4147| ----- | ------ | ---- | ------------------------------------- |
4148| index | number | 否   | 创建图片源时的序号,不选择时默认为0。 |
4149
4150**返回值:**
4151
4152| 类型                             | 说明                   |
4153| -------------------------------- | ---------------------- |
4154| [ImageInfo](#imageinfo) | 同步返回获取到的图片信息。 |
4155
4156**示例:**
4157
4158```ts
4159import { image } from '@kit.ImageKit';
4160
4161const context: Context = getContext();
4162//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。
4163let filePath: string = context.filesDir + "/test.jpg";
4164let imageSource = image.createImageSource(filePath);
4165let imageInfo = imageSource.getImageInfoSync(0);
4166if (imageInfo == undefined) {
4167  console.error('Failed to obtain the image information.');
4168} else {
4169  console.info('Succeeded in obtaining the image information.');
4170  console.info('imageInfo.size.height:' + imageInfo.size.height);
4171  console.info('imageInfo.size.width:' + imageInfo.size.width);
4172}
4173```
4174
4175### getImageProperty<sup>11+</sup>
4176
4177getImageProperty(key:PropertyKey, options?: ImagePropertyOptions): Promise\<string>
4178
4179获取图片中给定索引处图像的指定属性键的值,用Promise形式返回结果,仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。
4180
4181**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4182
4183**参数:**
4184
4185| 参数名  | 类型                                                 | 必填 | 说明                                 |
4186| ------- | ---------------------------------------------------- | ---- | ------------------------------------ |
4187| key     | [PropertyKey](#propertykey7)                                               | 是   | 图片属性名。                         |
4188| options | [ImagePropertyOptions](#imagepropertyoptions11) | 否   | 图片属性,包括图片序号与默认属性值。 |
4189
4190**返回值:**
4191
4192| 类型             | 说明                                                              |
4193| ---------------- | ----------------------------------------------------------------- |
4194| Promise\<string> | Promise对象,返回图片属性值,如获取失败则返回属性默认值。 |
4195
4196**错误码:**
4197
4198以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
4199
4200| 错误码ID | 错误信息 |
4201| ------- | --------------------------------------------|
4202| 401  | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed;              |
4203| 62980096 | The operation failed.             |
4204| 62980103 | The image data is not supported.         |
4205| 62980110 | The image source data is incorrect.      |
4206| 62980111 | The image source data is incomplete. |
4207| 62980112 | The image format does not match.       |
4208| 62980113 | Unknown image format.        |
4209| 62980115 | Invalid image parameter.      |
4210| 62980116| Failed to decode the image.            |
4211| 62980118 | Failed to create the image plugin.   |
4212| 62980122 | Failed to decode the image header.   |
4213| 62980123| Images in EXIF format are not supported.             |
4214| 62980135| The EXIF value is invalid.             |
4215
4216**示例:**
4217
4218```ts
4219import { BusinessError } from '@kit.BasicServicesKit';
4220
4221let options: image.ImagePropertyOptions = { index: 0, defaultValue: '9999' }
4222imageSourceApi.getImageProperty(image.PropertyKey.BITS_PER_SAMPLE, options)
4223.then((data: string) => {
4224  console.info('Succeeded in getting the value of the specified attribute key of the image.');
4225}).catch((error: BusinessError) => {
4226  console.error('Failed to get the value of the specified attribute key of the image.');
4227})
4228```
4229
4230### getImageProperty<sup>(deprecated)</sup>
4231
4232getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\<string>
4233
4234获取图片中给定索引处图像的指定属性键的值,用Promise形式返回结果,仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。
4235
4236> **说明:**
4237>
4238> 从API version 11开始不再维护,建议使用[getImageProperty](#getimageproperty11)代替。
4239
4240**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4241
4242**参数:**
4243
4244| 参数名  | 类型                                                 | 必填 | 说明                                 |
4245| ------- | ---------------------------------------------------- | ---- | ------------------------------------ |
4246| key     | string                                               | 是   | 图片属性名。                         |
4247| options | [GetImagePropertyOptions](#getimagepropertyoptionsdeprecated) | 否   | 图片属性,包括图片序号与默认属性值。 |
4248
4249**返回值:**
4250
4251| 类型             | 说明                                                              |
4252| ---------------- | ----------------------------------------------------------------- |
4253| Promise\<string> | Promise对象,返回图片属性值,如获取失败则返回属性默认值。 |
4254
4255**示例:**
4256
4257```ts
4258import { BusinessError } from '@kit.BasicServicesKit';
4259
4260imageSourceApi.getImageProperty("BitsPerSample")
4261  .then((data: string) => {
4262    console.info('Succeeded in getting the value of the specified attribute key of the image.');
4263  }).catch((error: BusinessError) => {
4264    console.error('Failed to get the value of the specified attribute key of the image.');
4265  })
4266```
4267
4268### getImageProperty<sup>(deprecated)</sup>
4269
4270getImageProperty(key:string, callback: AsyncCallback\<string>): void
4271
4272获取图片中给定索引处图像的指定属性键的值,用callback形式返回结果,仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。
4273
4274> **说明:**
4275>
4276> 从API version 11开始不再维护,建议使用[getImageProperty](#getimageproperty11)代替。
4277
4278**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4279
4280**参数:**
4281
4282| 参数名   | 类型                   | 必填 | 说明                                                         |
4283| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
4284| key      | string                 | 是   | 图片属性名。                                                 |
4285| callback | AsyncCallback\<string> | 是   | 回调函数,当获取图片属性值成功,err为undefined,data为获取到的图片属性值;否则为错误对象。 |
4286
4287**示例:**
4288
4289```ts
4290import { BusinessError } from '@kit.BasicServicesKit';
4291
4292imageSourceApi.getImageProperty("BitsPerSample", (error: BusinessError, data: string) => {
4293  if (error) {
4294    console.error('Failed to get the value of the specified attribute key of the image.');
4295  } else {
4296    console.info('Succeeded in getting the value of the specified attribute key of the image.');
4297  }
4298})
4299```
4300
4301### getImageProperty<sup>(deprecated)</sup>
4302
4303getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCallback\<string>): void
4304
4305获取图片指定属性键的值,callback形式返回结果,仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。
4306
4307> **说明:**
4308>
4309> 从API version 11开始不再维护,建议使用[getImageProperty](#getimageproperty11)代替。
4310
4311**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4312
4313**参数:**
4314
4315| 参数名   | 类型                                                 | 必填 | 说明                                                          |
4316| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------- |
4317| key      | string                                               | 是   | 图片属性名。                                                  |
4318| options  | [GetImagePropertyOptions](#getimagepropertyoptionsdeprecated) | 是   | 图片属性,包括图片序号与默认属性值。                          |
4319| callback | AsyncCallback\<string>                               | 是   | 回调函数,当获取图片属性值成功,err为undefined,data为获取到的图片属性值;否则为错误对象。|
4320
4321**示例:**
4322
4323```ts
4324import { BusinessError } from '@kit.BasicServicesKit';
4325
4326let property: image.GetImagePropertyOptions = { index: 0, defaultValue: '9999' }
4327imageSourceApi.getImageProperty("BitsPerSample", property, (error: BusinessError, data: string) => {
4328  if (error) {
4329    console.error('Failed to get the value of the specified attribute key of the image.');
4330  } else {
4331    console.info('Succeeded in getting the value of the specified attribute key of the image.');
4332  }
4333})
4334```
4335
4336### getImageProperties<sup>12+</sup>
4337
4338getImageProperties(key: Array&#60;PropertyKey&#62;): Promise<Record<PropertyKey, string|null>>
4339
4340批量获取图片中的指定属性键的值,用Promise形式返回结果。仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。
4341
4342**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4343
4344**参数:**
4345
4346| 参数名  | 类型                                                 | 必填 | 说明                                 |
4347| ------- | ---------------------------------------------------- | ---- | ------------------------------------ |
4348| key     | Array\<[PropertyKey](#propertykey7)>                                 | 是   | 图片属性名的数组。                         |
4349
4350**返回值:**
4351
4352| 类型             | 说明                                                              |
4353| ---------------- | ----------------------------------------------------------------- |
4354| Promise\<Record<[PropertyKey](#propertykey7), string \| null>> | Promise对象,返回图片属性值,如获取失败则返回null。 |
4355
4356**错误码:**
4357
4358以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
4359
4360| 错误码ID | 错误信息 |
4361| ------- | --------------------------------------------|
4362| 401  | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed;     |
4363| 62980096| The operation failed.             |
4364| 62980110| The image source data is incorrect.            |
4365| 62980113| Unknown image format.            |
4366| 62980116| Failed to decode the image.            |
4367
4368**示例:**
4369
4370```ts
4371import { image } from '@kit.ImageKit';
4372import { BusinessError } from '@kit.BasicServicesKit';
4373
4374let key = [image.PropertyKey.IMAGE_WIDTH, image.PropertyKey.IMAGE_LENGTH];
4375imageSourceApi.getImageProperties(key).then((data) => {
4376  console.info(JSON.stringify(data));
4377}).catch((err: BusinessError) => {
4378  console.error(JSON.stringify(err));
4379});
4380```
4381
4382### modifyImageProperty<sup>11+</sup>
4383
4384modifyImageProperty(key: PropertyKey, value: string): Promise\<void>
4385
4386通过指定的键修改图片属性的值,使用Promise形式返回结果,仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。
4387
4388> **说明:**
4389>
4390> 调用modifyImageProperty修改属性会改变属性字节长度,使用buffer创建的ImageSource调用modifyImageProperty会导致buffer内容覆盖,目前buffer创建的ImageSource不支持调用此接口,请改用fd或path创建的ImageSource。
4391
4392**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4393
4394**参数:**
4395
4396| 参数名  | 类型   | 必填 | 说明         |
4397| ------- | ------ | ---- | ------------ |
4398| key     | [PropertyKey](#propertykey7)   | 是   | 图片属性名。 |
4399| value   | string | 是   | 属性值。     |
4400
4401**返回值:**
4402
4403| 类型           | 说明                        |
4404| -------------- | --------------------------- |
4405| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
4406
4407**错误码:**
4408
4409以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
4410
4411| 错误码ID | 错误信息 |
4412| ------- | --------------------------------------------|
4413| 401  | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;    |
4414| 62980123| The image does not support EXIF decoding.             |
4415| 62980133| The EXIF data is out of range.             |
4416| 62980135| The EXIF value is invalid.             |
4417| 62980146| The EXIF data failed to be written to the file.        |
4418
4419**示例:**
4420
4421```ts
4422import { BusinessError } from '@kit.BasicServicesKit';
4423
4424imageSourceApi.modifyImageProperty(image.PropertyKey.IMAGE_WIDTH, "120").then(() => {
4425  imageSourceApi.getImageProperty(image.PropertyKey.IMAGE_WIDTH).then((width: string) => {
4426    console.info(`ImageWidth is :${width}`);
4427  }).catch((error: BusinessError) => {
4428    console.error('Failed to get the Image Width.');
4429  })
4430}).catch((error: BusinessError) => {
4431  console.error('Failed to modify the Image Width');
4432})
4433```
4434
4435### modifyImageProperty<sup>(deprecated)</sup>
4436
4437modifyImageProperty(key: string, value: string): Promise\<void>
4438
4439通过指定的键修改图片属性的值,使用Promise形式返回结果,仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。
4440
4441> **说明:**
4442>
4443> 调用modifyImageProperty修改属性会改变属性字节长度,使用buffer创建的ImageSource调用modifyImageProperty会导致buffer内容覆盖,目前buffer创建的ImageSource不支持调用此接口,请改用fd或path创建的ImageSource。
4444>
4445> 从API version 11开始不再维护,建议使用[modifyImageProperty](#modifyimageproperty11)代替。
4446
4447**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4448
4449**参数:**
4450
4451| 参数名  | 类型   | 必填 | 说明         |
4452| ------- | ------ | ---- | ------------ |
4453| key     | string | 是   | 图片属性名。 |
4454| value   | string | 是   | 属性值。     |
4455
4456**返回值:**
4457
4458| 类型           | 说明                        |
4459| -------------- | --------------------------- |
4460| Promise\<void> |  Promise对象。无返回结果的Promise对象。|
4461
4462**示例:**
4463
4464```ts
4465import { BusinessError } from '@kit.BasicServicesKit';
4466
4467imageSourceApi.modifyImageProperty("ImageWidth", "120").then(() => {
4468  imageSourceApi.getImageProperty("ImageWidth").then((width: string) => {
4469    console.info(`ImageWidth is :${width}`);
4470  }).catch((error: BusinessError) => {
4471    console.error('Failed to get the Image Width.');
4472  })
4473}).catch((error: BusinessError) => {
4474  console.error('Failed to modify the Image Width');
4475})
4476```
4477
4478### modifyImageProperty<sup>(deprecated)</sup>
4479
4480modifyImageProperty(key: string, value: string, callback: AsyncCallback\<void>): void
4481
4482通过指定的键修改图片属性的值,callback形式返回结果,仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。
4483
4484> **说明:**
4485>
4486> 调用modifyImageProperty修改属性会改变属性字节长度,使用buffer创建的ImageSource调用modifyImageProperty会导致buffer内容覆盖,目前buffer创建的ImageSource不支持调用此接口,请改用fd或path创建的ImageSource。
4487> 
4488>从API version 11开始不再维护,建议使用[modifyImageProperty](#modifyimageproperty11)代替。
4489
4490**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4491
4492**参数:**
4493
4494| 参数名   | 类型                | 必填 | 说明                           |
4495| -------- | ------------------- | ---- | ------------------------------ |
4496| key      | string              | 是   | 图片属性名。                   |
4497| value    | string              | 是   | 属性值。                       |
4498| callback | AsyncCallback\<void> | 是   | 回调函数,当修改图片属性值成功,err为undefined,否则为错误对象。 |
4499
4500**示例:**
4501
4502```ts
4503import { BusinessError } from '@kit.BasicServicesKit';
4504
4505imageSourceApi.modifyImageProperty("ImageWidth", "120", (err: BusinessError) => {
4506  if (err) {
4507    console.error(`Failed to modify the Image Width.code is ${err.code}, message is ${err.message}`);
4508  } else {
4509    console.info('Succeeded in modifying the Image Width.');
4510  }
4511})
4512```
4513
4514### modifyImageProperties<sup>12+</sup>
4515
4516modifyImageProperties(records: Record<PropertyKey, string|null>): Promise\<void>
4517
4518批量通过指定的键修改图片属性的值,使用Promise形式返回结果。仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。
4519
4520> **说明:**
4521>
4522> 调用modifyImageProperties修改属性会改变属性字节长度,使用buffer创建的ImageSource调用modifyImageProperties会导致buffer内容覆盖,目前buffer创建的ImageSource不支持调用此接口,请改用fd或path创建的ImageSource。
4523>
4524
4525**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4526
4527**参数:**
4528
4529| 参数名  | 类型   | 必填 | 说明         |
4530| ------- | ------ | ---- | ------------ |
4531| records     | Record<[PropertyKey](#propertykey7), string \| null>   | 是   | 包含图片属性名和属性值的数组。 |
4532
4533**返回值:**
4534
4535| 类型           | 说明                        |
4536| -------------- | --------------------------- |
4537| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
4538
4539**错误码:**
4540
4541以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
4542
4543| 错误码ID | 错误信息 |
4544| ------- | --------------------------------------------|
4545| 401  | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed;      |
4546| 62980123| The image does not support EXIF decoding.             |
4547| 62980133| The EXIF data is out of range.             |
4548| 62980135| The EXIF value is invalid.             |
4549| 62980146| The EXIF data failed to be written to the file.             |
4550
4551**示例:**
4552
4553```ts
4554import { image } from '@kit.ImageKit';
4555import { BusinessError } from '@kit.BasicServicesKit';
4556
4557let keyValues: Record<PropertyKey, string|null> = {
4558    [image.PropertyKey.IMAGE_WIDTH] : "1024",
4559    [image.PropertyKey.IMAGE_LENGTH] : "1024"
4560};
4561let checkKey = [image.PropertyKey.IMAGE_WIDTH, image.PropertyKey.IMAGE_LENGTH];
4562imageSourceApi.modifyImageProperties(keyValues).then(() => {
4563  imageSourceApi.getImageProperties(checkKey).then((data) => {
4564    console.info(JSON.stringify(data));
4565  }).catch((err: BusinessError) => {
4566    console.error(JSON.stringify(err));
4567  });
4568}).catch((err: BusinessError) => {
4569  console.error(JSON.stringify(err));
4570});
4571```
4572
4573### updateData<sup>9+</sup>
4574
4575updateData(buf: ArrayBuffer, isFinished: boolean, offset: number, length: number): Promise\<void>
4576
4577更新增量数据,使用Promise形式返回结果。
4578
4579**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4580
4581**参数:**
4582
4583| 参数名     | 类型        | 必填 | 说明         |
4584| ---------- | ----------- | ---- | ------------ |
4585| buf        | ArrayBuffer | 是   | 增量数据。   |
4586| isFinished | boolean     | 是   | 是否更新完。 |
4587| offset      | number      | 是   | 偏移量。     |
4588| length     | number      | 是   | 数组长。     |
4589
4590**返回值:**
4591
4592| 类型           | 说明                       |
4593| -------------- | -------------------------- |
4594| Promise\<void> | Promise对象。无返回结果的Promise对象。|
4595
4596**示例:**
4597
4598```ts
4599import { BusinessError } from '@kit.BasicServicesKit';
4600
4601const array: ArrayBuffer = new ArrayBuffer(100);
4602imageSourceApi.updateData(array, false, 0, 10).then(() => {
4603  console.info('Succeeded in updating data.');
4604}).catch((err: BusinessError) => {
4605  console.error(`Failed to update data.code is ${err.code},message is ${err.message}`);
4606})
4607```
4608
4609
4610### updateData<sup>9+</sup>
4611
4612updateData(buf: ArrayBuffer, isFinished: boolean, offset: number, length: number, callback: AsyncCallback\<void>): void
4613
4614更新增量数据,callback形式返回结果。
4615
4616**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4617
4618**参数:**
4619
4620| 参数名     | 类型                | 必填 | 说明                 |
4621| ---------- | ------------------- | ---- | -------------------- |
4622| buf        | ArrayBuffer         | 是   | 增量数据。           |
4623| isFinished | boolean             | 是   | 是否更新完。         |
4624| offset      | number              | 是   | 偏移量。             |
4625| length     | number              | 是   | 数组长。             |
4626| callback   | AsyncCallback\<void> | 是   |  回调函数,当更新增量数据成功,err为undefined,否则为错误对象。 |
4627
4628**示例:**
4629
4630```ts
4631import { BusinessError } from '@kit.BasicServicesKit';
4632
4633const array: ArrayBuffer = new ArrayBuffer(100);
4634imageSourceApi.updateData(array, false, 0, 10, (err: BusinessError) => {
4635  if (err) {
4636    console.error(`Failed to update data.code is ${err.code},message is ${err.message}`);
4637  } else {
4638    console.info('Succeeded in updating data.');
4639  }
4640})
4641```
4642
4643### createPicture<sup>13+</sup>
4644
4645createPicture(options?: DecodingOptionsForPicture): Promise\<Picture>
4646
4647通过图片解码参数创建Picture对象,使用Promise形式返回。
4648
4649**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4650
4651**参数:**
4652
4653| 参数名  | 类型                                                   | 必填 | 说明       |
4654| ------- | ------------------------------------------------------ | ---- | ---------- |
4655| options | [DecodingOptionsForPicture](#decodingoptionsforpicture13) | 否   | 解码参数。 |
4656
4657**返回值:**
4658
4659| 类型                         | 说明                       |
4660| ---------------------------- | -------------------------- |
4661| Promise\<[Picture](#picture13)> | Promise对象,返回Picture。 |
4662
4663**错误码:**
4664
4665以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
4666
4667| 错误码ID | 错误信息               |
4668| -------- | ---------------------- |
4669| 7700301  | Decode failed.         |
4670
4671**示例:**
4672
4673```ts
4674import { image } from '@kit.ImageKit';
4675
4676async function CreatePicture() {
4677  let options: image.DecodingOptionsForPicture = {
4678    desiredAuxiliaryPictures: [image.AuxiliaryPictureType.GAINMAP] //GAINMAP为需要解码的辅助图类型
4679  };
4680  let pictureObj: image.Picture = await imageSourceApi.createPicture(options);
4681  if (pictureObj != null) {
4682    console.info('Create picture succeeded');
4683  } else {
4684    console.info('Create picture failed');
4685  }
4686}
4687```
4688
4689### createPixelMap<sup>7+</sup>
4690
4691createPixelMap(options?: DecodingOptions): Promise\<PixelMap>
4692
4693通过图片解码参数创建PixelMap对象。
4694
4695**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
4696
4697**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4698
4699**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4700
4701**参数:**
4702
4703| 参数名  | 类型                                 | 必填 | 说明       |
4704| ------- | ------------------------------------ | ---- | ---------- |
4705| options | [DecodingOptions](#decodingoptions7) | 否   | 解码参数。 |
4706
4707**返回值:**
4708
4709| 类型                             | 说明                  |
4710| -------------------------------- | --------------------- |
4711| Promise\<[PixelMap](#pixelmap7)> | Promise对象,返回PixelMap。 |
4712
4713**示例:**
4714
4715```ts
4716import { BusinessError } from '@kit.BasicServicesKit';
4717
4718imageSourceApi.createPixelMap().then((pixelMap: image.PixelMap) => {
4719  console.info('Succeeded in creating pixelMap object through image decoding parameters.');
4720}).catch((error: BusinessError) => {
4721  console.error('Failed to create pixelMap object through image decoding parameters.');
4722})
4723```
4724
4725### createPixelMap<sup>7+</sup>
4726
4727createPixelMap(callback: AsyncCallback\<PixelMap>): void
4728
4729通过默认参数创建PixelMap对象,使用callback形式返回结果。
4730
4731**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
4732
4733**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4734
4735**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4736
4737**参数:**
4738
4739| 参数名     | 类型                                  | 必填 | 说明                       |
4740| -------- | ------------------------------------- | ---- | -------------------------- |
4741| callback | AsyncCallback<[PixelMap](#pixelmap7)> | 是   | 回调函数,当创建PixelMap对象成功,err为undefined,data为获取到的PixelMap对象;否则为错误对象。 |
4742
4743**示例:**
4744
4745```ts
4746import { BusinessError } from '@kit.BasicServicesKit';
4747
4748imageSourceApi.createPixelMap((err: BusinessError, pixelMap: image.PixelMap) => {
4749  if (err) {
4750    console.error(`Failed to create pixelMap.code is ${err.code},message is ${err.message}`);
4751  } else {
4752    console.info('Succeeded in creating pixelMap object.');
4753  }
4754})
4755```
4756
4757### createPixelMap<sup>7+</sup>
4758
4759createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): void
4760
4761通过图片解码参数创建PixelMap对象。
4762
4763**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
4764
4765**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4766
4767**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4768
4769**参数:**
4770
4771| 参数名   | 类型                                  | 必填 | 说明                       |
4772| -------- | ------------------------------------- | ---- | -------------------------- |
4773| options  | [DecodingOptions](#decodingoptions7)  | 是   | 解码参数。                 |
4774| callback | AsyncCallback<[PixelMap](#pixelmap7)> | 是   | 回调函数,当创建PixelMap对象成功,err为undefined,data为获取到的PixelMap对象;否则为错误对象。 |
4775
4776**示例:**
4777
4778```ts
4779import { BusinessError } from '@kit.BasicServicesKit';
4780
4781let decodingOptions: image.DecodingOptions = {
4782  sampleSize: 1,
4783  editable: true,
4784  desiredSize: { width: 1, height: 2 },
4785  rotate: 10,
4786  desiredPixelFormat: 3,
4787  desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 },
4788  index: 0
4789};
4790imageSourceApi.createPixelMap(decodingOptions, (err: BusinessError, pixelMap: image.PixelMap) => {
4791  if (err) {
4792    console.error(`Failed to create pixelMap.code is ${err.code},message is ${err.message}`);
4793  } else {
4794    console.info('Succeeded in creating pixelMap object.');
4795  }
4796})
4797```
4798
4799### createPixelMapSync<sup>12+</sup>
4800
4801createPixelMapSync(options?: DecodingOptions): PixelMap
4802
4803通过图片解码参数同步创建PixelMap对象。
4804
4805**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4806
4807**参数:**
4808
4809| 参数名   | 类型                                  | 必填 | 说明                       |
4810| -------- | ------------------------------------- | ---- | -------------------------- |
4811| options  | [DecodingOptions](#decodingoptions7)  | 否   | 解码参数。                 |
4812
4813**返回值:**
4814
4815| 类型                             | 说明                  |
4816| -------------------------------- | --------------------- |
4817| [PixelMap](#pixelmap7) | 用于同步返回创建结果。 |
4818
4819**示例:**
4820
4821```ts
4822import { image } from '@kit.ImageKit';
4823
4824const context: Context = getContext();
4825//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。
4826let filePath: string = context.filesDir + "/test.jpg";
4827let imageSource = image.createImageSource(filePath);
4828let decodingOptions: image.DecodingOptions = {
4829  sampleSize: 1,
4830  editable: true,
4831  desiredSize: { width: 1, height: 2 },
4832  rotate: 10,
4833  desiredPixelFormat: 3,
4834  desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 },
4835  index: 0
4836};
4837let pixelmap = imageSource.createPixelMapSync(decodingOptions);
4838if (pixelmap != undefined) {
4839  console.info('Succeeded in creating pixelMap object.');
4840} else {
4841  console.info('Failed to create pixelMap.');
4842}
4843```
4844
4845### createPixelMapList<sup>10+</sup>
4846
4847createPixelMapList(options?: DecodingOptions): Promise<Array\<PixelMap>>
4848
4849通过图片解码参数创建PixelMap数组。针对动图如Gif、Webp,此接口返回每帧图片数据;针对静态图,此接口返回唯一的一帧图片数据。
4850
4851**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4852
4853**参数:**
4854
4855| 参数名   | 类型                                  | 必填 | 说明                       |
4856| -------- | ------------------------------------- | ---- | -------------------------- |
4857| options  | [DecodingOptions](#decodingoptions7)  | 否   | 解码参数。                 |
4858
4859**返回值:**
4860
4861| 类型                             | 说明                  |
4862| -------------------------------- | --------------------- |
4863| Promise<Array<[PixelMap](#pixelmap7)>> | 异步返回PixeMap数组。 |
4864
4865**错误码:**
4866
4867以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
4868
4869| 错误码ID | 错误信息 |
4870| ------- | --------------------------------------------|
4871| 62980096| The operation failed.              |
4872| 62980099 | The shared memory data is abnormal. |
4873| 62980101 | The image data is abnormal. |
4874| 62980103| The image data is not supported.             |
4875| 62980106 | The image is too large. |
4876| 62980109 | Failed to crop the image. |
4877| 62980110| The image source data is incorrect.             |
4878| 62980111| The image source data is incomplete.           |
4879| 62980112 | The image format does not match. |
4880| 62980113 | Unknown image format. |
4881| 62980115 | Invalid image parameter. |
4882| 62980116 | Failed to decode the image. |
4883| 62980118| Failed to create the image plugin.             |
4884| 62980122 | Failed to decode the image header. |
4885| 62980137 | Invalid media operation. |
4886| 62980173 | The DMA memory does not exist. |
4887| 62980174 | The DMA memory data is abnormal. |
4888
4889**示例:**
4890
4891```ts
4892import { BusinessError } from '@kit.BasicServicesKit';
4893
4894let decodeOpts: image.DecodingOptions = {
4895  sampleSize: 1,
4896  editable: true,
4897  desiredSize: { width: 198, height: 202 },
4898  rotate: 0,
4899  desiredPixelFormat: 3,
4900  index: 0,
4901};
4902imageSourceApi.createPixelMapList(decodeOpts).then((pixelMapList: Array<image.PixelMap>) => {
4903  console.info('Succeeded in creating pixelMapList object.');
4904}).catch((err: BusinessError) => {
4905  console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`);
4906})
4907```
4908
4909### createPixelMapList<sup>10+</sup>
4910
4911createPixelMapList(callback: AsyncCallback<Array\<PixelMap>>): void
4912
4913通过默认参数创建PixelMap数组,使用callback形式返回结果。针对动图如Gif、Webp,此接口返回每帧图片数据;针对静态图,此接口返回唯一的一帧图片数据。
4914
4915**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4916
4917**参数:**
4918
4919| 参数名     | 类型                                  | 必填 | 说明                       |
4920| -------- | ------------------------------------- | ---- | -------------------------- |
4921| callback | AsyncCallback<Array<[PixelMap](#pixelmap7)>> | 是   | 回调函数,当创建PixelMap对象数组成功,err为undefined,data为获取到的PixelMap对象数组;否则为错误对象。  |
4922
4923**错误码:**
4924
4925以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
4926
4927| 错误码ID | 错误信息 |
4928| ------- | --------------------------------------------|
4929| 62980096 | The operation failed.             |
4930| 62980099 | The shared memory data is abnormal.  |
4931| 62980101 | The image data is abnormal.          |
4932| 62980103 | The image data is not supported.         |
4933| 62980106 | The image is too large.              |
4934| 62980109 | Failed to crop the image.            |
4935| 62980110 | The image source data is incorrect.      |
4936| 62980111 | The image source data is incomplete. |
4937| 62980112 | The image format does not match.       |
4938| 62980113 | Unknown image format.        |
4939| 62980115 | Invalid image parameter.      |
4940| 62980116 | Failed to decode the image.         |
4941| 62980118 | Failed to create the image plugin.   |
4942| 62980122 | Failed to decode the image header.   |
4943| 62980137 | Invalid media operation.     |
4944| 62980173 | The DMA memory does not exist.        |
4945| 62980174 | The DMA memory data is abnormal.    |
4946
4947**示例:**
4948
4949```ts
4950import { BusinessError } from '@kit.BasicServicesKit';
4951
4952imageSourceApi.createPixelMapList((err: BusinessError, pixelMapList: Array<image.PixelMap>) => {
4953  if (err) {
4954    console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`);
4955  } else {
4956    console.info('Succeeded in creating pixelMapList object.');
4957  }
4958})
4959```
4960
4961### createPixelMapList<sup>10+</sup>
4962
4963createPixelMapList(options: DecodingOptions, callback: AsyncCallback<Array\<PixelMap>>): void
4964
4965通过图片解码参数创建PixelMap数组,使用callback形式返回结果。针对动图如Gif、Webp,此接口返回每帧图片数据;针对静态图,此接口返回唯一的一帧图片数据。
4966
4967**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4968
4969**参数:**
4970
4971| 参数名   | 类型                 | 必填 | 说明                               |
4972| -------- | -------------------- | ---- | ---------------------------------- |
4973| options | [DecodingOptions](#decodingoptions7) | 是 | 解码参数。 |
4974| callback | AsyncCallback<Array<[PixelMap](#pixelmap7)>> | 是   | 回调函数,当创建PixelMap对象数组成功,err为undefined,data为获取到的PixelMap对象数组;否则为错误对象。  |
4975
4976**错误码:**
4977
4978以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
4979
4980| 错误码ID | 错误信息 |
4981| ------- | --------------------------------------------|
4982| 62980096 | The operation failed.            |
4983| 62980099 | The shared memory data is abnormal.  |
4984| 62980101 | The image data is abnormal.         |
4985| 62980103 | The image data is not supported.        |
4986| 62980106 | The image is too large.              |
4987| 62980109 | Failed to crop the image.           |
4988| 62980110 | The image source data is incorrect.      |
4989| 62980111 | The image source data is incomplete. |
4990| 62980112 | The image format does not match.        |
4991| 62980113 | Unknown image format.         |
4992| 62980115 | Invalid image parameter.      |
4993| 62980116 | Failed to decode the image.         |
4994| 62980118 | Failed to create the image plugin.  |
4995| 62980122 | Failed to decode the image header.   |
4996| 62980137 | Invalid media operation.      |
4997| 62980173 | The DMA memory does not exist.         |
4998| 62980174 | The DMA memory data is abnormal.     |
4999
5000**示例:**
5001
5002```ts
5003import { BusinessError } from '@kit.BasicServicesKit';
5004
5005let decodeOpts: image.DecodingOptions = {
5006  sampleSize: 1,
5007  editable: true,
5008  desiredSize: { width: 198, height: 202 },
5009  rotate: 0,
5010  desiredPixelFormat: 3,
5011  index: 0,
5012};
5013imageSourceApi.createPixelMapList(decodeOpts, (err: BusinessError, pixelMapList: Array<image.PixelMap>) => {
5014  if (err) {
5015    console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`);
5016  } else {
5017    console.info('Succeeded in creating pixelMapList object.');
5018  }
5019})
5020```
5021
5022### getDelayTimeList<sup>10+</sup>
5023
5024getDelayTimeList(callback: AsyncCallback<Array\<number>>): void
5025
5026获取图像延迟时间数组,使用callback形式返回结果。此接口仅用于gif图片和webp图片。
5027
5028**系统能力:** SystemCapability.Multimedia.Image.ImageSource
5029
5030**参数:**
5031
5032| 参数名   | 类型                 | 必填 | 说明                               |
5033| -------- | -------------------- | ---- | ---------------------------------- |
5034| callback | AsyncCallback<Array\<number>> | 是   | 回调函数,当获取图像延迟时间数组成功,err为undefined,data为获取到的图像延时时间数组;否则为错误对象。 |
5035
5036**错误码:**
5037
5038以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5039
5040| 错误码ID | 错误信息 |
5041| ------- | --------------------------------------------|
5042| 62980096| The operation failed.              |
5043| 62980110| The image source data is incorrect.             |
5044| 62980111| The image source data is incomplete.            |
5045| 62980112 | The image format does not match. |
5046| 62980113| Unknown image format. |
5047| 62980115 | Invalid image parameter. |
5048| 62980116| Failed to decode the image. |
5049| 62980118| Failed to create the image plugin. |
5050| 62980122| Failed to decode the image header. |
5051| 62980137 | Invalid media operation. |
5052| 62980149 | Invalid MIME type for the image source. |
5053
5054**示例:**
5055
5056```ts
5057import { BusinessError } from '@kit.BasicServicesKit';
5058
5059imageSourceApi.getDelayTimeList((err: BusinessError, delayTimes: Array<number>) => {
5060  if (err) {
5061    console.error(`Failed to get delayTimes object.code is ${err.code},message is ${err.message}`);
5062  } else {
5063    console.info('Succeeded in getting delayTimes object.');
5064  }
5065})
5066```
5067
5068### getDelayTimeList<sup>10+</sup>
5069
5070getDelayTimeList(): Promise<Array\<number>>
5071
5072获取图像延迟时间数组,使用Promise形式返回结果。此接口仅用于gif图片和webp图片。
5073
5074**系统能力:** SystemCapability.Multimedia.Image.ImageSource
5075
5076**返回值:**
5077
5078| 类型           | 说明                        |
5079| -------------- | --------------------------- |
5080| Promise<Array\<number>> | Promise对象,返回延迟时间数组。 |
5081
5082**错误码:**
5083
5084以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5085
5086| 错误码ID | 错误信息 |
5087| ------- | --------------------------------------------|
5088| 62980096 | The operation failed.             |
5089| 62980110 | The image source data is incorrect.      |
5090| 62980111 | The image source data is incomplete. |
5091| 62980112 | The image format does not match.        |
5092| 62980113 | Unknown image format.         |
5093| 62980115 | Invalid image parameter.      |
5094| 62980116 | Failed to decode the image.          |
5095| 62980118 | Failed to create the image plugin.  |
5096| 62980122 | Failed to decode the image header.   |
5097| 62980137 | Invalid media operation.      |
5098| 62980149 | Invalid MIME type for the image source.      |
5099
5100**示例:**
5101
5102```ts
5103import { BusinessError } from '@kit.BasicServicesKit';
5104
5105imageSourceApi.getDelayTimeList().then((delayTimes: Array<number>) => {
5106  console.info('Succeeded in getting delayTimes object.');
5107}).catch((err: BusinessError) => {
5108  console.error(`Failed to get delayTimes object.code is ${err.code},message is ${err.message}`);
5109})
5110```
5111
5112### getFrameCount<sup>10+</sup>
5113
5114getFrameCount(callback: AsyncCallback\<number>): void
5115
5116获取图像帧数,使用callback形式返回结果。
5117
5118**系统能力:** SystemCapability.Multimedia.Image.ImageSource
5119
5120**参数:**
5121
5122| 参数名   | 类型                 | 必填 | 说明                               |
5123| -------- | -------------------- | ---- | ---------------------------------- |
5124| callback | AsyncCallback\<number> | 是   | 回调函数,当获取图像帧数成功,err为undefined,data为获取到的图像帧数;否则为错误对象。 |
5125
5126**错误码:**
5127
5128以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5129
5130| 错误码ID | 错误信息 |
5131| ------- | --------------------------------------------|
5132| 62980096| The operation failed.              |
5133| 62980110| The image source data is incorrect. |
5134| 62980111| The image source data is incomplete. |
5135| 62980112| The image format does not match. |
5136| 62980113| Unknown image format. |
5137| 62980115| Invalid image parameter. |
5138| 62980116| Failed to decode the image. |
5139| 62980118| Failed to create the image plugin. |
5140| 62980122| Failed to decode the image header. |
5141| 62980137| Invalid media operation. |
5142
5143**示例:**
5144
5145```ts
5146import { BusinessError } from '@kit.BasicServicesKit';
5147
5148imageSourceApi.getFrameCount((err: BusinessError, frameCount: number) => {
5149  if (err) {
5150    console.error(`Failed to get frame count.code is ${err.code},message is ${err.message}`);
5151  } else {
5152    console.info('Succeeded in getting frame count.');
5153  }
5154})
5155```
5156
5157### getFrameCount<sup>10+</sup>
5158
5159getFrameCount(): Promise\<number>
5160
5161获取图像帧数,使用Promise形式返回结果。
5162
5163**系统能力:** SystemCapability.Multimedia.Image.ImageSource
5164
5165**返回值:**
5166
5167| 类型           | 说明                        |
5168| -------------- | --------------------------- |
5169| Promise\<number> | Promise对象,返回图像帧数。 |
5170
5171**错误码:**
5172
5173以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5174
5175| 错误码ID | 错误信息 |
5176| ------- | --------------------------------------------|
5177| 62980096 | The operation failed.             |
5178| 62980110 | The image source data is incorrect.      |
5179| 62980111 | The image source data is incomplete. |
5180| 62980112 | The image format does not match.        |
5181| 62980113 | Unknown image format.         |
5182| 62980115 | Invalid image parameter.      |
5183| 62980116 | Failed to decode the image.          |
5184| 62980118 | Failed to create the image plugin.   |
5185| 62980122 | Failed to decode the image header.  |
5186| 62980137 | Invalid media operation.      |
5187
5188**示例:**
5189
5190```ts
5191import { BusinessError } from '@kit.BasicServicesKit';
5192
5193imageSourceApi.getFrameCount().then((frameCount: number) => {
5194  console.info('Succeeded in getting frame count.');
5195}).catch((err: BusinessError) => {
5196  console.error(`Failed to get frame count.code is ${err.code},message is ${err.message}`);
5197})
5198```
5199
5200### getDisposalTypeList<sup>12+</sup>
5201
5202getDisposalTypeList(): Promise\<Array\<number>>
5203
5204获取图像帧过渡模式数组,使用Promise形式返回结果。此接口仅用于gif图片。
5205
5206**系统能力:** SystemCapability.Multimedia.Image.ImageSource
5207
5208**返回值:**
5209
5210| 类型           | 说明                        |
5211| -------------- | --------------------------- |
5212| Promise\<Array\<number>> | Promise对象,返回帧过渡模式数组。 |
5213
5214**错误码:**
5215
5216以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5217
5218| 错误码ID | 错误信息 |
5219| ------- | --------------------------------------------|
5220| 62980096 | The operation failed.      |
5221| 62980101 | The image data is abnormal. |
5222| 62980137 | Invalid media operation.        |
5223| 62980149 | Invalid MIME type for the image source.      |
5224
5225**示例:**
5226
5227```ts
5228import { BusinessError } from '@kit.BasicServicesKit';
5229imageSourceApi.getDisposalTypeList().then((disposalTypes: Array<number>) => {
5230  console.info('Succeeded in getting disposalTypes object.');
5231}).catch((err: BusinessError) => {
5232  console.error(`Failed to get disposalTypes object.code ${err.code},message is ${err.message}`);
5233})
5234```
5235
5236### release
5237
5238release(callback: AsyncCallback\<void>): void
5239
5240释放图片源实例,使用callback形式返回结果。
5241
5242ArkTS有内存回收机制,ImageSource对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
5243
5244**系统能力:** SystemCapability.Multimedia.Image.ImageSource
5245
5246**参数:**
5247
5248| 参数名   | 类型                 | 必填 | 说明                               |
5249| -------- | -------------------- | ---- | ---------------------------------- |
5250| callback | AsyncCallback\<void> | 是   | 回调函数,当资源释放成功,err为undefined,否则为错误对象。  |
5251
5252**示例:**
5253
5254```ts
5255import { BusinessError } from '@kit.BasicServicesKit';
5256
5257imageSourceApi.release((err: BusinessError) => {
5258  if (err) {
5259    console.error(`Failed to release the image source instance.code ${err.code},message is ${err.message}`);
5260  } else {
5261    console.info('Succeeded in releasing the image source instance.');
5262  }
5263})
5264```
5265
5266### release
5267
5268release(): Promise\<void>
5269
5270释放图片源实例,使用Promise形式返回结果。
5271
5272ArkTS有内存回收机制,ImageSource对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
5273
5274**系统能力:** SystemCapability.Multimedia.Image.ImageSource
5275
5276**返回值:**
5277
5278| 类型           | 说明                        |
5279| -------------- | --------------------------- |
5280| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
5281
5282**示例:**
5283
5284```ts
5285import { BusinessError } from '@kit.BasicServicesKit';
5286
5287imageSourceApi.release().then(() => {
5288  console.info('Succeeded in releasing the image source instance.');
5289}).catch((error: BusinessError) => {
5290  console.error(`Failed to release the image source instance.code ${error.code},message is ${error.message}`);
5291})
5292```
5293
5294## image.createImagePacker
5295
5296createImagePacker(): ImagePacker
5297
5298创建ImagePacker实例。
5299
5300**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
5301
5302**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5303
5304**返回值:**
5305
5306| 类型                        | 说明                  |
5307| --------------------------- | --------------------- |
5308| [ImagePacker](#imagepacker) | 返回ImagePacker实例。 |
5309
5310**示例:**
5311
5312```ts
5313const imagePackerApi: image.ImagePacker = image.createImagePacker();
5314```
5315
5316## ImagePacker
5317
5318图片打包器类,用于图片压缩和打包。在调用ImagePacker的方法前,需要先通过[createImagePacker](#imagecreateimagepacker)构建一个ImagePacker实例,当前支持格式有:jpeg、webp、png、heif<sup>12+</sup>(不同硬件设备支持情况不同)。
5319
5320### 属性
5321
5322**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5323
5324| 名称             | 类型           | 可读 | 可写 | 说明                       |
5325| ---------------- | -------------- | ---- | ---- | -------------------------- |
5326| supportedFormats | Array\<string> | 是   | 否   | 图片打包支持的格式 jpeg、webp、png、heif<sup>12+</sup>(不同硬件设备支持情况不同)。 |
5327
5328### packing
5329
5330packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void
5331
5332图片压缩或重新打包,使用callback形式返回结果。
5333
5334**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
5335
5336**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5337
5338**参数:**
5339
5340| 参数名   | 类型                               | 必填 | 说明                               |
5341| -------- | ---------------------------------- | ---- | ---------------------------------- |
5342| source   | [ImageSource](#imagesource)        | 是   | 打包的图片源。                     |
5343| option   | [PackingOption](#packingoption)    | 是   | 设置打包参数。                      |
5344| callback | AsyncCallback\<ArrayBuffer>        | 是   | 回调函数,当图片打包成功,err为undefined,data为获取到的压缩或打包数据;否则为错误对象。  |
5345
5346**示例:**
5347
5348```ts
5349import { BusinessError } from '@kit.BasicServicesKit';
5350
5351const context: Context = getContext();
5352//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource会创建失败导致后续无法正常执行。
5353let filePath: string = context.filesDir + "/test.jpg";
5354const imageSourceApi: image.ImageSource = image.createImageSource(filePath);
5355let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 };
5356imagePackerApi.packing(imageSourceApi, packOpts, (err: BusinessError, data: ArrayBuffer) => {
5357  if (err) {
5358    console.error(`Failed to pack the image.code ${err.code},message is ${err.message}`);
5359  } else {
5360    console.info('Succeeded in packing the image.');
5361  }
5362})
5363```
5364
5365### packing
5366
5367packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer>
5368
5369图片压缩或重新打包,使用Promise形式返回结果。
5370
5371**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
5372
5373**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5374
5375**参数:**
5376
5377| 参数名 | 类型                            | 必填 | 说明           |
5378| ------ | ------------------------------- | ---- | -------------- |
5379| source | [ImageSource](#imagesource)     | 是   | 打包的图片源。 |
5380| option | [PackingOption](#packingoption) | 是   | 设置打包参数。 |
5381
5382**返回值:**
5383
5384| 类型                         | 说明                                          |
5385| ---------------------------- | --------------------------------------------- |
5386| Promise\<ArrayBuffer>        | Promise对象,返回压缩或打包后的数据。 |
5387
5388**示例:**
5389
5390```ts
5391import { BusinessError } from '@kit.BasicServicesKit';
5392
5393const context: Context = getContext();
5394//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource会创建失败导致后续无法正常执行。
5395let filePath: string = context.filesDir + "/test.jpg";
5396const imageSourceApi: image.ImageSource = image.createImageSource(filePath);
5397let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }
5398imagePackerApi.packing(imageSourceApi, packOpts)
5399  .then((data: ArrayBuffer) => {
5400    console.info('Succeeded in packing the image.');
5401  }).catch((error: BusinessError) => {
5402    console.error(`Failed to pack the image.code ${error.code},message is ${error.message}`);
5403  })
5404```
5405
5406### packing<sup>8+</sup>
5407
5408packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void
5409
5410图片压缩或重新打包,使用callback形式返回结果。
5411
5412**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
5413
5414**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5415
5416**参数:**
5417
5418| 参数名   | 类型                            | 必填 | 说明                               |
5419| -------- | ------------------------------- | ---- | ---------------------------------- |
5420| source   | [PixelMap](#pixelmap7)           | 是   | 打包的PixelMap资源。               |
5421| option   | [PackingOption](#packingoption) | 是   | 设置打包参数。                     |
5422| callback | AsyncCallback\<ArrayBuffer>     | 是   | 回调函数,当图片打包成功,err为undefined,data为获取到的压缩或打包数据;否则为错误对象。  |
5423
5424**示例:**
5425
5426```ts
5427import { BusinessError } from '@kit.BasicServicesKit';
5428
5429const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
5430let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
5431image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => {
5432  let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }
5433  imagePackerApi.packing(pixelMap, packOpts, (err: BusinessError, data: ArrayBuffer) => {
5434    if (err) {
5435      console.error(`Failed to pack the image.code ${err.code},message is ${err.message}`);
5436    } else {
5437      console.info('Succeeded in packing the image.');
5438    }
5439  })
5440}).catch((error: BusinessError) => {
5441  console.error(`Failed to create the PixelMap.code ${error.code},message is ${error.message}`);
5442})
5443```
5444
5445### packing<sup>8+</sup>
5446
5447packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer>
5448
5449图片压缩或重新打包,使用Promise形式返回结果。
5450
5451**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
5452
5453**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5454
5455**参数:**
5456
5457| 参数名 | 类型                            | 必填 | 说明               |
5458| ------ | ------------------------------- | ---- | ------------------ |
5459| source | [PixelMap](#pixelmap7)           | 是   | 打包的PixelMap源。 |
5460| option | [PackingOption](#packingoption) | 是   | 设置打包参数。     |
5461
5462**返回值:**
5463
5464| 类型                  | 说明                                         |
5465| --------------------- | -------------------------------------------- |
5466| Promise\<ArrayBuffer> | Promise对象,返回压缩或打包后的数据。|
5467
5468**示例:**
5469
5470```ts
5471import { BusinessError } from '@kit.BasicServicesKit';
5472
5473const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
5474let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
5475image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => {
5476  let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }
5477  imagePackerApi.packing(pixelMap, packOpts)
5478    .then((data: ArrayBuffer) => {
5479      console.info('Succeeded in packing the image.');
5480    }).catch((error: BusinessError) => {
5481    console.error(`Failed to pack the image.code ${error.code},message is ${error.message}`);
5482  })
5483}).catch((error: BusinessError) => {
5484  console.error(`Failed to create PixelMap.code ${error.code},message is ${error.message}`);
5485})
5486```
5487
5488### packing<sup>13+</sup>
5489
5490packing(picture: Picture, options: PackingOption): Promise\<ArrayBuffer>
5491
5492将图像压缩或重新打包,使用Promise形式返回结果。
5493
5494**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5495
5496**参数:**
5497
5498| 参数名           | 类型                                                 | 必填 | 说明                 |
5499| ---------------- | ---------------------------------------------------- | ---- | -------------------- |
5500| picture | [Picture](#picture13)                           | 是   | 打包的Picture对象。 |
5501| option           | [PackingOption](#packingoption) | 是   | 设置打包参数。       |
5502
5503**返回值:**
5504
5505| 类型                  | 说明                                  |
5506| --------------------- | ------------------------------------- |
5507| Promise\<ArrayBuffer> | Promise对象,返回压缩或打包后的数据。 |
5508
5509**错误码:**
5510
5511以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5512
5513| 错误码ID | 错误信息                                                     |
5514| -------- | ------------------------------------------------------------ |
5515| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
5516| 7800301  | Encode failed.                                         |
5517
5518**示例:**
5519
5520```ts
5521import { BusinessError } from '@kit.BasicServicesKit';
5522import { image } from '@kit.ImageKit';
5523
5524async function Packing() {
5525  const context = getContext();
5526  const resourceMgr = context.resourceManager;
5527  const rawFile = await resourceMgr.getRawFileContent("test.jpg");
5528  let ops: image.SourceOptions = {
5529    sourceDensity: 98,
5530  }
5531  let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops);
5532  let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap();
5533  let pictureObj: image.Picture = image.createPicture(commodityPixelMap);
5534
5535  let funcName = "Packing";
5536  if (imagePackerApi != null) {
5537    let opts: image.PackingOption = {
5538      format: "image/jpeg",
5539      quality: 98,
5540      bufferSize: 10,
5541      desiredDynamicRange: image.PackingDynamicRange.AUTO,
5542      needsPackProperties: true};
5543    await imagePackerApi.packing(pictureObj, opts).then((data: ArrayBuffer) => {
5544        console.info(funcName, 'Succeeded in packing the image.'+ data);
5545      }).catch((error: BusinessError) => {
5546        console.error(funcName, 'Failed to pack the image.code ${error.code},message is ${error.message}');
5547      });
5548  }
5549}
5550```
5551
5552### release
5553
5554release(callback: AsyncCallback\<void>): void
5555
5556释放图片打包实例,使用callback形式返回结果。
5557
5558ArkTS有内存回收机制,ImagePacker对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
5559
5560**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5561
5562**参数:**
5563
5564| 参数名   | 类型                 | 必填 | 说明                           |
5565| -------- | -------------------- | ---- | ------------------------------ |
5566| callback | AsyncCallback\<void> | 是   | 回调函数,当释放图片打包实例成功,err为undefined,否则为错误对象。 |
5567
5568**示例:**
5569
5570```ts
5571import { BusinessError } from '@kit.BasicServicesKit';
5572
5573imagePackerApi.release((err: BusinessError)=>{
5574  if (err) {
5575    console.error(`Failed to release image packaging.code ${err.code},message is ${err.message}`);
5576  } else {
5577    console.info('Succeeded in releasing image packaging.');
5578  }
5579})
5580```
5581
5582### release
5583
5584release(): Promise\<void>
5585
5586释放图片打包实例,使用Promise形式返回释放结果。
5587
5588ArkTS有内存回收机制,ImagePacker对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
5589
5590**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5591
5592**返回值:**
5593
5594| 类型           | 说明                                                   |
5595| -------------- | ------------------------------------------------------ |
5596| Promise\<void> |  Promise对象。无返回结果的Promise对象。|
5597
5598**示例:**
5599
5600```ts
5601import { BusinessError } from '@kit.BasicServicesKit';
5602
5603imagePackerApi.release().then(() => {
5604  console.info('Succeeded in releasing image packaging.');
5605}).catch((error: BusinessError) => {
5606  console.error(`Failed to release image packaging.code ${error.code},message is ${error.message}`);
5607})
5608```
5609
5610### packToFile<sup>11+</sup>
5611
5612packToFile(source: ImageSource, fd: number, options: PackingOption, callback: AsyncCallback\<void>): void
5613
5614指定打包参数,将ImageSource图片源编码后直接打包进文件。使用callback形式返回结果。
5615
5616**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5617
5618**参数:**
5619
5620| 参数名   | 类型                            | 必填 | 说明                           |
5621| -------- | ------------------------------- | ---- | ------------------------------ |
5622| source   | [ImageSource](#imagesource)     | 是   | 打包的图片源。                 |
5623| fd       | number                          | 是   | 文件描述符。                   |
5624| options   | [PackingOption](#packingoption) | 是   | 设置打包参数。                 |
5625| callback | AsyncCallback\<void>            | 是   | 回调函数,当打包进文件成功,err为undefined,否则为错误对象。  |
5626
5627**示例:**
5628
5629```ts
5630import { BusinessError } from '@kit.BasicServicesKit';
5631import { fileIo as fs } from '@kit.CoreFileKit';
5632
5633const context: Context = getContext(this);
5634//此处'test.png'仅作示例,请开发者自行替换,否则imageSource会创建失败导致后续无法正常执行。
5635const path: string = context.filesDir + "/test.png";
5636const imageSourceApi: image.ImageSource = image.createImageSource(path);
5637let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 };
5638const filePath: string = context.filesDir + "/image_source.jpg";
5639let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
5640const imagePackerApi: image.ImagePacker = image.createImagePacker();
5641imagePackerApi.packToFile(imageSourceApi, file.fd, packOpts, (err: BusinessError) => {
5642  if (err) {
5643    console.error(`Failed to pack the image to file.code ${err.code},message is ${err.message}`);
5644  } else {
5645    console.info('Succeeded in packing the image to file.');
5646  }
5647})
5648```
5649
5650### packToFile<sup>11+</sup>
5651
5652packToFile (source: ImageSource, fd: number, options: PackingOption): Promise\<void>
5653
5654指定打包参数,将ImageSource图片源编码后直接打包进文件。使用Promise形式返回结果。
5655
5656**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5657
5658**参数:**
5659
5660| 参数名 | 类型                            | 必填 | 说明           |
5661| ------ | ------------------------------- | ---- | -------------- |
5662| source | [ImageSource](#imagesource)     | 是   | 打包的图片源。 |
5663| fd     | number                          | 是   | 文件描述符。   |
5664| options | [PackingOption](#packingoption) | 是   | 设置打包参数。 |
5665
5666**返回值:**
5667
5668| 类型           | 说明                              |
5669| -------------- | --------------------------------- |
5670| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
5671
5672**示例:**
5673
5674```ts
5675import { BusinessError } from '@kit.BasicServicesKit';
5676import { fileIo as fs } from '@kit.CoreFileKit';
5677
5678const context: Context = getContext(this);
5679//此处'test.png'仅作示例,请开发者自行替换,否则imageSource会创建失败导致后续无法正常执行。
5680const path: string = context.filesDir + "/test.png";
5681const imageSourceApi: image.ImageSource = image.createImageSource(path);
5682let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 };
5683const filePath: string = context.filesDir + "/image_source.jpg";
5684let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
5685const imagePackerApi: image.ImagePacker = image.createImagePacker();
5686imagePackerApi.packToFile(imageSourceApi, file.fd, packOpts).then(() => {
5687  console.info('Succeeded in packing the image to file.');
5688}).catch((error: BusinessError) => { 
5689  console.error(`Failed to pack the image to file.code ${error.code},message is ${error.message}`);
5690}) 
5691```
5692
5693### packToFile<sup>11+</sup>
5694
5695packToFile (source: PixelMap, fd: number, options: PackingOption,  callback: AsyncCallback\<void>): void;
5696
5697指定打包参数,将PixelMap图片源编码后直接打包进文件。使用callback形式返回结果。
5698
5699**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5700
5701**参数:**
5702
5703| 参数名   | 类型                            | 必填 | 说明                           |
5704| -------- | ------------------------------- | ---- | ------------------------------ |
5705| source   | [PixelMap](#pixelmap7)          | 是   | 打包的PixelMap资源。           |
5706| fd       | number                          | 是   | 文件描述符。                   |
5707| options   | [PackingOption](#packingoption) | 是   | 设置打包参数。                 |
5708| callback | AsyncCallback\<void>            | 是   | 回调函数,当打包图片进文件成功,err为undefined,否则为错误对象。  |
5709
5710**示例:**
5711
5712```ts
5713import { BusinessError } from '@kit.BasicServicesKit';
5714import { fileIo as fs } from '@kit.CoreFileKit';
5715
5716const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
5717let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
5718const context: Context = getContext(this);
5719const path: string = context.filesDir + "/pixel_map.jpg";
5720image.createPixelMap(color, opts).then((pixelmap: image.PixelMap) => {
5721  let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }
5722  let file = fs.openSync(path, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
5723  const imagePackerApi: image.ImagePacker = image.createImagePacker();
5724  imagePackerApi.packToFile(pixelmap, file.fd, packOpts, (err: BusinessError) => {
5725    if (err) {
5726      console.error(`Failed to pack the image to file.code ${err.code},message is ${err.message}`);
5727    } else {
5728      console.info('Succeeded in packing the image to file.');
5729    }
5730  })
5731})
5732```
5733
5734### packToFile<sup>11+</sup>
5735
5736packToFile (source: PixelMap, fd: number, options: PackingOption): Promise\<void>
5737
5738指定打包参数,将PixelMap图片源编码后直接打包进文件。使用Promise形式返回结果。
5739
5740**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5741
5742**参数:**
5743
5744| 参数名 | 类型                            | 必填 | 说明                 |
5745| ------ | ------------------------------- | ---- | -------------------- |
5746| source | [PixelMap](#pixelmap7)          | 是   | 打包的PixelMap资源。 |
5747| fd     | number                          | 是   | 文件描述符。         |
5748| options | [PackingOption](#packingoption) | 是   | 设置打包参数。       |
5749
5750**返回值:**
5751
5752| 类型           | 说明                              |
5753| -------------- | --------------------------------- |
5754| Promise\<void> |  Promise对象。无返回结果的Promise对象。|
5755
5756**示例:**
5757
5758```ts
5759import { BusinessError } from '@kit.BasicServicesKit';
5760import { fileIo as fs } from '@kit.CoreFileKit';
5761
5762const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
5763let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
5764const context: Context = getContext(this);
5765const path: string = context.filesDir + "/pixel_map.jpg";
5766image.createPixelMap(color, opts).then((pixelmap: image.PixelMap) => {
5767  let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }
5768  let file = fs.openSync(path, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
5769  const imagePackerApi: image.ImagePacker = image.createImagePacker();
5770  imagePackerApi.packToFile(pixelmap, file.fd, packOpts)
5771    .then(() => {
5772      console.info('Succeeded in packing the image to file.');
5773    }).catch((error: BusinessError) => {
5774    console.error(`Failed to pack the image to file.code ${error.code},message is ${error.message}`);
5775  })
5776})
5777```
5778
5779### packToFile<sup>13+</sup>
5780
5781packToFile(picture: Picture, fd: number, options: PackingOption): Promise\<void>
5782
5783指定打包参数,将Picture图片源编码后直接打包进文件。使用Promise形式返回结果。
5784
5785**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5786
5787**参数:**
5788
5789| 参数名  | 类型                         | 必填 | 说明                 |
5790| ------- | ---------------------------- | ---- | -------------------- |
5791| picture  | [Picture](#picture13)          | 是   | 打包的Picture资源。 |
5792| fd      | number                       | 是   | 文件描述符。         |
5793| options | [PackingOption](#packingoption) | 是   | 设置打包参数。       |
5794
5795**返回值:**
5796
5797| 类型           | 说明                      |
5798| -------------- | ------------------------- |
5799| Promise\<void> | 无返回结果的Promise对象。 |
5800
5801**错误码:**
5802
5803以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5804
5805| 错误码ID | 错误信息                                                     |
5806| -------- | ------------------------------------------------------------ |
5807| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
5808| 7800301  | Encode failed.                                         |
5809
5810**示例:**
5811
5812```ts
5813import { BusinessError } from '@kit.BasicServicesKit';
5814import { image } from '@kit.ImageKit';
5815import { fileIo as fs } from '@kit.CoreFileKit';
5816
5817async function PackToFile() {
5818  const context = getContext();
5819  const resourceMgr = context.resourceManager;
5820  const rawFile = await resourceMgr.getRawFileContent("test.jpg");
5821  let ops: image.SourceOptions = {
5822    sourceDensity: 98,
5823  }
5824  let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops);
5825  let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap();
5826  let pictureObj: image.Picture = image.createPicture(commodityPixelMap);
5827
5828  let funcName = "PackToFile";
5829  if (imagePackerApi != null) {
5830    const context: Context = getContext();
5831    const filePath: string = context.filesDir + "/test.jpg";
5832    let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
5833    let packOpts: image.PackingOption = {
5834      format: "image/jpeg",
5835      quality: 98,
5836      bufferSize: 10,
5837      desiredDynamicRange: image.PackingDynamicRange.AUTO,
5838      needsPackProperties: true};
5839    await imagePackerApi.packToFile(pictureObj, file.fd, packOpts).then(() => {
5840      console.info(funcName, 'Succeeded in packing the image to file.');
5841    }).catch((error: BusinessError) => {
5842      console.error(funcName, 'Failed to pack the image to file.code ${error.code},message is ${error.message}');
5843    });
5844  }
5845}
5846```
5847
5848## image.createAuxiliaryPicture<sup>13+</sup>
5849
5850createAuxiliaryPicture(buffer: ArrayBuffer, size: Size, type: AuxiliaryPictureType): AuxiliaryPicture
5851
5852通过ArrayBuffer图片数据、辅助图尺寸、辅助图类型创建AuxiliaryPicture实例。
5853
5854**系统能力:** SystemCapability.Multimedia.Image.
5855
5856**参数:**
5857
5858| 参数名 | 类型                                            | 必填 | 说明                         |
5859| ------ | ----------------------------------------------- | ---- | ---------------------------- |
5860| buffer | ArrayBuffer                                     | 是   | 以buffer形式存放的图像数据。 |
5861| size   | [Size](#size)                                   | 是   | 辅助图的尺寸。               |
5862| type   | [AuxiliaryPictureType](#auxiliarypicturetype13) | 是   | 辅助图类型。                 |
5863
5864**返回值:**
5865
5866| 类型                                    | 说明                                       |
5867| --------------------------------------- | ------------------------------------------ |
5868| [AuxiliaryPicture](#auxiliarypicture13) | 如果操作成功,则返回AuxiliaryPicture实例。 |
5869
5870**错误码:**
5871
5872以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5873
5874| 错误码ID | 错误信息                                                     |
5875| -------- | ------------------------------------------------------------ |
5876| 401      | Parameter error.Possible causes:1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
5877
5878**示例:**
5879
5880```ts
5881import { image } from '@kit.ImageKit';
5882
5883async function CreateAuxiliaryPicture() {
5884  let funcName = "CreateAuxiliaryPicture";
5885  const context = getContext();
5886  const resourceMgr = context.resourceManager;
5887  const rawFile = await resourceMgr.getRawFileContent("hdr.jpg"); //需要支持hdr的图片
5888  let auxBuffer: ArrayBuffer = rawFile.buffer as ArrayBuffer;
5889  let auxSize: Size = {
5890    height: 180,
5891    width: 240
5892  };
5893  let auxType: image.AuxiliaryPictureType = image.AuxiliaryPictureType.GAINMAP;
5894  let auxPictureObj: image.AuxiliaryPicture | null = image.createAuxiliaryPicture(auxBuffer, auxSize, auxType);
5895  if(auxPictureObj != null) {
5896    let type: image.AuxiliaryPictureType = auxPictureObj.getType();
5897    console.info(funcName, 'CreateAuxiliaryPicture succeeded this.Aux_picture.type.' + JSON.stringify(type));
5898  } else {
5899    console.error(funcName, 'CreateAuxiliaryPicture failed');
5900  }
5901}
5902```
5903
5904## AuxiliaryPicture<sup>13+</sup>
5905
5906辅助图一般用于辅助主图进行特殊信息的展示,使图像包含更丰富的信息。辅助图图像类,用于读取或写入图像的辅助图数据以及获取图像的辅助图信息。在调用AuxiliaryPicture的方法前,需要先通过[createAuxiliaryPicture](#imagecreateauxiliarypicture13)创建一个AuxiliaryPicture实例。
5907
5908### 属性
5909
5910**系统能力:** SystemCapability.Multimedia.Image.Core
5911
5912### writePixelsFromBuffer<sup>13+</sup>
5913
5914writePixelsFromBuffer(data: ArrayBuffer): Promise\<void>
5915
5916读取ArrayBuffer中的辅助图片数据,并将数据写入AuxiliaryPicture对象,使用Promise形式返回。
5917
5918**系统能力:** SystemCapability.Multimedia.Image.Core
5919
5920**参数:**
5921
5922| 参数名 | 类型        | 必填 | 说明             |
5923| ------ | ----------- | ---- | ---------------- |
5924| data   | ArrayBuffer | 是   | 辅助图像素数据。 |
5925
5926**返回值:**
5927
5928| 类型           | 说明                                   |
5929| -------------- | -------------------------------------- |
5930| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
5931
5932**错误码:**
5933
5934以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5935
5936| 错误码ID | 错误信息                                                     |
5937| -------- | ------------------------------------------------------------ |
5938| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
5939| 7600301  | Memory alloc failed.                                         |
5940| 7600302  | Memory copy failed.                                          |
5941
5942**示例:**
5943
5944```ts
5945import { image } from '@kit.ImageKit';
5946
5947async function WritePixelsFromBuffer() {
5948  const context = getContext();
5949  const resourceMgr = context.resourceManager;
5950  const rawFile = await resourceMgr.getRawFileContent("hdr.jpg"); //需要支持hdr的图片
5951  let ops: image.SourceOptions = {
5952    sourceDensity: 98,
5953  }
5954  let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops);
5955  let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap();
5956  let pictureObj: image.Picture = image.createPicture(commodityPixelMap);
5957  let auxPictureObj: image.AuxiliaryPicture | null = pictureObj.getAuxiliaryPicture(image.AuxiliaryPictureType.GAINMAP);
5958  if(auxPictureObj != null) {
5959    let auxBuffer: ArrayBuffer = await auxPictureObj.readPixelsToBuffer();
5960    await auxPictureObj.writePixelsFromBuffer(auxBuffer);
5961    console.info('Write pixels from buffer success.');
5962  } else {
5963    console.error('AuxPictureObj is null.');
5964  }
5965}
5966```
5967
5968### readPixelsToBuffer<sup>13+</sup>
5969
5970readPixelsToBuffer(): Promise\<ArrayBuffer>
5971
5972读取图像像素映射数据并将数据写入ArrayBuffer,使用Promise形式返回。
5973
5974**系统能力:** SystemCapability.Multimedia.Image.Core
5975
5976**返回值:**
5977
5978| 类型                  | 说明                              |
5979| --------------------- | --------------------------------- |
5980| Promise\<ArrayBuffer> | Promise对象。返回辅助图像素数据。 |
5981
5982**错误码:**
5983
5984以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5985
5986| 错误码ID | 错误信息             |
5987| -------- | -------------------- |
5988| 7600301  | Memory alloc failed. |
5989| 7600302  | Memory copy failed.  |
5990
5991**示例:**
5992
5993```ts
5994import { BusinessError } from '@kit.BasicServicesKit';
5995import { image } from '@kit.ImageKit';
5996
5997async function ReadPixelsToBuffer() {
5998  const context = getContext();
5999  const resourceMgr = context.resourceManager;
6000  const rawFile = await resourceMgr.getRawFileContent("hdr.jpg"); //需要支持hdr的图片
6001  let ops: image.SourceOptions = {
6002    sourceDensity: 98,
6003  }
6004  let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops);
6005  let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap();
6006  let pictureObj: image.Picture = image.createPicture(commodityPixelMap);
6007  let auxPictureObj: image.AuxiliaryPicture | null = pictureObj.getAuxiliaryPicture(image.AuxiliaryPictureType.GAINMAP);
6008  if(auxPictureObj != null) {
6009    await auxPictureObj.readPixelsToBuffer().then((pixelsBuffer: ArrayBuffer) => {
6010      console.info('Read pixels to buffer success.' );
6011    }).catch((error: BusinessError) => {
6012      console.error('Read pixels to buffer failed error.code: ' + JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message));
6013    });
6014  } else {
6015    console.error('AuxPictureObj is null.');
6016  }
6017}
6018```
6019
6020### getType<sup>13+</sup>
6021
6022getType(): AuxiliaryPictureType
6023
6024获取辅助图的类型。
6025
6026**系统能力:** SystemCapability.Multimedia.Image.Core
6027
6028**返回值:**
6029
6030| 类型                                            | 说明                         |
6031| ----------------------------------------------- | ---------------------------- |
6032| [AuxiliaryPictureType](#auxiliarypicturetype13) | 操作成功,返回辅助图的类型。 |
6033
6034**示例:**
6035
6036```ts
6037import { image } from '@kit.ImageKit';
6038
6039async function GetAuxiliaryPictureType() {
6040  if (auxPictureObj != null) {
6041    let type: image.AuxiliaryPictureType = auxPictureObj.getType();
6042    console.info('Success get auxiliary picture type ' +  JSON.stringify(type));
6043  } else {
6044    console.info('Failed get auxiliary picture type ');
6045  }
6046}
6047```
6048
6049### setMetadata<sup>13+</sup>
6050
6051setMetadata(metadataType: MetadataType, metadata: Metadata): Promise\<void>
6052
6053设置辅助图元数据。
6054
6055**系统能力:** SystemCapability.Multimedia.Image.Core
6056
6057**参数:**
6058
6059| 参数名       | 类型                            | 必填 | 说明                                 |
6060| ------------ | ------------------------------- | ---- | ------------------------------------ |
6061| metadataType | [MetadataType](#metadatatype13) | 是   | 元数据的类型,用于设置对应的元数据。 |
6062| metadata     | [Metadata](#metadata13)         | 是   | 元数据对象。                         |
6063
6064**返回值:**
6065
6066| 类型           | 说明                                   |
6067| -------------- | -------------------------------------- |
6068| Promise\<void> | Promise对象,无返回结果的Promise对象。 |
6069
6070**错误码:**
6071
6072以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
6073
6074| 错误码ID | 错误信息                                                     |
6075| -------- | ------------------------------------------------------------ |
6076| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
6077| 7600202  | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. |
6078
6079**示例:**
6080
6081```ts
6082import { BusinessError } from '@kit.BasicServicesKit';
6083import { image } from '@kit.ImageKit';
6084
6085async function SetAuxPictureObjMetadata() {
6086  const exifContext = getContext();
6087  const exifResourceMgr = exifContext.resourceManager;
6088  const exifRawFile = await exifResourceMgr.getRawFileContent("exif.jpg");//图片包含exif metadata
6089  let exifOps: image.SourceOptions = {
6090    sourceDensity: 98,
6091  }
6092  let exifImageSource: image.ImageSource = image.createImageSource(exifRawFile.buffer as ArrayBuffer, exifOps);
6093  let exifCommodityPixelMap: image.PixelMap = await exifImageSource.createPixelMap();
6094  let exifPictureObj: image.Picture = image.createPicture(exifCommodityPixelMap);
6095  if (exifPictureObj != null) {
6096    console.info('Create picture succeeded');
6097  } else {
6098    console.info('Create picture failed');
6099  }
6100
6101  if (auxPictureObj != null) {
6102    let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA;
6103    let exifMetaData: image.Metadata = await exifPictureObj.getMetadata(metadataType);
6104    auxPictureObj.setMetadata(metadataType, exifMetaData).then(() => {
6105      console.info('Set metadata success');
6106    }).catch((error: BusinessError) => {
6107      console.error('Set metadata failed.error.code: ${error.code}, error.message: ${error.message}');
6108    });
6109  } else {
6110    console.info('AuxPictureObjMetaData is null');
6111  }
6112}
6113```
6114
6115### getMetadata<sup>13+</sup>
6116
6117getMetadata(metadataType: MetadataType): Promise\<Metadata>
6118
6119从辅助图中获取元数据。
6120
6121**系统能力:** SystemCapability.Multimedia.Image.Core
6122
6123**参数:**
6124
6125| 参数名       | 类型                            | 必填 | 说明                                   |
6126| ------------ | ------------------------------- | ---- | -------------------------------------- |
6127| metadataType | [MetadataType](#metadatatype13) | 是   | 元数据类型,用于获取对应类型的元数据。 |
6128
6129**返回值:**
6130
6131| 类型                             | 说明             |
6132| -------------------------------- | ---------------- |
6133| Promise<[Metadata](#metadata13)> | 返回元数据对象。 |
6134
6135**错误码:**
6136
6137以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
6138
6139| 错误码ID | 错误信息                                                     |
6140| -------- | ------------------------------------------------------------ |
6141| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
6142| 7600202  | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. |
6143
6144**示例:**
6145
6146```ts
6147import { image } from '@kit.ImageKit';
6148
6149async function GetAuxPictureObjMetadata() {
6150  if (auxPictureObj != null) {
6151    let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA;
6152    let auxPictureObjMetaData: image.Metadata | null = await auxPictureObj.getMetadata(metadataType);
6153    if (auxPictureObjMetaData != null) {
6154      console.info('Get auxpictureobj Metadata success' );
6155    } else {
6156      console.info('Get auxpictureobj Metadata failed');
6157    }
6158  } else {
6159    console.info('Get auxpictureobj is null.');
6160  }
6161}
6162```
6163
6164### getAuxiliaryPictureinfo<sup>13+</sup>
6165
6166getAuxiliaryPictureInfo(): AuxiliaryPictureInfo
6167
6168获取有关此辅助图的图像信息。
6169
6170**系统能力:** SystemCapability.Multimedia.Image.Core
6171
6172**返回值:**
6173
6174| 类型                                            | 说明                              |
6175| ----------------------------------------------- | --------------------------------- |
6176| [AuxiliaryPictureInfo](#auxiliarypictureinfo13) | Promise对象,返回辅助图图像信息。 |
6177
6178**示例:**
6179
6180```ts
6181import { image } from '@kit.ImageKit';
6182
6183async function GetAuxiliaryPictureInfo() {
6184  if(auxPictureObj != null) {
6185    let auxinfo: image.AuxiliaryPictureInfo = auxPictureObj.getAuxiliaryPictureInfo();
6186    console.info('GetAuxiliaryPictureInfo Type: ' + auxinfo.auxiliaryPictureType +
6187      ' height: ' + auxinfo.size.height + ' width: ' + auxinfo.size.width +
6188      ' rowStride: ' +  auxinfo.rowStride +  ' pixelFormat: ' + auxinfo.pixelFormat +
6189      ' colorSpace: ' +  auxinfo.colorSpace);
6190  } else {
6191    console.info('Get auxiliary picture information failed');
6192  }
6193}
6194```
6195
6196### setAuxiliaryPictureinfo<sup>13+</sup>
6197
6198setAuxiliaryPictureInfo(info: AuxiliaryPictureInfo): void
6199
6200设置辅助图的图像信息。
6201
6202**系统能力:** SystemCapability.Multimedia.Image.Core
6203
6204**参数:**
6205
6206| 参数名 | 类型                                            | 必填 | 说明               |
6207| ------ | ----------------------------------------------- | ---- | ------------------ |
6208| info   | [AuxiliaryPictureInfo](#auxiliarypictureinfo13) | 是   | 辅助图的图像信息。 |
6209
6210**错误码:**
6211
6212以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
6213
6214| 错误码ID | 错误信息                                                     |
6215| -------- | :----------------------------------------------------------- |
6216| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
6217
6218**示例:**
6219
6220```ts
6221import { colorSpaceManager } from '@kit.ArkGraphics2D';
6222import { image } from '@kit.ImageKit';
6223
6224async function SetAuxiliaryPictureInfo() {
6225  if(auxPictureObj != null) {
6226    let colorSpaceName = colorSpaceManager.ColorSpace.SRGB;
6227    let info: image.AuxiliaryPictureInfo = {
6228      auxiliaryPictureType: image.AuxiliaryPictureType.GAINMAP,
6229      size: {height: 100, width: 200},
6230      pixelFormat: image.PixelMapFormat.RGBA_8888,
6231      rowStride: 0,
6232      colorSpace: colorSpaceManager.create(colorSpaceName),
6233    };
6234    auxPictureObj.setAuxiliaryPictureInfo(info);
6235  }
6236}
6237```
6238
6239### release<sup>13+</sup>
6240
6241release():void
6242
6243释放辅助图对象,无返回值。
6244
6245**系统能力:** SystemCapability.Multimedia.Image.Core
6246
6247**示例:**
6248
6249```ts
6250import { image } from '@kit.ImageKit';
6251
6252async function Release() {
6253  let funcName = "Release";
6254  if (auxPictureObj != null) {
6255    auxPictureObj.release();
6256    if (auxPictureObj.getType() == null) {
6257      console.info(funcName, 'Success !');
6258    } else {
6259      console.info(funcName, 'Failed !');
6260    }
6261  } else {
6262    console.info('PictureObj is null');
6263  }
6264}
6265```
6266
6267## Metadata<sup>13+</sup>
6268
6269图像元数据类,用于存储图像的元数据。
6270
6271### 属性
6272
6273**系统能力:** SystemCapability.Multimedia.Image.Core
6274
6275### getProperties<sup>13+</sup>
6276
6277getProperties(key: Array\<string>): Promise\<Record\<string, string | null>>
6278
6279获取图像中属性的值,此方法使用promise返回记录数组中的属性值。
6280
6281**系统能力:** SystemCapability.Multimedia.Image.Core
6282
6283**参数:**
6284
6285| 参数名 | 类型           | 必填 | 说明                     |
6286| ------ | -------------- | ---- | ------------------------ |
6287| key    | Array\<string> | 是   | 要获取其值的属性的名称。 |
6288
6289**返回值:**
6290
6291| 类型                                     | 说明                                                         |
6292| ---------------------------------------- | ------------------------------------------------------------ |
6293| Promise\<Record<string, string \| null>> | Promise对象,返回元数据要获取的属性的值,如获取失败则返回错误码。 |
6294
6295**错误码:**
6296
6297以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
6298
6299| 错误码ID | 错误信息                                                     |
6300| -------- | ------------------------------------------------------------ |
6301| 401      | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; |
6302| 7600202  | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. |
6303
6304**示例:**
6305
6306```ts
6307import { BusinessError } from '@kit.BasicServicesKit';
6308import { image } from '@kit.ImageKit';
6309
6310async function GetProperties() {
6311  const context = getContext();
6312  const resourceMgr = context.resourceManager;
6313  const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); //图片包含exif metadata
6314  let ops: image.SourceOptions = {
6315    sourceDensity: 98,
6316  }
6317  let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops);
6318  let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap();
6319  let pictureObj: image.Picture = image.createPicture(commodityPixelMap);
6320  let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA;
6321  let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType);
6322  if (metaData != null) {
6323    await metaData.getProperties(["ImageWidth", "ImageLength"]).then((data2) => {
6324      console.info('Get properties ',JSON.stringify(data2));
6325    }).catch((error: BusinessError) => {
6326      console.info('Get properties failed error.code: ' +JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message));
6327    });
6328  } else {
6329    console.info('Metadata is null.');
6330  }
6331}
6332```
6333
6334### setProperties<sup>13+</sup>
6335
6336setProperties(records: Record\<string, string | null>): Promise\<void>
6337
6338批量设置图片元数据中的指定属性的值,用Promise形式不返回结果。
6339
6340**系统能力:** SystemCapability.Multimedia.Image.Core
6341
6342**参数:**
6343
6344| 参数名  | 类型                           | 必填 | 说明                     |
6345| ------- | ------------------------------ | ---- | ------------------------ |
6346| records | Record<string, string \| null> | 是   | 要修改的属性和值的数组。 |
6347
6348**返回值:**
6349
6350| 类型           | 说明                                  |
6351| -------------- | ------------------------------------- |
6352| Promise\<void> | Promise对象,如获取失败则返回错误码。 |
6353
6354**错误码:**
6355
6356以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
6357
6358| 错误码ID | 错误信息                                                     |
6359| -------- | ------------------------------------------------------------ |
6360| 401      | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; |
6361| 7600202  | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. |
6362
6363**示例:**
6364
6365```ts
6366import { BusinessError } from '@kit.BasicServicesKit';
6367import { image } from '@kit.ImageKit';
6368
6369async function SetProperties() {
6370  const context = getContext();
6371  const resourceMgr = context.resourceManager;
6372  const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); //图片包含exif metadata
6373  let ops: image.SourceOptions = {
6374    sourceDensity: 98,
6375  }
6376  let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops);
6377  let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap();
6378  let pictureObj: image.Picture = image.createPicture(commodityPixelMap);
6379  let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA;
6380  let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType);
6381  if (metaData != null) {
6382    let setkey: Record<string, string | null> = {
6383      "ImageWidth": "200",
6384      "ImageLength": "300"
6385    };
6386    await metaData.setProperties(setkey).then(async () => {
6387      console.info('Set auxpictureobj properties success.');
6388    }).catch((error: BusinessError) => {
6389      console.error('Failed to set metadata Properties. code is ${error.code}, message is ${error.message}');
6390    })
6391  } else {
6392    console.info('AuxPictureObj metadata is null. ');
6393  }
6394}
6395```
6396
6397### getAllProperties<sup>13+</sup>
6398
6399getAllProperties(): Promise\<Record<string, string | null>>
6400
6401获取图片中所有元数据的属性和值,用Promise形式返回结果。
6402
6403**系统能力:** SystemCapability.Multimedia.Image.Core
6404
6405**返回值:**
6406
6407| 类型                                     | 说明                                        |
6408| ---------------------------------------- | ------------------------------------------- |
6409| Promise\<Record<string, string \| null>> | Promise对象,返回元数据拥有的所有属性的值。 |
6410
6411**示例:**
6412
6413```ts
6414import { BusinessError } from '@kit.BasicServicesKit';
6415import { image } from '@kit.ImageKit';
6416
6417async function GetAllProperties() {
6418  const context = getContext();
6419  const resourceMgr = context.resourceManager;
6420  const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); //图片包含exif metadata
6421  let ops: image.SourceOptions = {
6422    sourceDensity: 98,
6423  }
6424  let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops);
6425  let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap();
6426  let pictureObj: image.Picture = image.createPicture(commodityPixelMap);
6427  let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA;
6428  let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType);
6429  if (metaData != null) {
6430    await metaData.getAllProperties().then((data2) => {
6431      const count = Object.keys(data2).length;
6432      console.info('Metadata have ', count, ' properties');
6433      console.info('Get metadata all properties: ', JSON.stringify(data2));
6434    }).catch((error: BusinessError) => {
6435      console.error('Get metadata all properties failed error.code: ' +JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message));
6436    });
6437  } else {
6438    console.info('Metadata is null.');
6439  }
6440}
6441```
6442
6443### clone<sup>13+</sup>
6444
6445clone(): Promise\<Metadata>
6446
6447对元数据进行克隆,用Promise形式返回结果。
6448
6449**系统能力:** SystemCapability.Multimedia.Image.Core
6450
6451**返回值:**
6452
6453| 类型                              | 说明                              |
6454| --------------------------------- | --------------------------------- |
6455| Promise\<[Metadata](#metadata13)> | Promise对象,成功返回元数据实例。 |
6456
6457**错误码:**
6458
6459以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
6460
6461| 错误码ID | 错误信息             |
6462| -------- | -------------------- |
6463| 7600301  | Memory alloc failed. |
6464| 7600302  | Memory copy failed.  |
6465
6466**示例:**
6467
6468```ts
6469import { BusinessError } from '@kit.BasicServicesKit';
6470import { image } from '@kit.ImageKit';
6471
6472async function clone() {
6473  const context = getContext();
6474  const resourceMgr = context.resourceManager;
6475  const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); //图片包含exif metadata
6476  let ops: image.SourceOptions = {
6477    sourceDensity: 98,
6478  }
6479  let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops);
6480  let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap();
6481  let pictureObj: image.Picture = image.createPicture(commodityPixelMap);
6482  let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA;
6483  let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType);
6484  if (metaData != null) {
6485    let new_metadata: image.Metadata = await metaData.clone();
6486    new_metadata.getProperties(["ImageWidth"]).then((data1) => {
6487      console.info('Clone new_metadata and get Properties.', JSON.stringify(data1));
6488    }).catch((err: BusinessError) => {
6489      console.error('Clone new_metadata failed.', JSON.stringify(err));
6490    });
6491  } else {
6492    console.info('Metadata is null.');
6493  }
6494}
6495```
6496
6497## image.createImageReceiver<sup>11+</sup>
6498
6499createImageReceiver(size: Size, format: ImageFormat, capacity: number): ImageReceiver
6500
6501通过图片大小、图片格式、容量创建ImageReceiver实例。
6502
6503**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6504
6505**参数:**
6506
6507| 参数名   | 类型   | 必填 | 说明                   |
6508| -------- | ------ | ---- | ---------------------- |
6509| size    | [Size](#size)  | 是   | 图像的默认大小。       |
6510| format   | [ImageFormat](#imageformat9) | 是   | 图像格式,取值为[ImageFormat](#imageformat9)常量(目前仅支持 ImageFormat:JPEG,实际返回格式由生产者决定,如相机)。             |
6511| capacity | number | 是   | 同时访问的最大图像数。 |
6512
6513**返回值:**
6514
6515| 类型                             | 说明                                    |
6516| -------------------------------- | --------------------------------------- |
6517| [ImageReceiver](#imagereceiver9) | 如果操作成功,则返回ImageReceiver实例。 |
6518
6519**错误码:**
6520
6521以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
6522
6523| 错误码ID | 错误信息 |
6524| ------- | --------------------------------------------|
6525| 401| Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;   |
6526
6527**示例:**
6528
6529```ts
6530let size: image.Size = {
6531  height: 8192,
6532  width: 8
6533}
6534let receiver: image.ImageReceiver = image.createImageReceiver(size, image.ImageFormat.JPEG, 8);
6535```
6536
6537## image.createImageReceiver<sup>(deprecated)</sup>
6538
6539createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver
6540
6541通过宽、高、图片格式、容量创建ImageReceiver实例。
6542
6543> **说明:**
6544>
6545> 从API version 11开始不再维护,建议使用[createImageReceiver](#imagecreateimagereceiver11)代替。
6546
6547**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6548
6549**参数:**
6550
6551| 参数名   | 类型   | 必填 | 说明                   |
6552| -------- | ------ | ---- | ---------------------- |
6553| width    | number | 是   | 图像的默认宽度。       |
6554| height   | number | 是   | 图像的默认高度。       |
6555| format   | number | 是   | 图像格式,取值为[ImageFormat](#imageformat9)常量(目前仅支持 ImageFormat:JPEG,实际返回格式由生产者决定,如相机)。  |
6556| capacity | number | 是   | 同时访问的最大图像数。 |
6557
6558**返回值:**
6559
6560| 类型                             | 说明                                    |
6561| -------------------------------- | --------------------------------------- |
6562| [ImageReceiver](#imagereceiver9) | 如果操作成功,则返回ImageReceiver实例。 |
6563
6564**示例:**
6565
6566```ts
6567let receiver: image.ImageReceiver = image.createImageReceiver(8192, 8, image.ImageFormat.JPEG, 8);
6568```
6569
6570## ImageReceiver<sup>9+</sup>
6571
6572图像接收类,用于获取组件surface id,接收最新的图片和读取下一张图片,以及释放ImageReceiver实例。
6573
6574在调用以下方法前需要先创建ImageReceiver实例。
6575
6576### 属性
6577
6578**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6579
6580| 名称     | 类型                         | 可读 | 可写 | 说明               |
6581| -------- | ---------------------------- | ---- | ---- | ------------------ |
6582| size     | [Size](#size)                | 是   | 否   | 图片大小。         |
6583| capacity | number                       | 是   | 否   | 同时访问的图像数。 |
6584| format   | [ImageFormat](#imageformat9) | 是   | 否   | 图像格式。         |
6585
6586### getReceivingSurfaceId<sup>9+</sup>
6587
6588getReceivingSurfaceId(callback: AsyncCallback\<string>): void
6589
6590用于获取一个surface id供Camera或其他组件使用。使用callback返回结果。
6591
6592**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6593
6594**参数:**
6595
6596| 参数名   | 类型                   | 必填 | 说明                       |
6597| -------- | ---------------------- | ---- | -------------------------- |
6598| callback | AsyncCallback\<string> | 是   | 回调函数,当获取surface id成功,err为undefined,data为获取到的surface id;否则为错误对象。 |
6599
6600**示例:**
6601
6602```ts
6603import { BusinessError } from '@kit.BasicServicesKit';
6604
6605receiver.getReceivingSurfaceId((err: BusinessError, id: string) => {
6606  if (err) {
6607    console.error(`Failed to get the ReceivingSurfaceId.code ${err.code},message is ${err.message}`);
6608  } else {
6609    console.info('Succeeded in getting the ReceivingSurfaceId.');
6610  }
6611});
6612```
6613
6614### getReceivingSurfaceId<sup>9+</sup>
6615
6616getReceivingSurfaceId(): Promise\<string>
6617
6618用于获取一个surface id供Camera或其他组件使用。使用promise返回结果。
6619
6620**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6621
6622**返回值:**
6623
6624| 类型             | 说明                 |
6625| ---------------- | -------------------- |
6626| Promise\<string> | Promise对象,返回surface id。 |
6627
6628**示例:**
6629
6630```ts
6631import { BusinessError } from '@kit.BasicServicesKit';
6632
6633receiver.getReceivingSurfaceId().then((id: string) => { 
6634  console.info('Succeeded in getting the ReceivingSurfaceId.');
6635}).catch((error: BusinessError) => {
6636  console.error(`Failed to get the ReceivingSurfaceId.code ${error.code},message is ${error.message}`);
6637})
6638```
6639
6640### readLatestImage<sup>9+</sup>
6641
6642readLatestImage(callback: AsyncCallback\<Image>): void
6643
6644从ImageReceiver读取最新的图片,并使用callback返回结果。
6645
6646**注意**:此接口返回的[Image](#image9)对象使用完毕后需要调用[release](#release9-4)方法释放,释放后才可以继续接收新的数据。
6647
6648**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6649
6650**参数:**
6651
6652| 参数名     | 类型                            | 必填 | 说明                     |
6653| -------- | ------------------------------- | ---- | ------------------------ |
6654| callback | AsyncCallback<[Image](#image9)> | 是   | 回调函数,当读取最新图片成功,err为undefined,data为获取到的最新图片;否则为错误对象。  |
6655
6656**示例:**
6657
6658```ts
6659import { BusinessError } from '@kit.BasicServicesKit';
6660
6661receiver.readLatestImage((err: BusinessError, img: image.Image) => {
6662  if (err) {
6663    console.error(`Failed to read the latest Image.code ${err.code},message is ${err.message}`);
6664  } else {
6665    console.info('Succeeded in reading the latest Image.');
6666  }
6667});
6668```
6669
6670### readLatestImage<sup>9+</sup>
6671
6672readLatestImage(): Promise\<Image>
6673
6674从ImageReceiver读取最新的图片,并使用promise返回结果。
6675
6676**注意**:此接口返回的[Image](#image9)对象使用完毕后需要调用[release](#release9-4)方法释放,释放后才可以继续接收新的数据。
6677
6678**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6679
6680**返回值:**
6681
6682| 类型                      | 说明               |
6683| ------------------------- | ------------------ |
6684| Promise<[Image](#image9)> | Promise对象,返回最新图片。 |
6685
6686**示例:**
6687
6688```ts
6689import { BusinessError } from '@kit.BasicServicesKit';
6690
6691receiver.readLatestImage().then((img: image.Image) => {
6692  console.info('Succeeded in reading the latest Image.');
6693}).catch((error: BusinessError) => {
6694  console.error(`Failed to read the latest Image.code ${error.code},message is ${error.message}`);
6695})
6696```
6697
6698### readNextImage<sup>9+</sup>
6699
6700readNextImage(callback: AsyncCallback\<Image>): void
6701
6702从ImageReceiver读取下一张图片,并使用callback返回结果。
6703
6704**注意**:此接口返回的[Image](#image9)对象使用完毕后需要调用[release](#release9-4)方法释放,释放后才可以继续接收新的数据。
6705
6706**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6707
6708**参数:**
6709
6710| 参数名   | 类型                            | 必填 | 说明                       |
6711| -------- | ------------------------------- | ---- | -------------------------- |
6712| callback | AsyncCallback<[Image](#image9)> | 是   | 回调函数,当获取下一张图片成功,err为undefined,data为获取到的下一张图片;否则为错误对象。  |
6713
6714**示例:**
6715
6716```ts
6717import { BusinessError } from '@kit.BasicServicesKit';
6718
6719receiver.readNextImage((err: BusinessError, img: image.Image) => {
6720  if (err) {
6721    console.error(`Failed to read the next Image.code ${err.code},message is ${err.message}`);
6722  } else {
6723    console.info('Succeeded in reading the next Image.');
6724  }
6725});
6726```
6727
6728### readNextImage<sup>9+</sup>
6729
6730readNextImage(): Promise\<Image>
6731
6732从ImageReceiver读取下一张图片,并使用promise返回结果。
6733
6734**注意**:此接口返回的[Image](#image9)对象使用完毕后需要调用[release](#release9-4)方法释放,释放后才可以继续接收新的数据。
6735
6736**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6737
6738**返回值:**
6739
6740| 类型                      | 说明                 |
6741| ------------------------- | -------------------- |
6742| Promise<[Image](#image9)> | Promise对象,返回下一张图片。 |
6743
6744**示例:**
6745
6746```ts
6747import { BusinessError } from '@kit.BasicServicesKit';
6748
6749receiver.readNextImage().then((img: image.Image) => {
6750  console.info('Succeeded in reading the next Image.');
6751}).catch((error: BusinessError) => {
6752  console.error(`Failed to read the next Image.code ${error.code},message is ${error.message}`);
6753})
6754```
6755
6756### on<sup>9+</sup>
6757
6758on(type: 'imageArrival', callback: AsyncCallback\<void>): void
6759
6760接收图片时注册回调。
6761
6762**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6763
6764**参数:**
6765
6766| 参数名   | 类型                 | 必填 | 说明                                                   |
6767| -------- | -------------------- | ---- | ------------------------------------------------------ |
6768| type     | string               | 是   | 注册事件的类型,固定为'imageArrival',接收图片时触发。 |
6769| callback | AsyncCallback\<void> | 是   | 回调函数,当注册事件触发成功,err为undefined,否则为错误对象。                                        |
6770
6771**示例:**
6772
6773```ts
6774receiver.on('imageArrival', () => {
6775  // image arrival, do something.
6776})
6777```
6778
6779### release<sup>9+</sup>
6780
6781release(callback: AsyncCallback\<void>): void
6782
6783释放ImageReceiver实例并使用回调返回结果。
6784
6785ArkTS有内存回收机制,ImageReceiver对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
6786
6787**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6788
6789**参数:**
6790
6791| 参数名   | 类型                 | 必填 | 说明                     |
6792| -------- | -------------------- | ---- | ------------------------ |
6793| callback | AsyncCallback\<void> | 是   | 回调函数,当释放ImageReceiver实例成功,err为undefined,否则为错误对象。  |
6794
6795**示例:**
6796
6797```ts
6798import { BusinessError } from '@kit.BasicServicesKit';
6799
6800receiver.release((err: BusinessError) => {
6801  if (err) {
6802    console.error(`Failed to release the receiver.code ${err.code},message is ${err.message}`);
6803  } else {
6804    console.info('Succeeded in releasing the receiver.');
6805  }
6806})
6807```
6808
6809### release<sup>9+</sup>
6810
6811release(): Promise\<void>
6812
6813释放ImageReceiver实例并使用promise返回结果。
6814
6815ArkTS有内存回收机制,ImageReceiver对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
6816
6817**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6818
6819**返回值:**
6820
6821| 类型           | 说明               |
6822| -------------- | ------------------ |
6823| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
6824
6825**示例:**
6826
6827```ts
6828import { BusinessError } from '@kit.BasicServicesKit';
6829
6830receiver.release().then(() => {
6831  console.info('Succeeded in releasing the receiver.');
6832}).catch((error: BusinessError) => {
6833  console.error(`Failed to release the receiver.code ${error.code},message is ${error.message}`);
6834})
6835```
6836
6837## image.createImageCreator<sup>11+</sup>
6838
6839createImageCreator(size: Size, format: ImageFormat, capacity: number): ImageCreator
6840
6841通过图片大小、图片格式、容量创建ImageCreator实例。
6842
6843**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
6844
6845**参数:**
6846
6847| 参数名   | 类型   | 必填 | 说明                   |
6848| -------- | ------ | ---- | ---------------------- |
6849| size    | [Size](#size)  | 是   | 图像的默认大小。       |
6850| format   | [ImageFormat](#imageformat9) | 是   | 图像格式,如YCBCR_422_SP,JPEG。             |
6851| capacity | number | 是   | 同时访问的最大图像数。 |
6852
6853**返回值:**
6854
6855| 类型                           | 说明                                    |
6856| ------------------------------ | --------------------------------------- |
6857| [ImageCreator](#imagecreator9) | 如果操作成功,则返回ImageCreator实例。 |
6858
6859
6860**错误码:**
6861
6862以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
6863
6864| 错误码ID | 错误信息 |
6865| ------- | --------------------------------------------|
6866| 401| Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;          |
6867
6868**示例:**
6869
6870```ts
6871let size: image.Size = {
6872  height: 8192,
6873  width: 8
6874}
6875let creator: image.ImageCreator = image.createImageCreator(size, image.ImageFormat.JPEG, 8);
6876```
6877
6878## image.createImageCreator<sup>(deprecated)</sup>
6879
6880createImageCreator(width: number, height: number, format: number, capacity: number): ImageCreator
6881
6882通过宽、高、图片格式、容量创建ImageCreator实例。
6883
6884> **说明:**
6885>
6886> 从API version 11开始不再维护,建议使用[createImageCreator](#imagecreateimagecreator11)代替。
6887
6888**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
6889
6890**参数:**
6891
6892| 参数名   | 类型   | 必填 | 说明                   |
6893| -------- | ------ | ---- | ---------------------- |
6894| width    | number | 是   | 图像的默认宽度。       |
6895| height   | number | 是   | 图像的默认高度。       |
6896| format   | number | 是   | 图像格式,如YCBCR_422_SP,JPEG。             |
6897| capacity | number | 是   | 同时访问的最大图像数。 |
6898
6899**返回值:**
6900
6901| 类型                           | 说明                                    |
6902| ------------------------------ | --------------------------------------- |
6903| [ImageCreator](#imagecreator9) | 如果操作成功,则返回ImageCreator实例。 |
6904
6905**示例:**
6906
6907```ts
6908let creator: image.ImageCreator = image.createImageCreator(8192, 8, image.ImageFormat.JPEG, 8);
6909```
6910
6911## ImageCreator<sup>9+</sup>
6912
6913图像创建模块,用于请求图像原生数据区域,并开放给应用编译原生图像数据的能力。
6914在调用以下方法前需要先创建[ImageCreator](#imagecreator9)实例,ImageCreator不支持多线程。
6915
6916### 属性
6917
6918**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
6919
6920| 名称     | 类型                         | 可读 | 可写 | 说明               |
6921| -------- | ---------------------------- | ---- | ---- | ------------------ |
6922| capacity | number                       | 是   | 否   | 同时访问的图像数。 |
6923| format   | [ImageFormat](#imageformat9) | 是   | 否   | 图像格式。         |
6924
6925### dequeueImage<sup>9+</sup>
6926
6927dequeueImage(callback: AsyncCallback\<Image>): void
6928
6929从空闲队列中获取buffer图片,用于绘制UI内容,并使用callback返回结果。
6930
6931**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
6932
6933**参数:**
6934
6935| 参数名        | 类型                                    | 必填 | 说明                 |
6936| ------------- | ---------------------------------------| ---- | -------------------- |
6937| callback      | AsyncCallback\<[Image](#image9)>  | 是   | 回调函数,当获取最新图片成功,err为undefined,data为获取到的最新图片;否则为错误对象。  |
6938
6939**示例:**
6940
6941```ts
6942import { BusinessError } from '@kit.BasicServicesKit';
6943
6944creator.dequeueImage((err: BusinessError, img: image.Image) => {
6945  if (err) {
6946    console.error(`Failed to dequeue the Image.code ${err.code},message is ${err.message}`);
6947  } else {
6948    console.info('Succeeded in dequeuing the Image.');
6949  }
6950});
6951```
6952
6953### dequeueImage<sup>9+</sup>
6954
6955dequeueImage(): Promise\<Image>
6956
6957从空闲队列中获取buffer图片,用于绘制UI内容,并使用promise返回结果。
6958
6959**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
6960
6961**返回值:**
6962
6963| 类型             | 说明           |
6964| --------------- | ------------- |
6965| Promise\<[Image](#image9)> | Promise对象,返回最新图片。 |
6966
6967**示例:**
6968
6969```ts
6970import { BusinessError } from '@kit.BasicServicesKit';
6971
6972creator.dequeueImage().then((img: image.Image) => {
6973  console.info('Succeeded in dequeuing the Image.');
6974}).catch((error: BusinessError) => {
6975  console.error(`Failed to dequeue the Image.code ${error.code},message is ${error.message}`);
6976})
6977```
6978
6979### queueImage<sup>9+</sup>
6980
6981queueImage(interface: Image, callback: AsyncCallback\<void>): void
6982
6983将绘制好的图片放入Dirty队列,并使用callback返回结果。
6984
6985**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
6986
6987**参数:**
6988
6989| 参数名        | 类型                     | 必填 | 说明                 |
6990| ------------- | -------------------------| ---- | -------------------- |
6991| interface     | [Image](#image9)                    | 是   | 绘制好的buffer图像。 |
6992| callback      | AsyncCallback\<void>     | 是   | 回调函数,当将图片放入Dirty队列成功,err为undefined,否则为错误对象。  |
6993
6994**示例:**
6995
6996```ts
6997import { BusinessError } from '@kit.BasicServicesKit';
6998
6999creator.dequeueImage().then((img: image.Image) => {
7000  //绘制图片
7001  img.getComponent(4).then((component : image.Component) => {
7002    let bufferArr: Uint8Array = new Uint8Array(component.byteBuffer);
7003    for (let i = 0; i < bufferArr.length; i += 4) {
7004      bufferArr[i] = 0; //B
7005      bufferArr[i + 1] = 0; //G
7006      bufferArr[i + 2] = 255; //R
7007      bufferArr[i + 3] = 255; //A
7008    }
7009  })
7010  creator.queueImage(img, (err: BusinessError) => {
7011    if (err) {
7012      console.error(`Failed to queue the Image.code ${err.code},message is ${err.message}`);
7013    } else {
7014      console.info('Succeeded in queuing the Image.');
7015    }
7016  })
7017})
7018
7019```
7020
7021### queueImage<sup>9+</sup>
7022
7023queueImage(interface: Image): Promise\<void>
7024
7025将绘制好的图片放入Dirty队列,并使用promise返回结果。
7026
7027**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
7028
7029**参数:**
7030
7031| 参数名          | 类型     | 必填 | 说明                |
7032| ------------- | --------| ---- | ------------------- |
7033| interface     | [Image](#image9)   | 是   | 绘制好的buffer图像。 |
7034
7035**返回值:**
7036
7037| 类型            | 说明           |
7038| -------------- | ------------- |
7039| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
7040
7041**示例:**
7042
7043```ts
7044import { BusinessError } from '@kit.BasicServicesKit';
7045
7046creator.dequeueImage().then((img: image.Image) => {
7047  //绘制图片
7048  img.getComponent(4).then((component: image.Component) => {
7049    let bufferArr: Uint8Array = new Uint8Array(component.byteBuffer);
7050    for (let i = 0; i < bufferArr.length; i += 4) {
7051      bufferArr[i] = 0; //B
7052      bufferArr[i + 1] = 0; //G
7053      bufferArr[i + 2] = 255; //R
7054      bufferArr[i + 3] = 255; //A
7055    }
7056  })
7057  creator.queueImage(img).then(() => {
7058    console.info('Succeeded in queuing the Image.');
7059  }).catch((error: BusinessError) => {
7060    console.error(`Failed to queue the Image.code ${error.code},message is ${error.message}`);
7061  })
7062})
7063
7064```
7065
7066### on<sup>9+</sup>
7067
7068on(type: 'imageRelease', callback: AsyncCallback\<void>): void
7069
7070监听imageRelease事件,并使用callback返回结果。
7071
7072**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
7073
7074**参数:**
7075
7076| 参数名        | 类型                     | 必填 | 说明                 |
7077| ------------- | -------------------------| ---- | -------------------- |
7078| type          | string                   | 是   | 监听事件类型,如'imageRelease'。 |
7079| callback      | AsyncCallback\<void>     | 是   | 回调函数,当监听事件触发成功,err为undefined,否则为错误对象。  |
7080
7081**示例:**
7082
7083```ts
7084import { BusinessError } from '@kit.BasicServicesKit';
7085
7086creator.on('imageRelease', (err: BusinessError) => {
7087  if (err) {
7088    console.error(`Failed to get the imageRelease callback.code ${err.code},message is ${err.message}`);
7089  } else {
7090    console.info('Succeeded in getting imageRelease callback.');
7091  }
7092})
7093```
7094
7095### release<sup>9+</sup>
7096
7097release(callback: AsyncCallback\<void>): void
7098
7099释放当前图像,并使用callback返回结果。
7100
7101ArkTS有内存回收机制,ImageCreator对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
7102
7103**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
7104
7105**参数:**
7106
7107| 参数名           | 类型                     | 必填 | 说明                 |
7108| ------------- | -------------------------| ---- | -------------------- |
7109| callback      | AsyncCallback\<void>     | 是   | 回调函数,当图像释放成功,err为undefined,否则为错误对象。 |
7110
7111**示例:**
7112
7113```ts
7114import { BusinessError } from '@kit.BasicServicesKit';
7115
7116creator.release((err: BusinessError) => {
7117  if (err) {
7118    console.error(`Failed to release the creator.code ${err.code},message is ${err.message}`);
7119  } else {
7120    console.info('Succeeded in releasing creator.');
7121  }
7122});
7123```
7124### release<sup>9+</sup>
7125
7126release(): Promise\<void>
7127
7128释放当前图像,并使用promise返回结果。
7129
7130ArkTS有内存回收机制,ImageCreator对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
7131
7132**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
7133
7134**返回值:**
7135
7136| 类型            | 说明           |
7137| -------------- | ------------- |
7138| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
7139
7140**示例:**
7141
7142```ts
7143import { BusinessError } from '@kit.BasicServicesKit';
7144
7145creator.release().then(() => {
7146  console.info('Succeeded in releasing creator.');
7147}).catch((error: BusinessError) => {
7148  console.error(`Failed to release the creator.code ${error.code},message is ${error.message}`);
7149})
7150```
7151
7152## Image<sup>9+</sup>
7153
7154提供基本的图像操作,包括获取图像信息、读写图像数据。调用[readNextImage](#readnextimage9)和[readLatestImage](#readlatestimage9)接口时会返回image。
7155
7156### 属性
7157
7158**系统能力:** SystemCapability.Multimedia.Image.Core
7159
7160| 名称     | 类型               | 可读 | 可写 | 说明                                               |
7161| -------- | ------------------ | ---- | ---- | -------------------------------------------------- |
7162| clipRect | [Region](#region8) | 是   | 是   | 要裁剪的图像区域。                                 |
7163| size     | [Size](#size)      | 是   | 否   | 图像大小。如果image对象所存储的是相机预览流数据,即YUV图像数据,那么获取到的size中的宽高分别对应YUV图像的宽高; 如果image对象所存储的是相机拍照流数据,即JPEG图像,由于已经是编码后的文件,size中的宽等于JPEG文件大小,高等于1。image对象所存储的数据是预览流还是拍照流,取决于应用将receiver中的surfaceId传给相机的previewOutput还是captureOutput。                                |
7164| format   | number             | 是   | 否   | 图像格式,参考[OH_NativeBuffer_Format](../apis-arkgraphics2d/_o_h___native_buffer.md#oh_nativebuffer_format)。 |
7165| timestamp<sup>12+</sup> | number         | 是      | 否   | 图像时间戳。时间戳以纳秒为单位,通常是单调递增的。时间戳的具体含义和基准取决于图像的生产者,在相机预览/拍照场景,生产者就是相机。来自不同生产者的图像的时间戳可能有不同的含义和基准,因此可能无法进行比较。如果要获取某张照片的生成时间,可以通过[getImageProperty](#getimageproperty11)接口读取相关的EXIF信息。|
7166
7167### getComponent<sup>9+</sup>
7168
7169getComponent(componentType: ComponentType, callback: AsyncCallback\<Component>): void
7170
7171根据图像的组件类型从图像中获取组件缓存并使用callback返回结果。
7172
7173**系统能力:** SystemCapability.Multimedia.Image.Core
7174
7175**参数:**
7176
7177| 参数名        | 类型                                    | 必填 | 说明                 |
7178| ------------- | --------------------------------------- | ---- | -------------------- |
7179| componentType | [ComponentType](#componenttype9)        | 是   | 图像的组件类型。(目前仅支持 ComponentType:JPEG,实际返回格式由生产者决定,如相机)    |
7180| callback      | AsyncCallback<[Component](#component9)> | 是   | 回调函数,当返回组件缓冲区成功,err为undefined,data为获取到的组件缓冲区;否则为错误对象。  |
7181
7182**示例:**
7183
7184```ts
7185import { BusinessError } from '@kit.BasicServicesKit';
7186
7187img.getComponent(4, (err: BusinessError, component: image.Component) => {
7188  if (err) {
7189    console.error(`Failed to get the component.code ${err.code},message is ${err.message}`);
7190  } else {
7191    console.info('Succeeded in getting component.');
7192  }
7193})
7194```
7195
7196### getComponent<sup>9+</sup>
7197
7198getComponent(componentType: ComponentType): Promise\<Component>
7199
7200根据图像的组件类型从图像中获取组件缓存并使用Promise方式返回结果。
7201
7202**系统能力:** SystemCapability.Multimedia.Image.Core
7203
7204**参数:**
7205
7206| 参数名        | 类型                             | 必填 | 说明             |
7207| ------------- | -------------------------------- | ---- | ---------------- |
7208| componentType | [ComponentType](#componenttype9) | 是   | 图像的组件类型。(目前仅支持 ComponentType:JPEG,实际返回格式由生产者决定,如相机) |
7209
7210**返回值:**
7211
7212| 类型                              | 说明                              |
7213| --------------------------------- | --------------------------------- |
7214| Promise<[Component](#component9)> | Promise对象,返回组件缓冲区。 |
7215
7216**示例:**
7217
7218```ts
7219import { BusinessError } from '@kit.BasicServicesKit';
7220
7221img.getComponent(4).then((component: image.Component) => {
7222  console.info('Succeeded in getting component.');
7223}).catch((error: BusinessError) => {
7224  console.error(`Failed to get the component.code ${error.code},message is ${error.message}`);
7225})
7226```
7227
7228### release<sup>9+</sup>
7229
7230release(callback: AsyncCallback\<void>): void
7231
7232释放当前图像并使用callback返回结果。
7233
7234在接收另一个图像前必须先释放对应资源。
7235
7236ArkTS有内存回收机制,Image对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
7237
7238**系统能力:** SystemCapability.Multimedia.Image.Core
7239
7240**参数:**
7241
7242| 参数名   | 类型                 | 必填 | 说明           |
7243| -------- | -------------------- | ---- | -------------- |
7244| callback | AsyncCallback\<void> | 是   | 回调函数,当图像释放成功,err为undefined,否则为错误对象。  |
7245
7246**示例:**
7247
7248```ts
7249import { BusinessError } from '@kit.BasicServicesKit';
7250
7251img.release((err: BusinessError) => {
7252  if (err) {
7253    console.error(`Failed to release the image instance.code ${err.code},message is ${err.message}`);
7254  } else {
7255    console.info('Succeeded in releasing the image instance.');
7256  }
7257})
7258```
7259
7260### release<sup>9+</sup>
7261
7262release(): Promise\<void>
7263
7264释放当前图像并使用Promise方式返回结果。
7265
7266在接收另一个图像前必须先释放对应资源。
7267
7268ArkTS有内存回收机制,Image对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
7269
7270**系统能力:** SystemCapability.Multimedia.Image.Core
7271
7272**返回值:**
7273
7274| 类型           | 说明                  |
7275| -------------- | --------------------- |
7276| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
7277
7278**示例:**
7279
7280```ts
7281import { BusinessError } from '@kit.BasicServicesKit';
7282
7283img.release().then(() => {
7284  console.info('Succeeded in releasing the image instance.');
7285}).catch((error: BusinessError) => {
7286  console.error(`Failed to release the image instance.code ${error.code},message is ${error.message}`);
7287})
7288```
7289
7290## PositionArea<sup>7+</sup>
7291
7292表示图片指定区域内的数据。
7293
7294**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
7295
7296**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
7297
7298**系统能力:** SystemCapability.Multimedia.Image.Core
7299
7300| 名称   | 类型               | 只读|  可选| 说明                                                         |
7301| ------ | ------------------ | ---| -----|------------------------------------------------------- |
7302| pixels | ArrayBuffer        | 否 |   否   | 像素。                                                       |
7303| offset | number             | 否 |   否  |  偏移量。                                                     |
7304| stride | number             | 否 |   否  | 跨距,内存中每行像素所占的空间。stride >= region.size.width*4。                   |
7305| region | [Region](#region8) | 否 |   否  |区域,按照区域读写。写入的区域宽度加X坐标不能大于原图的宽度,写入的区域高度加Y坐标不能大于原图的高度。 |
7306
7307## ImageInfo
7308
7309表示图片信息。
7310
7311**系统能力:** SystemCapability.Multimedia.Image.Core
7312
7313| 名称 | 类型          | 只读 | 可选 | 说明       |
7314| ---- | ------------- | --- |-----|---------- |
7315| size<sup>6+</sup> | [Size](#size) | 否 |  否  |图片大小。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 |
7316| density<sup>9+</sup> | number | 否  | 否 |像素密度,单位为ppi。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 |
7317| stride<sup>11+</sup> | number | 否  | 否  | 跨距,内存中每行像素所占的空间。stride >= region.size.width*4 <br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 |
7318| pixelFormat<sup>12+</sup> | [PixelMapFormat](#pixelmapformat7) | 否  |  否 | 像素格式。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 |
7319| alphaType<sup>12+</sup> | [AlphaType](#alphatype9)  | 否  |  否  |透明度。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 |
7320| mimeType<sup>12+</sup> | string  |  否  |   否  |图片真实格式(MIME type)。  |
7321| isHdr<sup>12+</sup> | boolean  |  否  | 否  | 图片是否为高动态范围(HDR)。对于[ImageSource](#imagesource),代表源图片是否为HDR;对于[PixelMap](#pixelmap7),代表解码后的pixelmap是否为HDR。 |
7322
7323## Size
7324
7325表示图片尺寸。
7326
7327**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
7328
7329**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
7330
7331**系统能力:** SystemCapability.Multimedia.Image.Core
7332
7333| 名称   | 类型   | 只读 |  可选  |说明           |
7334| ------ | ------ | -- |-----| -------------- |
7335| height | number | 否  |  否  |输出图片的高,单位:像素。 |
7336| width  | number | 否  |  否 | 输出图片的宽,单位:像素。 |
7337
7338## PixelMapFormat<sup>7+</sup>
7339
7340枚举,图片像素格式。
7341
7342**系统能力:** SystemCapability.Multimedia.Image.Core
7343
7344| 名称                   |   值   | 说明              |
7345| ---------------------- | ------ | ----------------- |
7346| UNKNOWN                | 0      | 未知格式。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。        |
7347| RGB_565                | 2      | 格式为RGB_565。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。     |
7348| RGBA_8888              | 3      | 格式为RGBA_8888。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 |
7349| BGRA_8888<sup>9+</sup> | 4      | 格式为BGRA_8888。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 |
7350| RGB_888<sup>9+</sup>   | 5      | 格式为RGB_888。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。   |
7351| ALPHA_8<sup>9+</sup>   | 6      | 格式为ALPHA_8。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。   |
7352| RGBA_F16<sup>9+</sup>  | 7      | 格式为RGBA_F16。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。  |
7353| NV21<sup>9+</sup>      | 8      | 格式为NV21。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。      |
7354| NV12<sup>9+</sup>      | 9      | 格式为NV12。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。      |
7355| RGBA_1010102<sup>12+</sup> | 10 | 格式为RGBA_1010102 |
7356| YCBCR_P010<sup>12+</sup> | 11 | 格式为YCBCR_P010 |
7357| YCRCB_P010<sup>12+</sup> | 12 | 格式为YCRCB_P010 |
7358
7359## AlphaType<sup>9+</sup>
7360
7361枚举,图像的透明度类型。
7362
7363**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
7364
7365**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
7366
7367**系统能力:** SystemCapability.Multimedia.Image.Core
7368
7369| 名称     |   值   | 说明                    |
7370| -------- | ------ | ----------------------- |
7371| UNKNOWN  | 0      | 未知透明度。            |
7372| OPAQUE   | 1      | 没有alpha或图片不透明。 |
7373| PREMUL   | 2      | RGB预乘alpha。         |
7374| UNPREMUL | 3      | RGB非预乘alpha。       |
7375
7376## AuxiliaryPictureType<sup>13+</sup>
7377
7378枚举,辅助图的图像类型。
7379
7380**系统能力:** SystemCapability.Multimedia.Image.Core
7381
7382| 名称          | 值   | 说明         |
7383| ------------- | ---- | ------------ |
7384| GAINMAP       | 1    | 增益图,代表了一种增强SDR图像以产生具有可变显示调整能力的HDR图像的机制。它是一组描述如何应用gainmap元数据的组合。     |
7385| DEPTH_MAP     | 2    | 深度图,储存图像的深度数据,通过捕捉每个像素与摄像机之间的距离,提供场景的三维结构信息,通常用于3D重建和场景理解。     |
7386| UNREFOCUS_MAP | 3    | 人像未对焦的原图,提供了一种在人像拍摄中突出背景模糊效果的方式,能够帮助用户在后期处理中选择焦点区域,增加创作自由度。   |
7387| LINEAR_MAP    | 4    | 线性图,用于提供额外的数据视角或补充信息,通常用于视觉效果的增强,它可以包含场景中光照、颜色或其他视觉元素的线性表示。     |
7388| FRAGMENT_MAP  | 5    | 水印裁剪图,表示在原图中被水印覆盖的区域,该图像用于修复或移除水印影响,恢复图像的完整性和可视性。 |
7389
7390## AuxiliaryPictureInfo<sup>13+</sup>
7391
7392表示辅助图图像信息。
7393
7394**系统能力:** SystemCapability.Multimedia.Image.Core
7395
7396| 名称                      | 类型                                                         | 只读 | 可选 | 说明                                                         |
7397| ------------------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ |
7398| auxiliaryPictureType      | [AuxiliaryPictureType](#auxiliarypicturetype13)              | 否   | 否   | 辅助图的图像类型。                                           |
7399| size         | [Size](#size)                                                | 否   | 否   | 图片大小。 |
7400| rowStride                 | number                                                       | 否   | 否   | 行距。                                                       |
7401| pixelFormat | [PixelMapFormat](#pixelmapformat7)                           | 否   | 否   | 像素格式。 |
7402| colorSpace                | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | 否   | 否   | 目标色彩空间。                                               |
7403
7404## MetadataType<sup>13+</sup>
7405
7406枚举,图片元数据类型。
7407
7408**系统能力:** SystemCapability.Multimedia.Image.Core
7409
7410| 名称              | 值   | 说明               |
7411| ----------------- | ---- | ------------------ |
7412| EXIF_METADATA     | 1    | exif数据。         |
7413| FRAGMENT_METADATA | 2    | 水印裁切图元数据。 |
7414
7415## ScaleMode<sup>9+</sup>
7416
7417枚举,图像的缩放模式。
7418
7419**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
7420
7421**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
7422
7423**系统能力:** SystemCapability.Multimedia.Image.Core
7424
7425| 名称            |   值   | 说明                                               |
7426| --------------- | ------ | -------------------------------------------------- |
7427| CENTER_CROP     | 1      | 缩放图像以填充目标图像区域并居中裁剪区域外的效果。 |
7428| FIT_TARGET_SIZE | 0      | 图像适合目标尺寸的效果。                           |
7429
7430## SourceOptions<sup>9+</sup>
7431
7432ImageSource的初始化选项。
7433
7434**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
7435
7436**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
7437
7438**系统能力:** SystemCapability.Multimedia.Image.Core
7439
7440| 名称              | 类型                               | 只读 | 可选 | 说明               |
7441| ----------------- | ---------------------------------- | ---- | ---- | ------------------ |
7442| sourceDensity     | number                             | 否   | 否   | 图片资源像素密度,单位DPI。<br>在解码参数[DecodingOptions](#decodingoptions7)未设置desiredSize的前提下,当前参数SourceOptions.sourceDensityDecodingOptions.fitDensity非零时将对解码输出的pixelmap进行缩放。<br>缩放后宽计算公式如下(高同理):(width * fitDensity + (sourceDensity >> 1)) / sourceDensity。|
7443| sourcePixelFormat | [PixelMapFormat](#pixelmapformat7) | 否   | 是   | 图片像素格式,默认值为UNKNOWN。     |
7444| sourceSize        | [Size](#size)                      | 否   | 是   | 图像像素大小,默认值为空。     |
7445
7446
7447## InitializationOptions<sup>8+</sup>
7448
7449PixelMap的初始化选项。
7450
7451**系统能力:** SystemCapability.Multimedia.Image.Core
7452
7453| 名称                     | 类型                               | 只读 |可选 |  说明           |
7454| ------------------------ | ---------------------------------- | ----| -----|  -------------- |
7455| alphaType<sup>9+</sup>   | [AlphaType](#alphatype9)           | 否   | 是| 透明度。默认值为IMAGE_ALPHA_TYPE_PREMUL。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。      |
7456| editable                 | boolean                            | 否   | 是| 是否可编辑。默认值为false。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。|
7457| srcPixelFormat<sup>12+</sup>  | [PixelMapFormat](#pixelmapformat7) | 否 | 是 | 传入的buffer数据的像素格式。默认值为BGRA_8888。|
7458| pixelFormat              | [PixelMapFormat](#pixelmapformat7) | 否 | 是| 生成的pixelMap的像素格式。默认值为RGBA_8888。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。     |
7459| scaleMode<sup>9+</sup>   | [ScaleMode](#scalemode9)           | 否  | 是 | 缩略值。默认值为0。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。       |
7460| size                     | [Size](#size)                      | 否  | 否|创建图片大小。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 |
7461
7462## DecodingOptions<sup>7+</sup>
7463
7464图像解码设置选项。
7465
7466**系统能力:** SystemCapability.Multimedia.Image.ImageSource
7467
7468| 名称               | 类型                               | 只读 | 可选 | 说明             |
7469| ------------------ | ---------------------------------- | ---- | ---- | ---------------- |
7470| sampleSize         | number                             | 否   | 是   | 缩略图采样大小,默认值为1。当前只能取1。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 |
7471| rotate             | number                             | 否   | 是   | 旋转角度。默认值为0。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。       |
7472| editable           | boolean                            | 否   | 是   | 是否可编辑。默认值为false。当取值为false时,图片不可二次编辑,如writepixels操作将失败。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。  |
7473| desiredSize        | [Size](#size)                      | 否   | 是   | 期望输出大小。默认值为空。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。   |
7474| desiredRegion      | [Region](#region8)                 | 否   | 是   | 解码区域。默认值为空。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。       |
7475| desiredPixelFormat | [PixelMapFormat](#pixelmapformat7) | 否   | 是   | 解码的像素格式。默认值为RGBA_8888。仅支持设置:RGBA_8888、BGRA_8888和RGB_565。有透明通道图片格式不支持设置RGB_565,如PNG、GIF、ICO和WEBP。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 |
7476| index              | number                             | 否   | 是   | 解码图片序号。默认值为0。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。   |
7477| fitDensity<sup>9+</sup> | number                        | 否   | 是   | 图像像素密度,单位为ppi。默认值为0。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。   |
7478| desiredColorSpace<sup>11+</sup> | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | 否   | 是   | 目标色彩空间。默认值为UNKNOWN。 |
7479| desiredDynamicRange<sup>12+</sup> | [DecodingDynamicRange](#decodingdynamicrange12) | 否   | 是   | 目标动态范围,默认值为SDR。<br>通过[CreateIncrementalSource](#imagecreateincrementalsource9)创建的imagesource不支持设置此属性,默认解码为SDR内容。<br>如果平台不支持HDR,设置无效,默认解码为SDR内容。 |
7480
7481## DecodingOptionsForPicture<sup>13+</sup>
7482
7483图像解码设置选项。
7484
7485**系统能力:** SystemCapability.Multimedia.Image.ImageSource
7486
7487| 名称                     | 类型                                                    | 只读 | 可选 | 说明                                                         |
7488| ------------------------ | ------------------------------------------------------- | ---- | ---- | ------------------------------------------------------------ |
7489| desiredAuxiliaryPictures | Array\<[AuxiliaryPictureType](#auxiliarypicturetype13)> | 否   | 否   | 设置AuxiliaryPicture类型,默认解码所有AuxiliaryPicture类型。 |
7490
7491## Region<sup>8+</sup>
7492
7493表示区域信息。
7494
7495**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
7496
7497**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
7498
7499**系统能力:** SystemCapability.Multimedia.Image.Core
7500
7501| 名称 | 类型          | 只读 | 可选| 说明         |
7502| ---- | ------------- | ---- | ---- | ------------ |
7503| size | [Size](#size) | 否   | 否   | 区域大小。   |
7504| x    | number        | 否   | 否  | 区域横坐标。 |
7505| y    | number        | 否  | 否  | 区域纵坐标。 |
7506
7507## PackingOption
7508
7509表示图片打包选项。
7510
7511**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
7512
7513| 名称    | 类型   | 只读 | 可选 | 说明                                                |
7514| ------- | ------ | ---- | ---- | --------------------------------------------------- |
7515| format  | string | 否   | 否   | 目标格式。</br>当前只支持"image/jpeg"、"image/webp"、"image/png"和"image/heif"<sup>12+</sup>(不同硬件设备支持情况不同)。<br>**说明:** 因为jpeg不支持透明通道,若使用带透明通道的数据编码jpeg格式,透明色将变为黑色。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
7516| quality | number | 否   | 否   | JPEG编码中设定输出图片质量的参数,取值范围为0-100。0质量最低,100质量最高,质量越高生成图片所占空间越大。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
7517| bufferSize<sup>9+</sup> | number | 否   | 是   | 接收编码数据的缓冲区大小,单位为Byte。如果不设置大小,默认为25M。如果编码图片超过25M,需要指定大小。bufferSize需大于编码后图片大小。使用[packToFile](#packtofile11)不受此参数限制。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
7518| desiredDynamicRange<sup>12+</sup> | [PackingDynamicRange](#packingdynamicrange12) | 否   | 是   | 目标动态范围。默认值为SDR。 |
7519| needsPackProperties<sup>12+</sup> | boolean | 否   | 是   | 是否需要编码图片属性信息,例如EXIF。默认值为false。 |
7520
7521## ImagePropertyOptions<sup>11+</sup>
7522
7523表示查询图片属性的索引。
7524
7525**系统能力:** SystemCapability.Multimedia.Image.ImageSource
7526
7527| 名称         | 类型   | 只读 | 可选 | 说明         |
7528| ------------ | ------ | ---- | ---- | ------------ |
7529| index        | number | 是   | 是   | 图片序号。默认值为0。   |
7530| defaultValue | string | 是   | 是   | 默认属性值。默认值为空。 |
7531
7532## GetImagePropertyOptions<sup>(deprecated)</sup>
7533
7534表示查询图片属性的索引。
7535
7536> **说明:**
7537>
7538> 从API version 11开始不再维护,建议使用[ImagePropertyOptions](#imagepropertyoptions11)代替。
7539
7540**系统能力:** SystemCapability.Multimedia.Image.ImageSource
7541
7542| 名称         | 类型   | 只读 | 可选 | 说明         |
7543| ------------ | ------ | ---- | ---- | ------------ |
7544| index        | number | 否   | 是   | 图片序号。默认值为0。   |
7545| defaultValue | string | 否   | 是   | 默认属性值。默认值为空。 |
7546
7547## PropertyKey<sup>7+</sup>
7548
7549枚举,Exif(Exchangeable image file format)图片信息。
7550
7551**系统能力:** SystemCapability.Multimedia.Image.Core
7552
7553| 名称               |   值                    |   说明                    |
7554| ----------------- | ----------------------- |---------------------------|
7555| NEW_SUBFILE_TYPE <sup>12+</sup>           | "NewSubfileType"            | **读写能力:** 可读写<br> 在Exif中,"NewSubfileType"字段用于标识子文件的数据类型,如全分辨率图像、缩略图或多帧图像的一部分。其值是位掩码,0代表全分辨率图像,1代表缩略图,2代表多帧图像的一部分。|
7556| SUBFILE_TYPE <sup>12+</sup>               | "SubfileType"               | **读写能力:** 可读写<br> 此标签指示此子文件中的数据类型。标签已弃用,请使用NewSubfileType替代。|
7557| IMAGE_WIDTH                               | "ImageWidth"                | **读写能力:** 可读写<br> 图片宽度。|
7558| IMAGE_LENGTH                              | "ImageLength"               | **读写能力:** 可读写<br> 图片长度。|
7559| BITS_PER_SAMPLE                           | "BitsPerSample"             | **读写能力:** 可读写<br> 每个像素比特数。|
7560| COMPRESSION <sup>12+</sup>                | "Compression"               | **读写能力:** 可读写<br> 图像压缩方案。|
7561| PHOTOMETRIC_INTERPRETATION <sup>12+</sup> | "PhotometricInterpretation" | **读写能力:** 可读写<br> 像素构成,例如 RGB 或 YCbCr。|
7562| IMAGE_DESCRIPTION<sup>10+</sup>           | "ImageDescription"          | **读写能力:** 可读写<br> 图像信息描述。|
7563| MAKE<sup>10+</sup>                        | "Make"                      | **读写能力:** 可读写<br> 生产商。|
7564| MODEL<sup>10+</sup>                       | "Model"                     | **读写能力:** 可读写<br> 设备型号。|
7565| STRIP_OFFSETS <sup>12+</sup>              | "StripOffsets"              | **读写能力:** 可读写<br> 每个strip的字节偏移量。|
7566| ORIENTATION                               | "Orientation"               | **读写能力:** 可读写<br> 图片方向。<br/>- 1:Top-left,图像未旋转。<br/>- 2:Top-right,镜像水平翻转。<br/>- 3:Bottom-right,图像旋转180°。<br/>- 4:Bottom-left,镜像垂直翻转。<br/>- 5:Left-top,镜像水平翻转再顺时针旋转270°。<br/>- 6:Right-top,顺时针旋转90°。<br/>- 7:Right-bottom,镜像水平翻转再顺时针旋转90°。<br/>- 8:Left-bottom,顺时针旋转270°。<br/>- 未定义值返回Unknown Value。|
7567| SAMPLES_PER_PIXEL <sup>12+</sup>          | "SamplesPerPixel"           | **读写能力:** 可读写<br> 每个像素的分量数。由于该标准适用于 RGB 和 YCbCr 图像,因此该标签的值设置为 3。在 JPEG 压缩数据中,使用 JPEG 标记代替该标签。|
7568| ROWS_PER_STRIP <sup>12+</sup>             | "RowsPerStrip"              | **读写能力:** 可读写<br> 每个strip的图像数据行数。|
7569| STRIP_BYTE_COUNTS <sup>12+</sup>          | "StripByteCounts"           | **读写能力:** 可读写<br> 每个图像数据带的总字节数。|
7570| X_RESOLUTION <sup>12+</sup>               | "XResolution"               | **读写能力:** 可读写<br> 图像宽度方向的分辨率。|
7571| Y_RESOLUTION <sup>12+</sup>               | "YResolution"               | **读写能力:** 可读写<br> 图像高度方向的分辨率。|
7572| PLANAR_CONFIGURATION <sup>12+</sup>       | "PlanarConfiguration"       | **读写能力:** 可读写<br> 表示像素组件的记录格式,chunky格式或是planar格式。|
7573| RESOLUTION_UNIT <sup>12+</sup>            | "ResolutionUnit"            | **读写能力:** 可读写<br> 用于测量XResolution和YResolution的单位。|
7574| TRANSFER_FUNCTION <sup>12+</sup>          | "TransferFunction"          | **读写能力:** 可读写<br> 图像的传递函数,通常用于颜色校正。|
7575| SOFTWARE <sup>12+</sup>                   | "Software"                  | **读写能力:** 可读写<br> 用于生成图像的软件的名称和版本。|
7576| DATE_TIME<sup>10+</sup>                   | "DateTime"                  | **读写能力:** 可读写<br> 日期时间。|
7577| ARTIST <sup>12+</sup>                     | "Artist"                    | **读写能力:** 可读写<br> 创建图像的用户名称。|
7578| WHITE_POINT <sup>12+</sup>                | "WhitePoint"                | **读写能力:** 可读写<br> 图像的白点色度。|
7579| PRIMARY_CHROMATICITIES <sup>12+</sup>     | "PrimaryChromaticities"     | **读写能力:** 可读写<br> 图像的主要颜色的色度。|
7580| PHOTO_MODE<sup>10+</sup>                  | "PhotoMode"                 | **读写能力:** 可读写<br> 拍照模式。|
7581| JPEG_INTERCHANGE_FORMAT <sup>12+</sup>    | "JPEGInterchangeFormat"     | **读写能力:** 可读写<br> JPEG压缩缩略图数据开始字节(SOI)的偏移。|
7582| JPEG_INTERCHANGE_FORMAT_LENGTH <sup>12+</sup> | "JPEGInterchangeFormatLength" | **读写能力:** 可读写<br> JPEG压缩缩略图数据的字节数。|
7583| YCBCR_COEFFICIENTS <sup>12+</sup>         | "YCbCrCoefficients"         | **读写能力:** 可读写<br> 从RGB到YCbCr图像数据的转换矩阵系数。|
7584| YCBCR_SUB_SAMPLING <sup>12+</sup>         | "YCbCrSubSampling"          | **读写能力:** 可读写<br> 色度分量与亮度分量的采样比率。|
7585| YCBCR_POSITIONING <sup>12+</sup>          | "YCbCrPositioning"          | **读写能力:** 可读写<br> 色度分量相对于亮度分量的位置。|
7586| REFERENCE_BLACK_WHITE <sup>12+</sup>      | "ReferenceBlackWhite"       | **读写能力:** 可读写<br> 参考黑点值和参考白点值。|
7587| COPYRIGHT <sup>12+</sup>                  | "Copyright"                 | **读写能力:** 可读写<br> 图像的版权信息。|
7588| EXPOSURE_TIME<sup>9+</sup>                | "ExposureTime"              | **读写能力:** 可读写<br> 曝光时间,例如1/33 sec。|
7589| F_NUMBER<sup>9+</sup>                     | "FNumber"                   | **读写能力:** 可读写<br> 光圈值,例如f/1.8。|
7590| EXPOSURE_PROGRAM <sup>12+</sup>           | "ExposureProgram"           | **读写能力:** 可读写<br> 拍照时相机用来设置曝光的程序的类别。|
7591| SPECTRAL_SENSITIVITY <sup>12+</sup>       | "SpectralSensitivity"       | **读写能力:** 可读写<br> 表示所用相机的每个通道的光谱灵敏度。|
7592| GPS_VERSION_ID <sup>12+</sup>             | "GPSVersionID"              | **读写能力:** 可读写<br> GPSInfoIFD的版本。|
7593| GPS_LATITUDE_REF                          | "GPSLatitudeRef"            | **读写能力:** 可读写<br> 纬度引用,例如N或S。|
7594| GPS_LATITUDE                              | "GPSLatitude"               | **读写能力:** 可读写<br> 图片纬度。修改时应按"度,分,秒"格式传入,如"39,54,7.542"|
7595| GPS_LONGITUDE_REF                         | "GPSLongitudeRef"           | **读写能力:** 可读写<br> 经度引用,例如W或E。|
7596| GPS_LONGITUDE                             | "GPSLongitude"              | **读写能力:** 可读写<br> 图片经度。修改时应按"度,分,秒"格式传入,如"116,19,42.16"|
7597| GPS_ALTITUDE_REF <sup>12+</sup>           | "GPSAltitudeRef"            | **读写能力:** 可读写<br> 用于GPS高度的参照高度。|
7598| GPS_ALTITUDE <sup>12+</sup>               | "GPSAltitude"               | **读写能力:** 可读写<br> 基于GPSAltitudeRef的高度。|
7599| GPS_TIME_STAMP<sup>10+</sup>              | "GPSTimeStamp"              | **读写能力:** 可读写<br> GPS时间戳。|
7600| GPS_SATELLITES <sup>12+</sup>             | "GPSSatellites"             | **读写能力:** 可读写<br> 用于测量的GPS卫星。|
7601| GPS_STATUS <sup>12+</sup>                 | "GPSStatus"                 | **读写能力:** 可读写<br> 录制图像时GPS接收器的状态。|
7602| GPS_MEASURE_MODE <sup>12+</sup>           | "GPSMeasureMode"            | **读写能力:** 可读写<br> GPS测量模式。|
7603| GPS_DOP <sup>12+</sup>                    | "GPSDOP"                    | **读写能力:** 可读写<br> GPS DOP(数据精度等级)。|
7604| GPS_SPEED_REF <sup>12+</sup>              | "GPSSpeedRef"               | **读写能力:** 可读写<br> 用来表示GPS接收器移动速度的单位。|
7605| GPS_SPEED <sup>12+</sup>                  | "GPSSpeed"                  | **读写能力:** 可读写<br> GPS接收器的移动速度。|
7606| GPS_TRACK_REF <sup>12+</sup>              | "GPSTrackRef"               | **读写能力:** 可读写<br> GPS接收机移动方向的参照。|
7607| GPS_TRACK <sup>12+</sup>                  | "GPSTrack"                  | **读写能力:** 可读写<br> GPS接收机的移动方向。|
7608| GPS_IMG_DIRECTION_REF <sup>12+</sup>      | "GPSImgDirectionRef"        | **读写能力:** 可读写<br> 图像方向的参照。|
7609| GPS_IMG_DIRECTION <sup>12+</sup>          | "GPSImgDirection"           | **读写能力:** 可读写<br> 拍摄时图像的方向。|
7610| GPS_MAP_DATUM <sup>12+</sup>              | "GPSMapDatum"               | **读写能力:** 可读写<br> GPS接收器使用的大地测量数据。|
7611| GPS_DEST_LATITUDE_REF <sup>12+</sup>      | "GPSDestLatitudeRef"        | **读写能力:** 可读写<br> 目的地点的纬度参照。|
7612| GPS_DEST_LATITUDE <sup>12+</sup>          | "GPSDestLatitude"           | **读写能力:** 可读写<br> 目的地点的纬度。|
7613| GPS_DEST_LONGITUDE_REF <sup>12+</sup>     | "GPSDestLongitudeRef"       | **读写能力:** 可读写<br> 目的地点的经度参照。|
7614| GPS_DEST_LONGITUDE <sup>12+</sup>         | "GPSDestLongitude"          | **读写能力:** 可读写<br> 目的地点的经度。|
7615| GPS_DEST_BEARING_REF <sup>12+</sup>       | "GPSDestBearingRef"         | **读写能力:** 可读写<br> 指向目的地点的方位参照。|
7616| GPS_DEST_BEARING <sup>12+</sup>           | "GPSDestBearing"            | **读写能力:** 可读写<br> 目的地方位。|
7617| GPS_DEST_DISTANCE_REF <sup>12+</sup>      | "GPSDestDistanceRef"        | **读写能力:** 可读写<br> 目标点距离的测量单位。|
7618| GPS_DEST_DISTANCE <sup>12+</sup>          | "GPSDestDistance"           | **读写能力:** 可读写<br> 到目的地点的距离。|
7619| GPS_PROCESSING_METHOD <sup>12+</sup>      | "GPSProcessingMethod"       | **读写能力:** 可读写<br> 记录定位方法名的字符字符串。|
7620| GPS_AREA_INFORMATION <sup>12+</sup>       | "GPSAreaInformation"        | **读写能力:** 可读写<br> 记录GPS区域名的字符字符串。|
7621| GPS_DATE_STAMP<sup>10+</sup>              | "GPSDateStamp"              | **读写能力:** 可读写<br> GPS日期戳。|
7622| GPS_DIFFERENTIAL <sup>12+</sup>           | "GPSDifferential"           | **读写能力:** 可读写<br> 此字段表示GPS数据是否应用了差分校正,对于精确的位置准确性至关重要。|
7623| GPS_H_POSITIONING_ERROR <sup>12+</sup>    | "GPSHPositioningError"      | **读写能力:** 可读写<br> 此标签指示水平定位误差,单位为米。|
7624| ISO_SPEED_RATINGS<sup>9+</sup>            | "ISOSpeedRatings"           | **读写能力:** 可读写<br> ISO感光度,例如400。|
7625| PHOTOGRAPHIC_SENSITIVITY <sup>12+</sup>   | "PhotographicSensitivity"   | **读写能力:** 可读写<br> 此标签指示拍摄图像时相机或输入设备的灵敏度。|
7626| OECF <sup>12+</sup>                       | "OECF"                      | **读写能力:** 可读写<br> 表示ISO 14524中规定的光电转换函数(OECF)。|
7627| SENSITIVITY_TYPE<sup>10+</sup>            | "SensitivityType"           | **读写能力:** 可读写<br> 灵敏度类型。|
7628| STANDARD_OUTPUT_SENSITIVITY<sup>10+</sup> | "StandardOutputSensitivity" | **读写能力:** 可读写<br> 标准输出灵敏度。|
7629| RECOMMENDED_EXPOSURE_INDEX<sup>10+</sup>  | "RecommendedExposureIndex"  | **读写能力:** 可读写<br> 推荐曝光指数。|
7630| ISO_SPEED<sup>10+</sup>                   | "ISOSpeedRatings"           | **读写能力:** 可读写<br> ISO速度等级。|
7631| ISO_SPEED_LATITUDE_YYY <sup>12+</sup>     | "ISOSpeedLatitudeyyy"       | **读写能力:** 可读写<br> 该标签指示摄像机或输入设备的ISO速度纬度yyy值,该值在ISO 12232中定义。|
7632| ISO_SPEED_LATITUDE_ZZZ <sup>12+</sup>     | "ISOSpeedLatitudezzz"       | **读写能力:** 可读写<br> 该标签指示摄像机或输入设备的ISO速度纬度zzz值,该值在ISO 12232中定义。|
7633| EXIF_VERSION <sup>12+</sup>               | "ExifVersion"               | **读写能力:** 可读写<br> 支持的Exif标准版本。|
7634| DATE_TIME_ORIGINAL<sup>9+</sup>           | "DateTimeOriginal"          | **读写能力:** 可读写<br> 拍摄时间,例如2022:09:06 15:48:00。|
7635| DATE_TIME_DIGITIZED <sup>12+</sup>        | "DateTimeDigitized"         | **读写能力:** 可读写<br> 图像作为数字数据存储的日期和时间,格式为YYYY:MM:DD HH:MM:SS|
7636| OFFSET_TIME <sup>12+</sup>                | "OffsetTime"                | **读写能力:** 可读写<br> 在Exif中,OffsetTime字段表示与UTC(协调世界时)的时间偏移,格式为±HH:MM,用于确定照片拍摄的本地时间。|
7637| OFFSET_TIME_ORIGINAL <sup>12+</sup>       | "OffsetTimeOriginal"        | **读写能力:** 可读写<br> 此标签记录原始图像创建时的UTC偏移量,对于时间敏感的应用至关重要。|
7638| OFFSET_TIME_DIGITIZED <sup>12+</sup>      | "OffsetTimeDigitized"       | **读写能力:** 可读写<br> 此标签记录图像数字化时的UTC偏移量,有助于准确调整时间戳。|
7639| COMPONENTS_CONFIGURATION <sup>12+</sup>   | "ComponentsConfiguration"   | **读写能力:** 可读写<br> 压缩数据的特定信息。|
7640| COMPRESSED_BITS_PER_PIXEL <sup>12+</sup>  | "CompressedBitsPerPixel"    | **读写能力:** 可读写<br> 用于压缩图像的压缩模式,单位为每像素位数。|
7641| SHUTTER_SPEED <sup>12+</sup>              | "ShutterSpeedValue"         | **读写能力:** 可读写<br> 快门速度,以APEX(摄影曝光的加法系统)值表示。|
7642| APERTURE_VALUE<sup>10+</sup>              | "ApertureValue"             | **读写能力:** 可读写<br> 光圈值。|
7643| BRIGHTNESS_VALUE <sup>12+</sup>           | "BrightnessValue"           | **读写能力:** 可读写<br> 图像的亮度值,以APEX单位表示。|
7644| EXPOSURE_BIAS_VALUE<sup>10+</sup>         | "ExposureBiasValue"         | **读写能力:** 可读写<br> 曝光偏差值。|
7645| MAX_APERTURE_VALUE <sup>12+</sup>         | "MaxApertureValue"          | **读写能力:** 可读写<br> 最小F数镜头。|
7646| SUBJECT_DISTANCE <sup>12+</sup>           | "SubjectDistance"           | **读写能力:** 可读写<br> 测量单位为米的主体距离。|
7647| METERING_MODE<sup>10+</sup>               | "MeteringMode"              | **读写能力:** 可读写<br> 测光模式。|
7648| LIGHT_SOURCE<sup>10+</sup>                | "LightSource"               | **读写能力:** 可读写<br> 光源。|
7649| FLASH <sup>10+</sup>                      | "Flash"                     | **读写能力:** 可读写<br> 闪光灯,记录闪光灯状态。|
7650| FOCAL_LENGTH <sup>10+</sup>               | "FocalLength"               | **读写能力:** 可读写<br> 焦距。|
7651| SUBJECT_AREA <sup>12+</sup>               | "SubjectArea"               | **读写能力:** 可读写<br> 该标签指示整个场景中主要主体的位置和区域。|
7652| MAKER_NOTE <sup>12+</sup>                 | "MakerNote"                 | **读写能力:** 只读<br> Exif/DCF制造商使用的标签,用于记录任何所需信息。|
7653| SCENE_POINTER <sup>12+</sup>              | "HwMnoteScenePointer"       | **读写能力:** 只读<br> 场景指针。|
7654| SCENE_VERSION <sup>12+</sup>              | "HwMnoteSceneVersion"       | **读写能力:** 只读<br> 场景算法版本信息。|
7655| SCENE_FOOD_CONF<sup>11+</sup>             | "HwMnoteSceneFoodConf"      | **读写能力:** 只读<br> 拍照场景:食物。|
7656| SCENE_STAGE_CONF<sup>11+</sup>            | "HwMnoteSceneStageConf"     | **读写能力:** 只读<br> 拍照场景:舞台。|
7657| SCENE_BLUE_SKY_CONF<sup>11+</sup>         | "HwMnoteSceneBlueSkyConf"   | **读写能力:** 只读<br> 拍照场景:蓝天。|
7658| SCENE_GREEN_PLANT_CONF<sup>11+</sup>      | "HwMnoteSceneGreenPlantConf" | **读写能力:** 只读<br> 拍照场景:绿植。|
7659| SCENE_BEACH_CONF<sup>11+</sup>            | "HwMnoteSceneBeachConf"     | **读写能力:** 只读<br> 拍照场景:沙滩。|
7660| SCENE_SNOW_CONF<sup>11+</sup>             | "HwMnoteSceneSnowConf"      | **读写能力:** 只读<br> 拍照场景:下雪。|
7661| SCENE_SUNSET_CONF<sup>11+</sup>           | "HwMnoteSceneSunsetConf"    | **读写能力:** 只读<br> 拍照场景:日落。|
7662| SCENE_FLOWERS_CONF<sup>11+</sup>          | "HwMnoteSceneFlowersConf"   | **读写能力:** 只读<br> 拍照场景:花。|
7663| SCENE_NIGHT_CONF<sup>11+</sup>            | "HwMnoteSceneNightConf"     | **读写能力:** 只读<br> 拍照场景:夜晚。|
7664| SCENE_TEXT_CONF<sup>11+</sup>             | "HwMnoteSceneTextConf"      | **读写能力:** 只读<br> 拍照场景:文本。|
7665| FACE_POINTER <sup>12+</sup>               | "HwMnoteFacePointer"        | **读写能力:** 只读<br> 脸部指针。|
7666| FACE_VERSION <sup>12+</sup>               | "HwMnoteFaceVersion"        | **读写能力:** 只读<br> 人脸算法版本信息。|
7667| FACE_COUNT<sup>11+</sup>                  | "HwMnoteFaceCount"          | **读写能力:** 只读<br> 人脸数量。|
7668| FACE_CONF <sup>12+</sup>                  | "HwMnoteFaceConf"           | **读写能力:** 只读<br> 人脸置信度。|
7669| FACE_SMILE_SCORE <sup>12+</sup>           | "HwMnoteFaceSmileScore"     | **读写能力:** 只读<br> FaceCount张人脸的笑脸分数。|
7670| FACE_RECT <sup>12+</sup>                  | "HwMnoteFaceRect"           | **读写能力:** 只读<br> 脸部矩形。|
7671| FACE_LEYE_CENTER <sup>12+</sup>           | "HwMnoteFaceLeyeCenter"     | **读写能力:** 只读<br> 左眼中心。|
7672| FACE_REYE_CENTER <sup>12+</sup>           | "HwMnoteFaceReyeCenter"     | **读写能力:** 只读<br> 右眼中心。|
7673| FACE_MOUTH_CENTER <sup>12+</sup>          | "HwMnoteFaceMouthCenter"    | **读写能力:** 只读<br> 嘴中心。|
7674| CAPTURE_MODE <sup>10+</sup>               | "HwMnoteCaptureMode"        | **读写能力:** 可读写<br> 捕获模式。|
7675| BURST_NUMBER <sup>12+</sup>               | "HwMnoteBurstNumber"        | **读写能力:** 只读<br> 连拍次数。|
7676| FRONT_CAMERA <sup>12+</sup>               | "HwMnoteFrontCamera"        | **读写能力:** 只读<br> 是否是前置相机自拍。|
7677| ROLL_ANGLE <sup>11+</sup>                 | "HwMnoteRollAngle"          | **读写能力:** 只读<br> 滚动角度。|
7678| PITCH_ANGLE<sup>11+</sup>                 | "HwMnotePitchAngle"         | **读写能力:** 只读<br> 俯仰角度。|
7679| PHYSICAL_APERTURE <sup>10+</sup>          | "HwMnotePhysicalAperture"   | **读写能力:** 只读<br> 物理孔径,光圈大小。|
7680| FOCUS_MODE<sup>11+</sup>                  | "HwMnoteFocusMode"          | **读写能力:** 只读<br> 对焦模式。|
7681| USER_COMMENT <sup>10+</sup>               | "UserComment"               | **读写能力:** 可读写<br> 用户注释。|
7682| SUBSEC_TIME <sup>12+</sup>                | "SubsecTime"                | **读写能力:** 可读写<br> 用于为DateTime标签记录秒的分数的标签。|
7683| SUBSEC_TIME_ORIGINAL <sup>12+</sup>       | "SubsecTimeOriginal"        | **读写能力:** 可读写<br> 用于为DateTimeOriginal标签记录秒的分数的标签。|
7684| SUBSEC_TIME_DIGITIZED <sup>12+</sup>      | "SubsecTimeDigitized"       | **读写能力:** 可读写<br> 用于为DateTimeDigitized标签记录秒的分数的标签。|
7685| FLASHPIX_VERSION <sup>12+</sup>           | "FlashpixVersion"           | **读写能力:** 可读写<br> 该标签表示FPXR文件支持的Flashpix格式版本,增强了设备兼容性。|
7686| COLOR_SPACE <sup>12+</sup>                | "ColorSpace"                | **读写能力:** 可读写<br> 色彩空间信息标签,通常记录为色彩空间指定符。|
7687| PIXEL_X_DIMENSION <sup>10+</sup>          | "PixelXDimension"           | **读写能力:** 可读写<br> 像素X尺寸。|
7688| PIXEL_Y_DIMENSION<sup>10+</sup>           | "PixelYDimension"           | **读写能力:** 可读写<br> 像素Y尺寸。|
7689| RELATED_SOUND_FILE <sup>12+</sup>         | "RelatedSoundFile"          | **读写能力:** 可读写<br> 与图像数据相关的音频文件的名称。|
7690| FLASH_ENERGY <sup>12+</sup>               | "FlashEnergy"               | **读写能力:** 可读写<br> 图像捕获时的闪光能量,以BCPS表示。|
7691| SPATIAL_FREQUENCY_RESPONSE <sup>12+</sup> | "SpatialFrequencyResponse"  | **读写能力:** 可读写<br> 相机或输入设备的空间频率表。|
7692| FOCAL_PLANE_X_RESOLUTION <sup>12+</sup>   | "FocalPlaneXResolution"     | **读写能力:** 可读写<br> 图像宽度中每FocalPlaneResolutionUnit的像素。|
7693| FOCAL_PLANE_Y_RESOLUTION <sup>12+</sup>   | "FocalPlaneYResolution"     | **读写能力:** 可读写<br> 图像高度中每FocalPlaneResolutionUnit的像素。|
7694| FOCAL_PLANE_RESOLUTION_UNIT <sup>12+</sup> | "FocalPlaneResolutionUnit"  | **读写能力:** 可读写<br> 测量FocalPlaneXResolution和FocalPlaneYResolution的单位。|
7695| SUBJECT_LOCATION <sup>12+</sup>           | "SubjectLocation"           | **读写能力:** 可读写<br> 主要对象相对于左边缘的位置。|
7696| EXPOSURE_INDEX <sup>12+</sup>             | "ExposureIndex"             | **读写能力:** 可读写<br> 捕获时选定的曝光指数。|
7697| SENSING_METHOD <sup>12+</sup>             | "SensingMethod"             | **读写能力:** 可读写<br> 相机上的图像传感器类型。|
7698| FILE_SOURCE <sup>12+</sup>                | "FileSource"                | **读写能力:** 可读写<br> 表明图像来源。|
7699| SCENE_TYPE<sup>9+</sup>                   | "SceneType"                 | **读写能力:** 可读写<br> 拍摄场景模式,例如人像、风光、运动、夜景等。|
7700| CFA_PATTERN <sup>12+</sup>                | "CFAPattern"                | **读写能力:** 可读写<br> 图像传感器的色彩滤光片(CFA)几何图案。|
7701| CUSTOM_RENDERED <sup>12+</sup>            | "CustomRendered"            | **读写能力:** 可读写<br> 指示图像数据上的特殊处理。|
7702| EXPOSURE_MODE <sup>12+</sup>              | "ExposureMode"              | **读写能力:** 可读写<br> 拍摄时设置的曝光模式。|
7703| WHITE_BALANCE <sup>10+</sup>              | "WhiteBalance"              | **读写能力:** 可读写<br> 白平衡。|
7704| DIGITAL_ZOOM_RATIO <sup>12+</sup>         | "DigitalZoomRatio"          | **读写能力:** 可读写<br> 捕获时的数字变焦比率。|
7705| FOCAL_LENGTH_IN_35_MM_FILM <sup>10+</sup> | "FocalLengthIn35mmFilm"     | **读写能力:** 可读写<br> 焦距35毫米胶片。|
7706| SCENE_CAPTURE_TYPE <sup>12+</sup>         | "SceneCaptureType"          | **读写能力:** 可读写<br> 捕获的场景类型。|
7707| GAIN_CONTROL <sup>12+</sup>               | "GainControl"               | **读写能力:** 可读写<br> 整体图像增益调整的程度。|
7708| CONTRAST <sup>12+</sup>                   | "Contrast"                  | **读写能力:** 可读写<br> 相机应用的对比度处理方向。|
7709| SATURATION <sup>12+</sup>                 | "Saturation"                | **读写能力:** 可读写<br> 相机应用的饱和度处理方向。|
7710| SHARPNESS <sup>12+</sup>                  | "Sharpness"                 | **读写能力:** 可读写<br> 相机应用的锐度处理方向。|
7711| DEVICE_SETTING_DESCRIPTION <sup>12+</sup> | "DeviceSettingDescription"  | **读写能力:** 可读写<br> 特定相机模型的拍照条件信息。|
7712| SUBJECT_DISTANCE_RANGE <sup>12+</sup>     | "SubjectDistanceRange"      | **读写能力:** 可读写<br> 表示主体到相机的距离范围。|
7713| IMAGE_UNIQUE_ID <sup>12+</sup>            | "ImageUniqueID"             | **读写能力:** 可读写<br> 为每张图片唯一分配的标识符。|
7714| CAMERA_OWNER_NAME <sup>12+</sup>          | "CameraOwnerName"           | **读写能力:** 可读写<br> 相机所有者的姓名。|
7715| BODY_SERIAL_NUMBER <sup>12+</sup>         | "BodySerialNumber"          | **读写能力:** 可读写<br> 相机机身的序列号。|
7716| LENS_SPECIFICATION <sup>12+</sup>         | "LensSpecification"         | **读写能力:** 可读写<br> 使用的镜头规格。|
7717| LENS_MAKE <sup>12+</sup>                  | "LensMake"                  | **读写能力:** 可读写<br> 镜头的制造商。|
7718| LENS_MODEL <sup>12+</sup>                 | "LensModel"                 | **读写能力:** 可读写<br> 镜头的型号名称。|
7719| LENS_SERIAL_NUMBER <sup>12+</sup>         | "LensSerialNumber"          | **读写能力:** 可读写<br> 镜头的序列号。|
7720| COMPOSITE_IMAGE <sup>12+</sup>            | "CompositeImage"            | **读写能力:** 可读写<br> 表示图像是否为合成图像。|
7721| SOURCE_IMAGE_NUMBER_OF_COMPOSITE_IMAGE <sup>12+</sup>   | "SourceImageNumberOfCompositeImage"       | **读写能力:** 可读写<br> 用于合成图像的源图像数量。|
7722| SOURCE_EXPOSURE_TIMES_OF_COMPOSITE_IMAGE <sup>12+</sup> | "SourceExposureTimesOfCompositeImage"     | **读写能力:** 可读写<br> 合成图像的源图像曝光时间。|
7723| GAMMA <sup>12+</sup>                      | "Gamma"                     | **读写能力:** 可读写<br> 表示系数伽马的值。|
7724| DNG_VERSION <sup>12+</sup>                | "DNGVersion"                | **读写能力:** 可读写<br> DNG版本标签编码了符合DNG规范的四级版本号。|
7725| DEFAULT_CROP_SIZE <sup>12+</sup>          | "DefaultCropSize"           | **读写能力:** 可读写<br> DefaultCropSize指定了原始坐标中的最终图像大小,考虑了额外的边缘像素。|
7726| GIF_LOOP_COUNT <sup>12+</sup>             | "GIFLoopCount"              | **读写能力:** 只读<br> GIF图片循环次数。0表示无限循环,其他值表示循环次数。|
7727| IS_XMAGE_SUPPORTED <sup>12+</sup> | "HwMnoteIsXmageSupported" | **读写能力:** 可读写<br>是否支持XMAGE。 |
7728| XMAGE_MODE <sup>12+</sup> | "HwMnoteXmageMode" | **读写能力:** 可读写<br>XMAGE水印模式。 |
7729| XMAGE_LEFT <sup>12+</sup> | "HwMnoteXmageLeft" | **读写能力:** 可读写<br>水印区域X1坐标。 |
7730| XMAGE_TOP <sup>12+</sup> | "HwMnoteXmageTop" | **读写能力:** 可读写<br>水印区域Y1坐标。 |
7731| XMAGE_RIGHT <sup>12+</sup> | "HwMnoteXmageRight" | **读写能力:** 可读写<br>水印区域X2坐标。 |
7732| XMAGE_BOTTOM <sup>12+</sup> | "HwMnoteXmageBottom" | **读写能力:** 可读写<br>水印区域Y2坐标。 |
7733| CLOUD_ENHANCEMENT_MODE <sup>12+</sup> | "HwMnoteCloudEnhancementMode" | **读写能力:** 可读写<br>云增强模式。 |
7734| WIND_SNAPSHOT_MODE <sup>12+</sup> | "HwMnoteWindSnapshotMode" | **读写能力:** 只读<br>运动快拍模式。 |
7735
7736## ImageFormat<sup>9+</sup>
7737
7738枚举,图片格式。
7739
7740**系统能力:** SystemCapability.Multimedia.Image.Core
7741
7742| 名称         |   值   | 说明                 |
7743| ------------ | ------ | -------------------- |
7744| YCBCR_422_SP | 1000   | YCBCR422半平面格式。 |
7745| JPEG         | 2000   | JPEG编码格式。       |
7746
7747## ComponentType<sup>9+</sup>
7748
7749枚举,图像的组件类型。
7750
7751**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
7752
7753| 名称  |   值   | 说明        |
7754| ----- | ------ | ----------- |
7755| YUV_Y | 1      | 亮度信息。  |
7756| YUV_U | 2      | 色度信息。  |
7757| YUV_V | 3      | 色度信息。  |
7758| JPEG  | 4      | JPEG 类型。 |
7759
7760## Component<sup>9+</sup>
7761
7762描述图像颜色分量。
7763
7764**系统能力:** SystemCapability.Multimedia.Image.Core
7765
7766| 名称          | 类型                             | 只读 | 可选 | 说明         |
7767| ------------- | -------------------------------- | ---- | ---- | ------------ |
7768| componentType | [ComponentType](#componenttype9) | 是   | 否   | 组件类型。   |
7769| rowStride     | number                           | 是   | 否   | 行距。读取相机预览流数据时,需要考虑按stride进行读取,具体用法见[ArkTS双路预览示例](../../media/camera/camera-dual-channel-preview.md)。       |
7770| pixelStride   | number                           | 是   | 否   | 像素间距。   |
7771| byteBuffer    | ArrayBuffer                      | 是   | 否   | 组件缓冲区。 |
7772
7773## DecodingDynamicRange<sup>12+</sup>
7774
7775描述解码时期望的图像动态范围。
7776
7777**系统能力:** SystemCapability.Multimedia.Image.Core
7778
7779| 名称          | 值       | 说明         |
7780| ------------- | ----------| ------------ |
7781| AUTO          | 0    | 自适应,根据图片信息处理。即如果图片本身为HDR图片,则会按照HDR内容解码;反之按照SDR内容解码。通过[CreateIncrementalSource](#imagecreateincrementalsource9)创建的imagesource会解码为SDR内容。  |
7782| SDR           | 1    | 按照标准动态范围处理图片。   |
7783| HDR           | 2    | 按照高动态范围处理图片。通过[CreateIncrementalSource](#imagecreateincrementalsource9)创建的imagesource会解码为SDR内容。     |
7784
7785## PackingDynamicRange<sup>12+</sup>
7786
7787描述编码时期望的图像动态范围。
7788
7789**系统能力:** SystemCapability.Multimedia.Image.Core
7790
7791| 名称          | 值       | 说明         |
7792| ------------- | ----------| ------------ |
7793| AUTO          | 0    | 自适应,根据[pixelmap](#pixelmap7)内容处理。即如果pixelmap本身为HDR,则会按照HDR内容进行编码;反之按照SDR内容编码。  |
7794| SDR           | 1    | 按照标准动态范围处理图片。   |
7795
7796## HdrMetadataKey<sup>12+</sup>
7797
7798枚举,[pixelmap](#pixelmap7)使用的HDR相关元数据信息的关键字。
7799
7800**系统能力:** SystemCapability.Multimedia.Image.Core
7801
7802| 名称          | 值       | 说明         |
7803| ------------- | ----------| ------------ |
7804| HDR_METADATA_TYPE    | 0    | [pixelmap](#pixelmap7)使用的元数据类型。  |
7805| HDR_STATIC_METADATA  | 1    | 静态元数据。   |
7806| HDR_DYNAMIC_METADATA | 2    | 动态元数据。   |
7807| HDR_GAINMAP_METADATA | 3    | Gainmap使用的元数据。   |
7808
7809## HdrMetadataType<sup>12+</sup>
7810
7811枚举,[HdrMetadataKey](#hdrmetadatakey12)中HDR_METADATA_TYPE关键字对应的值。
7812
7813**系统能力:** SystemCapability.Multimedia.Image.Core
7814
7815| 名称          | 值       | 说明         |
7816| ------------- | ----------| ------------ |
7817| NONE     | 0    | 无元数据内容。  |
7818| BASE     | 1    | 表示用于基础图的元数据。   |
7819| GAINMAP  | 2    | 表示用于Gainmap图的元数据。   |
7820| ALTERNATE| 3    | 表示用于合成后HDR图的元数据。   |
7821
7822## HdrStaticMetadata<sup>12+</sup>
7823
7824静态元数据值,[HdrMetadataKey](#hdrmetadatakey12)中HDR_STATIC_METADATA关键字对应的值。
7825
7826**系统能力:** SystemCapability.Multimedia.Image.Core
7827
7828| 名称          | 类型       | 只读 | 可选 | 说明         |
7829| ------------- | ----------| -- | -- | ------------ |
7830| displayPrimariesX     | Array\<number>  | 否 | 否 | 归一化后显示设备三基色的X坐标,数组的长度为3,以0.00002为单位,范围[0.0, 1.0]。  |
7831| displayPrimariesY     | Array\<number>  | 否 | 否 | 归一化后显示设备三基色的Y坐标,数组的长度为3,以0.00002为单位,范围[0.0, 1.0]。  |
7832| whitePointX  | number  | 否 | 否 | 归一化后白点值的X坐标,以0.00002为单位,范围[0.0, 1.0]。   |
7833| whitePointY  | number   | 否 | 否 | 归一化后白点值的Y坐标,以0.00002为单位,范围[0.0, 1.0]。   |
7834| maxLuminance  | number  | 否 | 否 | 图像主监视器最大亮度。以1为单位,最大值为65535。   |
7835| minLuminance  | number   | 否 | 否 | 图像主监视器最小亮度。以0.0001为单位,最大值6.55535。   |
7836| maxContentLightLevel  | number  | 否 | 否 | 显示内容的最大亮度。以1为单位,最大值为65535。   |
7837| maxFrameAverageLightLevel  | number  | 否 | 否 | 显示内容的最大平均亮度,以1为单位,最大值为65535。 |
7838
7839## GainmapChannel<sup>12+</sup>
7840
7841Gainmap图单个通道的数据内容,参考ISO 21496-1。
7842
7843**系统能力:** SystemCapability.Multimedia.Image.Core
7844
7845| 名称          | 类型       | 只读 | 可选 | 说明         |
7846| ------------- | ----------| -- | -- | ------------ |
7847| gainmapMax     | number   | 否 | 否 | 增强图像的最大值,参考ISO 21496-1。  |
7848| gainmapMin     | number   | 否 | 否 | 增强图像的最小值,参考ISO 21496-1。  |
7849| gamma  | number    | 否 | 否 | gamma值,参考ISO 21496-1。   |
7850| baseOffset  | number     | 否 | 否 | 基础图的偏移,参考ISO 21496-1。   |
7851| alternateOffset  | number    | 否 | 否 | 提取的可选择图像偏移量,参考ISO 21496-1。    |
7852
7853## HdrGainmapMetadata<sup>12+</sup>
7854
7855Gainmap使用的元数据值,[HdrMetadataKey](#hdrmetadatakey12)中HDR_GAINMAP_METADATA关键字对应的值,参考ISO 21496-1。
7856
7857**系统能力:** SystemCapability.Multimedia.Image.Core
7858
7859| 名称          | 类型       | 只读 | 可选 | 说明         |
7860| ------------- | ----------| -- | -- | ------------ |
7861| writerVersion     | number   | 否 | 否 | 元数据编写器使用的版本。  |
7862| miniVersion     | number   | 否 | 否 | 元数据解析需要理解的最小版本。  |
7863| gainmapChannelCount  | number    | 否 | 否 | Gainmap的颜色通道数,值为3时RGB通道的元数据值不同,值为1时各通道元数据值相同,参考ISO 21496-1。  |
7864| useBaseColorFlag  | boolean     | 否 | 否 | 是否使用基础图的色彩空间,参考ISO 21496-1。   |
7865| baseHeadroom  | number    | 否 | 否 |  基础图提亮比,参考ISO 21496-1。   |
7866| alternateHeadroom  | number     | 否 | 否 |  提取的可选择图像提亮比,参考ISO 21496-1。  |
7867| channels  | Array<[GainmapChannel](#gainmapchannel12)> | 否 | 否 | 各通道的数据,长度为3,参考ISO 21496-1。 |
7868
7869## HdrMetadataValue<sup>12+</sup>
7870
7871type HdrMetadataValue = HdrMetadataType | HdrStaticMetadata | ArrayBuffer | HdrGainmapMetadata
7872
7873PixelMap使用的HDR元数据值类型,和[HdrMetadataKey](#hdrmetadatakey12)关键字相对应。
7874
7875**系统能力:** SystemCapability.Multimedia.Image.Core
7876
7877| 类型                | 说明                                            |
7878| ------------------- | ----------------------------------------------- |
7879| [HdrMetadataType](#hdrmetadatatype12) | [HdrMetadataKey](#hdrmetadatakey12)中HDR_GAINMAP_METADATA关键字对应的元数据值类型。 |
7880| [HdrStaticMetadata](#hdrstaticmetadata12) | [HdrMetadataKey](#hdrmetadatakey12)中HDR_STATIC_METADATA关键字对应的元数据值类型。 |
7881| ArrayBuffer | [HdrMetadataKey](#hdrmetadatakey12)中HDR_DYNAMIC_METADATA关键字对应的元数据值类型。 |
7882| [HdrGainmapMetadata](#hdrgainmapmetadata12) | [HdrMetadataKey](#hdrmetadatakey12)中HDR_GAINMAP_METADATA关键字对应的元数据值类型。 |
7883
7884## AntiAliasingLevel<sup>12+</sup>
7885
7886缩放时的缩放算法。
7887
7888**系统能力:** SystemCapability.Multimedia.Image.Core
7889
7890| 名称                   |   值   | 说明              |
7891| ---------------------- | ------ | ----------------- |
7892| NONE                | 0      | 默认为最近邻缩放算法。        |
7893| LOW                 | 1      | 双线性缩放算法。     |
7894| MEDIUM              | 2      | 双线性缩放算法,同步开启mipmap。|
7895| HIGH                | 3      | cubic缩放算法。 |
7896
7897## 补充说明
7898### SVG标签说明
7899
7900从API version 10开始支持SVG标签,使用版本为(SVG) 1.1,SVG文件需添加xml声明,应以“<?xml”开头,并且SVG标签需设置width,height。当前支持的标签列表有:
7901- a
7902- circla
7903- clipPath
7904- defs
7905- ellipse
7906- feBlend
7907- feColorMatrix
7908- feComposite
7909- feDiffuseLighting
7910- feDisplacementMap
7911- feDistantLight
7912- feFlood
7913- feGaussianBlur
7914- feImage
7915- feMorphology
7916- feOffset
7917- fePointLight
7918- feSpecularLighting
7919- feSpotLight
7920- feTurbulence
7921- filter
7922- g
7923- image
7924- line
7925- linearGradient
7926- mask
7927- path
7928- pattern
7929- polygon
7930- polyline
7931- radialGradient
7932- rect
7933- stop
7934- svg
7935- text
7936- textPath
7937- tspan
7938- use