• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 CreatePixelMap() {
181  const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
182  let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } }
183  image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => {
184    console.info('Succeeded in creating pixelmap.');
185  }).catch((error: BusinessError) => {
186    console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`);
187  })
188}
189```
190
191## image.createPixelMap<sup>8+</sup>
192
193createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: AsyncCallback\<PixelMap>): void
194
195通过属性创建PixelMap,默认采用BGRA_8888格式处理数据,通过回调函数返回结果。
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 CreatePixelMap() {
213  const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
214  let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } }
215  image.createPixelMap(color, opts, (error: BusinessError, pixelMap: image.PixelMap) => {
216    if(error) {
217      console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`);
218      return;
219    } else {
220      console.info('Succeeded in creating pixelmap.');
221    }
222  })
223}
224```
225
226## image.createPixelMapFromParcel<sup>11+</sup>
227
228createPixelMapFromParcel(sequence: rpc.MessageSequence): PixelMap
229
230从MessageSequence中获取PixelMap。
231
232**系统能力:** SystemCapability.Multimedia.Image.Core
233
234**参数:**
235
236| 参数名                 | 类型                                                  | 必填 | 说明                                     |
237| ---------------------- | ----------------------------------------------------- | ---- | ---------------------------------------- |
238| sequence               | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | 是   | 保存有PixelMap信息的MessageSequence。      |
239
240**返回值:**
241
242| 类型                             | 说明                  |
243| -------------------------------- | --------------------- |
244| [PixelMap](#pixelmap7) | 成功同步返回PixelMap对象,失败抛出异常。 |
245
246**错误码:**
247
248以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
249
250| 错误码ID | 错误信息 |
251| ------- | --------------------------------------------|
252| 62980096 | Operation failed|
253| 62980097 | IPC error.|
254| 62980115 | Invalid input parameter|
255| 62980105 | Failed to get the data|
256| 62980177 | Abnormal API environment|
257| 62980178 | Failed to create the PixelMap|
258| 62980179 | Abnormal buffer size|
259| 62980180 | FD mapping failed|
260| 62980246 | Failed to read the PixelMap|
261
262**示例:**
263
264```ts
265import { image } from '@kit.ImageKit';
266import { rpc } from '@kit.IPCKit';
267import { BusinessError } from '@kit.BasicServicesKit';
268
269class MySequence implements rpc.Parcelable {
270  pixel_map: image.PixelMap;
271  constructor(conPixelmap: image.PixelMap) {
272    this.pixel_map = conPixelmap;
273  }
274  marshalling(messageSequence: rpc.MessageSequence) {
275    this.pixel_map.marshalling(messageSequence);
276    return true;
277  }
278  unmarshalling(messageSequence: rpc.MessageSequence) {
279    try {
280      this.pixel_map = image.createPixelMapFromParcel(messageSequence);
281    } catch(e) {
282      let error = e as BusinessError;
283      console.error(`createPixelMapFromParcel error. code is ${error.code}, message is ${error.message}`);
284      return false;
285    }
286    return true;
287  }
288}
289async function CreatePixelMapFromParcel() {
290  const color: ArrayBuffer = new ArrayBuffer(96);
291  let bufferArr: Uint8Array = new Uint8Array(color);
292  for (let i = 0; i < bufferArr.length; i++) {
293    bufferArr[i] = 0x80;
294  }
295  let opts: image.InitializationOptions = {
296    editable: true,
297    pixelFormat: image.PixelMapFormat.BGRA_8888,
298    size: { height: 4, width: 6 },
299    alphaType: image.AlphaType.UNPREMUL
300  }
301  let pixelMap: image.PixelMap | undefined = undefined;
302  image.createPixelMap(color, opts).then((srcPixelMap: image.PixelMap) => {
303    pixelMap = srcPixelMap;
304  })
305  if (pixelMap != undefined) {
306    // 序列化
307    let parcelable: MySequence = new MySequence(pixelMap);
308    let data: rpc.MessageSequence = rpc.MessageSequence.create();
309    data.writeParcelable(parcelable);
310
311    // 反序列化 rpc获取到data
312    let ret: MySequence = new MySequence(pixelMap);
313    data.readParcelable(ret);
314
315    // 获取到pixelmap
316    let unmarshPixelmap = ret.pixel_map;
317  }
318}
319```
320
321## image.createPixelMapFromSurface<sup>11+</sup>
322
323createPixelMapFromSurface(surfaceId: string, region: Region): Promise\<PixelMap>
324
325根据Surface id和区域信息,创建一个PixelMap对象。该区域的大小由[Region](#region8).size指定。使用Promise形式返回。
326
327> **说明:**
328> 1. [Region](#region8).size的宽高需和[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)组件的宽高保持一致。
329> 2. 当开发设备为折叠屏,折叠状态切换时,需自行调整[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)组件的宽高。
330
331**系统能力:** SystemCapability.Multimedia.Image.Core
332
333**参数:**
334
335| 参数名                 | 类型                 | 必填 | 说明                                     |
336| ---------------------- | -------------       | ---- | ---------------------------------------- |
337| surfaceId              | string              | 是   | 从[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)组件获取的surfaceId。|
338| region                 | [Region](#region8)  | 是   | 区域信息。 |
339
340**返回值:**
341| 类型                             | 说明                  |
342| -------------------------------- | --------------------- |
343| Promise\<[PixelMap](#pixelmap7)> | Promise对象,返回PixelMap。 |
344
345**错误码:**
346
347以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
348
349| 错误码ID | 错误信息 |
350| ------- | --------------------------------------------|
351| 62980115 | If the image parameter invalid.|
352| 62980105 | Failed to get the data|
353| 62980178 | Failed to create the PixelMap|
354
355**示例:**
356
357```ts
358import { BusinessError } from '@kit.BasicServicesKit';
359
360async function CreatePixelMapFromSurface(surfaceId: string) {
361  let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } };
362  image.createPixelMapFromSurface(surfaceId, region).then(() => {
363    console.info('Succeeded in creating pixelmap from Surface');
364  }).catch((error: BusinessError) => {
365    console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`);
366  });
367}
368```
369
370## image.createPixelMapFromSurfaceSync<sup>12+</sup>
371
372createPixelMapFromSurfaceSync(surfaceId: string, region: Region): PixelMap
373
374以同步方式,根据Surface id和区域信息,创建一个PixelMap对象。该区域的大小由[Region](#region8).size指定。
375
376> **说明:**
377> 1. [Region](#region8).size的宽高需和[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)组件的宽高保持一致。
378> 2. 当开发设备为折叠屏,折叠状态切换时,需自行调整[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)组件的宽高。
379
380**系统能力:** SystemCapability.Multimedia.Image.Core
381
382**参数:**
383
384| 参数名                 | 类型                 | 必填 | 说明                                     |
385| ---------------------- | -------------       | ---- | ---------------------------------------- |
386| surfaceId              | string              | 是   | 从[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)组件获取的surfaceId。|
387| region                 | [Region](#region8)  | 是   | 区域信息。 |
388
389**返回值:**
390| 类型                             | 说明                  |
391| -------------------------------- | --------------------- |
392| [PixelMap](#pixelmap7) | 成功同步返回PixelMap对象,失败抛出异常。 |
393
394**错误码:**
395
396以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
397
398| 错误码ID | 错误信息 |
399| ------- | --------------------------------------------|
400|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed|
401| 62980105 | Failed to get the data|
402| 62980178 | Failed to create the PixelMap|
403
404**示例:**
405
406```ts
407import { BusinessError } from '@kit.BasicServicesKit';
408
409async function Demo(surfaceId: string) {
410  let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } };
411  let pixelMap : image.PixelMap = image.createPixelMapFromSurfaceSync(surfaceId, region);
412  return pixelMap;
413}
414```
415
416## image.createPixelMapSync<sup>12+</sup>
417
418createPixelMapSync(colors: ArrayBuffer, options: InitializationOptions): PixelMap
419
420通过属性创建PixelMap,同步返回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 CreatePixelMapSync() {
450  const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
451  let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } }
452  let pixelMap : image.PixelMap = image.createPixelMapSync(color, opts);
453  return pixelMap;
454}
455```
456
457## image.createPixelMapSync<sup>12+</sup>
458
459createPixelMapSync(options: InitializationOptions): PixelMap
460
461通过属性创建PixelMap,同步返回PixelMap结果。
462
463**系统能力:** SystemCapability.Multimedia.Image.Core
464
465**参数:**
466
467| 参数名  | 类型                                             | 必填 | 说明                                                             |
468| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- |
469| options | [InitializationOptions](#initializationoptions8) | 是   | 创建像素的属性,包括透明度,尺寸,缩略值,像素格式和是否可编辑。 |
470
471**返回值:**
472| 类型                             | 说明                  |
473| -------------------------------- | --------------------- |
474| [PixelMap](#pixelmap7) | 成功同步返回PixelMap对象,失败抛出异常。 |
475
476**错误码:**
477
478以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
479
480| 错误码ID | 错误信息 |
481| ------- | --------------------------------------------|
482|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed|
483
484**示例:**
485
486```ts
487import { BusinessError } from '@kit.BasicServicesKit';
488
489async function CreatePixelMapSync() {
490  let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } }
491  let pixelMap : image.PixelMap = image.createPixelMapSync(opts);
492  return pixelMap;
493}
494```
495
496## image.createPremultipliedPixelMap<sup>12+</sup>
497
498createPremultipliedPixelMap(src: PixelMap, dst: PixelMap, callback: AsyncCallback\<void>): void
499
500将PixelMap的透明通道非预乘模式转变为预乘模式,转换后的数据存入目标PixelMap,通过回调函数返回结果。
501
502**系统能力:** SystemCapability.Multimedia.Image.Core
503
504**参数:**
505
506| 参数名   | 类型                                             | 必填 | 说明                       |
507| -------- | ------------------------------------------------ | ---- | -------------------------- |
508| src | [PixelMap](#pixelmap7) | 是   | 源PixelMap对象。 |
509| dst | [PixelMap](#pixelmap7) | 是   | 目标PixelMap对象。 |
510|callback | AsyncCallback\<void> | 是   | 回调函数,当创建PixelMap成功,err为undefined,否则为错误对象。 |
511
512**错误码:**
513
514以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
515
516| 错误码ID | 错误信息 |
517| ------- | --------------------------------------------|
518|  401          | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed|
519|  62980103     | The image data is not supported |
520|  62980246      | Failed to read the pixelMap |
521|  62980248     | Pixelmap not allow modify |
522
523**示例:**
524
525```ts
526import { BusinessError } from '@kit.BasicServicesKit';
527
528async function CreatePremultipliedPixelMap() {
529  const color: ArrayBuffer = new ArrayBuffer(16); // 16为需要创建的像素buffer大小,取值为:height * width *4
530  let bufferArr = new Uint8Array(color);
531  for (let i = 0; i < bufferArr.length; i += 4) {
532    bufferArr[i] = 255;
533    bufferArr[i+1] = 255;
534    bufferArr[i+2] = 122;
535    bufferArr[i+3] = 122;
536  }
537  let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.UNPREMUL}
538  let srcPixelmap = image.createPixelMapSync(color, optsForUnpre);
539  let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.PREMUL}
540  let dstPixelMap = image.createPixelMapSync(optsForPre);
541  image.createPremultipliedPixelMap(srcPixelmap, dstPixelMap, (error: BusinessError) => {
542    if(error) {
543      console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`);
544      return;
545    } else {
546      console.info('Succeeded in converting pixelmap.');
547    }
548  })
549}
550```
551
552## image.createPremultipliedPixelMap<sup>12+</sup>
553
554createPremultipliedPixelMap(src: PixelMap, dst: PixelMap): Promise\<void>
555
556将PixelMap数据按照透明度非预乘格式转为预乘格式,转换后的数据存入另一个PixelMap,通过Promise返回结果。
557
558**系统能力:** SystemCapability.Multimedia.Image.Core
559
560**参数:**
561
562| 参数名   | 类型                                             | 必填 | 说明                       |
563| -------- | ------------------------------------------------ | ---- | -------------------------- |
564| src | [PixelMap](#pixelmap7) | 是   | 源PixelMap对象 |
565| dst | [PixelMap](#pixelmap7) | 是   | 目标PixelMap对象 |
566
567**返回值:**
568
569| 类型                             | 说明                                                                    |
570| -------------------------------- | ----------------------------------------------------------------------- |
571| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
572
573**错误码:**
574
575以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
576
577| 错误码ID | 错误信息 |
578| ------- | --------------------------------------------|
579|  401          | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed|
580|  62980103     | The image data is not supported |
581|  62980246      | Failed to read the pixelMap |
582|  62980248     | Pixelmap not allow modify |
583
584**示例:**
585
586```ts
587import { BusinessError } from '@kit.BasicServicesKit';
588
589async function CreatePremultipliedPixelMap() {
590  const color: ArrayBuffer = new ArrayBuffer(16); // 16为需要创建的像素buffer大小,取值为:height * width *4
591  let bufferArr = new Uint8Array(color);
592  for (let i = 0; i < bufferArr.length; i += 4) {
593    bufferArr[i] = 255;
594    bufferArr[i+1] = 255;
595    bufferArr[i+2] = 122;
596    bufferArr[i+3] = 122;
597  }
598  let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.UNPREMUL}
599  let srcPixelmap = image.createPixelMapSync(color, optsForUnpre);
600  let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.PREMUL}
601  let dstPixelMap = image.createPixelMapSync(optsForPre);
602  image.createPremultipliedPixelMap(srcPixelmap, dstPixelMap).then(() => {
603    console.info('Succeeded in converting pixelmap.');
604  }).catch((error: BusinessError) => {
605    console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`);
606  })
607}
608```
609
610## image.createUnpremultipliedPixelMap<sup>12+</sup>
611
612createUnpremultipliedPixelMap(src: PixelMap, dst: PixelMap, callback: AsyncCallback\<void>): void
613
614将PixelMap的透明通道预乘模式转变为非预乘模式,转换后的数据存入目标PixelMap,通过回调函数返回结果。
615
616**系统能力:** SystemCapability.Multimedia.Image.Core
617
618**参数:**
619
620| 参数名   | 类型                                             | 必填 | 说明                       |
621| -------- | ------------------------------------------------ | ---- | -------------------------- |
622| src | [PixelMap](#pixelmap7) | 是   | 源PixelMap对象。 |
623| dst | [PixelMap](#pixelmap7) | 是   | 目标PixelMap对象。|
624|callback | AsyncCallback\<void> | 是   | 回调函数,当创建PixelMap成功,err为undefined,否则为错误对象。|
625
626**错误码:**
627
628以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
629
630| 错误码ID | 错误信息 |
631| ------- | --------------------------------------------|
632|  401          | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed|
633|  62980103     | The image data is not supported |
634|  62980246      | Failed to read the pixelMap |
635|  62980248     | Pixelmap not allow modify |
636
637**示例:**
638
639```ts
640import { BusinessError } from '@kit.BasicServicesKit';
641
642async function CreateUnpremultipliedPixelMap() {
643  const color: ArrayBuffer = new ArrayBuffer(16); // 16为需要创建的像素buffer大小,取值为:height * width *4
644  let bufferArr = new Uint8Array(color);
645  for (let i = 0; i < bufferArr.length; i += 4) {
646    bufferArr[i] = 255;
647    bufferArr[i+1] = 255;
648    bufferArr[i+2] = 122;
649    bufferArr[i+3] = 122;
650  }
651  let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.PREMUL}
652  let srcPixelmap = image.createPixelMapSync(color, optsForPre);
653  let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.UNPREMUL}
654  let dstPixelMap = image.createPixelMapSync(optsForUnpre);
655  image.createUnpremultipliedPixelMap(srcPixelmap, dstPixelMap, (error: BusinessError) => {
656    if(error) {
657      console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`);
658      return;
659    } else {
660      console.info('Succeeded in converting pixelmap.');
661    }
662  })
663}
664```
665
666## image.createUnpremultipliedPixelMap<sup>12+</sup>
667
668createUnpremultipliedPixelMap(src: PixelMap, dst: PixelMap): Promise\<void>
669
670将PixelMap的透明通道预乘模式转变为非预乘模式,转换后的数据存入目标PixelMap,通过Promise返回结果。
671
672**系统能力:** SystemCapability.Multimedia.Image.Core
673
674**参数:**
675
676| 参数名  | 类型                                             | 必填 | 说明                                                             |
677| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- |
678| src | [PixelMap](#pixelmap7) | 是   | 源PixelMap对象。 |
679| dst | [PixelMap](#pixelmap7) | 是   | 目标PixelMap对象。 |
680
681**返回值:**
682
683| 类型                             | 说明                                                                    |
684| -------------------------------- | ----------------------------------------------------------------------- |
685| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
686
687**错误码:**
688
689以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
690
691| 错误码ID | 错误信息 |
692| ------- | --------------------------------------------|
693|  401          | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed|
694|  62980103    | The image data is not supported |
695|  62980246    | Failed to read the pixelMap. |
696|  62980248    | Pixelmap not allow modify. |
697
698**示例:**
699
700```ts
701import { BusinessError } from '@kit.BasicServicesKit';
702
703async function CreateUnpremultipliedPixelMap() {
704  const color: ArrayBuffer = new ArrayBuffer(16); // 16为需要创建的像素buffer大小,取值为:height * width *4
705  let bufferArr = new Uint8Array(color);
706  for (let i = 0; i < bufferArr.length; i += 4) {
707    bufferArr[i] = 255;
708    bufferArr[i+1] = 255;
709    bufferArr[i+2] = 122;
710    bufferArr[i+3] = 122;
711  }
712  let optsForPre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.PREMUL}
713  let srcPixelmap = image.createPixelMapSync(color, optsForPre);
714  let optsForUnpre: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 2, width: 2 } , alphaType: image.AlphaType.UNPREMUL}
715  let dstPixelMap = image.createPixelMapSync(optsForUnpre);
716  image.createUnpremultipliedPixelMap(srcPixelmap, dstPixelMap).then(() => {
717    console.info('Succeeded in converting pixelmap.');
718  }).catch((error: BusinessError) => {
719    console.error(`Failed to convert pixelmap. code is ${error.code}, message is ${error.message}`);
720  })
721}
722```
723
724
725## Picture<sup>13+</sup>
726
727一些包含特殊信息的图片可以解码为多图对象,多图对象一般包含主图、辅助图和元数据。其中主图包含图像的大部分信息,主要用于显示图像内容;辅助图用于存储与主图相关但不同的数据,展示图像更丰富的信息;元数据一般用来存储关于图像文件的信息。多图对象类用于读取或写入多图对象。在调用Picture的方法前,需要先通过[createPicture](#imagecreatepicture13)创建一个Picture实例。
728
729### 属性
730
731**系统能力:** SystemCapability.Multimedia.Image.Core
732
733### getMainPixelmap<sup>13+</sup>
734
735getMainPixelmap(): PixelMap
736
737获取主图的pixelmap。
738
739**系统能力:** SystemCapability.Multimedia.Image.Core
740
741**返回值:**
742
743| 类型                | 说明                   |
744| ------------------- | ---------------------- |
745| [PixelMap](#pixelmap7) | 同步返回PixelMap对象。 |
746
747**示例:**
748
749```ts
750import { BusinessError } from '@kit.BasicServicesKit';
751import { image } from '@kit.ImageKit';
752
753async function GetMainPixelmap() {
754  let funcName = "getMainPixelmap";
755  if (pictureObj != null) {
756    let mainPixelmap: image.PixelMap = pictureObj.getMainPixelmap();
757    if (mainPixelmap != null) {
758      mainPixelmap.getImageInfo().then((imageInfo: image.ImageInfo) => {
759        if (imageInfo != null) {
760          console.info('GetMainPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width);
761        }
762      }).catch((error: BusinessError) => {
763        console.error(funcName, 'Failed error.code: ${error.code} ,error.message: ${error.message}');
764      });
765    }
766  } else {
767    console.info('PictureObj is null');
768  }
769}
770```
771
772### getHdrComposedPixelmap<sup>13+</sup>
773
774getHdrComposedPixelmap(): Promise\<PixelMap>
775
776合成hdr图并获取hdr图的pixelmap,使用Promise形式返回结果。
777
778**系统能力:** SystemCapability.Multimedia.Image.Core
779
780**返回值:**
781
782| 类型                          | 说明                        |
783| ----------------------------- | --------------------------- |
784| Promise\<[PixelMap](#pixelmap7)> | Promise对象,返回PixelMap。 |
785
786**错误码:**
787
788以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
789
790| 错误码ID | 错误信息               |
791| -------- | ---------------------- |
792| 7600901  | Unknown error.         |
793| 7600201  | Unsupported operation. |
794
795**示例:**
796
797```ts
798import { BusinessError } from '@kit.BasicServicesKit';
799import { image } from '@kit.ImageKit';
800
801async function GetHdrComposedPixelmap() {
802  let funcName = "getHdrComposedPixelmap";
803  if (pictureObj != null) { //图片包含Hdr图
804    let hdrComposedPixelmap: image.PixelMap = await pictureObj.getHdrComposedPixelmap();
805    if (hdrComposedPixelmap != null) {
806      hdrComposedPixelmap.getImageInfo().then((imageInfo: image.ImageInfo) => {
807        if (imageInfo != null) {
808          console.info('GetHdrComposedPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width);
809        }
810      }).catch((error: BusinessError) => {
811        console.error(funcName, 'Failed error.code: ${error.code} ,error.message: ${error.message}');
812      });
813    }
814  } else {
815    console.info('PictureObj is null');
816  }
817}
818```
819
820### getGainmapPixelmap<sup>13+</sup>
821
822getGainmapPixelmap(): PixelMap | null
823
824获取增益图的pixelmap。
825
826**系统能力:** SystemCapability.Multimedia.Image.Core
827
828**返回值:**
829
830| 类型                      | 说明                                   |
831| ------------------------- | -------------------------------------- |
832| [PixelMap](#pixelmap7) \| null | 返回Pixelmap对象,如果没有则返回null。 |
833
834**示例:**
835
836```ts
837import { BusinessError } from '@kit.BasicServicesKit';
838import { image } from '@kit.ImageKit';
839
840async function GetGainmapPixelmap() {
841  let funcName = "getGainmapPixelmap";
842  if (pictureObj != null) { //图片包含增益图
843    let gainPixelmap: image.PixelMap | null = pictureObj.getGainmapPixelmap();
844    if (gainPixelmap != null) {
845      gainPixelmap.getImageInfo().then((imageInfo: image.ImageInfo) => {
846        if (imageInfo != null) {
847          console.info('GetGainmapPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width);
848        } else {
849          console.info('GainPixelmap is null');
850        }
851      }).catch((error: BusinessError) => {
852        console.error(funcName, 'Failed error.code: ${error.code} ,error.message: ${error.message}');
853      });
854    } else {
855      console.info('GainPixelmap is null');
856    }
857  } else {
858    console.info('PictureObj is null');
859  }
860}
861```
862
863### setAuxiliaryPicture<sup>13+</sup>
864
865setAuxiliaryPicture(type: AuxiliaryPictureType, auxiliaryPicture: AuxiliaryPicture): void
866
867设置辅助图。
868
869**系统能力:** SystemCapability.Multimedia.Image.Core
870
871**参数:**
872
873| 参数名           | 类型                 | 必填 | 说明         |
874| ---------------- | -------------------- | ---- | ------------ |
875| type             | [AuxiliaryPictureType](#auxiliarypicturetype13) | 是   | 辅助图类型。 |
876| auxiliaryPicture | [AuxiliaryPicture](#auxiliarypicture13)     | 是   | 辅助图对象。 |
877
878**错误码:**
879
880以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
881
882| 错误码ID | 错误信息                                                     |
883| -------- | ------------------------------------------------------------ |
884| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
885
886**示例:**
887
888```ts
889import { image } from '@kit.ImageKit';
890
891async function SetAuxiliaryPicture() {
892  const context = getContext();
893  const resourceMgr = context.resourceManager;
894  const rawFile = await resourceMgr.getRawFileContent("hdr.jpg");//需要支持hdr的图片
895  let ops: image.SourceOptions = {
896    sourceDensity: 98,
897  }
898  let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops);
899  let pixelMap: image.PixelMap = await imageSource.createPixelMap();
900  let auxPicture: image.Picture = image.createPicture(pixelMap);
901  if (auxPicture != null) {
902    console.info('Create picture succeeded');
903  } else {
904    console.info('Create picture failed');
905  }
906
907  if (pictureObj != null) {
908    let type: image.AuxiliaryPictureType = image.AuxiliaryPictureType.GAINMAP;
909    let auxPictureObj: image.AuxiliaryPicture | null = await auxPicture.getAuxiliaryPicture(type);
910    if (auxPictureObj != null) {
911      pictureObj.setAuxiliaryPicture(type, auxPictureObj);
912    }
913  }
914}
915```
916
917### getAuxiliaryPicture<sup>13+</sup>
918
919getAuxiliaryPicture(type: AuxiliaryPictureType): AuxiliaryPicture | null
920
921根据类型获取辅助图。
922
923**系统能力:** SystemCapability.Multimedia.Image.Core
924
925**参数:**
926
927| 参数名 | 类型                 | 必填 | 说明         |
928| ------ | -------------------- | ---- | ------------ |
929| type   | [AuxiliaryPictureType](#auxiliarypicturetype13) | 是   | 辅助图类型。 |
930
931**返回值:**
932
933| 类型                   | 说明                                           |
934| ---------------------- | ---------------------------------------------- |
935| [AuxiliaryPicture](#auxiliarypicture13) \| null | 返回AuxiliaryPicture对象,如果没有则返回null。 |
936
937**错误码:**
938
939以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
940
941| 错误码ID | 错误信息                                                     |
942| -------- | ------------------------------------------------------------ |
943| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
944
945**示例:**
946
947```ts
948import { image } from '@kit.ImageKit';
949
950async function GetAuxiliaryPicture() {
951  if (pictureObj != null) {
952    let type: image.AuxiliaryPictureType = image.AuxiliaryPictureType.GAINMAP;
953    let auxPictureObj: image.AuxiliaryPicture | null = pictureObj.getAuxiliaryPicture(type);
954  }
955}
956```
957
958### setMetadata<sup>13+</sup>
959
960setMetadata(metadataType: MetadataType, metadata: Metadata): Promise\<void>
961
962设置主图的元数据。
963
964**系统能力:** SystemCapability.Multimedia.Image.Core
965
966**参数:**
967
968| 参数名       | 类型         | 必填 | 说明         |
969| ------------ | ------------ | ---- | ------------ |
970| metadataType | [MetadataType](#metadatatype13) | 是   | 元数据类型。 |
971| metadata     | [Metadata](#metadata13)     | 是   | 元数据对象。 |
972
973**返回值:**
974
975| 类型           | 说明                                   |
976| -------------- | -------------------------------------- |
977| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
978
979**错误码:**
980
981以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
982
983| 错误码ID | 错误信息                                                     |
984| -------- | ------------------------------------------------------------ |
985| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
986| 7600202  | Unsupported metadata. Possible causes: Unsupported metadata type. |
987
988**示例:**
989
990```ts
991import { BusinessError } from '@kit.BasicServicesKit';
992import { image } from '@kit.ImageKit';
993
994async function SetPictureObjMetadata() {
995  const exifContext = getContext();
996  const exifResourceMgr = exifContext.resourceManager;
997  const exifRawFile = await exifResourceMgr.getRawFileContent("exif.jpg");//含有exif metadata的图片
998  let exifOps: image.SourceOptions = {
999    sourceDensity: 98,
1000  }
1001  let exifImageSource: image.ImageSource = image.createImageSource(exifRawFile.buffer as ArrayBuffer, exifOps);
1002  let exifCommodityPixelMap: image.PixelMap = await exifImageSource.createPixelMap();
1003  let exifPictureObj: image.Picture = image.createPicture(exifCommodityPixelMap);
1004  if (exifPictureObj != null) {
1005    console.info('Create picture succeeded');
1006  } else {
1007    console.info('Create picture failed');
1008  }
1009
1010  if (pictureObj != null) {
1011    let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA;
1012    let exifMetaData: image.Metadata = await exifPictureObj.getMetadata(metadataType);
1013    pictureObj.setMetadata(metadataType, exifMetaData).then(() => {
1014      console.info('Set metadata success');
1015    }).catch((error: BusinessError) => {
1016      console.error('Failed to set metadata. error.code: ' +JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message));
1017    });
1018  } else {
1019    console.info('PictureObj is null');
1020  }
1021}
1022```
1023
1024### getMetadata<sup>13+</sup>
1025
1026getMetadata(metadataType: MetadataType): Promise\<Metadata>
1027
1028获取主图的元数据。
1029
1030**系统能力:** SystemCapability.Multimedia.Image.Core
1031
1032**参数:**
1033
1034| 参数名       | 类型         | 必填 | 说明         |
1035| ------------ | ------------ | ---- | ------------ |
1036| metadataType | [MetadataType](#metadatatype13) | 是   | 元数据类型。 |
1037
1038**返回值:**
1039
1040| 类型               | 说明                      |
1041| ------------------ | ------------------------- |
1042| Promise\<[Metadata](#metadata13)> | Promise对象。返回元数据。 |
1043
1044**错误码:**
1045
1046以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
1047
1048| 错误码ID | 错误信息                                                     |
1049| -------- | ------------------------------------------------------------ |
1050| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
1051| 7600202  | Unsupported metadata. Possible causes: Unsupported metadata type. |
1052
1053**示例:**
1054
1055```ts
1056import { image } from '@kit.ImageKit';
1057
1058async function GetPictureObjMetadataProperties() {
1059  if (pictureObj != null) {
1060    let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA;
1061    let pictureObjMetaData: image.Metadata = await pictureObj.getMetadata(metadataType);
1062    if (pictureObjMetaData != null) {
1063      console.info('get picture metadata success');
1064    } else {
1065      console.info('get picture metadata is failed');
1066    }
1067  } else {
1068    console.info(" pictureObj is null");
1069  }
1070}
1071```
1072
1073### marshalling<sup>13+</sup>
1074
1075marshalling(sequence: rpc.MessageSequence): void
1076
1077将picture序列化后写入MessageSequence。
1078
1079**系统能力:** SystemCapability.Multimedia.Image.Core
1080
1081**参数:**
1082
1083| 参数名   | 类型                                                                | 必填 | 说明                      |
1084| -------- | ------------------------------------------------------------------- | ---- | ------------------------- |
1085| sequence | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | 是   | 新创建的MessageSequence。 |
1086
1087**错误码:**
1088
1089以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
1090
1091| 错误码ID | 错误信息                                                     |
1092| -------- | ------------------------------------------------------------ |
1093| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
1094| 62980097 | IPC error.                                                   |
1095
1096**示例:**
1097
1098```ts
1099import { BusinessError } from '@kit.BasicServicesKit';
1100import { image } from '@kit.ImageKit';
1101import { rpc } from '@kit.IPCKit';
1102
1103class MySequence implements rpc.Parcelable {
1104  picture: image.Picture | null = null;
1105  constructor(conPicture: image.Picture) {
1106    this.picture = conPicture;
1107  }
1108  marshalling(messageSequence: rpc.MessageSequence) {
1109    if(this.picture != null) {
1110      this.picture.marshalling(messageSequence);
1111      console.info('Marshalling success !');
1112      return true;
1113    } else {
1114      console.info('Marshalling failed !');
1115      return false;
1116    }
1117  }
1118  unmarshalling(messageSequence : rpc.MessageSequence) {
1119    this.picture = image.createPictureFromParcel(messageSequence);
1120    this.picture.getMainPixelmap().getImageInfo().then((imageInfo : image.ImageInfo) => {
1121      console.info('Unmarshalling to get mainPixelmap information height:' + imageInfo.size.height + ' width:' + imageInfo.size.width);
1122    }).catch((error: BusinessError) => {
1123      console.error('Unmarshalling failed error.code: ${error.code} ,error.message: ${error.message}');
1124    });
1125    return true;
1126  }
1127}
1128
1129async function Marshalling_UnMarshalling() {
1130  if (pictureObj != null) {
1131    let parcelable: MySequence = new MySequence(pictureObj);
1132    let data: rpc.MessageSequence = rpc.MessageSequence.create();
1133    // marshalling
1134    data.writeParcelable(parcelable);
1135    let ret: MySequence = new MySequence(pictureObj);
1136    // unmarshalling
1137    data.readParcelable(ret);
1138  } else {
1139    console.info('PictureObj is null');
1140  }
1141}
1142```
1143
1144### release<sup>13+</sup>
1145
1146release(): void
1147
1148释放picture对象。
1149
1150**系统能力:** SystemCapability.Multimedia.Image.Core
1151
1152**示例:**
1153
1154```ts
1155import { image } from '@kit.ImageKit';
1156
1157async function Release() {
1158  let funcName = "Release";
1159  if (pictureObj != null) {
1160    pictureObj.release();
1161    if (pictureObj.getMainPixelmap() == null) {
1162      console.info(funcName, 'Success !');
1163    } else {
1164      console.info(funcName, 'Failed !');
1165    }
1166  } else {
1167    console.info('PictureObj is null');
1168  }
1169}
1170```
1171
1172## PixelMap<sup>7+</sup>
1173
1174图像像素类,用于读取或写入图像数据以及获取图像信息。在调用PixelMap的方法前,需要先通过[createPixelMap](#imagecreatepixelmap8)创建一个PixelMap实例。目前pixelmap序列化大小最大128MB,超过会送显失败。大小计算方式为(宽\*高\*每像素占用字节数)。
1175
1176从API version 11开始,PixelMap支持通过worker跨线程调用。当PixelMap通过[Worker](../apis-arkts/js-apis-worker.md)跨线程后,原线程的PixelMap的所有接口均不能调用,否则将报错501 服务器不具备完成请求的功能。
1177
1178在调用PixelMap的方法前,需要先通过[image.createPixelMap](#imagecreatepixelmap8)构建一个PixelMap对象。
1179
1180### 属性
1181
1182**系统能力:** SystemCapability.Multimedia.Image.Core
1183
1184| 名称              | 类型    | 可读 | 可写 | 说明                       |
1185| -----------------| ------- | ---- | ---- | -------------------------- |
1186| isEditable        | boolean | 是   | 否   | 设定是否图像像素可被编辑。 <br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 |
1187| isStrideAlignment<sup>11+</sup> | boolean | 是   | 否   | 设定图像内存是否为DMA内存。 |
1188
1189### readPixelsToBuffer<sup>7+</sup>
1190
1191readPixelsToBuffer(dst: ArrayBuffer): Promise\<void>
1192
1193按照PixelMap的像素格式,读取PixelMap的图像像素数据,并写入缓冲区中,使用Promise形式返回。
1194
1195**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1196
1197**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1198
1199**系统能力:** SystemCapability.Multimedia.Image.Core
1200
1201**参数:**
1202
1203| 参数名 | 类型        | 必填 | 说明                                                                                                  |
1204| ------ | ----------- | ---- | ----------------------------------------------------------------------------------------------------- |
1205| dst    | ArrayBuffer | 是   | 缓冲区,函数执行结束后获取的图像像素数据写入到该内存区域内。缓冲区大小由[getPixelBytesNumber](#getpixelbytesnumber7)接口获取。 |
1206
1207**返回值:**
1208
1209| 类型           | 说明                                            |
1210| -------------- | ----------------------------------------------- |
1211| Promise\<void> | Promise对象。无返回结果的Promise对象。  |
1212
1213**示例:**
1214
1215```ts
1216import { BusinessError } from '@kit.BasicServicesKit';
1217
1218async function ReadPixelsToBuffer() {
1219  const readBuffer: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
1220  if (pixelMap != undefined) {
1221    pixelMap.readPixelsToBuffer(readBuffer).then(() => {
1222      console.info('Succeeded in reading image pixel data.'); // 符合条件则进入
1223    }).catch((error: BusinessError) => {
1224      console.error(`Failed to read image pixel data. code is ${error.code}, message is ${error.message}`);// 不符合条件则进入
1225    })
1226  }
1227}
1228```
1229
1230### readPixelsToBuffer<sup>7+</sup>
1231
1232readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\<void>): void
1233
1234按照PixelMap的像素格式,读取PixelMap的图像像素数据,并写入缓冲区中,使用callback形式返回。
1235
1236**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1237
1238**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1239
1240**系统能力:** SystemCapability.Multimedia.Image.Core
1241
1242**参数:**
1243
1244| 参数名   | 类型                 | 必填 | 说明                                                                                                  |
1245| -------- | -------------------- | ---- | ----------------------------------------------------------------------------------------------------- |
1246| dst      | ArrayBuffer          | 是   | 缓冲区,函数执行结束后获取的图像像素数据写入到该内存区域内。缓冲区大小由[getPixelBytesNumber](#getpixelbytesnumber7)接口获取。 |
1247| callback | AsyncCallback\<void> | 是   | 回调函数。当读取像素数据到ArrayBuffer成功,err为undefined,否则为错误对象。  |
1248
1249**示例:**
1250
1251```ts
1252import { BusinessError } from '@kit.BasicServicesKit';
1253
1254async function ReadPixelsToBuffer() {
1255  const readBuffer: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
1256  if (pixelMap != undefined) {
1257    pixelMap.readPixelsToBuffer(readBuffer, (error: BusinessError, res: void) => {
1258      if(error) {
1259        console.error(`Failed to read image pixel data. code is ${error.code}, message is ${error.message}`);// 不符合条件则进入
1260        return;
1261      } else {
1262        console.info('Succeeded in reading image pixel data.');  //符合条件则进入
1263      }
1264    })
1265  }
1266}
1267```
1268
1269### readPixelsToBufferSync<sup>12+</sup>
1270
1271readPixelsToBufferSync(dst: ArrayBuffer): void
1272
1273按照PixelMap的像素格式,读取PixelMap的图像像素数据,并写入缓冲区中,同步返回结果。
1274
1275**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1276
1277**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1278
1279**系统能力:** SystemCapability.Multimedia.Image.Core
1280
1281**参数:**
1282
1283| 参数名   | 类型                 | 必填 | 说明                                                                                                  |
1284| -------- | -------------------- | ---- | ----------------------------------------------------------------------------------------------------- |
1285| dst      | ArrayBuffer          | 是   | 缓冲区,函数执行结束后获取的图像像素数据写入到该内存区域内。缓冲区大小由[getPixelBytesNumber](#getpixelbytesnumber7)接口获取。 |
1286
1287**错误码:**
1288
1289以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
1290
1291| 错误码ID | 错误信息 |
1292| ------- | --------------------------------------------|
1293|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
1294|  501    | Resource Unavailable |
1295
1296**示例:**
1297
1298```ts
1299import { BusinessError } from '@kit.BasicServicesKit';
1300
1301async function ReadPixelsToBufferSync() {
1302  const readBuffer: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
1303  if (pixelMap != undefined) {
1304    pixelMap.readPixelsToBufferSync(readBuffer);
1305  }
1306}
1307```
1308
1309### readPixels<sup>7+</sup>
1310
1311readPixels(area: PositionArea): Promise\<void>
1312
1313固定按照BGRA_8888格式,读取PixelMap指定区域内的图像像素数据,并写入[PositionArea](#positionarea7).pixels缓冲区中,该区域由[PositionArea](#positionarea7).region指定,使用Promise形式返回。
1314
1315可用公式计算PositionArea需要申请的内存大小。
1316
1317YUV的区域计算公式:读取区域(region.size{width * height})* 1.5 (1倍的Y分量+0.25倍U分量+0.25倍V分量)
1318
1319RGBA的区域计算公式:读取区域(region.size{width * height})* 4 (1倍的R分量+1倍G分量+1倍B分量+1倍A分量)
1320
1321**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1322
1323**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1324
1325**系统能力:** SystemCapability.Multimedia.Image.Core
1326
1327**参数:**
1328
1329| 参数名 | 类型                           | 必填 | 说明                     |
1330| ------ | ------------------------------ | ---- | ------------------------ |
1331| area   | [PositionArea](#positionarea7) | 是   | 区域大小,根据区域读取。 |
1332
1333**返回值:**
1334
1335| 类型           | 说明                                                |
1336| :------------- | :-------------------------------------------------- |
1337| Promise\<void> | Promise对象。无返回结果的Promise对象。  |
1338
1339**示例:**
1340
1341```ts
1342import { BusinessError } from '@kit.BasicServicesKit';
1343
1344async function ReadPixels() {
1345  const area: image.PositionArea = {
1346    pixels: new ArrayBuffer(8), // 8为需要创建的像素buffer大小,取值为:height * width *4
1347    offset: 0,
1348    stride: 8,
1349    region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
1350  };
1351  if (pixelMap != undefined) {
1352    pixelMap.readPixels(area).then(() => {
1353      console.info('Succeeded in reading the image data in the area.'); //符合条件则进入
1354    }).catch((error: BusinessError) => {
1355      console.error(`Failed to read the image data in the area. code is ${error.code}, message is ${error.message}`);// 不符合条件则进入
1356    })
1357  }
1358}
1359
1360async function ReadPixels() {
1361  const area: image.PositionArea = {
1362    pixels: new ArrayBuffer(6),  // 6为需要创建的像素buffer大小,取值为:height * width *1.5
1363    offset: 0,
1364    stride: 8,
1365    region: { size: { height: 2, width: 2 }, x: 0, y: 0 }
1366  };
1367  if (pixelMap != undefined) {
1368    pixelMap.readPixels(area).then(() => {
1369      console.info('Succeeded in reading the image data in the area.'); //符合条件则进入
1370    }).catch((error: BusinessError) => {
1371      console.error(`Failed to read the image data in the area. code is ${error.code}, message is ${error.message}`);// 不符合条件则进入
1372    })
1373  }
1374}
1375```
1376
1377### readPixels<sup>7+</sup>
1378
1379readPixels(area: PositionArea, callback: AsyncCallback\<void>): void
1380
1381固定按照BGRA_8888格式,读取PixelMap指定区域内的图像像素数据,并写入[PositionArea](#positionarea7).pixels缓冲区中,该区域由[PositionArea](#positionarea7).region指定,使用callback形式返回。
1382
1383可用公式计算PositionArea需要申请的内存大小。
1384
1385YUV的区域计算公式:读取区域(region.size{width * height})* 1.5 (1倍的Y分量+0.25倍U分量+0.25倍V分量)
1386
1387RGBA的区域计算公式:读取区域(region.size{width * height})* 4 (1倍的R分量+1倍G分量+1倍B分量+1倍A分量)
1388
1389**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1390
1391**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1392
1393**系统能力:** SystemCapability.Multimedia.Image.Core
1394
1395**参数:**
1396
1397| 参数名   | 类型                           | 必填 | 说明                           |
1398| -------- | ------------------------------ | ---- | ------------------------------ |
1399| area     | [PositionArea](#positionarea7) | 是   | 区域大小,根据区域读取。       |
1400| callback | AsyncCallback\<void>           | 是   |  回调函数。当读取区域内的图片数据成功,err为undefined,否则为错误对象。 |
1401
1402**示例:**
1403
1404```ts
1405import { BusinessError } from '@kit.BasicServicesKit';
1406
1407async function ReadPixels() {
1408  const area: image.PositionArea = {
1409    pixels: new ArrayBuffer(8), // 8为需要创建的像素buffer大小,取值为:height * width *4
1410    offset: 0,
1411    stride: 8,
1412    region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
1413  };
1414  if (pixelMap != undefined) {
1415    pixelMap.readPixels(area, (error: BusinessError) => {
1416      if (error) {
1417        console.error(`Failed to read pixelmap from the specified area. code is ${error.code}, message is ${error.message}`);
1418        return;
1419      } else {
1420        console.info('Succeeded in reading pixelmap from the specified area.');
1421      }
1422    })
1423  }
1424}
1425
1426async function ReadPixels() {
1427  const area: image.PositionArea = {
1428    pixels: new ArrayBuffer(6), // 6为需要创建的像素buffer大小,取值为:height * width *1.5
1429    offset: 0,
1430    stride: 8,
1431    region: { size: { height: 2, width: 2 }, x: 0, y: 0 }
1432  };
1433  if (pixelMap != undefined) {
1434    pixelMap.readPixels(area, (error: BusinessError) => {
1435      if (error) {
1436        console.error(`Failed to read pixelmap from the specified area. code is ${error.code}, message is ${error.message}`);
1437        return;
1438      } else {
1439        console.info('Succeeded in reading pixelmap from the specified area.');
1440      }
1441    })
1442  }
1443}
1444```
1445
1446### readPixelsSync<sup>12+</sup>
1447
1448readPixelsSync(area: PositionArea): void
1449
1450固定按照BGRA_8888格式,读取PixelMap指定区域内的图像像素数据,并写入[PositionArea](#positionarea7).pixels缓冲区中,该区域由[PositionArea](#positionarea7).region指定,同步返回结果。
1451
1452**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1453
1454**系统能力:** SystemCapability.Multimedia.Image.Core
1455
1456**参数:**
1457
1458| 参数名 | 类型                           | 必填 | 说明                     |
1459| ------ | ------------------------------ | ---- | ------------------------ |
1460| area   | [PositionArea](#positionarea7) | 是   | 区域大小,根据区域读取。 |
1461
1462**错误码:**
1463
1464以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
1465
1466| 错误码ID | 错误信息 |
1467| ------- | --------------------------------------------|
1468|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
1469|  501    | Resource Unavailable |
1470
1471**示例:**
1472
1473```ts
1474import { BusinessError } from '@kit.BasicServicesKit';
1475
1476async function ReadPixelsSync() {
1477  const area : image.PositionArea = {
1478    pixels: new ArrayBuffer(8),
1479    offset: 0,
1480    stride: 8,
1481    region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
1482  };
1483  if (pixelMap != undefined) {
1484    pixelMap.readPixelsSync(area);
1485  }
1486}
1487```
1488
1489### writePixels<sup>7+</sup>
1490
1491writePixels(area: PositionArea): Promise\<void>
1492
1493固定按照BGRA_8888格式,读取[PositionArea](#positionarea7).pixels缓冲区中的图像像素数据,并写入PixelMap指定区域内,该区域由[PositionArea](#positionarea7).region指定,使用Promise形式返回。
1494
1495可用公式计算PositionArea需要申请的内存大小。
1496
1497YUV的区域计算公式:读取区域(region.size{width * height})* 1.5 (1倍的Y分量+0.25倍U分量+0.25倍V分量)
1498
1499RGBA的区域计算公式:读取区域(region.size{width * height})* 4 (1倍的R分量+1倍G分量+1倍B分量+1倍A分量)
1500
1501**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1502
1503**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1504
1505**系统能力:** SystemCapability.Multimedia.Image.Core
1506
1507**参数:**
1508
1509| 参数名 | 类型                           | 必填 | 说明                 |
1510| ------ | ------------------------------ | ---- | -------------------- |
1511| area   | [PositionArea](#positionarea7) | 是   | 区域,根据区域写入。 |
1512
1513**返回值:**
1514
1515| 类型           | 说明                                                |
1516| :------------- | :-------------------------------------------------- |
1517| Promise\<void> | Promise对象。无返回结果的Promise对象。  |
1518
1519**示例:**
1520
1521```ts
1522import { BusinessError } from '@kit.BasicServicesKit';
1523
1524async function WritePixels() {
1525  const area: image.PositionArea = {
1526    pixels: new ArrayBuffer(8), // 8为需要创建的像素buffer大小,取值为:height * width *4
1527    offset: 0,
1528    stride: 8,
1529    region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
1530  };
1531  let bufferArr: Uint8Array = new Uint8Array(area.pixels);
1532  for (let i = 0; i < bufferArr.length; i++) {
1533    bufferArr[i] = i + 1;
1534  }
1535  if (pixelMap != undefined) {
1536    pixelMap.writePixels(area).then(() => {
1537      console.info('Succeeded in writing pixelmap into the specified area.');
1538    }).catch((error: BusinessError) => {
1539      console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`);
1540    })
1541  }
1542}
1543
1544async function WritePixels() {
1545  const area: image.PositionArea = {
1546    pixels: new ArrayBuffer(6), // 6为需要创建的像素buffer大小,取值为:height * width *1.5
1547    offset: 0,
1548    stride: 8,
1549    region: { size: { height: 2, width: 2 }, x: 0, y: 0 }
1550  };
1551  let bufferArr: Uint8Array = new Uint8Array(area.pixels);
1552  for (let i = 0; i < bufferArr.length; i++) {
1553    bufferArr[i] = i + 1;
1554  }
1555  if (pixelMap != undefined) {
1556    pixelMap.writePixels(area).then(() => {
1557      console.info('Succeeded in writing pixelmap into the specified area.');
1558    }).catch((error: BusinessError) => {
1559      console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`);
1560    })
1561  }
1562}
1563```
1564
1565### writePixels<sup>7+</sup>
1566
1567writePixels(area: PositionArea, callback: AsyncCallback\<void>): void
1568
1569固定按照BGRA_8888格式,读取[PositionArea](#positionarea7).pixels缓冲区中的图像像素数据,并写入PixelMap指定区域内,该区域由[PositionArea](#positionarea7).region指定,使用callback形式返回。
1570
1571可用公式计算PositionArea需要申请的内存大小。
1572
1573YUV的区域计算公式:读取区域(region.size{width * height})* 1.5 (1倍的Y分量+0.25倍U分量+0.25倍V分量)
1574
1575RGBA的区域计算公式:读取区域(region.size{width * height})* 4 (1倍的R分量+1倍G分量+1倍B分量+1倍A分量)
1576
1577**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1578
1579**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1580
1581**系统能力:** SystemCapability.Multimedia.Image.Core
1582
1583**参数:**
1584
1585| 参数名    | 类型                           | 必填 | 说明                           |
1586| --------- | ------------------------------ | ---- | ------------------------------ |
1587| area      | [PositionArea](#positionarea7) | 是   | 区域,根据区域写入。           |
1588| callback  | AsyncCallback\<void>           | 是   | 回调函数,当写入成功,err为undefined,否则为错误对象。 |
1589
1590**示例:**
1591
1592```ts
1593import { BusinessError } from '@kit.BasicServicesKit';
1594
1595async function WritePixels() {
1596  const area: image.PositionArea = { pixels: new ArrayBuffer(8), // 8为需要创建的像素buffer大小,取值为:height * width *4
1597    offset: 0,
1598    stride: 8,
1599    region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
1600  };
1601  let bufferArr: Uint8Array = new Uint8Array(area.pixels);
1602  for (let i = 0; i < bufferArr.length; i++) {
1603    bufferArr[i] = i + 1;
1604  }
1605  if (pixelMap != undefined) {
1606    pixelMap.writePixels(area, (error : BusinessError) => {
1607      if (error) {
1608        console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`);
1609        return;
1610      } else {
1611        console.info('Succeeded in writing pixelmap into the specified area.');
1612      }
1613    })
1614  }
1615}
1616
1617async function WritePixels() {
1618  const area: image.PositionArea = { pixels: new ArrayBuffer(6), // 6为需要创建的像素buffer大小,取值为:height * width *1.5
1619    offset: 0,
1620    stride: 8,
1621    region: { size: { height: 2, width: 2 }, x: 0, y: 0 }
1622  };
1623  let bufferArr: Uint8Array = new Uint8Array(area.pixels);
1624  for (let i = 0; i < bufferArr.length; i++) {
1625    bufferArr[i] = i + 1;
1626  }
1627  if (pixelMap != undefined) {
1628    pixelMap.writePixels(area, (error : BusinessError) => {
1629      if (error) {
1630        console.error(`Failed to write pixelmap into the specified area. code is ${error.code}, message is ${error.message}`);
1631        return;
1632      } else {
1633        console.info('Succeeded in writing pixelmap into the specified area.');
1634      }
1635    })
1636  }
1637}
1638```
1639
1640### writePixelsSync<sup>12+</sup>
1641
1642writePixelsSync(area: PositionArea): void
1643
1644固定按照BGRA_8888格式,读取[PositionArea](#positionarea7).pixels缓冲区中的图像像素数据,并写入PixelMap指定区域内,该区域由[PositionArea](#positionarea7).region指定,同步回结果。
1645
1646**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1647
1648**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1649
1650**系统能力:** SystemCapability.Multimedia.Image.Core
1651
1652**参数:**
1653
1654| 参数名 | 类型                           | 必填 | 说明                 |
1655| ------ | ------------------------------ | ---- | -------------------- |
1656| area   | [PositionArea](#positionarea7) | 是   | 区域,根据区域写入。 |
1657
1658**错误码:**
1659
1660以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
1661
1662| 错误码ID | 错误信息 |
1663| ------- | --------------------------------------------|
1664|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
1665|  501    | Resource Unavailable |
1666
1667**示例:**
1668
1669```ts
1670import { BusinessError } from '@kit.BasicServicesKit';
1671
1672async function WritePixelsSync() {
1673  const area: image.PositionArea = {
1674    pixels: new ArrayBuffer(8),
1675    offset: 0,
1676    stride: 8,
1677    region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
1678  };
1679  let bufferArr: Uint8Array = new Uint8Array(area.pixels);
1680  for (let i = 0; i < bufferArr.length; i++) {
1681    bufferArr[i] = i + 1;
1682  }
1683  if (pixelMap != undefined) {
1684    pixelMap.writePixelsSync(area);
1685  }
1686}
1687```
1688
1689### writeBufferToPixels<sup>7+</sup>
1690
1691writeBufferToPixels(src: ArrayBuffer): Promise\<void>
1692
1693按照PixelMap的像素格式,读取缓冲区中的图像像素数据,并写入PixelMap,使用Promise形式返回。
1694
1695**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1696
1697**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1698
1699**系统能力:** SystemCapability.Multimedia.Image.Core
1700
1701**参数:**
1702
1703| 参数名 | 类型        | 必填 | 说明           |
1704| ------ | ----------- | ---- | -------------- |
1705| src    | ArrayBuffer | 是   | 缓冲区,函数执行时会将该缓冲区中的图像像素数据写入到PixelMap。缓冲区大小由[getPixelBytesNumber](#getpixelbytesnumber7)接口获取。 |
1706
1707**返回值:**
1708
1709| 类型           | 说明                                            |
1710| -------------- | ----------------------------------------------- |
1711| Promise\<void> | Promise对象。无返回结果的Promise对象。  |
1712
1713**示例:**
1714
1715```ts
1716import { BusinessError } from '@kit.BasicServicesKit';
1717
1718async function WriteBufferToPixels() {
1719  const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
1720  let bufferArr: Uint8Array = new Uint8Array(color);
1721  for (let i = 0; i < bufferArr.length; i++) {
1722    bufferArr[i] = i + 1;
1723  }
1724  if (pixelMap != undefined) {
1725    pixelMap.writeBufferToPixels(color).then(() => {
1726      console.info("Succeeded in writing data from a buffer to a PixelMap.");
1727    }).catch((error: BusinessError) => {
1728      console.error(`Failed to write data from a buffer to a PixelMap. code is ${error.code}, message is ${error.message}`);
1729    })
1730  }
1731}
1732```
1733
1734### writeBufferToPixels<sup>7+</sup>
1735
1736writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\<void>): void
1737
1738按照PixelMap的像素格式,读取缓冲区中的图像像素数据,并写入PixelMap,使用callback形式返回。
1739
1740**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1741
1742**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1743
1744**系统能力:** SystemCapability.Multimedia.Image.Core
1745
1746**参数:**
1747
1748| 参数名   | 类型                 | 必填 | 说明                           |
1749| -------- | -------------------- | ---- | ------------------------------ |
1750| src      | ArrayBuffer          | 是   | 缓冲区,函数执行时会将该缓冲区中的图像像素数据写入到PixelMap。缓冲区大小由[getPixelBytesNumber](#getpixelbytesnumber7)接口获取。 |
1751| callback | AsyncCallback\<void> | 是   | 回调函数。当缓冲区中的图像像素数据写入PixelMap成功,err为undefined,否则为错误对象。 |
1752
1753**示例:**
1754
1755```ts
1756import { BusinessError } from '@kit.BasicServicesKit';
1757
1758async function WriteBufferToPixels() {
1759  const color: ArrayBuffer = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
1760  let bufferArr: Uint8Array = new Uint8Array(color);
1761  for (let i = 0; i < bufferArr.length; i++) {
1762    bufferArr[i] = i + 1;
1763  }
1764  if (pixelMap != undefined) {
1765    pixelMap.writeBufferToPixels(color, (error: BusinessError) => {
1766      if (error) {
1767        console.error(`Failed to write data from a buffer to a PixelMap. code is ${error.code}, message is ${error.message}`);
1768        return;
1769      } else {
1770        console.info("Succeeded in writing data from a buffer to a PixelMap.");
1771      }
1772    })
1773  }
1774}
1775```
1776
1777### writeBufferToPixelsSync<sup>12+</sup>
1778
1779writeBufferToPixelsSync(src: ArrayBuffer): void
1780
1781按照PixelMap的像素格式,读取缓冲区中的图像像素数据,并写入PixelMap,同步返回结果。
1782
1783**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1784
1785**系统能力:** SystemCapability.Multimedia.Image.Core
1786
1787**参数:**
1788
1789| 参数名 | 类型        | 必填 | 说明           |
1790| ------ | ----------- | ---- | -------------- |
1791| src    | ArrayBuffer | 是   | 缓冲区,函数执行时会将该缓冲区中的图像像素数据写入到PixelMap。缓冲区大小由[getPixelBytesNumber](#getpixelbytesnumber7)接口获取。 |
1792
1793**错误码:**
1794
1795以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
1796
1797| 错误码ID | 错误信息 |
1798| ------- | --------------------------------------------|
1799|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
1800|  501    | Resource Unavailable |
1801
1802**示例:**
1803
1804```ts
1805import { BusinessError } from '@kit.BasicServicesKit';
1806
1807async function WriteBufferToPixelsSync() {
1808  const color : ArrayBuffer = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
1809  let bufferArr : Uint8Array = new Uint8Array(color);
1810  for (let i = 0; i < bufferArr.length; i++) {
1811    bufferArr[i] = i + 1;
1812  }
1813  if (pixelMap != undefined) {
1814    pixelMap.writeBufferToPixelsSync(color);
1815  }
1816}
1817```
1818
1819
1820### getImageInfo<sup>7+</sup>
1821
1822getImageInfo(): Promise\<ImageInfo>
1823
1824获取图像像素信息,使用Promise形式返回获取的图像像素信息。
1825
1826**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1827
1828**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1829
1830**系统能力:** SystemCapability.Multimedia.Image.Core
1831
1832**返回值:**
1833
1834| 类型                              | 说明                                                        |
1835| --------------------------------- | ----------------------------------------------------------- |
1836| Promise\<[ImageInfo](#imageinfo)> | Promise对象,返回图像像素信息。 |
1837
1838**示例:**
1839
1840```ts
1841import { BusinessError } from '@kit.BasicServicesKit';
1842
1843async function GetImageInfo() {
1844  if (pixelMap != undefined) {
1845    pixelMap.getImageInfo().then((imageInfo: image.ImageInfo) => {
1846      if (imageInfo != undefined) {
1847        console.info("Succeeded in obtaining the image pixel map information."+ imageInfo.size.height);
1848      }
1849    }).catch((error: BusinessError) => {
1850      console.error(`Failed to obtain the image pixel map information. code is ${error.code}, message is ${error.message}`);
1851    })
1852  }
1853}
1854```
1855
1856### getImageInfo<sup>7+</sup>
1857
1858getImageInfo(callback: AsyncCallback\<ImageInfo>): void
1859
1860获取图像像素信息,使用callback形式返回获取的图像像素信息。
1861
1862**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1863
1864**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1865
1866**系统能力:** SystemCapability.Multimedia.Image.Core
1867
1868**参数:**
1869
1870| 参数名   | 类型                                    | 必填 | 说明                                                         |
1871| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
1872| callback | AsyncCallback\<[ImageInfo](#imageinfo)> | 是   | 回调函数。当获取图像像素信息成功,err为undefined,data为获取到的图像像素信息;否则为错误对象。 |
1873
1874**示例:**
1875
1876```ts
1877import { BusinessError } from '@kit.BasicServicesKit';
1878
1879async function GetImageInfo() {
1880  if (pixelMap != undefined) {
1881    pixelMap.getImageInfo((error: BusinessError, imageInfo: image.ImageInfo) => {
1882      if (error) {
1883        console.error(`Failed to obtain the image pixel map information. code is ${error.code}, message is ${error.message}`);
1884        return;
1885      } else {
1886        console.info("Succeeded in obtaining the image pixel map information."+ imageInfo.size.height);
1887      }
1888    })
1889  }
1890}
1891```
1892
1893### getImageInfoSync<sup>12+</sup>
1894
1895getImageInfoSync(): ImageInfo
1896
1897以同步方法获取图像像素信息。
1898
1899**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1900
1901**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1902
1903**系统能力:** SystemCapability.Multimedia.Image.ImageSource
1904
1905**返回值:**
1906
1907| 类型                              | 说明                                                        |
1908| --------------------------------- | ----------------------------------------------------------- |
1909| [ImageInfo](#imageinfo)           | 图像像素信息                                                |
1910
1911**错误码:**
1912
1913以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
1914
1915| 错误码ID | 错误信息 |
1916| ------- | --------------------------------------------|
1917|  501    | Resource Unavailable |
1918
1919**示例:**
1920
1921```ts
1922import { BusinessError } from '@kit.BasicServicesKit';
1923
1924async function GetImageInfoSync() {
1925  if (pixelMap != undefined) {
1926    let imageInfo : image.ImageInfo = pixelMap.getImageInfoSync();
1927    return imageInfo;
1928  }
1929  return undefined;
1930}
1931```
1932
1933### getBytesNumberPerRow<sup>7+</sup>
1934
1935getBytesNumberPerRow(): number
1936
1937获取图像像素每行字节数。
1938
1939**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1940
1941**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1942
1943**系统能力:** SystemCapability.Multimedia.Image.Core
1944
1945**返回值:**
1946
1947| 类型   | 说明                 |
1948| ------ | -------------------- |
1949| number | 图像像素的行字节数。 |
1950
1951**示例:**
1952
1953```ts
1954let rowCount: number = pixelMap.getBytesNumberPerRow();
1955```
1956
1957### getPixelBytesNumber<sup>7+</sup>
1958
1959getPixelBytesNumber(): number
1960
1961获取图像像素的总字节数。
1962
1963**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1964
1965**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1966
1967**系统能力:** SystemCapability.Multimedia.Image.Core
1968
1969**返回值:**
1970
1971| 类型   | 说明                 |
1972| ------ | -------------------- |
1973| number | 图像像素的总字节数。 |
1974
1975**示例:**
1976
1977```ts
1978let pixelBytesNumber: number = pixelMap.getPixelBytesNumber();
1979```
1980
1981### getDensity<sup>9+</sup>
1982
1983getDensity():number
1984
1985获取当前图像像素的密度。
1986
1987**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
1988
1989**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1990
1991**系统能力:** SystemCapability.Multimedia.Image.Core
1992
1993**返回值:**
1994
1995| 类型   | 说明            |
1996| ------ | --------------- |
1997| number | 图像像素的密度。|
1998
1999**示例:**
2000
2001```ts
2002let getDensity: number = pixelMap.getDensity();
2003```
2004
2005### opacity<sup>9+</sup>
2006
2007opacity(rate: number, callback: AsyncCallback\<void>): void
2008
2009通过设置透明比率来让PixelMap达到对应的透明效果,yuv图片不支持设置透明度,使用callback形式返回。
2010
2011**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2012
2013**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2014
2015**系统能力:** SystemCapability.Multimedia.Image.Core
2016
2017**参数:**
2018
2019| 参数名   | 类型                 | 必填 | 说明                           |
2020| -------- | -------------------- | ---- | ------------------------------ |
2021| rate     | number               | 是   | 透明比率的值。   |
2022| callback | AsyncCallback\<void> | 是   | 回调函数。当设置透明比率成功,err为undefined,否则为错误对象。 |
2023
2024**示例:**
2025
2026```ts
2027import { BusinessError } from '@kit.BasicServicesKit';
2028
2029async function Opacity() {
2030  let rate: number = 0.5;
2031  if (pixelMap != undefined) {
2032    pixelMap.opacity(rate, (err: BusinessError) => {
2033      if (err) {
2034        console.error(`Failed to set opacity. code is ${err.code}, message is ${err.message}`);
2035        return;
2036      } else {
2037        console.info("Succeeded in setting opacity.");
2038      }
2039    })
2040  }
2041}
2042```
2043
2044### opacity<sup>9+</sup>
2045
2046opacity(rate: number): Promise\<void>
2047
2048通过设置透明比率来让PixelMap达到对应的透明效果,yuv图片不支持设置透明度,使用Promise形式返回。
2049
2050**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2051
2052**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2053
2054**系统能力:** SystemCapability.Multimedia.Image.Core
2055
2056**参数:**
2057
2058| 参数名 | 类型   | 必填 | 说明                        |
2059| ------ | ------ | ---- | --------------------------- |
2060| rate   | number | 是   | 透明比率的值。|
2061
2062**返回值:**
2063
2064| 类型           | 说明                                            |
2065| -------------- | ----------------------------------------------- |
2066| Promise\<void> | Promise对象。无返回结果的Promise对象。  |
2067
2068**示例:**
2069
2070```ts
2071import { BusinessError } from '@kit.BasicServicesKit';
2072
2073async function Opacity() {
2074  let rate: number = 0.5;
2075  if (pixelMap != undefined) {
2076    pixelMap.opacity(rate).then(() => {
2077      console.info('Succeeded in setting opacity.');
2078    }).catch((err: BusinessError) => {
2079      console.error(`Failed to set opacity. code is ${err.code}, message is ${err.message}`);
2080    })
2081  }
2082}
2083```
2084
2085### opacitySync<sup>12+</sup>
2086
2087opacitySync(rate: number): void
2088
2089设置PixelMap的透明比率,yuv图片不支持设置透明度,初始化PixelMap并同步返回结果。
2090
2091**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2092
2093**系统能力:** SystemCapability.Multimedia.Image.Core
2094
2095**参数:**
2096
2097| 参数名   | 类型                 | 必填 | 说明                           |
2098| -------- | -------------------- | ---- | ------------------------------ |
2099| rate     | number               | 是   | 透明比率的值。   |
2100
2101**错误码:**
2102
2103以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
2104
2105| 错误码ID | 错误信息 |
2106| ------- | --------------------------------------------|
2107|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
2108|  501    | Resource Unavailable |
2109
2110**示例:**
2111
2112```ts
2113import { BusinessError } from '@kit.BasicServicesKit';
2114
2115async function OpacitySync() {
2116  let rate : number = 0.5;
2117  if (pixelMap != undefined) {
2118    pixelMap.opacitySync(rate);
2119  }
2120}
2121```
2122
2123### createAlphaPixelmap<sup>9+</sup>
2124
2125createAlphaPixelmap(): Promise\<PixelMap>
2126
2127根据Alpha通道的信息,来生成一个仅包含Alpha通道信息的pixelmap,可用于阴影效果,yuv格式不支持此接口,使用Promise形式返回。
2128
2129**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2130
2131**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2132
2133**系统能力:** SystemCapability.Multimedia.Image.Core
2134
2135**返回值:**
2136
2137| 类型                             | 说明                        |
2138| -------------------------------- | --------------------------- |
2139| Promise\<[PixelMap](#pixelmap7)> | Promise对象,返回PixelMap。 |
2140
2141**示例:**
2142
2143```ts
2144import { BusinessError } from '@kit.BasicServicesKit';
2145
2146async function CreateAlphaPixelmap() {
2147  if (pixelMap != undefined) {
2148    pixelMap.createAlphaPixelmap().then((alphaPixelMap: image.PixelMap) => {
2149      console.info('Succeeded in creating alpha pixelmap.');
2150    }).catch((error: BusinessError) => {
2151      console.error(`Failed to create alpha pixelmap. code is ${error.code}, message is ${error.message}`);
2152    })
2153  }
2154}
2155```
2156
2157### createAlphaPixelmap<sup>9+</sup>
2158
2159createAlphaPixelmap(callback: AsyncCallback\<PixelMap>): void
2160
2161根据Alpha通道的信息,来生成一个仅包含Alpha通道信息的pixelmap,可用于阴影效果,yuv格式不支持此接口,使用callback形式返回。
2162
2163**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2164
2165**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2166
2167**系统能力:** SystemCapability.Multimedia.Image.Core
2168
2169**参数:**
2170
2171| 参数名   | 类型                     | 必填 | 说明                     |
2172| -------- | ------------------------ | ---- | ------------------------ |
2173| callback | AsyncCallback\<[PixelMap](#pixelmap7)> | 是   |  回调函数,当创建PixelMap成功,err为undefined,data为获取到的PixelMap对象;否则为错误对象。 |
2174
2175**示例:**
2176
2177```ts
2178import { BusinessError } from '@kit.BasicServicesKit';
2179
2180async function CreateAlphaPixelmap() {
2181  if (pixelMap != undefined) {
2182    pixelMap.createAlphaPixelmap((err: BusinessError, alphaPixelMap: image.PixelMap) => {
2183      if (alphaPixelMap == undefined) {
2184        console.error(`Failed to obtain new pixel map. code is ${err.code}, message is ${err.message}`);
2185        return;
2186      } else {
2187        console.info('Succeeded in obtaining new pixel map.');
2188      }
2189    })
2190  }
2191}
2192```
2193
2194### createAlphaPixelmapSync<sup>12+</sup>
2195
2196createAlphaPixelmapSync(): PixelMap
2197
2198根据Alpha通道的信息,生成一个仅包含Alpha通道信息的PixelMap,可用于阴影效果,yuv格式不支持此接口,同步返回PixelMap类型的结果。
2199
2200**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2201
2202**系统能力:** SystemCapability.Multimedia.Image.Core
2203
2204**返回值:**
2205
2206| 类型                             | 说明                  |
2207| -------------------------------- | --------------------- |
2208| [PixelMap](#pixelmap7) | 成功同步返回PixelMap对象,失败抛出异常。 |
2209
2210**错误码:**
2211
2212以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
2213
2214| 错误码ID | 错误信息 |
2215| ------- | --------------------------------------------|
2216|  401    | Parameter error. Possible causes: 1.Parameter verification failed |
2217|  501    | Resource Unavailable |
2218
2219**示例:**
2220
2221```ts
2222import { BusinessError } from '@kit.BasicServicesKit';
2223
2224async function CreateAlphaPixelmapSync() {
2225  if (pixelMap != undefined) {
2226    let pixelmap : image.PixelMap = pixelMap.createAlphaPixelmapSync();
2227    return pixelmap;
2228  }
2229  return undefined;
2230}
2231```
2232
2233### scale<sup>9+</sup>
2234
2235scale(x: number, y: number, callback: AsyncCallback\<void>): void
2236
2237根据输入的宽高对图片进行缩放,使用callback形式返回。
2238
2239**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2240
2241**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2242
2243**系统能力:** SystemCapability.Multimedia.Image.Core
2244
2245**参数:**
2246
2247| 参数名   | 类型                 | 必填 | 说明                            |
2248| -------- | -------------------- | ---- | ------------------------------- |
2249| x        | number               | 是   | 宽度的缩放倍数。|
2250| y        | number               | 是   | 高度的缩放倍数。|
2251| callback | AsyncCallback\<void> | 是   | 回调函数。当对图片进行缩放成功,err为undefined,否则为错误对象。 |
2252
2253**示例:**
2254
2255```ts
2256import { BusinessError } from '@kit.BasicServicesKit';
2257
2258async function Scale() {
2259  let scaleX: number = 2.0;
2260  let scaleY: number = 1.0;
2261  if (pixelMap != undefined) {
2262    pixelMap.scale(scaleX, scaleY, (err: BusinessError) => {
2263      if (err) {
2264        console.error(`Failed to scale pixelmap. code is ${err.code}, message is ${err.message}`);
2265        return;
2266      } else {
2267        console.info("Succeeded in scaling pixelmap.");
2268      }
2269    })
2270  }
2271}
2272```
2273
2274### scale<sup>9+</sup>
2275
2276scale(x: number, y: number): Promise\<void>
2277
2278根据输入的宽高对图片进行缩放,使用Promise形式返回。
2279
2280**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2281
2282**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2283
2284**系统能力:** SystemCapability.Multimedia.Image.Core
2285
2286**参数:**
2287
2288| 参数名 | 类型   | 必填 | 说明                            |
2289| ------ | ------ | ---- | ------------------------------- |
2290| x      | number | 是   | 宽度的缩放倍数。|
2291| y      | number | 是   | 高度的缩放倍数。|
2292
2293**返回值:**
2294
2295| 类型           | 说明                        |
2296| -------------- | --------------------------- |
2297| Promise\<void> |  Promise对象。无返回结果的Promise对象。|
2298
2299**示例:**
2300
2301```ts
2302import { BusinessError } from '@kit.BasicServicesKit';
2303
2304async function Scale() {
2305  let scaleX: number = 2.0;
2306  let scaleY: number = 1.0;
2307  if (pixelMap != undefined) {
2308    pixelMap.scale(scaleX, scaleY).then(() => {
2309      console.info('Succeeded in scaling pixelmap.');
2310    }).catch((err: BusinessError) => {
2311      console.error(`Failed to scale pixelmap. code is ${err.code}, message is ${err.message}`);
2312
2313    })
2314  }
2315}
2316```
2317
2318### scaleSync<sup>12+</sup>
2319
2320scaleSync(x: number, y: number): void
2321
2322以同步方法根据输入的宽高对图片进行缩放。
2323
2324**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2325
2326**系统能力:** SystemCapability.Multimedia.Image.Core
2327
2328**参数:**
2329
2330| 参数名 | 类型   | 必填 | 说明                            |
2331| ------ | ------ | ---- | ------------------------------- |
2332| x      | number | 是   | 宽度的缩放倍数。|
2333| y      | number | 是   | 高度的缩放倍数。|
2334
2335**错误码:**
2336
2337以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
2338
2339| 错误码ID | 错误信息 |
2340| ------- | --------------------------------------------|
2341|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
2342|  501    | Resource Unavailable |
2343
2344**示例:**
2345
2346```ts
2347import { BusinessError } from '@kit.BasicServicesKit';
2348
2349async function ScaleSync() {
2350  let scaleX: number = 2.0;
2351  let scaleY: number = 1.0;
2352  if (pixelMap != undefined) {
2353    pixelMap.scaleSync(scaleX, scaleY);
2354  }
2355}
2356```
2357
2358### scale<sup>12+</sup>
2359
2360scale(x: number, y: number, level: AntiAliasingLevel): Promise\<void>
2361
2362根据输入的宽高对图片进行缩放,使用Promise形式返回。
2363
2364**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2365
2366**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2367
2368**系统能力:** SystemCapability.Multimedia.Image.Core
2369
2370**参数:**
2371
2372| 参数名 | 类型   | 必填 | 说明                            |
2373| ------ | ------ | ---- | ------------------------------- |
2374| x      | number | 是   | 宽度的缩放倍数。|
2375| y      | number | 是   | 高度的缩放倍数。|
2376| level  | [AntiAliasingLevel](#antialiasinglevel12) | 是   | 采用的缩放算法。|
2377
2378**返回值:**
2379
2380| 类型           | 说明                        |
2381| -------------- | --------------------------- |
2382| Promise\<void> |  Promise对象。无返回结果的Promise对象。|
2383
2384**错误码:**
2385
2386以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
2387
2388| 错误码ID | 错误信息 |
2389| ------- | --------------------------------------------|
2390|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
2391|  501    | Resource Unavailable |
2392
2393**示例:**
2394
2395```ts
2396import { BusinessError } from '@kit.BasicServicesKit';
2397
2398async function Scale() {
2399  let scaleX: number = 2.0;
2400  let scaleY: number = 1.0;
2401  if (pixelMap != undefined) {
2402    pixelMap.scale(scaleX, scaleY, image.AntiAliasingLevel.LOW).then(() => {
2403      console.info('Succeeded in scaling pixelmap.');
2404    }).catch((err: BusinessError) => {
2405      console.error(`Failed to scale pixelmap. code is ${err.code}, message is ${err.message}`);
2406
2407    })
2408  }
2409}
2410```
2411
2412### scaleSync<sup>12+</sup>
2413
2414scaleSync(x: number, y: number, level: AntiAliasingLevel): void
2415
2416以同步方法根据输入的宽高对图片进行缩放。
2417
2418**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2419
2420**系统能力:** SystemCapability.Multimedia.Image.Core
2421
2422**参数:**
2423
2424| 参数名 | 类型   | 必填 | 说明                            |
2425| ------ | ------ | ---- | ------------------------------- |
2426| x      | number | 是   | 宽度的缩放倍数。|
2427| y      | number | 是   | 高度的缩放倍数。|
2428| level  | [AntiAliasingLevel](#antialiasinglevel12) | 是   | 采用的缩放算法。|
2429
2430**错误码:**
2431
2432以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
2433
2434| 错误码ID | 错误信息 |
2435| ------- | --------------------------------------------|
2436|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
2437|  501    | Resource Unavailable |
2438
2439**示例:**
2440
2441```ts
2442import { BusinessError } from '@kit.BasicServicesKit';
2443
2444async function ScaleSync() {
2445  let scaleX: number = 2.0;
2446  let scaleY: number = 1.0;
2447  if (pixelMap != undefined) {
2448    pixelMap.scaleSync(scaleX, scaleY, image.AntiAliasingLevel.LOW);
2449  }
2450}
2451```
2452
2453### translate<sup>9+</sup>
2454
2455translate(x: number, y: number, callback: AsyncCallback\<void>): void
2456
2457根据输入的坐标对图片进行位置变换,translate后的图片尺寸:width+X ,height+Y,使用callback形式返回。
2458
2459**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2460
2461**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2462
2463**系统能力:** SystemCapability.Multimedia.Image.Core
2464
2465**参数:**
2466
2467| 参数名   | 类型                 | 必填 | 说明                          |
2468| -------- | -------------------- | ---- | ----------------------------- |
2469| x        | number               | 是   | 区域横坐标。                  |
2470| y        | number               | 是   | 区域纵坐标。                  |
2471| callback | AsyncCallback\<void> | 是   | 回调函数。当对图片进行位置变换成功,err为undefined,否则为错误对象。|
2472
2473**示例:**
2474
2475```ts
2476import { BusinessError } from '@kit.BasicServicesKit';
2477
2478async function Translate() {
2479  let translateX: number = 50.0;
2480  let translateY: number = 10.0;
2481  if (pixelMap != undefined) {
2482    pixelMap.translate(translateX, translateY, (err: BusinessError) => {
2483      if (err) {
2484        console.error(`Failed to translate pixelmap. code is ${err.code}, message is ${err.message}`);
2485        return;
2486      } else {
2487        console.info("Succeeded in translating pixelmap.");
2488      }
2489    })
2490  }
2491}
2492```
2493
2494### translate<sup>9+</sup>
2495
2496translate(x: number, y: number): Promise\<void>
2497
2498根据输入的坐标对图片进行位置变换,translate后的图片尺寸:width+X ,height+Y,使用Promise形式返回。
2499
2500**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2501
2502**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2503
2504**系统能力:** SystemCapability.Multimedia.Image.Core
2505
2506**参数:**
2507
2508| 参数名 | 类型   | 必填 | 说明        |
2509| ------ | ------ | ---- | ----------- |
2510| x      | number | 是   | 区域横坐标。|
2511| y      | number | 是   | 区域纵坐标。|
2512
2513**返回值:**
2514
2515| 类型           | 说明                        |
2516| -------------- | --------------------------- |
2517| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
2518
2519**示例:**
2520
2521```ts
2522import { BusinessError } from '@kit.BasicServicesKit';
2523
2524async function Translate() {
2525  let translateX: number = 50.0;
2526  let translateY: number = 10.0;
2527  if (pixelMap != undefined) {
2528    pixelMap.translate(translateX, translateY).then(() => {
2529      console.info('Succeeded in translating pixelmap.');
2530    }).catch((err: BusinessError) => {
2531      console.error(`Failed to translate pixelmap. code is ${err.code}, message is ${err.message}`);
2532    })
2533  }
2534}
2535```
2536
2537### translateSync<sup>12+</sup>
2538
2539translateSync(x: number, y: number): void
2540
2541根据输入的坐标对图片进行位置变换并同步返回结果。
2542
2543**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2544
2545**系统能力:** SystemCapability.Multimedia.Image.Core
2546
2547**参数:**
2548
2549| 参数名   | 类型                 | 必填 | 说明                            |
2550| -------- | -------------------- | ---- | ------------------------------- |
2551| x        | number               | 是   | 区域横坐标。|
2552| y        | number               | 是   | 区域纵坐标。|
2553
2554**错误码:**
2555
2556以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
2557
2558| 错误码ID | 错误信息 |
2559| ------- | --------------------------------------------|
2560|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
2561|  501    | Resource Unavailable |
2562
2563**示例:**
2564
2565```ts
2566import { BusinessError } from '@kit.BasicServicesKit';
2567
2568async function TranslateSync() {
2569  let translateX : number = 50.0;
2570  let translateY : number = 10.0;
2571  if (pixelMap != undefined) {
2572    pixelMap.translateSync(translateX, translateY);
2573  }
2574}
2575```
2576
2577### rotate<sup>9+</sup>
2578
2579rotate(angle: number, callback: AsyncCallback\<void>): void
2580
2581根据输入的角度对图片进行旋转,使用callback形式返回。
2582
2583**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2584
2585**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2586
2587**系统能力:** SystemCapability.Multimedia.Image.Core
2588
2589**参数:**
2590
2591| 参数名   | 类型                 | 必填 | 说明                          |
2592| -------- | -------------------- | ---- | ----------------------------- |
2593| angle    | number               | 是   | 图片旋转的角度。              |
2594| callback | AsyncCallback\<void> | 是   | 回调函数。当对图片进行旋转成功,err为undefined,否则为错误对象。|
2595
2596**示例:**
2597
2598```ts
2599import { BusinessError } from '@kit.BasicServicesKit';
2600
2601async function Rotate() {
2602  let angle: number = 90.0;
2603  if (pixelMap != undefined) {
2604    pixelMap.rotate(angle, (err: BusinessError) => {
2605      if (err) {
2606        console.error(`Failed to rotate pixelmap. code is ${err.code}, message is ${err.message}`);
2607        return;
2608      } else {
2609        console.info("Succeeded in rotating pixelmap.");
2610      }
2611    })
2612  }
2613}
2614```
2615
2616### rotate<sup>9+</sup>
2617
2618rotate(angle: number): Promise\<void>
2619
2620根据输入的角度对图片进行旋转,使用Promise形式返回。
2621
2622**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2623
2624**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2625
2626**系统能力:** SystemCapability.Multimedia.Image.Core
2627
2628**参数:**
2629
2630| 参数名 | 类型   | 必填 | 说明                          |
2631| ------ | ------ | ---- | ----------------------------- |
2632| angle  | number | 是   | 图片旋转的角度。              |
2633
2634**返回值:**
2635
2636| 类型           | 说明                        |
2637| -------------- | --------------------------- |
2638| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
2639
2640**示例:**
2641
2642```ts
2643import { BusinessError } from '@kit.BasicServicesKit';
2644
2645async function Rotate() {
2646  let angle: number = 90.0;
2647  if (pixelMap != undefined) {
2648    pixelMap.rotate(angle).then(() => {
2649      console.info('Succeeded in rotating pixelmap.');
2650    }).catch((err: BusinessError) => {
2651      console.error(`Failed to rotate pixelmap. code is ${err.code}, message is ${err.message}`);
2652    })
2653  }
2654}
2655```
2656
2657### rotateSync<sup>12+</sup>
2658
2659rotateSync(angle: number): void
2660
2661根据输入的角度对图片进行旋转并同步返回结果。
2662
2663**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2664
2665**系统能力:** SystemCapability.Multimedia.Image.Core
2666
2667**参数:**
2668
2669| 参数名   | 类型                 | 必填 | 说明                          |
2670| -------- | -------------------- | ---- | ----------------------------- |
2671| angle    | number               | 是   | 图片旋转的角度。              |
2672
2673**错误码:**
2674
2675以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
2676
2677| 错误码ID | 错误信息 |
2678| ------- | --------------------------------------------|
2679|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
2680|  501    | Resource Unavailable |
2681
2682**示例:**
2683
2684```ts
2685import { BusinessError } from '@kit.BasicServicesKit';
2686
2687async function RotateSync() {
2688  let angle : number = 90.0;
2689  if (pixelMap != undefined) {
2690    pixelMap.rotateSync(angle);
2691  }
2692}
2693```
2694
2695### flip<sup>9+</sup>
2696
2697flip(horizontal: boolean, vertical: boolean, callback: AsyncCallback\<void>): void
2698
2699根据输入的条件对图片进行翻转,使用callback形式返回。
2700
2701**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2702
2703**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2704
2705**系统能力:** SystemCapability.Multimedia.Image.Core
2706
2707**参数:**
2708
2709| 参数名     | 类型                 | 必填 | 说明                          |
2710| ---------- | -------------------- | ---- | ----------------------------- |
2711| horizontal | boolean              | 是   | 水平翻转。                    |
2712| vertical   | boolean              | 是   | 垂直翻转。                    |
2713| callback   | AsyncCallback\<void> | 是   | 回调函数,当对图片翻转成功,err为undefined,否则为错误对象。|
2714
2715**示例:**
2716
2717```ts
2718import { BusinessError } from '@kit.BasicServicesKit';
2719
2720async function Flip() {
2721  let horizontal: boolean = true;
2722  let vertical: boolean = false;
2723  if (pixelMap != undefined) {
2724    pixelMap.flip(horizontal, vertical, (err: BusinessError) => {
2725      if (err) {
2726        console.error(`Failed to flip pixelmap. code is ${err.code}, message is ${err.message}`);
2727        return;
2728      } else {
2729        console.info("Succeeded in flipping pixelmap.");
2730      }
2731    })
2732  }
2733}
2734```
2735
2736### flip<sup>9+</sup>
2737
2738flip(horizontal: boolean, vertical: boolean): Promise\<void>
2739
2740根据输入的条件对图片进行翻转,使用Promise形式返回。
2741
2742**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2743
2744**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2745
2746**系统能力:** SystemCapability.Multimedia.Image.Core
2747
2748**参数:**
2749
2750| 参数名     | 类型    | 必填 | 说明      |
2751| ---------- | ------- | ---- | --------- |
2752| horizontal | boolean | 是   | 水平翻转。|
2753| vertical   | boolean | 是   | 垂直翻转。|
2754
2755**返回值:**
2756
2757| 类型           | 说明                        |
2758| -------------- | --------------------------- |
2759| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
2760
2761**示例:**
2762
2763```ts
2764import { BusinessError } from '@kit.BasicServicesKit';
2765
2766async function Flip() {
2767  let horizontal: boolean = true;
2768  let vertical: boolean = false;
2769  if (pixelMap != undefined) {
2770    pixelMap.flip(horizontal, vertical).then(() => {
2771      console.info('Succeeded in flipping pixelmap.');
2772    }).catch((err: BusinessError) => {
2773      console.error(`Failed to flip pixelmap. code is ${err.code}, message is ${err.message}`);
2774    })
2775  }
2776}
2777```
2778
2779### flipSync<sup>12+</sup>
2780
2781flipSync(horizontal: boolean, vertical: boolean): void
2782
2783根据输入的条件对图片进行翻转并同步返回结果。
2784
2785**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2786
2787**系统能力:** SystemCapability.Multimedia.Image.Core
2788
2789**参数:**
2790
2791| 参数名     | 类型                 | 必填 | 说明                          |
2792| ---------- | -------------------- | ---- | ----------------------------- |
2793| horizontal | boolean              | 是   | 水平翻转。                    |
2794| vertical   | boolean              | 是   | 垂直翻转。                    |
2795
2796**错误码:**
2797
2798以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
2799
2800| 错误码ID | 错误信息 |
2801| ------- | --------------------------------------------|
2802|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
2803|  501    | Resource Unavailable |
2804
2805**示例:**
2806
2807```ts
2808import { BusinessError } from '@kit.BasicServicesKit';
2809
2810async function FlipSync() {
2811  let horizontal : boolean = true;
2812  let vertical : boolean = false;
2813  if (pixelMap != undefined) {
2814    pixelMap.flipSync(horizontal, vertical);
2815  }
2816}
2817```
2818
2819### crop<sup>9+</sup>
2820
2821crop(region: Region, callback: AsyncCallback\<void>): void
2822
2823根据输入的尺寸对图片进行裁剪,使用callback形式返回。
2824
2825**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2826
2827**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2828
2829**系统能力:** SystemCapability.Multimedia.Image.Core
2830
2831**参数:**
2832
2833| 参数名   | 类型                 | 必填 | 说明                          |
2834| -------- | -------------------- | ---- | ----------------------------- |
2835| region   | [Region](#region8)   | 是   | 裁剪的尺寸。                  |
2836| callback | AsyncCallback\<void> | 是   |  回调函数。当对图片进行裁剪成功,err为undefined,否则为错误对象。|
2837
2838**示例:**
2839
2840```ts
2841import { BusinessError } from '@kit.BasicServicesKit';
2842
2843async function Crop() {
2844  let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } };
2845  if (pixelMap != undefined) {
2846    pixelMap.crop(region, (err: BusinessError) => {
2847      if (err) {
2848        console.error(`Failed to crop pixelmap. code is ${err.code}, message is ${err.message}`);
2849        return;
2850      } else {
2851        console.info("Succeeded in cropping pixelmap.");
2852      }
2853    })
2854  }
2855}
2856```
2857
2858### crop<sup>9+</sup>
2859
2860crop(region: Region): Promise\<void>
2861
2862根据输入的尺寸对图片进行裁剪,使用Promise形式返回。
2863
2864**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
2865
2866**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2867
2868**系统能力:** SystemCapability.Multimedia.Image.Core
2869
2870**参数:**
2871
2872| 参数名 | 类型               | 必填 | 说明        |
2873| ------ | ------------------ | ---- | ----------- |
2874| region | [Region](#region8) | 是   | 裁剪的尺寸。|
2875
2876**返回值:**
2877
2878| 类型           | 说明                        |
2879| -------------- | --------------------------- |
2880| Promise\<void> |  Promise对象。无返回结果的Promise对象。|
2881
2882**示例:**
2883
2884```ts
2885import { BusinessError } from '@kit.BasicServicesKit';
2886
2887async function Crop() {
2888  let region: image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } };
2889  if (pixelMap != undefined) {
2890    pixelMap.crop(region).then(() => {
2891      console.info('Succeeded in cropping pixelmap.');
2892    }).catch((err: BusinessError) => {
2893      console.error(`Failed to crop pixelmap. code is ${err.code}, message is ${err.message}`);
2894
2895    });
2896  }
2897}
2898```
2899
2900### cropSync<sup>12+</sup>
2901
2902cropSync(region: Region): void
2903
2904根据输入的尺寸裁剪图片。
2905
2906**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2907
2908**系统能力:** SystemCapability.Multimedia.Image.Core
2909
2910**参数:**
2911
2912| 参数名   | 类型                 | 必填 | 说明                          |
2913| -------- | -------------------- | ---- | ----------------------------- |
2914| region   | [Region](#region8)   | 是   | 裁剪的尺寸。                  |
2915
2916**错误码:**
2917
2918以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
2919
2920| 错误码ID | 错误信息 |
2921| ------- | --------------------------------------------|
2922|  401    | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
2923|  501    | Resource Unavailable |
2924
2925**示例:**
2926
2927```ts
2928import { BusinessError } from '@kit.BasicServicesKit';
2929
2930async function CropSync() {
2931  let region : image.Region = { x: 0, y: 0, size: { height: 100, width: 100 } };
2932  if (pixelMap != undefined) {
2933    pixelMap.cropSync(region);
2934  }
2935}
2936```
2937
2938### getColorSpace<sup>10+</sup>
2939
2940getColorSpace(): colorSpaceManager.ColorSpaceManager
2941
2942获取图像广色域信息。
2943
2944**系统能力:** SystemCapability.Multimedia.Image.Core
2945
2946**返回值:**
2947
2948| 类型                                | 说明             |
2949| ----------------------------------- | ---------------- |
2950| [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | 图像广色域信息。 |
2951
2952**错误码:**
2953
2954以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
2955
2956| 错误码ID | 错误信息 |
2957| ------- | --------------------------------------------|
2958| 62980101| If the image data abnormal.            |
2959| 62980103| If the image data unsupport.             |
2960| 62980115| If the image parameter invalid.            |
2961
2962**示例:**
2963
2964```ts
2965async function GetColorSpace() {
2966  if (pixelMap != undefined) {
2967    let csm = pixelMap.getColorSpace();
2968  }
2969}
2970```
2971
2972### setColorSpace<sup>10+</sup>
2973
2974setColorSpace(colorSpace: colorSpaceManager.ColorSpaceManager): void
2975
2976设置图像广色域信息。
2977
2978**系统能力:** SystemCapability.Multimedia.Image.Core
2979
2980**参数:**
2981
2982| 参数名     | 类型                                | 必填 | 说明            |
2983| ---------- | ----------------------------------- | ---- | --------------- |
2984| colorSpace | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | 是   | 图像广色域信息。|
2985
2986**错误码:**
2987
2988以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
2989
2990| 错误码ID | 错误信息 |
2991| ------- | --------------------------------------------|
2992| 62980111| The image source data is incomplete.        |
2993| 62980115| If the image parameter invalid.             |
2994
2995**示例:**
2996
2997```ts
2998import { colorSpaceManager } from '@kit.ArkGraphics2D';
2999async function SetColorSpace() {
3000  let colorSpaceName = colorSpaceManager.ColorSpace.SRGB;
3001  let csm: colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName);
3002  if (pixelMap != undefined) {
3003    pixelMap.setColorSpace(csm);
3004  }
3005}
3006```
3007
3008### applyColorSpace<sup>11+</sup>
3009
3010applyColorSpace(targetColorSpace: colorSpaceManager.ColorSpaceManager, callback: AsyncCallback\<void>): void
3011
3012根据输入的目标色彩空间对图像像素颜色进行色彩空间转换,使用callback形式返回。
3013
3014**系统能力:** SystemCapability.Multimedia.Image.Core
3015
3016**参数:**
3017
3018| 参数名   | 类型                 | 必填 | 说明                          |
3019| -------- | -------------------- | ---- | ----------------------------- |
3020| targetColorSpace | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | 是   | 目标色彩空间,支持SRGB、DCI_P3、DISPLAY_P3、ADOBE_RGB_1998。|
3021| callback | AsyncCallback\<void> | 是   | 回调函数。当对图像像素颜色进行色彩空间转换成功,err为undefined,否则为错误对象。|
3022
3023**错误码:**
3024
3025以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
3026
3027| 错误码ID | 错误信息 |
3028| ------- | ------------------------------------------|
3029| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
3030| 62980104| Failed to initialize the internal object. |
3031| 62980108| Failed to convert the color space.       |
3032| 62980115| Invalid image parameter.            |
3033
3034**示例:**
3035
3036```ts
3037import { colorSpaceManager } from '@kit.ArkGraphics2D';
3038import { BusinessError } from '@kit.BasicServicesKit';
3039
3040async function ApplyColorSpace() {
3041  let colorSpaceName = colorSpaceManager.ColorSpace.SRGB;
3042  let targetColorSpace: colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName);
3043  if (pixelMap != undefined) {
3044    pixelMap.applyColorSpace(targetColorSpace, (err: BusinessError) => {
3045      if (err) {
3046        console.error(`Failed to apply color space for pixelmap object. code is ${err.code}, message is ${err.message}`);
3047        return;
3048      } else {
3049        console.info('Succeeded in applying color space for pixelmap object.');
3050      }
3051    })
3052  }
3053}
3054```
3055
3056### applyColorSpace<sup>11+</sup>
3057
3058applyColorSpace(targetColorSpace: colorSpaceManager.ColorSpaceManager): Promise\<void>
3059
3060根据输入的目标色彩空间对图像像素颜色进行色彩空间转换,使用Promise形式返回。
3061
3062**系统能力:** SystemCapability.Multimedia.Image.Core
3063
3064**参数:**
3065
3066| 参数名 | 类型               | 必填 | 说明        |
3067| ------ | ------------------ | ---- | ----------- |
3068| targetColorSpace | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | 是   | 目标色彩空间,支持SRGB、DCI_P3、DISPLAY_P3、ADOBE_RGB_1998。|
3069
3070**返回值:**
3071
3072| 类型           | 说明                        |
3073| -------------- | --------------------------- |
3074| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
3075
3076**错误码:**
3077
3078以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
3079
3080| 错误码ID | 错误信息 |
3081| ------- | ------------------------------------------|
3082| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed |
3083| 62980104| Failed to initialize the internal object. |
3084| 62980108| Failed to convert the color space.       |
3085| 62980115| Invalid image parameter.            |
3086
3087**示例:**
3088
3089```ts
3090import { colorSpaceManager } from '@kit.ArkGraphics2D';
3091import { BusinessError } from '@kit.BasicServicesKit';
3092
3093async function ApplyColorSpace() {
3094  let colorSpaceName = colorSpaceManager.ColorSpace.SRGB;
3095  let targetColorSpace: colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName);
3096  if (pixelMap != undefined) {
3097    pixelMap.applyColorSpace(targetColorSpace).then(() => {
3098      console.info('Succeeded in applying color space for pixelmap object.');
3099    }).catch((error: BusinessError) => {
3100      console.error(`Failed to apply color space for pixelmap object. code is ${error.code}, message is ${error.message}`);
3101    })
3102  }
3103}
3104```
3105
3106### toSdr<sup>12+<sup>
3107
3108toSdr(): Promise\<void>
3109
3110将HDR的图像内容转换为SDR的图像内容,异步使用Promise形式返回。
3111
3112**系统能力:** SystemCapability.Multimedia.Image.Core
3113
3114**返回值:**
3115
3116| 类型           | 说明                        |
3117| -------------- | --------------------------- |
3118| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
3119
3120**错误码:**
3121
3122以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
3123
3124| 错误码ID | 错误信息 |
3125| ------- | --------------------------------------------|
3126| 62980137 | Invalid image operation.              |
3127
3128**示例:**
3129
3130```ts
3131import image from '@ohos.multimedia.image'
3132import resourceManager from '@ohos.resourceManager'
3133import { BusinessError } from '@kit.BasicServicesKit';
3134
3135//此处'hdr.jpg'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。
3136let img = getContext().resourceManager.getMediaContentSync($r('app.media.hdr'));
3137let imageSource = image.createImageSource(img.buffer.slice(0));
3138let decodingOptions: image.DecodingOptions = {
3139  desiredDynamicRange: image.DecodingDynamicRange.AUTO
3140};
3141let pixelmap = imageSource.createPixelMapSync(decodingOptions);
3142if (pixelmap != undefined) {
3143  console.info('Succeeded in creating pixelMap object.');
3144  pixelmap.toSdr().then(() => {
3145    let imageInfo = pixelmap.getImageInfoSync();
3146    console.info("after toSdr ,imageInfo isHdr:" + imageInfo.isHdr);
3147  }).catch((err: BusinessError) => {
3148    console.error(`Failed to set sdr. code is ${err.code}, message is ${err.message}`);
3149  });
3150} else {
3151  console.info('Failed to create pixelMap.');
3152}
3153```
3154
3155### getMetadata<sup>12+</sup>
3156
3157getMetadata(key: HdrMetadataKey): HdrMetadataValue
3158
3159从PixelMap中获取元数据。
3160
3161**系统能力:** SystemCapability.Multimedia.Image.Core
3162
3163**参数:**
3164
3165| 参数名        | 类型                             | 必填 | 说明             |
3166| ------------- | -------------------------------- | ---- | ---------------- |
3167| key | [HdrMetadataKey](#hdrmetadatakey12) | 是   | HDR元数据的关键字,可用于查询对应值。 |
3168
3169**返回值:**
3170
3171| 类型                              | 说明                              |
3172| --------------------------------- | --------------------------------- |
3173| [HdrMetadataValue](#hdrmetadatavalue12) | 返回元数据的值。 |
3174
3175**错误码:**
3176
3177以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
3178
3179| 错误码ID | 错误信息 |
3180| ------- | --------------------------------------------|
3181| 401| Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.          |
3182| 501 | Resource unavailable.          |
3183| 62980173 | The DMA memory does not exist.          |
3184| 62980302 | Memory copy failed.          |
3185
3186**示例:**
3187
3188```ts
3189import { BusinessError } from '@kit.BasicServicesKit';
3190import image from '@ohos.multimedia.image'
3191
3192// 'app.media.test'需要替换为本地hdr图片。
3193let img = getContext().resourceManager.getMediaContentSync($r('app.media.test'));
3194let imageSource = image.createImageSource(img.buffer.slice(0));
3195let decodingOptions: image.DecodingOptions = {
3196  desiredDynamicRange: image.DecodingDynamicRange.AUTO
3197};
3198let pixelmap = imageSource.createPixelMapSync(decodingOptions);
3199if (pixelmap != undefined) {
3200  console.info('Succeeded in creating pixelMap object.');
3201  try {
3202    let staticMetadata = pixelmap.getMetadata(image.HdrMetadataKey.HDR_STATIC_METADATA);
3203    console.info("getmetadata:" + JSON.stringify(staticMetadata));
3204  } catch (e) {
3205    console.info('pixelmap create failed' + e);
3206  }
3207} else {
3208  console.info('Failed to create pixelMap.');
3209}
3210```
3211
3212### setMetadata<sup>12+</sup>
3213
3214setMetadata(key: HdrMetadataKey, value: HdrMetadataValue): Promise\<void>
3215
3216设置PixelMap元数据。
3217
3218**系统能力:** SystemCapability.Multimedia.Image.Core
3219
3220**参数:**
3221
3222| 参数名        | 类型                             | 必填 | 说明             |
3223| ------------- | -------------------------------- | ---- | ---------------- |
3224| key | [HdrMetadataKey](#hdrmetadatakey12) | 是   | HDR元数据的关键字,用于设置对应值 |
3225| value | [HdrMetadataValue](#hdrmetadatavalue12) | 是   | 元数据的值 |
3226
3227**返回值:**
3228
3229| 类型           | 说明                  |
3230| -------------- | --------------------- |
3231| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
3232
3233**错误码:**
3234
3235以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
3236
3237| 错误码ID | 错误信息 |
3238| ------- | --------------------------------------------|
3239| 401|  Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.         |
3240| 501 | Resource unavailable.          |
3241| 62980173 | The DMA memory does not exist.          |
3242| 62980302 | Memory copy failed.          |
3243
3244**示例:**
3245
3246```ts
3247import image from '@ohos.multimedia.image'
3248import { BusinessError } from '@kit.BasicServicesKit';
3249
3250let staticMetadata: image.HdrStaticMetadata = {
3251  displayPrimariesX: [1.1, 1.1, 1.1],
3252  displayPrimariesY: [1.2, 1.2, 1.2],
3253  whitePointX: 1.1,
3254  whitePointY: 1.2,
3255  maxLuminance: 2.1,
3256  minLuminance: 1.0,
3257  maxContentLightLevel: 2.1,
3258  maxFrameAverageLightLevel: 2.1,
3259}
3260const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
3261let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } }
3262image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => {
3263  pixelMap.setMetadata(image.HdrMetadataKey.HDR_STATIC_METADATA, staticMetadata).then(() => {
3264    console.info('Succeeded in setting pixelMap metadata.');
3265  }).catch((error: BusinessError) => {
3266    console.error(`Failed to set the metadata.code ${error.code},message is ${error.message}`);
3267  })
3268}).catch((error: BusinessError) => {
3269  console.error(`Failed to create the PixelMap.code ${error.code},message is ${error.message}`);
3270})
3271
3272```
3273
3274### setTransferDetached<sup>12+<sup>
3275
3276setTransferDetached(detached: boolean): void
3277
3278pixelmap在跨线程传输时,断开原线程的引用。适用于需立即释放pixelmap的场景。
3279
3280**系统能力:** SystemCapability.Multimedia.Image.Core
3281
3282**参数:**
3283
3284| 参数名   | 类型               | 必填 | 说明                          |
3285| ------- | ------------------ | ---- | ----------------------------- |
3286| detached | boolean   | 是   | 是否断开原线程引用                  |
3287
3288**错误码:**
3289
3290以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
3291
3292| 错误码ID | 错误信息 |
3293| ------- | --------------------------------------------|
3294|  501    | Resource Unavailable |
3295
3296**示例:**
3297
3298```ts
3299import { BusinessError } from '@kit.BasicServicesKit';
3300import image from '@ohos.multimedia.image';
3301import taskpool from '@ohos.taskpool';
3302
3303@Concurrent
3304// 子线程方法
3305async function loadPixelMap(rawFileDescriptor: number): Promise<PixelMap> {
3306  // 创建imageSource。
3307  const imageSource = image.createImageSource(rawFileDescriptor);
3308  // 创建pixelMap。
3309  const pixelMap = imageSource.createPixelMapSync();
3310  // 释放imageSource。
3311  imageSource.release();
3312  // 使pixelMap在跨线程传输完成后,断开原线程的引用。
3313  pixelMap.setTransferDetached(true);
3314  // 返回pixelMap给主线程。
3315  return pixelMap;
3316}
3317
3318@Entry
3319@Component
3320struct Demo {
3321  @State pixelMap: PixelMap | undefined = undefined;
3322  // 主线程方法
3323  private loadImageFromThread(): void {
3324    const resourceMgr = getContext(this).resourceManager;
3325    // 此处‘example.jpg’仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。
3326    resourceMgr.getRawFd('example.jpg').then(rawFileDescriptor => {
3327      taskpool.execute(loadPixelMap, rawFileDescriptor).then(pixelMap => {
3328        if (pixelMap) {
3329          this.pixelMap = pixelMap as PixelMap;
3330          console.log('Succeeded in creating pixelMap.');
3331          // 主线程释放pixelMap。由于子线程返回pixelMap时已调用setTransferDetached,所以此处能够立即释放pixelMap。
3332          this.pixelMap.release();
3333        } else {
3334          console.error('Failed to create pixelMap.');
3335        }
3336      });
3337    });
3338  }
3339  build() {
3340    // ...
3341  }
3342}
3343```
3344
3345### marshalling<sup>10+</sup>
3346
3347marshalling(sequence: rpc.MessageSequence): void
3348
3349将PixelMap序列化后写入MessageSequence。
3350
3351**系统能力:** SystemCapability.Multimedia.Image.Core
3352
3353**参数:**
3354
3355| 参数名                 | 类型                                                  | 必填 | 说明                                     |
3356| ---------------------- | ------------------------------------------------------ | ---- | ---------------------------------------- |
3357| sequence               | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9)  | 是   | 新创建的MessageSequence。                 |
3358
3359**错误码:**
3360
3361以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
3362
3363| 错误码ID | 错误信息 |
3364| ------- | --------------------------------------------|
3365| 62980115 | Invalid image parameter.              |
3366| 62980097 | IPC error.             |
3367
3368**示例:**
3369
3370```ts
3371import { image } from '@kit.ImageKit';
3372import { rpc } from '@kit.IPCKit';
3373
3374class MySequence implements rpc.Parcelable {
3375  pixel_map: image.PixelMap;
3376  constructor(conPixelMap : image.PixelMap) {
3377    this.pixel_map = conPixelMap;
3378  }
3379  marshalling(messageSequence : rpc.MessageSequence) {
3380    this.pixel_map.marshalling(messageSequence);
3381    console.info('marshalling');
3382    return true;
3383  }
3384  unmarshalling(messageSequence : rpc.MessageSequence) {
3385    image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}}).then((pixelParcel: image.PixelMap) => {
3386      pixelParcel.unmarshalling(messageSequence).then(async (pixelMap: image.PixelMap) => {
3387        this.pixel_map = pixelMap;
3388        pixelMap.getImageInfo().then((imageInfo: image.ImageInfo) => {
3389          console.info("unmarshalling information h:" + imageInfo.size.height + "w:" + imageInfo.size.width);
3390        })
3391      })
3392    });
3393    return true;
3394  }
3395}
3396async function Marshalling() {
3397  const color: ArrayBuffer = new ArrayBuffer(96);
3398  let bufferArr: Uint8Array = new Uint8Array(color);
3399  for (let i = 0; i < bufferArr.length; i++) {
3400    bufferArr[i] = 0x80;
3401  }
3402  let opts: image.InitializationOptions = {
3403    editable: true,
3404    pixelFormat: image.PixelMapFormat.BGRA_8888,
3405    size: { height: 4, width: 6 },
3406    alphaType: image.AlphaType.UNPREMUL
3407  }
3408  let pixelMap: image.PixelMap | undefined = undefined;
3409  image.createPixelMap(color, opts).then((srcPixelMap: image.PixelMap) => {
3410    pixelMap = srcPixelMap;
3411  })
3412  if (pixelMap != undefined) {
3413    // 序列化
3414    let parcelable: MySequence = new MySequence(pixelMap);
3415    let data: rpc.MessageSequence = rpc.MessageSequence.create();
3416    data.writeParcelable(parcelable);
3417
3418    // 反序列化 rpc获取到data
3419    let ret: MySequence = new MySequence(pixelMap);
3420    data.readParcelable(ret);
3421  }
3422}
3423```
3424
3425### unmarshalling<sup>10+</sup>
3426
3427unmarshalling(sequence: rpc.MessageSequence): Promise\<PixelMap>
3428
3429从MessageSequence中获取PixelMap,
3430如需使用同步方式创建PixelMap可使用:[createPixelMapFromParcel](#imagecreatepixelmapfromparcel11)。
3431
3432**系统能力:** SystemCapability.Multimedia.Image.Core
3433
3434**参数:**
3435
3436| 参数名                 | 类型                                                  | 必填 | 说明                                     |
3437| ---------------------- | ----------------------------------------------------- | ---- | ---------------------------------------- |
3438| sequence               | [rpc.MessageSequence](../apis-ipc-kit/js-apis-rpc.md#messagesequence9) | 是   | 保存有PixelMap信息的MessageSequence。      |
3439
3440**返回值:**
3441
3442| 类型                             | 说明                  |
3443| -------------------------------- | --------------------- |
3444| Promise\<[PixelMap](#pixelmap7)> |Promise对象,返回PixelMap。 |
3445
3446**错误码:**
3447
3448以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
3449
3450| 错误码ID | 错误信息 |
3451| ------- | --------------------------------------------|
3452| 62980115 | Invalid image parameter.              |
3453| 62980097 | IPC error.              |
3454| 62980096 | The operation failed.         |
3455
3456**示例:**
3457
3458```ts
3459import { image } from '@kit.ImageKit';
3460import { rpc } from '@kit.IPCKit';
3461
3462class MySequence implements rpc.Parcelable {
3463  pixel_map: image.PixelMap;
3464  constructor(conPixelMap: image.PixelMap) {
3465    this.pixel_map = conPixelMap;
3466  }
3467  marshalling(messageSequence: rpc.MessageSequence) {
3468    this.pixel_map.marshalling(messageSequence);
3469    console.info('marshalling');
3470    return true;
3471  }
3472  unmarshalling(messageSequence: rpc.MessageSequence) {
3473    image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}}).then((pixelParcel : image.PixelMap) => {
3474      pixelParcel.unmarshalling(messageSequence).then(async (pixelMap : image.PixelMap) => {
3475        this.pixel_map = pixelMap;
3476        pixelMap.getImageInfo().then((imageInfo : image.ImageInfo) => {
3477          console.info("unmarshalling information h:" + imageInfo.size.height + "w:" + imageInfo.size.width);
3478        })
3479      })
3480    });
3481    return true;
3482  }
3483}
3484async function Unmarshalling() {
3485  const color: ArrayBuffer = new ArrayBuffer(96);
3486  let bufferArr: Uint8Array = new Uint8Array(color);
3487  for (let i = 0; i < bufferArr.length; i++) {
3488    bufferArr[i] = 0x80;
3489  }
3490  let opts: image.InitializationOptions = {
3491    editable: true,
3492    pixelFormat: image.PixelMapFormat.BGRA_8888,
3493    size: { height: 4, width: 6 },
3494    alphaType: image.AlphaType.UNPREMUL
3495  }
3496  let pixelMap: image.PixelMap | undefined = undefined;
3497  image.createPixelMap(color, opts).then((srcPixelMap : image.PixelMap) => {
3498    pixelMap = srcPixelMap;
3499  })
3500  if (pixelMap != undefined) {
3501    // 序列化
3502    let parcelable: MySequence = new MySequence(pixelMap);
3503    let data : rpc.MessageSequence = rpc.MessageSequence.create();
3504    data.writeParcelable(parcelable);
3505
3506    // 反序列化 rpc获取到data
3507    let ret : MySequence = new MySequence(pixelMap);
3508    data.readParcelable(ret);
3509  }
3510}
3511```
3512
3513### release<sup>7+</sup>
3514
3515release():Promise\<void>
3516
3517释放PixelMap对象,使用Promise形式返回释放结果。
3518
3519ArkTS有内存回收机制,PixelMap对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
3520
3521**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
3522
3523**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3524
3525**系统能力:** SystemCapability.Multimedia.Image.Core
3526
3527**返回值:**
3528
3529| 类型           | 说明                            |
3530| -------------- | ------------------------------- |
3531| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
3532
3533**示例:**
3534
3535```ts
3536import { BusinessError } from '@kit.BasicServicesKit';
3537
3538async function Release() {
3539  if (pixelMap != undefined) {
3540    pixelMap.release().then(() => {
3541      console.info('Succeeded in releasing pixelmap object.');
3542    }).catch((error: BusinessError) => {
3543      console.error(`Failed to release pixelmap object. code is ${error.code}, message is ${error.message}`);
3544    })
3545  }
3546}
3547```
3548
3549### release<sup>7+</sup>
3550
3551release(callback: AsyncCallback\<void>): void
3552
3553释放PixelMap对象,使用callback形式返回释放结果。
3554
3555ArkTS有内存回收机制,PixelMap对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
3556
3557**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
3558
3559**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3560
3561**系统能力:** SystemCapability.Multimedia.Image.Core
3562
3563**参数:**
3564
3565| 参数名   | 类型                 | 必填 | 说明               |
3566| -------- | -------------------- | ---- | ------------------ |
3567| callback | AsyncCallback\<void> | 是   | 回调函数。当对PixelMap对象释放成功,err为undefined,否则为错误对象。 |
3568
3569**示例:**
3570
3571```ts
3572import { BusinessError } from '@kit.BasicServicesKit';
3573
3574async function Release() {
3575  if (pixelMap != undefined) {
3576    pixelMap.release((err: BusinessError) => {
3577      if (err) {
3578        console.error(`Failed to release pixelmap object. code is ${err.code}, message is ${err.message}`);
3579        return;
3580      } else {
3581        console.info('Succeeded in releasing pixelmap object.');
3582      }
3583    })
3584  }
3585}
3586```
3587
3588### convertPixelFormat<sup>12+</sup>
3589
3590convertPixelFormat(targetPixelFormat: PixelMapFormat): Promise\<void>
3591
3592YUV和RGB类型互转,目前仅支持NV12/NV21RGB888/RGBA8888/RGB565/BGRA8888/RGBAF16互转,YCRCB_P010/YCBCR_P010与RGBA1010102互转。
3593
3594**系统能力:** SystemCapability.Multimedia.Image.Core
3595
3596**参数:**
3597
3598| 参数名   | 类型                 | 必填 | 说明               |
3599| -------- | -------------------- | ---- | ------------------ |
3600| targetPixelFormat | [PixelMapFormat](#pixelmapformat7) | 是   | 目标像素格式,用于YUV和RGB类型互转。目前仅支持NV12/NV21RGB888/RGBA8888/RGB565/BGRA8888/RGBAF16互转,YCRCB_P010/YCBCR_P010与RGBA1010102互转。 |
3601
3602**返回值:**
3603
3604| 类型           | 说明                            |
3605| -------------- | ------------------------------- |
3606| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
3607
3608**错误码:**
3609
3610以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
3611
3612| 错误码ID | 错误信息 |
3613| ------- | --------------------------------------------|
3614| 62980111 | The image source data is incomplete. |
3615| 62980115 | Invalid input parameter.              |
3616| 62980178 | Failed to create the pixelmap. |
3617| 62980274 | The conversion failed |
3618| 62980276 | The type to be converted is an unsupported target pixel format|
3619
3620**示例:**
3621
3622```ts
3623import { BusinessError } from '@kit.BasicServicesKit';
3624
3625if (pixelMap != undefined) {
3626  // 设置目标像素格式为NV12
3627  let targetPixelFormat = image.PixelMapFormat.NV12;
3628  pixelMap.convertPixelFormat(targetPixelFormat).then(() => {
3629    // pixelMap转换成NV12格式成功
3630    console.info('PixelMapFormat convert Succeeded');
3631  }).catch((error: BusinessError) => {
3632    // pixelMap转换成NV12格式失败
3633    console.error(`PixelMapFormat convert Failed. code is ${error.code}, message is ${error.message}`);
3634  })
3635}
3636```
3637
3638### setMemoryNameSync<sup>13+</sup>
3639
3640setMemoryNameSync(name: string): void
3641
3642设置PixelMap内存标识符。
3643
3644**系统能力:** SystemCapability.Multimedia.Image.Core
3645
3646**参数:**
3647
3648| 参数名        | 类型                             | 必填 | 说明             |
3649| ------------- | -------------------------------- | ---- | ---------------- |
3650| name | string | 是   | pixelmap内存标识符,只允许DMA和ASHMEM内存形式的piexelmap设置,支持1-31位长度。 |
3651
3652**错误码:**
3653
3654以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
3655
3656| 错误码ID | 错误信息 |
3657| ------- | --------------------------------------------|
3658| 401 | Parameter error. Possible causes: 1.The length of the input parameter is too long. 2.Parameter verification failed. |
3659| 501 | Resource unavailable. |
3660| 62980286 | Memory format not supported. |
3661
3662**示例:**
3663
3664```ts
3665import { BusinessError } from '@ohos.base';
3666
3667async function SetMemoryNameSync() {
3668  if (pixelMap != undefined) {
3669    try {
3670      pixelMap.setMemoryNameSync("PixelMapName Test");
3671    } catch(e) {
3672      let error = e as BusinessError;
3673      console.error(`setMemoryNameSync error. code is ${error.code}, message is ${error.message}`);
3674    }
3675  }
3676}
3677```
3678
3679## image.createImageSource
3680
3681createImageSource(uri: string): ImageSource
3682
3683通过传入的uri创建图片源实例。
3684
3685
3686**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3687
3688**系统能力:** SystemCapability.Multimedia.Image.ImageSource
3689
3690**参数:**
3691
3692| 参数名 | 类型   | 必填 | 说明                               |
3693| ------ | ------ | ---- | ---------------------------------- |
3694| uri    | string | 是   | 图片路径,当前仅支持应用沙箱路径。</br>当前支持格式有:.jpg .png .gif .bmp .webp .dng .heic<sup>12+</sup>(不同硬件设备支持情况不同) [.svg<sup>10+</sup>](#svg标签说明) .ico<sup>11+</sup>。 |
3695
3696**返回值:**
3697
3698| 类型                        | 说明                                         |
3699| --------------------------- | -------------------------------------------- |
3700| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |
3701
3702**示例:**
3703
3704```ts
3705const context: Context = getContext(this);
3706//此处'test.jpg'仅作示例,请开发者自行替换。否则imageSource会创建失败,导致后续无法正常执行。
3707const path: string = context.filesDir + "/test.jpg";
3708const imageSourceApi: image.ImageSource = image.createImageSource(path);
3709```
3710
3711## image.createImageSource<sup>9+</sup>
3712
3713createImageSource(uri: string, options: SourceOptions): ImageSource
3714
3715通过传入的uri创建图片源实例。
3716
3717**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
3718
3719**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3720
3721**系统能力:** SystemCapability.Multimedia.Image.ImageSource
3722
3723**参数:**
3724
3725| 参数名  | 类型                            | 必填 | 说明                                |
3726| ------- | ------------------------------- | ---- | ----------------------------------- |
3727| uri     | string                          | 是   | 图片路径,当前仅支持应用沙箱路径。</br>当前支持格式有:.jpg .png .gif .bmp .webp .dng .heic<sup>12+</sup>(不同硬件设备支持情况不同)[.svg<sup>10+</sup>](#svg标签说明) .ico<sup>11+</sup>。 |
3728| options | [SourceOptions](#sourceoptions9) | 是   | 图片属性,包括图片像素密度、像素格式和图片尺寸。|
3729
3730**返回值:**
3731
3732| 类型                        | 说明                                         |
3733| --------------------------- | -------------------------------------------- |
3734| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |
3735
3736**示例:**
3737
3738```ts
3739let sourceOptions: image.SourceOptions = { sourceDensity: 120 };
3740const context: Context = getContext(this);
3741//此处'test.png'仅作示例,请开发者自行替换。否则imageSource会创建失败,导致后续无法正常执行。
3742const path: string = context.filesDir + "/test.png";
3743let imageSourceApi: image.ImageSource = image.createImageSource(path, sourceOptions);
3744```
3745
3746## image.createImageSource<sup>7+</sup>
3747
3748createImageSource(fd: number): ImageSource
3749
3750通过传入文件描述符来创建图片源实例。
3751
3752**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3753
3754**系统能力:** SystemCapability.Multimedia.Image.ImageSource
3755
3756**参数:**
3757
3758| 参数名 | 类型   | 必填 | 说明          |
3759| ------ | ------ | ---- | ------------- |
3760| fd     | number | 是   | 文件描述符fd。|
3761
3762**返回值:**
3763
3764| 类型                        | 说明                                         |
3765| --------------------------- | -------------------------------------------- |
3766| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |
3767
3768**示例:**
3769
3770```ts
3771import { fileIo as fs } from '@kit.CoreFileKit';
3772
3773const context: Context = getContext(this);
3774//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource会创建失败导致后续无法正常执行。
3775let filePath: string = context.filesDir + "/test.jpg";
3776let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
3777const imageSourceApi: image.ImageSource = image.createImageSource(file.fd);
3778```
3779
3780## image.createImageSource<sup>9+</sup>
3781
3782createImageSource(fd: number, options: SourceOptions): ImageSource
3783
3784通过传入文件描述符来创建图片源实例。
3785
3786**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
3787
3788**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3789
3790**系统能力:** SystemCapability.Multimedia.Image.ImageSource
3791
3792**参数:**
3793
3794| 参数名  | 类型                            | 必填 | 说明                                |
3795| ------- | ------------------------------- | ---- | ----------------------------------- |
3796| fd      | number                          | 是   | 文件描述符fd。                      |
3797| options | [SourceOptions](#sourceoptions9) | 是   | 图片属性,包括图片像素密度、像素格式和图片尺寸。|
3798
3799**返回值:**
3800
3801| 类型                        | 说明                                         |
3802| --------------------------- | -------------------------------------------- |
3803| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |
3804
3805**示例:**
3806
3807```ts
3808import { fileIo as fs } from '@kit.CoreFileKit';
3809
3810let sourceOptions: image.SourceOptions = { sourceDensity: 120 };
3811const context: Context = getContext();
3812//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。
3813const filePath: string = context.filesDir + "/test.jpg";
3814let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
3815const imageSourceApi: image.ImageSource = image.createImageSource(file.fd, sourceOptions);
3816```
3817
3818## image.createImageSource<sup>9+</sup>
3819
3820createImageSource(buf: ArrayBuffer): ImageSource
3821
3822通过缓冲区创建图片源实例。buf数据应该是未解码的数据,不要传入类似于RBGA,YUV的像素buffer数据,如果想通过像素buffer数据创建pixelMap,可以调用[image.createPixelMapSync](#createpixelmapsync12)这一类接口。
3823
3824**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
3825
3826**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3827
3828**系统能力:** SystemCapability.Multimedia.Image.ImageSource
3829
3830**参数:**
3831
3832| 参数名 | 类型        | 必填 | 说明             |
3833| ------ | ----------- | ---- | ---------------- |
3834| buf    | ArrayBuffer | 是   | 图像缓冲区数组。 |
3835
3836**返回值:**
3837
3838| 类型                        | 说明                                         |
3839| --------------------------- | -------------------------------------------- |
3840| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |
3841
3842
3843**示例:**
3844
3845```ts
3846const buf: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
3847const imageSourceApi: image.ImageSource = image.createImageSource(buf);
3848```
3849
3850## image.createImageSource<sup>9+</sup>
3851
3852createImageSource(buf: ArrayBuffer, options: SourceOptions): ImageSource
3853
3854通过缓冲区创建图片源实例。buf数据应该是未解码的数据,不要传入类似于RBGA,YUV的像素buffer数据,如果想通过像素buffer数据创建pixelMap,可以调用[image.createPixelMapSync](#createpixelmapsync12)这一类接口。
3855
3856**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
3857
3858**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3859
3860**系统能力:** SystemCapability.Multimedia.Image.ImageSource
3861
3862**参数:**
3863
3864| 参数名 | 类型                             | 必填 | 说明                                 |
3865| ------ | -------------------------------- | ---- | ------------------------------------ |
3866| buf    | ArrayBuffer                      | 是   | 图像缓冲区数组。                     |
3867| options | [SourceOptions](#sourceoptions9) | 是   | 图片属性,包括图片像素密度、像素格式和图片尺寸。 |
3868
3869**返回值:**
3870
3871| 类型                        | 说明                                         |
3872| --------------------------- | -------------------------------------------- |
3873| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |
3874
3875**示例:**
3876
3877```ts
3878const data: ArrayBuffer = new ArrayBuffer(112);
3879let sourceOptions: image.SourceOptions = { sourceDensity: 120 };
3880const imageSourceApi: image.ImageSource = image.createImageSource(data, sourceOptions);
3881```
3882
3883## image.createImageSource<sup>11+</sup>
3884
3885createImageSource(rawfile: resourceManager.RawFileDescriptor, options?: SourceOptions): ImageSource
3886
3887通过图像资源文件的RawFileDescriptor创建图片源实例。
3888
3889**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3890
3891**系统能力:** SystemCapability.Multimedia.Image.ImageSource
3892
3893**参数:**
3894
3895| 参数名 | 类型                             | 必填 | 说明                                 |
3896| ------ | -------------------------------- | ---- | ------------------------------------ |
3897| rawfile | [resourceManager.RawFileDescriptor](../apis-localization-kit/js-apis-resource-manager.md#rawfiledescriptor8) | 是 | 图像资源文件的RawFileDescriptor。 |
3898| options | [SourceOptions](#sourceoptions9) | 否 | 图片属性,包括图片像素密度、像素格式和图片尺寸。 |
3899
3900**返回值:**
3901
3902| 类型                        | 说明                                         |
3903| --------------------------- | -------------------------------------------- |
3904| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |
3905
3906**示例:**
3907
3908```ts
3909import { resourceManager } from '@kit.LocalizationKit';
3910
3911const context: Context = getContext(this);
3912// 获取resourceManager资源管理器
3913const resourceMgr: resourceManager.ResourceManager = context.resourceManager;
3914//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。
3915resourceMgr.getRawFd('test.jpg').then((rawFileDescriptor: resourceManager.RawFileDescriptor) => {
3916  const imageSourceApi: image.ImageSource = image.createImageSource(rawFileDescriptor);
3917}).catch((error: BusinessError) => {
3918  console.error(`Failed to get RawFileDescriptor.code is ${error.code}, message is ${error.message}`);
3919})
3920```
3921
3922## image.CreateIncrementalSource<sup>9+</sup>
3923
3924CreateIncrementalSource(buf: ArrayBuffer): ImageSource
3925
3926通过缓冲区以增量的方式创建图片源实例,IncrementalSource不支持读写Exif信息。
3927
3928以增量方式创建的图片源实例ImageSource,仅支持使用以下功能,同步、异步callback、异步Promise均支持。
3929- 获取图片信息:指定序号-[getImageInfo](#getimageinfo)、直接获取-[getImageInfo](#getimageinfo-1)
3930- 获取图片中给定索引处图像的指定属性键的值:[getImageProperty](#getimageproperty11)
3931- 批量获取图片中的指定属性键的值:[getImageProperties](#getimageproperties12)
3932- 更新增量数据:[updateData](#updatedata9)
3933- 创建PixelMap对象:通过图片解码参数创建-[createPixelMap](#createpixelmap7)、通过默认参数创建-[createPixelMap](#createpixelmap7-1) 、通过图片解码参数-[createPixelMap](#createpixelmap7-2)
3934- 释放图片源实例:[release](#release)
3935
3936**系统能力:** SystemCapability.Multimedia.Image.ImageSource
3937
3938**参数:**
3939
3940| 参数名  | 类型        | 必填 | 说明      |
3941| ------- | ------------| ---- | ----------|
3942| buf     | ArrayBuffer | 是   | 增量数据。|
3943
3944**返回值:**
3945
3946| 类型                        | 说明                              |
3947| --------------------------- | --------------------------------- |
3948| [ImageSource](#imagesource) | 返回图片源,失败时返回undefined。 |
3949
3950**示例:**
3951
3952```ts
3953const context: Context = getContext(this)
3954let imageArray = context.resourceManager.getMediaContentSync($r('app.media.startIcon')) // 获取图像资源
3955// 此处'app.media.startIcon'仅作示例,请开发者自行替换,否则imageArray创建失败会导致后续无法正常执行。
3956let splitBuff1 = imageArray.slice(0, imageArray.byteLength / 2)  // 分片
3957let splitBuff2 = imageArray.slice(imageArray.byteLength / 2)
3958const imageSourceIncrementalSApi: image.ImageSource = image.CreateIncrementalSource(new ArrayBuffer(imageArray.byteLength));
3959imageSourceIncrementalSApi.updateData(splitBuff1, false, 0, splitBuff1.byteLength).then(() => {
3960  imageSourceIncrementalSApi.updateData(splitBuff2, true, 0, splitBuff2.byteLength).then(() => {
3961    let pixelMap = imageSourceIncrementalSApi.createPixelMapSync()
3962    let imageInfo = pixelMap.getImageInfoSync()
3963    console.info('Succeeded in creating pixelMap')
3964  }).catch((error : BusinessError) => {
3965    console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`)
3966  })
3967}).catch((error : BusinessError) => {
3968  console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`)
3969})
3970```
3971
3972## image.CreateIncrementalSource<sup>9+</sup>
3973
3974CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource
3975
3976通过缓冲区以增量的方式创建图片源实例,IncrementalSource不支持读写Exif信息。
3977
3978此接口支持的功能与[CreateIncrementalSource(buf: ArrayBuffer): ImageSource](#imagecreateincrementalsource9)所生成的实例支持的功能相同
3979
3980**系统能力:** SystemCapability.Multimedia.Image.ImageSource
3981
3982**参数:**
3983
3984| 参数名  | 类型                            | 必填 | 说明                                 |
3985| ------- | ------------------------------- | ---- | ------------------------------------ |
3986| buf     | ArrayBuffer                     | 是   | 增量数据。                           |
3987| options | [SourceOptions](#sourceoptions9) | 否   | 图片属性,包括图片像素密度、像素格式和图片尺寸。 |
3988
3989**返回值:**
3990
3991| 类型                        | 说明                              |
3992| --------------------------- | --------------------------------- |
3993| [ImageSource](#imagesource) | 返回图片源,失败时返回undefined。 |
3994
3995**示例:**
3996
3997```ts
3998const context: Context = getContext(this)
3999let imageArray = context.resourceManager.getMediaContentSync($r('app.media.startIcon')) // 获取图像资源
4000// 此处'app.media.startIcon'仅作示例,请开发者自行替换,否则imageArray创建失败会导致后续无法正常执行。
4001let splitBuff1 = imageArray.slice(0, imageArray.byteLength / 2)  // 分片
4002let splitBuff2 = imageArray.slice(imageArray.byteLength / 2)
4003let sourceOptions: image.SourceOptions = { sourceDensity: 120};
4004
4005const imageSourceIncrementalSApi: image.ImageSource = image.CreateIncrementalSource(new ArrayBuffer(imageArray.byteLength), sourceOptions);
4006imageSourceIncrementalSApi.updateData(splitBuff1, false, 0, splitBuff1.byteLength).then(() => {
4007  imageSourceIncrementalSApi.updateData(splitBuff2, true, 0, splitBuff2.byteLength).then(() => {
4008    let pixelMap = imageSourceIncrementalSApi.createPixelMapSync()
4009    let imageInfo = pixelMap.getImageInfoSync()
4010    console.info('Succeeded in creating pixelMap')
4011  }).catch((error : BusinessError) => {
4012    console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`)
4013  })
4014}).catch((error : BusinessError) => {
4015  console.error(`Failed to updateData error code is ${error.code}, message is ${error.message}`)
4016})
4017```
4018
4019## ImageSource
4020
4021图片源类,用于获取图片相关信息。在调用ImageSource的方法前,需要先通过[createImageSource](#imagecreateimagesource)构建一个ImageSource实例。
4022
4023### 属性
4024
4025**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4026
4027| 名称             | 类型           | 可读 | 可写 | 说明                                                         |
4028| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
4029| supportedFormats | Array\<string> | 是   | 否   | 支持的图片格式,包括:png,jpeg,bmp,gif,webp,dng,heif<sup>12+</sup>(不同硬件设备支持情况不同)。 |
4030
4031### getImageInfo
4032
4033getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void
4034
4035获取指定序号的图片信息,使用callback形式返回图片信息。
4036
4037**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
4038
4039**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4040
4041**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4042
4043**参数:**
4044
4045| 参数名   | 类型                                   | 必填 | 说明                                     |
4046| -------- | -------------------------------------- | ---- | ---------------------------------------- |
4047| index    | number                                 | 是   | 创建图片源时的序号。                     |
4048| callback | AsyncCallback<[ImageInfo](#imageinfo)> | 是   | 回调函数。当获取图片信息成功,err为undefined,data为获取到的图片信息;否则为错误对象。 |
4049
4050**示例:**
4051
4052```ts
4053import { BusinessError } from '@kit.BasicServicesKit';
4054
4055imageSourceApi.getImageInfo(0, (error: BusinessError, imageInfo: image.ImageInfo) => {
4056  if (error) {
4057    console.error(`Failed to obtain the image information.code is ${error.code}, message is ${error.message}`);
4058  } else {
4059    console.info('Succeeded in obtaining the image information.');
4060  }
4061})
4062```
4063
4064### getImageInfo
4065
4066getImageInfo(callback: AsyncCallback\<ImageInfo>): void
4067
4068获取图片信息,使用callback形式返回图片信息。
4069
4070**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
4071
4072**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4073
4074**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4075
4076**参数:**
4077
4078| 参数名   | 类型                                   | 必填 | 说明                                     |
4079| -------- | -------------------------------------- | ---- | ---------------------------------------- |
4080| callback | AsyncCallback<[ImageInfo](#imageinfo)> | 是   | 回调函数。当获取图片信息成功,err为undefined,data为获取到的图片信息;否则为错误对象。 |
4081
4082**示例:**
4083
4084```ts
4085import { BusinessError } from '@kit.BasicServicesKit';
4086
4087imageSourceApi.getImageInfo((err: BusinessError, imageInfo: image.ImageInfo) => {
4088  if (err) {
4089    console.error(`Failed to obtain the image information.code is ${err.code}, message is ${err.message}`);
4090  } else {
4091    console.info('Succeeded in obtaining the image information.');
4092  }
4093})
4094```
4095
4096### getImageInfo
4097
4098getImageInfo(index?: number): Promise\<ImageInfo>
4099
4100获取图片信息,使用Promise形式返回图片信息。
4101
4102**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
4103
4104**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4105
4106**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4107
4108**参数:**
4109
4110| 参数名| 类型   | 必填 | 说明                                  |
4111| ----- | ------ | ---- | ------------------------------------- |
4112| index | number | 否   | 创建图片源时的序号,不选择时默认为0。 |
4113
4114**返回值:**
4115
4116| 类型                             | 说明                   |
4117| -------------------------------- | ---------------------- |
4118| Promise<[ImageInfo](#imageinfo)> | Promise对象,返回获取到的图片信息。 |
4119
4120**示例:**
4121
4122```ts
4123import { BusinessError } from '@kit.BasicServicesKit';
4124
4125imageSourceApi.getImageInfo(0)
4126  .then((imageInfo: image.ImageInfo) => {
4127    console.info('Succeeded in obtaining the image information.');
4128  }).catch((error: BusinessError) => {
4129    console.error(`Failed to obtain the image information.code is ${error.code}, message is ${error.message}`);
4130  })
4131```
4132
4133### getImageInfoSync<sup>12+</sup>
4134
4135getImageInfoSync(index?: number): ImageInfo
4136
4137获取指定序号的图片信息,使用同步形式返回图片信息。
4138
4139**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4140
4141**参数:**
4142
4143| 参数名| 类型   | 必填 | 说明                                  |
4144| ----- | ------ | ---- | ------------------------------------- |
4145| index | number | 否   | 创建图片源时的序号,不选择时默认为0。 |
4146
4147**返回值:**
4148
4149| 类型                             | 说明                   |
4150| -------------------------------- | ---------------------- |
4151| [ImageInfo](#imageinfo) | 同步返回获取到的图片信息。 |
4152
4153**示例:**
4154
4155```ts
4156import { image } from '@kit.ImageKit';
4157
4158const context: Context = getContext();
4159//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。
4160let filePath: string = context.filesDir + "/test.jpg";
4161let imageSource = image.createImageSource(filePath);
4162let imageInfo = imageSource.getImageInfoSync(0);
4163if (imageInfo == undefined) {
4164  console.error('Failed to obtain the image information.');
4165} else {
4166  console.info('Succeeded in obtaining the image information.');
4167  console.info('imageInfo.size.height:' + imageInfo.size.height);
4168  console.info('imageInfo.size.width:' + imageInfo.size.width);
4169}
4170```
4171
4172### getImageProperty<sup>11+</sup>
4173
4174getImageProperty(key:PropertyKey, options?: ImagePropertyOptions): Promise\<string>
4175
4176获取图片中给定索引处图像的指定属性键的值,用Promise形式返回结果,仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。
4177
4178**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4179
4180**参数:**
4181
4182| 参数名  | 类型                                                 | 必填 | 说明                                 |
4183| ------- | ---------------------------------------------------- | ---- | ------------------------------------ |
4184| key     | [PropertyKey](#propertykey7)                                               | 是   | 图片属性名。                         |
4185| options | [ImagePropertyOptions](#imagepropertyoptions11) | 否   | 图片属性,包括图片序号与默认属性值。 |
4186
4187**返回值:**
4188
4189| 类型             | 说明                                                              |
4190| ---------------- | ----------------------------------------------------------------- |
4191| Promise\<string> | Promise对象,返回图片属性值,如获取失败则返回属性默认值。 |
4192
4193**错误码:**
4194
4195以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
4196
4197| 错误码ID | 错误信息 |
4198| ------- | --------------------------------------------|
4199| 401  | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed;              |
4200| 62980096 | The operation failed.             |
4201| 62980103 | The image data is not supported.         |
4202| 62980110 | The image source data is incorrect.      |
4203| 62980111 | The image source data is incomplete. |
4204| 62980112 | The image format does not match.       |
4205| 62980113 | Unknown image format.        |
4206| 62980115 | Invalid image parameter.      |
4207| 62980116| Failed to decode the image.            |
4208| 62980118 | Failed to create the image plugin.   |
4209| 62980122 | Failed to decode the image header.   |
4210| 62980123| Images in EXIF format are not supported.             |
4211| 62980135| The EXIF value is invalid.             |
4212
4213**示例:**
4214
4215```ts
4216import { BusinessError } from '@kit.BasicServicesKit';
4217
4218let options: image.ImagePropertyOptions = { index: 0, defaultValue: '9999' }
4219imageSourceApi.getImageProperty(image.PropertyKey.BITS_PER_SAMPLE, options)
4220.then((data: string) => {
4221  console.info('Succeeded in getting the value of the specified attribute key of the image.');
4222}).catch((error: BusinessError) => {
4223  console.error('Failed to get the value of the specified attribute key of the image.');
4224})
4225```
4226
4227### getImageProperty<sup>(deprecated)</sup>
4228
4229getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\<string>
4230
4231获取图片中给定索引处图像的指定属性键的值,用Promise形式返回结果,仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。
4232
4233> **说明:**
4234>
4235> 从API version 11开始不再维护,建议使用[getImageProperty](#getimageproperty11)代替。
4236
4237**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4238
4239**参数:**
4240
4241| 参数名  | 类型                                                 | 必填 | 说明                                 |
4242| ------- | ---------------------------------------------------- | ---- | ------------------------------------ |
4243| key     | string                                               | 是   | 图片属性名。                         |
4244| options | [GetImagePropertyOptions](#getimagepropertyoptionsdeprecated) | 否   | 图片属性,包括图片序号与默认属性值。 |
4245
4246**返回值:**
4247
4248| 类型             | 说明                                                              |
4249| ---------------- | ----------------------------------------------------------------- |
4250| Promise\<string> | Promise对象,返回图片属性值,如获取失败则返回属性默认值。 |
4251
4252**示例:**
4253
4254```ts
4255import { BusinessError } from '@kit.BasicServicesKit';
4256
4257imageSourceApi.getImageProperty("BitsPerSample")
4258  .then((data: string) => {
4259    console.info('Succeeded in getting the value of the specified attribute key of the image.');
4260  }).catch((error: BusinessError) => {
4261    console.error('Failed to get the value of the specified attribute key of the image.');
4262  })
4263```
4264
4265### getImageProperty<sup>(deprecated)</sup>
4266
4267getImageProperty(key:string, callback: AsyncCallback\<string>): void
4268
4269获取图片中给定索引处图像的指定属性键的值,用callback形式返回结果,仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。
4270
4271> **说明:**
4272>
4273> 从API version 11开始不再维护,建议使用[getImageProperty](#getimageproperty11)代替。
4274
4275**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4276
4277**参数:**
4278
4279| 参数名   | 类型                   | 必填 | 说明                                                         |
4280| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
4281| key      | string                 | 是   | 图片属性名。                                                 |
4282| callback | AsyncCallback\<string> | 是   | 回调函数,当获取图片属性值成功,err为undefined,data为获取到的图片属性值;否则为错误对象。 |
4283
4284**示例:**
4285
4286```ts
4287import { BusinessError } from '@kit.BasicServicesKit';
4288
4289imageSourceApi.getImageProperty("BitsPerSample", (error: BusinessError, data: string) => {
4290  if (error) {
4291    console.error('Failed to get the value of the specified attribute key of the image.');
4292  } else {
4293    console.info('Succeeded in getting the value of the specified attribute key of the image.');
4294  }
4295})
4296```
4297
4298### getImageProperty<sup>(deprecated)</sup>
4299
4300getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCallback\<string>): void
4301
4302获取图片指定属性键的值,callback形式返回结果,仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。
4303
4304> **说明:**
4305>
4306> 从API version 11开始不再维护,建议使用[getImageProperty](#getimageproperty11)代替。
4307
4308**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4309
4310**参数:**
4311
4312| 参数名   | 类型                                                 | 必填 | 说明                                                          |
4313| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------- |
4314| key      | string                                               | 是   | 图片属性名。                                                  |
4315| options  | [GetImagePropertyOptions](#getimagepropertyoptionsdeprecated) | 是   | 图片属性,包括图片序号与默认属性值。                          |
4316| callback | AsyncCallback\<string>                               | 是   | 回调函数,当获取图片属性值成功,err为undefined,data为获取到的图片属性值;否则为错误对象。|
4317
4318**示例:**
4319
4320```ts
4321import { BusinessError } from '@kit.BasicServicesKit';
4322
4323let property: image.GetImagePropertyOptions = { index: 0, defaultValue: '9999' }
4324imageSourceApi.getImageProperty("BitsPerSample", property, (error: BusinessError, data: string) => {
4325  if (error) {
4326    console.error('Failed to get the value of the specified attribute key of the image.');
4327  } else {
4328    console.info('Succeeded in getting the value of the specified attribute key of the image.');
4329  }
4330})
4331```
4332
4333### getImageProperties<sup>12+</sup>
4334
4335getImageProperties(key: Array&#60;PropertyKey&#62;): Promise<Record<PropertyKey, string|null>>
4336
4337批量获取图片中的指定属性键的值,用Promise形式返回结果。仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。
4338
4339**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4340
4341**参数:**
4342
4343| 参数名  | 类型                                                 | 必填 | 说明                                 |
4344| ------- | ---------------------------------------------------- | ---- | ------------------------------------ |
4345| key     | Array\<[PropertyKey](#propertykey7)>                                 | 是   | 图片属性名的数组。                         |
4346
4347**返回值:**
4348
4349| 类型             | 说明                                                              |
4350| ---------------- | ----------------------------------------------------------------- |
4351| Promise\<Record<[PropertyKey](#propertykey7), string \| null>> | Promise对象,返回图片属性值,如获取失败则返回null。 |
4352
4353**错误码:**
4354
4355以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
4356
4357| 错误码ID | 错误信息 |
4358| ------- | --------------------------------------------|
4359| 401  | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed;     |
4360| 62980096| The operation failed.             |
4361| 62980110| The image source data is incorrect.            |
4362| 62980113| Unknown image format.            |
4363| 62980116| Failed to decode the image.            |
4364
4365**示例:**
4366
4367```ts
4368import { image } from '@kit.ImageKit';
4369import { BusinessError } from '@kit.BasicServicesKit';
4370
4371let key = [image.PropertyKey.IMAGE_WIDTH, image.PropertyKey.IMAGE_LENGTH];
4372imageSourceApi.getImageProperties(key).then((data) => {
4373  console.info(JSON.stringify(data));
4374}).catch((err: BusinessError) => {
4375  console.error(JSON.stringify(err));
4376});
4377```
4378
4379### modifyImageProperty<sup>11+</sup>
4380
4381modifyImageProperty(key: PropertyKey, value: string): Promise\<void>
4382
4383通过指定的键修改图片属性的值,使用Promise形式返回结果,仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。
4384
4385> **说明:**
4386>
4387> 调用modifyImageProperty修改属性会改变属性字节长度,使用buffer创建的ImageSource调用modifyImageProperty会导致buffer内容覆盖,目前buffer创建的ImageSource不支持调用此接口,请改用fd或path创建的ImageSource。
4388
4389**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4390
4391**参数:**
4392
4393| 参数名  | 类型   | 必填 | 说明         |
4394| ------- | ------ | ---- | ------------ |
4395| key     | [PropertyKey](#propertykey7)   | 是   | 图片属性名。 |
4396| value   | string | 是   | 属性值。     |
4397
4398**返回值:**
4399
4400| 类型           | 说明                        |
4401| -------------- | --------------------------- |
4402| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
4403
4404**错误码:**
4405
4406以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
4407
4408| 错误码ID | 错误信息 |
4409| ------- | --------------------------------------------|
4410| 401  | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;    |
4411| 62980123| The image does not support EXIF decoding.             |
4412| 62980133| The EXIF data is out of range.             |
4413| 62980135| The EXIF value is invalid.             |
4414| 62980146| The EXIF data failed to be written to the file.        |
4415
4416**示例:**
4417
4418```ts
4419import { BusinessError } from '@kit.BasicServicesKit';
4420
4421imageSourceApi.modifyImageProperty(image.PropertyKey.IMAGE_WIDTH, "120").then(() => {
4422  imageSourceApi.getImageProperty(image.PropertyKey.IMAGE_WIDTH).then((width: string) => {
4423    console.info(`ImageWidth is :${width}`);
4424  }).catch((error: BusinessError) => {
4425    console.error('Failed to get the Image Width.');
4426  })
4427}).catch((error: BusinessError) => {
4428  console.error('Failed to modify the Image Width');
4429})
4430```
4431
4432### modifyImageProperty<sup>(deprecated)</sup>
4433
4434modifyImageProperty(key: string, value: string): Promise\<void>
4435
4436通过指定的键修改图片属性的值,使用Promise形式返回结果,仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。
4437
4438> **说明:**
4439>
4440> 调用modifyImageProperty修改属性会改变属性字节长度,使用buffer创建的ImageSource调用modifyImageProperty会导致buffer内容覆盖,目前buffer创建的ImageSource不支持调用此接口,请改用fd或path创建的ImageSource。
4441>
4442> 从API version 11开始不再维护,建议使用[modifyImageProperty](#modifyimageproperty11)代替。
4443
4444**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4445
4446**参数:**
4447
4448| 参数名  | 类型   | 必填 | 说明         |
4449| ------- | ------ | ---- | ------------ |
4450| key     | string | 是   | 图片属性名。 |
4451| value   | string | 是   | 属性值。     |
4452
4453**返回值:**
4454
4455| 类型           | 说明                        |
4456| -------------- | --------------------------- |
4457| Promise\<void> |  Promise对象。无返回结果的Promise对象。|
4458
4459**示例:**
4460
4461```ts
4462import { BusinessError } from '@kit.BasicServicesKit';
4463
4464imageSourceApi.modifyImageProperty("ImageWidth", "120").then(() => {
4465  imageSourceApi.getImageProperty("ImageWidth").then((width: string) => {
4466    console.info(`ImageWidth is :${width}`);
4467  }).catch((error: BusinessError) => {
4468    console.error('Failed to get the Image Width.');
4469  })
4470}).catch((error: BusinessError) => {
4471  console.error('Failed to modify the Image Width');
4472})
4473```
4474
4475### modifyImageProperty<sup>(deprecated)</sup>
4476
4477modifyImageProperty(key: string, value: string, callback: AsyncCallback\<void>): void
4478
4479通过指定的键修改图片属性的值,callback形式返回结果,仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。
4480
4481> **说明:**
4482>
4483> 调用modifyImageProperty修改属性会改变属性字节长度,使用buffer创建的ImageSource调用modifyImageProperty会导致buffer内容覆盖,目前buffer创建的ImageSource不支持调用此接口,请改用fd或path创建的ImageSource。
4484>
4485>从API version 11开始不再维护,建议使用[modifyImageProperty](#modifyimageproperty11)代替。
4486
4487**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4488
4489**参数:**
4490
4491| 参数名   | 类型                | 必填 | 说明                           |
4492| -------- | ------------------- | ---- | ------------------------------ |
4493| key      | string              | 是   | 图片属性名。                   |
4494| value    | string              | 是   | 属性值。                       |
4495| callback | AsyncCallback\<void> | 是   | 回调函数,当修改图片属性值成功,err为undefined,否则为错误对象。 |
4496
4497**示例:**
4498
4499```ts
4500import { BusinessError } from '@kit.BasicServicesKit';
4501
4502imageSourceApi.modifyImageProperty("ImageWidth", "120", (err: BusinessError) => {
4503  if (err) {
4504    console.error(`Failed to modify the Image Width.code is ${err.code}, message is ${err.message}`);
4505  } else {
4506    console.info('Succeeded in modifying the Image Width.');
4507  }
4508})
4509```
4510
4511### modifyImageProperties<sup>12+</sup>
4512
4513modifyImageProperties(records: Record<PropertyKey, string|null>): Promise\<void>
4514
4515批量通过指定的键修改图片属性的值,使用Promise形式返回结果。仅支持JPEG、PNG和HEIF<sup>12+</sup>(不同硬件设备支持情况不同)文件,且需要包含exif信息。其中可以通过supportedFormats属性查询是否支持HEIF格式的exif读写。
4516
4517> **说明:**
4518>
4519> 调用modifyImageProperties修改属性会改变属性字节长度,使用buffer创建的ImageSource调用modifyImageProperties会导致buffer内容覆盖,目前buffer创建的ImageSource不支持调用此接口,请改用fd或path创建的ImageSource。
4520>
4521
4522**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4523
4524**参数:**
4525
4526| 参数名  | 类型   | 必填 | 说明         |
4527| ------- | ------ | ---- | ------------ |
4528| records     | Record<[PropertyKey](#propertykey7), string \| null>   | 是   | 包含图片属性名和属性值的数组。 |
4529
4530**返回值:**
4531
4532| 类型           | 说明                        |
4533| -------------- | --------------------------- |
4534| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
4535
4536**错误码:**
4537
4538以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
4539
4540| 错误码ID | 错误信息 |
4541| ------- | --------------------------------------------|
4542| 401  | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed;      |
4543| 62980123| The image does not support EXIF decoding.             |
4544| 62980133| The EXIF data is out of range.             |
4545| 62980135| The EXIF value is invalid.             |
4546| 62980146| The EXIF data failed to be written to the file.             |
4547
4548**示例:**
4549
4550```ts
4551import { image } from '@kit.ImageKit';
4552import { BusinessError } from '@kit.BasicServicesKit';
4553
4554let keyValues: Record<PropertyKey, string|null> = {
4555    [image.PropertyKey.IMAGE_WIDTH] : "1024",
4556    [image.PropertyKey.IMAGE_LENGTH] : "1024"
4557};
4558let checkKey = [image.PropertyKey.IMAGE_WIDTH, image.PropertyKey.IMAGE_LENGTH];
4559imageSourceApi.modifyImageProperties(keyValues).then(() => {
4560  imageSourceApi.getImageProperties(checkKey).then((data) => {
4561    console.info(JSON.stringify(data));
4562  }).catch((err: BusinessError) => {
4563    console.error(JSON.stringify(err));
4564  });
4565}).catch((err: BusinessError) => {
4566  console.error(JSON.stringify(err));
4567});
4568```
4569
4570### updateData<sup>9+</sup>
4571
4572updateData(buf: ArrayBuffer, isFinished: boolean, offset: number, length: number): Promise\<void>
4573
4574更新增量数据,使用Promise形式返回结果。
4575
4576**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4577
4578**参数:**
4579
4580| 参数名     | 类型        | 必填 | 说明         |
4581| ---------- | ----------- | ---- | ------------ |
4582| buf        | ArrayBuffer | 是   | 增量数据。   |
4583| isFinished | boolean     | 是   | 是否更新完。 |
4584| offset      | number      | 是   | 偏移量。     |
4585| length     | number      | 是   | 数组长。     |
4586
4587**返回值:**
4588
4589| 类型           | 说明                       |
4590| -------------- | -------------------------- |
4591| Promise\<void> | Promise对象。无返回结果的Promise对象。|
4592
4593**示例:**
4594
4595```ts
4596import { BusinessError } from '@kit.BasicServicesKit';
4597
4598const array: ArrayBuffer = new ArrayBuffer(100);
4599imageSourceApi.updateData(array, false, 0, 10).then(() => {
4600  console.info('Succeeded in updating data.');
4601}).catch((err: BusinessError) => {
4602  console.error(`Failed to update data.code is ${err.code},message is ${err.message}`);
4603})
4604```
4605
4606
4607### updateData<sup>9+</sup>
4608
4609updateData(buf: ArrayBuffer, isFinished: boolean, offset: number, length: number, callback: AsyncCallback\<void>): void
4610
4611更新增量数据,callback形式返回结果。
4612
4613**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4614
4615**参数:**
4616
4617| 参数名     | 类型                | 必填 | 说明                 |
4618| ---------- | ------------------- | ---- | -------------------- |
4619| buf        | ArrayBuffer         | 是   | 增量数据。           |
4620| isFinished | boolean             | 是   | 是否更新完。         |
4621| offset      | number              | 是   | 偏移量。             |
4622| length     | number              | 是   | 数组长。             |
4623| callback   | AsyncCallback\<void> | 是   |  回调函数,当更新增量数据成功,err为undefined,否则为错误对象。 |
4624
4625**示例:**
4626
4627```ts
4628import { BusinessError } from '@kit.BasicServicesKit';
4629
4630const array: ArrayBuffer = new ArrayBuffer(100);
4631imageSourceApi.updateData(array, false, 0, 10, (err: BusinessError) => {
4632  if (err) {
4633    console.error(`Failed to update data.code is ${err.code},message is ${err.message}`);
4634  } else {
4635    console.info('Succeeded in updating data.');
4636  }
4637})
4638```
4639
4640### createPicture<sup>13+</sup>
4641
4642createPicture(options?: DecodingOptionsForPicture): Promise\<Picture>
4643
4644通过图片解码参数创建Picture对象,使用Promise形式返回。
4645
4646**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4647
4648**参数:**
4649
4650| 参数名  | 类型                                                   | 必填 | 说明       |
4651| ------- | ------------------------------------------------------ | ---- | ---------- |
4652| options | [DecodingOptionsForPicture](#decodingoptionsforpicture13) | 否   | 解码参数。 |
4653
4654**返回值:**
4655
4656| 类型                         | 说明                       |
4657| ---------------------------- | -------------------------- |
4658| Promise\<[Picture](#picture13)> | Promise对象,返回Picture。 |
4659
4660**错误码:**
4661
4662以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
4663
4664| 错误码ID | 错误信息                                                     |
4665| -------- | ------------------------------------------------------------ |
4666| 401      | Parameter error.Possible causes: 1.Mandatory parameters are left unspecified.2.Incorrect parameter types; 3.Parameter verification failed. |
4667| 7700301  | Decode failed.                                               |
4668
4669**示例:**
4670
4671```ts
4672import { image } from '@kit.ImageKit';
4673
4674async function CreatePicture() {
4675  let options: image.DecodingOptionsForPicture = {
4676    desiredAuxiliaryPictures: [image.AuxiliaryPictureType.GAINMAP] //GAINMAP为需要解码的辅助图类型
4677  };
4678  let pictureObj: image.Picture = await imageSourceApi.createPicture(options);
4679  if (pictureObj != null) {
4680    console.info('Create picture succeeded');
4681  } else {
4682    console.info('Create picture failed');
4683  }
4684}
4685```
4686
4687### createPixelMap<sup>7+</sup>
4688
4689createPixelMap(options?: DecodingOptions): Promise\<PixelMap>
4690
4691通过图片解码参数创建PixelMap对象。
4692
4693**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
4694
4695**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4696
4697**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4698
4699**参数:**
4700
4701| 参数名  | 类型                                 | 必填 | 说明       |
4702| ------- | ------------------------------------ | ---- | ---------- |
4703| options | [DecodingOptions](#decodingoptions7) | 否   | 解码参数。 |
4704
4705**返回值:**
4706
4707| 类型                             | 说明                  |
4708| -------------------------------- | --------------------- |
4709| Promise\<[PixelMap](#pixelmap7)> | Promise对象,返回PixelMap。 |
4710
4711**示例:**
4712
4713```ts
4714import { BusinessError } from '@kit.BasicServicesKit';
4715
4716imageSourceApi.createPixelMap().then((pixelMap: image.PixelMap) => {
4717  console.info('Succeeded in creating pixelMap object through image decoding parameters.');
4718}).catch((error: BusinessError) => {
4719  console.error('Failed to create pixelMap object through image decoding parameters.');
4720})
4721```
4722
4723### createPixelMap<sup>7+</sup>
4724
4725createPixelMap(callback: AsyncCallback\<PixelMap>): void
4726
4727通过默认参数创建PixelMap对象,使用callback形式返回结果。
4728
4729**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
4730
4731**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4732
4733**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4734
4735**参数:**
4736
4737| 参数名     | 类型                                  | 必填 | 说明                       |
4738| -------- | ------------------------------------- | ---- | -------------------------- |
4739| callback | AsyncCallback<[PixelMap](#pixelmap7)> | 是   | 回调函数,当创建PixelMap对象成功,err为undefined,data为获取到的PixelMap对象;否则为错误对象。 |
4740
4741**示例:**
4742
4743```ts
4744import { BusinessError } from '@kit.BasicServicesKit';
4745
4746imageSourceApi.createPixelMap((err: BusinessError, pixelMap: image.PixelMap) => {
4747  if (err) {
4748    console.error(`Failed to create pixelMap.code is ${err.code},message is ${err.message}`);
4749  } else {
4750    console.info('Succeeded in creating pixelMap object.');
4751  }
4752})
4753```
4754
4755### createPixelMap<sup>7+</sup>
4756
4757createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): void
4758
4759通过图片解码参数创建PixelMap对象。
4760
4761**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
4762
4763**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4764
4765**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4766
4767**参数:**
4768
4769| 参数名   | 类型                                  | 必填 | 说明                       |
4770| -------- | ------------------------------------- | ---- | -------------------------- |
4771| options  | [DecodingOptions](#decodingoptions7)  | 是   | 解码参数。                 |
4772| callback | AsyncCallback<[PixelMap](#pixelmap7)> | 是   | 回调函数,当创建PixelMap对象成功,err为undefined,data为获取到的PixelMap对象;否则为错误对象。 |
4773
4774**示例:**
4775
4776```ts
4777import { BusinessError } from '@kit.BasicServicesKit';
4778
4779let decodingOptions: image.DecodingOptions = {
4780  sampleSize: 1,
4781  editable: true,
4782  desiredSize: { width: 1, height: 2 },
4783  rotate: 10,
4784  desiredPixelFormat: image.PixelMapFormat.RGBA_8888,
4785  desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 },
4786  index: 0
4787};
4788imageSourceApi.createPixelMap(decodingOptions, (err: BusinessError, pixelMap: image.PixelMap) => {
4789  if (err) {
4790    console.error(`Failed to create pixelMap.code is ${err.code},message is ${err.message}`);
4791  } else {
4792    console.info('Succeeded in creating pixelMap object.');
4793  }
4794})
4795```
4796
4797### createPixelMapSync<sup>12+</sup>
4798
4799createPixelMapSync(options?: DecodingOptions): PixelMap
4800
4801通过图片解码参数同步创建PixelMap对象。
4802
4803**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4804
4805**参数:**
4806
4807| 参数名   | 类型                                  | 必填 | 说明                       |
4808| -------- | ------------------------------------- | ---- | -------------------------- |
4809| options  | [DecodingOptions](#decodingoptions7)  | 否   | 解码参数。                 |
4810
4811**返回值:**
4812
4813| 类型                             | 说明                  |
4814| -------------------------------- | --------------------- |
4815| [PixelMap](#pixelmap7) | 用于同步返回创建结果。 |
4816
4817**示例:**
4818
4819```ts
4820import { image } from '@kit.ImageKit';
4821
4822const context: Context = getContext();
4823//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。
4824let filePath: string = context.filesDir + "/test.jpg";
4825let imageSource = image.createImageSource(filePath);
4826let decodingOptions: image.DecodingOptions = {
4827  sampleSize: 1,
4828  editable: true,
4829  desiredSize: { width: 1, height: 2 },
4830  rotate: 10,
4831  desiredPixelFormat: image.PixelMapFormat.RGBA_8888,
4832  desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 },
4833  index: 0
4834};
4835let pixelmap = imageSource.createPixelMapSync(decodingOptions);
4836if (pixelmap != undefined) {
4837  console.info('Succeeded in creating pixelMap object.');
4838} else {
4839  console.info('Failed to create pixelMap.');
4840}
4841```
4842
4843### createPixelMapList<sup>10+</sup>
4844
4845createPixelMapList(options?: DecodingOptions): Promise<Array\<PixelMap>>
4846
4847通过图片解码参数创建PixelMap数组。针对动图如Gif、Webp,此接口返回每帧图片数据;针对静态图,此接口返回唯一的一帧图片数据。
4848
4849**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4850
4851**参数:**
4852
4853| 参数名   | 类型                                  | 必填 | 说明                       |
4854| -------- | ------------------------------------- | ---- | -------------------------- |
4855| options  | [DecodingOptions](#decodingoptions7)  | 否   | 解码参数。                 |
4856
4857**返回值:**
4858
4859| 类型                             | 说明                  |
4860| -------------------------------- | --------------------- |
4861| Promise<Array<[PixelMap](#pixelmap7)>> | 异步返回PixeMap数组。 |
4862
4863**错误码:**
4864
4865以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
4866
4867| 错误码ID | 错误信息 |
4868| ------- | --------------------------------------------|
4869| 62980096| The operation failed.              |
4870| 62980099 | The shared memory data is abnormal. |
4871| 62980101 | The image data is abnormal. |
4872| 62980103| The image data is not supported.             |
4873| 62980106 | The image is too large. |
4874| 62980109 | Failed to crop the image. |
4875| 62980110| The image source data is incorrect.             |
4876| 62980111| The image source data is incomplete.           |
4877| 62980112 | The image format does not match. |
4878| 62980113 | Unknown image format. |
4879| 62980115 | Invalid image parameter. |
4880| 62980116 | Failed to decode the image. |
4881| 62980118| Failed to create the image plugin.             |
4882| 62980122 | Failed to decode the image header. |
4883| 62980137 | Invalid media operation. |
4884| 62980173 | The DMA memory does not exist. |
4885| 62980174 | The DMA memory data is abnormal. |
4886
4887**示例:**
4888
4889```ts
4890import { BusinessError } from '@kit.BasicServicesKit';
4891
4892let decodeOpts: image.DecodingOptions = {
4893  sampleSize: 1,
4894  editable: true,
4895  desiredSize: { width: 198, height: 202 },
4896  rotate: 0,
4897  desiredPixelFormat: image.PixelMapFormat.RGBA_8888,
4898  index: 0,
4899};
4900imageSourceApi.createPixelMapList(decodeOpts).then((pixelMapList: Array<image.PixelMap>) => {
4901  console.info('Succeeded in creating pixelMapList object.');
4902}).catch((err: BusinessError) => {
4903  console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`);
4904})
4905```
4906
4907### createPixelMapList<sup>10+</sup>
4908
4909createPixelMapList(callback: AsyncCallback<Array\<PixelMap>>): void
4910
4911通过默认参数创建PixelMap数组,使用callback形式返回结果。针对动图如Gif、Webp,此接口返回每帧图片数据;针对静态图,此接口返回唯一的一帧图片数据。
4912
4913**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4914
4915**参数:**
4916
4917| 参数名     | 类型                                  | 必填 | 说明                       |
4918| -------- | ------------------------------------- | ---- | -------------------------- |
4919| callback | AsyncCallback<Array<[PixelMap](#pixelmap7)>> | 是   | 回调函数,当创建PixelMap对象数组成功,err为undefined,data为获取到的PixelMap对象数组;否则为错误对象。  |
4920
4921**错误码:**
4922
4923以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
4924
4925| 错误码ID | 错误信息 |
4926| ------- | --------------------------------------------|
4927| 62980096 | The operation failed.             |
4928| 62980099 | The shared memory data is abnormal.  |
4929| 62980101 | The image data is abnormal.          |
4930| 62980103 | The image data is not supported.         |
4931| 62980106 | The image is too large.              |
4932| 62980109 | Failed to crop the image.            |
4933| 62980110 | The image source data is incorrect.      |
4934| 62980111 | The image source data is incomplete. |
4935| 62980112 | The image format does not match.       |
4936| 62980113 | Unknown image format.        |
4937| 62980115 | Invalid image parameter.      |
4938| 62980116 | Failed to decode the image.         |
4939| 62980118 | Failed to create the image plugin.   |
4940| 62980122 | Failed to decode the image header.   |
4941| 62980137 | Invalid media operation.     |
4942| 62980173 | The DMA memory does not exist.        |
4943| 62980174 | The DMA memory data is abnormal.    |
4944
4945**示例:**
4946
4947```ts
4948import { BusinessError } from '@kit.BasicServicesKit';
4949
4950imageSourceApi.createPixelMapList((err: BusinessError, pixelMapList: Array<image.PixelMap>) => {
4951  if (err) {
4952    console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`);
4953  } else {
4954    console.info('Succeeded in creating pixelMapList object.');
4955  }
4956})
4957```
4958
4959### createPixelMapList<sup>10+</sup>
4960
4961createPixelMapList(options: DecodingOptions, callback: AsyncCallback<Array\<PixelMap>>): void
4962
4963通过图片解码参数创建PixelMap数组,使用callback形式返回结果。针对动图如Gif、Webp,此接口返回每帧图片数据;针对静态图,此接口返回唯一的一帧图片数据。
4964
4965**系统能力:** SystemCapability.Multimedia.Image.ImageSource
4966
4967**参数:**
4968
4969| 参数名   | 类型                 | 必填 | 说明                               |
4970| -------- | -------------------- | ---- | ---------------------------------- |
4971| options | [DecodingOptions](#decodingoptions7) | 是 | 解码参数。 |
4972| callback | AsyncCallback<Array<[PixelMap](#pixelmap7)>> | 是   | 回调函数,当创建PixelMap对象数组成功,err为undefined,data为获取到的PixelMap对象数组;否则为错误对象。  |
4973
4974**错误码:**
4975
4976以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
4977
4978| 错误码ID | 错误信息 |
4979| ------- | --------------------------------------------|
4980| 62980096 | The operation failed.            |
4981| 62980099 | The shared memory data is abnormal.  |
4982| 62980101 | The image data is abnormal.         |
4983| 62980103 | The image data is not supported.        |
4984| 62980106 | The image is too large.              |
4985| 62980109 | Failed to crop the image.           |
4986| 62980110 | The image source data is incorrect.      |
4987| 62980111 | The image source data is incomplete. |
4988| 62980112 | The image format does not match.        |
4989| 62980113 | Unknown image format.         |
4990| 62980115 | Invalid image parameter.      |
4991| 62980116 | Failed to decode the image.         |
4992| 62980118 | Failed to create the image plugin.  |
4993| 62980122 | Failed to decode the image header.   |
4994| 62980137 | Invalid media operation.      |
4995| 62980173 | The DMA memory does not exist.         |
4996| 62980174 | The DMA memory data is abnormal.     |
4997
4998**示例:**
4999
5000```ts
5001import { BusinessError } from '@kit.BasicServicesKit';
5002
5003let decodeOpts: image.DecodingOptions = {
5004  sampleSize: 1,
5005  editable: true,
5006  desiredSize: { width: 198, height: 202 },
5007  rotate: 0,
5008  desiredPixelFormat: image.PixelMapFormat.RGBA_8888,
5009  index: 0,
5010};
5011imageSourceApi.createPixelMapList(decodeOpts, (err: BusinessError, pixelMapList: Array<image.PixelMap>) => {
5012  if (err) {
5013    console.error(`Failed to create pixelMapList object.code is ${err.code},message is ${err.message}`);
5014  } else {
5015    console.info('Succeeded in creating pixelMapList object.');
5016  }
5017})
5018```
5019
5020### getDelayTimeList<sup>10+</sup>
5021
5022getDelayTimeList(callback: AsyncCallback<Array\<number>>): void
5023
5024获取图像延迟时间数组,使用callback形式返回结果。此接口仅用于gif图片和webp图片。
5025
5026**系统能力:** SystemCapability.Multimedia.Image.ImageSource
5027
5028**参数:**
5029
5030| 参数名   | 类型                 | 必填 | 说明                               |
5031| -------- | -------------------- | ---- | ---------------------------------- |
5032| callback | AsyncCallback<Array\<number>> | 是   | 回调函数,当获取图像延迟时间数组成功,err为undefined,data为获取到的图像延时时间数组;否则为错误对象。 |
5033
5034**错误码:**
5035
5036以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5037
5038| 错误码ID | 错误信息 |
5039| ------- | --------------------------------------------|
5040| 62980096| The operation failed.              |
5041| 62980110| The image source data is incorrect.             |
5042| 62980111| The image source data is incomplete.            |
5043| 62980112 | The image format does not match. |
5044| 62980113| Unknown image format. |
5045| 62980115 | Invalid image parameter. |
5046| 62980116| Failed to decode the image. |
5047| 62980118| Failed to create the image plugin. |
5048| 62980122| Failed to decode the image header. |
5049| 62980137 | Invalid media operation. |
5050| 62980149 | Invalid MIME type for the image source. |
5051
5052**示例:**
5053
5054```ts
5055import { BusinessError } from '@kit.BasicServicesKit';
5056
5057imageSourceApi.getDelayTimeList((err: BusinessError, delayTimes: Array<number>) => {
5058  if (err) {
5059    console.error(`Failed to get delayTimes object.code is ${err.code},message is ${err.message}`);
5060  } else {
5061    console.info('Succeeded in getting delayTimes object.');
5062  }
5063})
5064```
5065
5066### getDelayTimeList<sup>10+</sup>
5067
5068getDelayTimeList(): Promise<Array\<number>>
5069
5070获取图像延迟时间数组,使用Promise形式返回结果。此接口仅用于gif图片和webp图片。
5071
5072**系统能力:** SystemCapability.Multimedia.Image.ImageSource
5073
5074**返回值:**
5075
5076| 类型           | 说明                        |
5077| -------------- | --------------------------- |
5078| Promise<Array\<number>> | Promise对象,返回延迟时间数组。 |
5079
5080**错误码:**
5081
5082以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5083
5084| 错误码ID | 错误信息 |
5085| ------- | --------------------------------------------|
5086| 62980096 | The operation failed.             |
5087| 62980110 | The image source data is incorrect.      |
5088| 62980111 | The image source data is incomplete. |
5089| 62980112 | The image format does not match.        |
5090| 62980113 | Unknown image format.         |
5091| 62980115 | Invalid image parameter.      |
5092| 62980116 | Failed to decode the image.          |
5093| 62980118 | Failed to create the image plugin.  |
5094| 62980122 | Failed to decode the image header.   |
5095| 62980137 | Invalid media operation.      |
5096| 62980149 | Invalid MIME type for the image source.      |
5097
5098**示例:**
5099
5100```ts
5101import { BusinessError } from '@kit.BasicServicesKit';
5102
5103imageSourceApi.getDelayTimeList().then((delayTimes: Array<number>) => {
5104  console.info('Succeeded in getting delayTimes object.');
5105}).catch((err: BusinessError) => {
5106  console.error(`Failed to get delayTimes object.code is ${err.code},message is ${err.message}`);
5107})
5108```
5109
5110### getFrameCount<sup>10+</sup>
5111
5112getFrameCount(callback: AsyncCallback\<number>): void
5113
5114获取图像帧数,使用callback形式返回结果。
5115
5116**系统能力:** SystemCapability.Multimedia.Image.ImageSource
5117
5118**参数:**
5119
5120| 参数名   | 类型                 | 必填 | 说明                               |
5121| -------- | -------------------- | ---- | ---------------------------------- |
5122| callback | AsyncCallback\<number> | 是   | 回调函数,当获取图像帧数成功,err为undefined,data为获取到的图像帧数;否则为错误对象。 |
5123
5124**错误码:**
5125
5126以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5127
5128| 错误码ID | 错误信息 |
5129| ------- | --------------------------------------------|
5130| 62980096| The operation failed.              |
5131| 62980110| The image source data is incorrect. |
5132| 62980111| The image source data is incomplete. |
5133| 62980112| The image format does not match. |
5134| 62980113| Unknown image format. |
5135| 62980115| Invalid image parameter. |
5136| 62980116| Failed to decode the image. |
5137| 62980118| Failed to create the image plugin. |
5138| 62980122| Failed to decode the image header. |
5139| 62980137| Invalid media operation. |
5140
5141**示例:**
5142
5143```ts
5144import { BusinessError } from '@kit.BasicServicesKit';
5145
5146imageSourceApi.getFrameCount((err: BusinessError, frameCount: number) => {
5147  if (err) {
5148    console.error(`Failed to get frame count.code is ${err.code},message is ${err.message}`);
5149  } else {
5150    console.info('Succeeded in getting frame count.');
5151  }
5152})
5153```
5154
5155### getFrameCount<sup>10+</sup>
5156
5157getFrameCount(): Promise\<number>
5158
5159获取图像帧数,使用Promise形式返回结果。
5160
5161**系统能力:** SystemCapability.Multimedia.Image.ImageSource
5162
5163**返回值:**
5164
5165| 类型           | 说明                        |
5166| -------------- | --------------------------- |
5167| Promise\<number> | Promise对象,返回图像帧数。 |
5168
5169**错误码:**
5170
5171以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5172
5173| 错误码ID | 错误信息 |
5174| ------- | --------------------------------------------|
5175| 62980096 | The operation failed.             |
5176| 62980110 | The image source data is incorrect.      |
5177| 62980111 | The image source data is incomplete. |
5178| 62980112 | The image format does not match.        |
5179| 62980113 | Unknown image format.         |
5180| 62980115 | Invalid image parameter.      |
5181| 62980116 | Failed to decode the image.          |
5182| 62980118 | Failed to create the image plugin.   |
5183| 62980122 | Failed to decode the image header.  |
5184| 62980137 | Invalid media operation.      |
5185
5186**示例:**
5187
5188```ts
5189import { BusinessError } from '@kit.BasicServicesKit';
5190
5191imageSourceApi.getFrameCount().then((frameCount: number) => {
5192  console.info('Succeeded in getting frame count.');
5193}).catch((err: BusinessError) => {
5194  console.error(`Failed to get frame count.code is ${err.code},message is ${err.message}`);
5195})
5196```
5197
5198### getDisposalTypeList<sup>12+</sup>
5199
5200getDisposalTypeList(): Promise\<Array\<number>>
5201
5202获取图像帧过渡模式数组,使用Promise形式返回结果。此接口仅用于gif图片。
5203
5204**系统能力:** SystemCapability.Multimedia.Image.ImageSource
5205
5206**返回值:**
5207
5208| 类型           | 说明                        |
5209| -------------- | --------------------------- |
5210| Promise\<Array\<number>> | Promise对象,返回帧过渡模式数组。 |
5211
5212**错误码:**
5213
5214以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5215
5216| 错误码ID | 错误信息 |
5217| ------- | --------------------------------------------|
5218| 62980096 | The operation failed.      |
5219| 62980101 | The image data is abnormal. |
5220| 62980137 | Invalid media operation.        |
5221| 62980149 | Invalid MIME type for the image source.      |
5222
5223**示例:**
5224
5225```ts
5226import { BusinessError } from '@kit.BasicServicesKit';
5227imageSourceApi.getDisposalTypeList().then((disposalTypes: Array<number>) => {
5228  console.info('Succeeded in getting disposalTypes object.');
5229}).catch((err: BusinessError) => {
5230  console.error(`Failed to get disposalTypes object.code ${err.code},message is ${err.message}`);
5231})
5232```
5233
5234### release
5235
5236release(callback: AsyncCallback\<void>): void
5237
5238释放图片源实例,使用callback形式返回结果。
5239
5240ArkTS有内存回收机制,ImageSource对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
5241
5242**系统能力:** SystemCapability.Multimedia.Image.ImageSource
5243
5244**参数:**
5245
5246| 参数名   | 类型                 | 必填 | 说明                               |
5247| -------- | -------------------- | ---- | ---------------------------------- |
5248| callback | AsyncCallback\<void> | 是   | 回调函数,当资源释放成功,err为undefined,否则为错误对象。  |
5249
5250**示例:**
5251
5252```ts
5253import { BusinessError } from '@kit.BasicServicesKit';
5254
5255imageSourceApi.release((err: BusinessError) => {
5256  if (err) {
5257    console.error(`Failed to release the image source instance.code ${err.code},message is ${err.message}`);
5258  } else {
5259    console.info('Succeeded in releasing the image source instance.');
5260  }
5261})
5262```
5263
5264### release
5265
5266release(): Promise\<void>
5267
5268释放图片源实例,使用Promise形式返回结果。
5269
5270ArkTS有内存回收机制,ImageSource对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
5271
5272**系统能力:** SystemCapability.Multimedia.Image.ImageSource
5273
5274**返回值:**
5275
5276| 类型           | 说明                        |
5277| -------------- | --------------------------- |
5278| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
5279
5280**示例:**
5281
5282```ts
5283import { BusinessError } from '@kit.BasicServicesKit';
5284
5285imageSourceApi.release().then(() => {
5286  console.info('Succeeded in releasing the image source instance.');
5287}).catch((error: BusinessError) => {
5288  console.error(`Failed to release the image source instance.code ${error.code},message is ${error.message}`);
5289})
5290```
5291
5292## image.createImagePacker
5293
5294createImagePacker(): ImagePacker
5295
5296创建ImagePacker实例。
5297
5298**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
5299
5300**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5301
5302**返回值:**
5303
5304| 类型                        | 说明                  |
5305| --------------------------- | --------------------- |
5306| [ImagePacker](#imagepacker) | 返回ImagePacker实例。 |
5307
5308**示例:**
5309
5310```ts
5311const imagePackerApi: image.ImagePacker = image.createImagePacker();
5312```
5313
5314## ImagePacker
5315
5316图片打包器类,用于图片压缩和打包。在调用ImagePacker的方法前,需要先通过[createImagePacker](#imagecreateimagepacker)构建一个ImagePacker实例,当前支持格式有:jpeg、webp、png、heif<sup>12+</sup>(不同硬件设备支持情况不同)。
5317
5318### 属性
5319
5320**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5321
5322| 名称             | 类型           | 可读 | 可写 | 说明                       |
5323| ---------------- | -------------- | ---- | ---- | -------------------------- |
5324| supportedFormats | Array\<string> | 是   | 否   | 图片打包支持的格式 jpeg、webp、png、heif<sup>12+</sup>(不同硬件设备支持情况不同)。 |
5325
5326### packToData<sup>13+</sup>
5327
5328packToData(source: ImageSource, options: PackingOption): Promise\<ArrayBuffer>
5329
5330图片压缩或重新打包,使用Promise形式返回结果。
5331
5332**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
5333
5334**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5335
5336**参数:**
5337
5338| 参数名 | 类型                            | 必填 | 说明           |
5339| ------ | ------------------------------- | ---- | -------------- |
5340| source | [ImageSource](#imagesource)     | 是   | 打包的图片源。 |
5341| options | [PackingOption](#packingoption) | 是   | 设置打包参数。 |
5342
5343**错误码:**
5344
5345以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5346
5347| 错误码ID | 错误信息 |
5348| ------- | --------------------------------------------|
5349| 401 | If the parameter is invalid. |
5350| 62980096| The Operation failed.              |
5351| 62980101 | The image data is abnormal. |
5352| 62980106 | The image is too large. |
5353| 62980113 | Unknown image format. |
5354| 62980119 | If encoder occur error during encoding.             |
5355| 62980120 | Add pixelmap out of range. |
5356| 62980172 | Failed to encode icc. |
5357| 62980252 | Failed to create surface. |
5358
5359**返回值:**
5360
5361| 类型                         | 说明                                          |
5362| ---------------------------- | --------------------------------------------- |
5363| Promise\<ArrayBuffer>        | Promise对象,返回压缩或打包后的数据。 |
5364
5365**示例:**
5366
5367```ts
5368import { BusinessError } from '@kit.BasicServicesKit';
5369
5370const context: Context = getContext();
5371//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource会创建失败导致后续无法正常执行。
5372let filePath: string = context.filesDir + "/test.jpg";
5373const imageSourceApi: image.ImageSource = image.createImageSource(filePath);
5374let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }
5375imagePackerApi.packToData(imageSourceApi, packOpts)
5376  .then((data: ArrayBuffer) => {
5377    console.info('Succeeded in packing the image.');
5378  }).catch((error: BusinessError) => {
5379    console.error(`Failed to pack the image.code ${error.code},message is ${error.message}`);
5380  })
5381```
5382
5383### packToData<sup>13+</sup>
5384
5385packToData(source: PixelMap, options: PackingOption): Promise\<ArrayBuffer>
5386
5387图片压缩或重新打包,使用Promise形式返回结果。
5388
5389**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
5390
5391**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5392
5393**参数:**
5394
5395| 参数名 | 类型                            | 必填 | 说明               |
5396| ------ | ------------------------------- | ---- | ------------------ |
5397| source | [PixelMap](#pixelmap7)           | 是   | 打包的PixelMap源。 |
5398| options | [PackingOption](#packingoption) | 是   | 设置打包参数。     |
5399
5400**返回值:**
5401
5402| 类型                  | 说明                                         |
5403| --------------------- | -------------------------------------------- |
5404| Promise\<ArrayBuffer> | Promise对象,返回压缩或打包后的数据。|
5405
5406**错误码:**
5407
5408以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5409
5410| 错误码ID | 错误信息 |
5411| ------- | --------------------------------------------|
5412| 401 | If the parameter is invalid. |
5413| 62980096| The Operation failed.              |
5414| 62980101 | The image data is abnormal. |
5415| 62980106 | The image is too large. |
5416| 62980113 | Unknown image format. |
5417| 62980119 | If encoder occur error during encoding.             |
5418| 62980120 | Add pixelmap out of range. |
5419| 62980172 | Failed to encode icc. |
5420| 62980252 | Failed to create surface. |
5421
5422**示例:**
5423
5424```ts
5425import { BusinessError } from '@kit.BasicServicesKit';
5426
5427const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
5428let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
5429image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => {
5430  let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }
5431  imagePackerApi.packToData(pixelMap, packOpts)
5432    .then((data: ArrayBuffer) => {
5433      console.info('Succeeded in packing the image.');
5434    }).catch((error: BusinessError) => {
5435    console.error(`Failed to pack the image.code ${error.code},message is ${error.message}`);
5436  })
5437}).catch((error: BusinessError) => {
5438  console.error(`Failed to create PixelMap.code ${error.code},message is ${error.message}`);
5439})
5440```
5441
5442### packing<sup>13+</sup>
5443
5444packing(picture: Picture, options: PackingOption): Promise\<ArrayBuffer>
5445
5446将图像压缩或重新打包,使用Promise形式返回结果。
5447
5448**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5449
5450**参数:**
5451
5452| 参数名           | 类型                                                 | 必填 | 说明                 |
5453| ---------------- | ---------------------------------------------------- | ---- | -------------------- |
5454| picture | [Picture](#picture13)                           | 是   | 打包的Picture对象。 |
5455| options          | [PackingOption](#packingoption) | 是   | 设置打包参数。       |
5456
5457**返回值:**
5458
5459| 类型                  | 说明                                  |
5460| --------------------- | ------------------------------------- |
5461| Promise\<ArrayBuffer> | Promise对象,返回压缩或打包后的数据。 |
5462
5463**错误码:**
5464
5465以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5466
5467| 错误码ID | 错误信息                                                     |
5468| -------- | ------------------------------------------------------------ |
5469| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
5470| 7800301  | Encode failed.                                         |
5471
5472**示例:**
5473
5474```ts
5475import { BusinessError } from '@kit.BasicServicesKit';
5476import { image } from '@kit.ImageKit';
5477
5478async function Packing() {
5479  const context = getContext();
5480  const resourceMgr = context.resourceManager;
5481  const rawFile = await resourceMgr.getRawFileContent("test.jpg");
5482  let ops: image.SourceOptions = {
5483    sourceDensity: 98,
5484  }
5485  let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops);
5486  let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap();
5487  let pictureObj: image.Picture = image.createPicture(commodityPixelMap);
5488
5489  let funcName = "Packing";
5490  if (imagePackerApi != null) {
5491    let opts: image.PackingOption = {
5492      format: "image/jpeg",
5493      quality: 98,
5494      bufferSize: 10,
5495      desiredDynamicRange: image.PackingDynamicRange.AUTO,
5496      needsPackProperties: true};
5497    await imagePackerApi.packing(pictureObj, opts).then((data: ArrayBuffer) => {
5498        console.info(funcName, 'Succeeded in packing the image.'+ data);
5499      }).catch((error: BusinessError) => {
5500        console.error(funcName, 'Failed to pack the image.code ${error.code},message is ${error.message}');
5501      });
5502  }
5503}
5504```
5505
5506### packing<sup>(deprecated)</sup>
5507
5508packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void
5509
5510图片压缩或重新打包,使用callback形式返回结果。
5511
5512> **说明:**
5513>
5514> 从API version 6开始支持,从API version 13开始废弃,建议使用[packToData](#packtodata13)代替。
5515
5516**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
5517
5518**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5519
5520**参数:**
5521
5522| 参数名   | 类型                               | 必填 | 说明                               |
5523| -------- | ---------------------------------- | ---- | ---------------------------------- |
5524| source   | [ImageSource](#imagesource)        | 是   | 打包的图片源。                     |
5525| option   | [PackingOption](#packingoption)    | 是   | 设置打包参数。                      |
5526| callback | AsyncCallback\<ArrayBuffer>        | 是   | 回调函数,当图片打包成功,err为undefined,data为获取到的压缩或打包数据;否则为错误对象。  |
5527
5528**示例:**
5529
5530```ts
5531import { BusinessError } from '@kit.BasicServicesKit';
5532
5533const context: Context = getContext();
5534//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource会创建失败导致后续无法正常执行。
5535let filePath: string = context.filesDir + "/test.jpg";
5536const imageSourceApi: image.ImageSource = image.createImageSource(filePath);
5537let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 };
5538imagePackerApi.packing(imageSourceApi, packOpts, (err: BusinessError, data: ArrayBuffer) => {
5539  if (err) {
5540    console.error(`Failed to pack the image.code ${err.code},message is ${err.message}`);
5541  } else {
5542    console.info('Succeeded in packing the image.');
5543  }
5544})
5545```
5546
5547### packing<sup>(deprecated)</sup>
5548
5549packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer>
5550
5551图片压缩或重新打包,使用Promise形式返回结果。
5552
5553> **说明:**
5554>
5555> 从API version 6开始支持,从API version 13开始废弃,建议使用[packToData](#packtodata13)代替。
5556
5557**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
5558
5559**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5560
5561**参数:**
5562
5563| 参数名 | 类型                            | 必填 | 说明           |
5564| ------ | ------------------------------- | ---- | -------------- |
5565| source | [ImageSource](#imagesource)     | 是   | 打包的图片源。 |
5566| option | [PackingOption](#packingoption) | 是   | 设置打包参数。 |
5567
5568**返回值:**
5569
5570| 类型                         | 说明                                          |
5571| ---------------------------- | --------------------------------------------- |
5572| Promise\<ArrayBuffer>        | Promise对象,返回压缩或打包后的数据。 |
5573
5574**示例:**
5575
5576```ts
5577import { BusinessError } from '@kit.BasicServicesKit';
5578
5579const context: Context = getContext();
5580//此处'test.jpg'仅作示例,请开发者自行替换,否则imageSource会创建失败导致后续无法正常执行。
5581let filePath: string = context.filesDir + "/test.jpg";
5582const imageSourceApi: image.ImageSource = image.createImageSource(filePath);
5583let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }
5584imagePackerApi.packing(imageSourceApi, packOpts)
5585  .then((data: ArrayBuffer) => {
5586    console.info('Succeeded in packing the image.');
5587  }).catch((error: BusinessError) => {
5588    console.error(`Failed to pack the image.code ${error.code},message is ${error.message}`);
5589  })
5590```
5591
5592### packing<sup>(deprecated)</sup>
5593
5594packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void
5595
5596图片压缩或重新打包,使用callback形式返回结果。
5597
5598> **说明:**
5599>
5600> 从API version 8开始支持,从API version 13开始废弃,建议使用[packToData](#packtodata13-1)代替。
5601
5602**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
5603
5604**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5605
5606**参数:**
5607
5608| 参数名   | 类型                            | 必填 | 说明                               |
5609| -------- | ------------------------------- | ---- | ---------------------------------- |
5610| source   | [PixelMap](#pixelmap7)           | 是   | 打包的PixelMap资源。               |
5611| option   | [PackingOption](#packingoption) | 是   | 设置打包参数。                     |
5612| callback | AsyncCallback\<ArrayBuffer>     | 是   | 回调函数,当图片打包成功,err为undefined,data为获取到的压缩或打包数据;否则为错误对象。  |
5613
5614**示例:**
5615
5616```ts
5617import { BusinessError } from '@kit.BasicServicesKit';
5618
5619const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
5620let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
5621image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => {
5622  let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }
5623  imagePackerApi.packing(pixelMap, packOpts, (err: BusinessError, data: ArrayBuffer) => {
5624    if (err) {
5625      console.error(`Failed to pack the image.code ${err.code},message is ${err.message}`);
5626    } else {
5627      console.info('Succeeded in packing the image.');
5628    }
5629  })
5630}).catch((error: BusinessError) => {
5631  console.error(`Failed to create the PixelMap.code ${error.code},message is ${error.message}`);
5632})
5633```
5634
5635### packing<sup>(deprecated)</sup>
5636
5637packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer>
5638
5639图片压缩或重新打包,使用Promise形式返回结果。
5640
5641> **说明:**
5642>
5643> 从API version 8开始支持,从API version 13开始废弃,建议使用[packToData](#packtodata13-1)代替。
5644
5645**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
5646
5647**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5648
5649**参数:**
5650
5651| 参数名 | 类型                            | 必填 | 说明               |
5652| ------ | ------------------------------- | ---- | ------------------ |
5653| source | [PixelMap](#pixelmap7)           | 是   | 打包的PixelMap源。 |
5654| option | [PackingOption](#packingoption) | 是   | 设置打包参数。     |
5655
5656**返回值:**
5657
5658| 类型                  | 说明                                         |
5659| --------------------- | -------------------------------------------- |
5660| Promise\<ArrayBuffer> | Promise对象,返回压缩或打包后的数据。|
5661
5662**示例:**
5663
5664```ts
5665import { BusinessError } from '@kit.BasicServicesKit';
5666
5667const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
5668let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
5669image.createPixelMap(color, opts).then((pixelMap: image.PixelMap) => {
5670  let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }
5671  imagePackerApi.packing(pixelMap, packOpts)
5672    .then((data: ArrayBuffer) => {
5673      console.info('Succeeded in packing the image.');
5674    }).catch((error: BusinessError) => {
5675    console.error(`Failed to pack the image.code ${error.code},message is ${error.message}`);
5676  })
5677}).catch((error: BusinessError) => {
5678  console.error(`Failed to create PixelMap.code ${error.code},message is ${error.message}`);
5679})
5680```
5681
5682### release
5683
5684release(callback: AsyncCallback\<void>): void
5685
5686释放图片打包实例,使用callback形式返回结果。
5687
5688ArkTS有内存回收机制,ImagePacker对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
5689
5690**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5691
5692**参数:**
5693
5694| 参数名   | 类型                 | 必填 | 说明                           |
5695| -------- | -------------------- | ---- | ------------------------------ |
5696| callback | AsyncCallback\<void> | 是   | 回调函数,当释放图片打包实例成功,err为undefined,否则为错误对象。 |
5697
5698**示例:**
5699
5700```ts
5701import { BusinessError } from '@kit.BasicServicesKit';
5702
5703imagePackerApi.release((err: BusinessError)=>{
5704  if (err) {
5705    console.error(`Failed to release image packaging.code ${err.code},message is ${err.message}`);
5706  } else {
5707    console.info('Succeeded in releasing image packaging.');
5708  }
5709})
5710```
5711
5712### release
5713
5714release(): Promise\<void>
5715
5716释放图片打包实例,使用Promise形式返回释放结果。
5717
5718ArkTS有内存回收机制,ImagePacker对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
5719
5720**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5721
5722**返回值:**
5723
5724| 类型           | 说明                                                   |
5725| -------------- | ------------------------------------------------------ |
5726| Promise\<void> |  Promise对象。无返回结果的Promise对象。|
5727
5728**示例:**
5729
5730```ts
5731import { BusinessError } from '@kit.BasicServicesKit';
5732
5733imagePackerApi.release().then(() => {
5734  console.info('Succeeded in releasing image packaging.');
5735}).catch((error: BusinessError) => {
5736  console.error(`Failed to release image packaging.code ${error.code},message is ${error.message}`);
5737})
5738```
5739
5740### packToFile<sup>11+</sup>
5741
5742packToFile(source: ImageSource, fd: number, options: PackingOption, callback: AsyncCallback\<void>): void
5743
5744指定打包参数,将ImageSource图片源编码后直接打包进文件。使用callback形式返回结果。
5745
5746**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5747
5748**参数:**
5749
5750| 参数名   | 类型                            | 必填 | 说明                           |
5751| -------- | ------------------------------- | ---- | ------------------------------ |
5752| source   | [ImageSource](#imagesource)     | 是   | 打包的图片源。                 |
5753| fd       | number                          | 是   | 文件描述符。                   |
5754| options   | [PackingOption](#packingoption) | 是   | 设置打包参数。                 |
5755| callback | AsyncCallback\<void>            | 是   | 回调函数,当打包进文件成功,err为undefined,否则为错误对象。  |
5756
5757**错误码:**
5758
5759以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5760
5761| 错误码ID | 错误信息 |
5762| ------- | --------------------------------------------|
5763| 62980096| The Operation failed.              |
5764| 62980101 | The image data is abnormal. |
5765| 62980106 | The image is too large. |
5766| 62980113 | Unknown image format. |
5767| 62980115 | If the parameter is invalid. |
5768| 62980119 | If encoder occur error during encoding.             |
5769| 62980120 | Add pixelmap out of range. |
5770| 62980172 | Failed to encode icc. |
5771| 62980252 | Failed to create surface. |
5772
5773**示例:**
5774
5775```ts
5776import { BusinessError } from '@kit.BasicServicesKit';
5777import { fileIo as fs } from '@kit.CoreFileKit';
5778
5779const context: Context = getContext(this);
5780//此处'test.png'仅作示例,请开发者自行替换,否则imageSource会创建失败导致后续无法正常执行。
5781const path: string = context.filesDir + "/test.png";
5782const imageSourceApi: image.ImageSource = image.createImageSource(path);
5783let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 };
5784const filePath: string = context.filesDir + "/image_source.jpg";
5785let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
5786const imagePackerApi: image.ImagePacker = image.createImagePacker();
5787imagePackerApi.packToFile(imageSourceApi, file.fd, packOpts, (err: BusinessError) => {
5788  if (err) {
5789    console.error(`Failed to pack the image to file.code ${err.code},message is ${err.message}`);
5790  } else {
5791    console.info('Succeeded in packing the image to file.');
5792  }
5793})
5794```
5795
5796### packToFile<sup>11+</sup>
5797
5798packToFile (source: ImageSource, fd: number, options: PackingOption): Promise\<void>
5799
5800指定打包参数,将ImageSource图片源编码后直接打包进文件。使用Promise形式返回结果。
5801
5802**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5803
5804**参数:**
5805
5806| 参数名 | 类型                            | 必填 | 说明           |
5807| ------ | ------------------------------- | ---- | -------------- |
5808| source | [ImageSource](#imagesource)     | 是   | 打包的图片源。 |
5809| fd     | number                          | 是   | 文件描述符。   |
5810| options | [PackingOption](#packingoption) | 是   | 设置打包参数。 |
5811
5812**返回值:**
5813
5814| 类型           | 说明                              |
5815| -------------- | --------------------------------- |
5816| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
5817
5818**错误码:**
5819
5820以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5821
5822| 错误码ID | 错误信息 |
5823| ------- | --------------------------------------------|
5824| 62980096| The Operation failed.              |
5825| 62980101 | The image data is abnormal. |
5826| 62980106 | The image is too large. |
5827| 62980113 | Unknown image format. |
5828| 62980115 | If the parameter is invalid. |
5829| 62980119 | If encoder occur error during encoding.             |
5830| 62980120 | Add pixelmap out of range. |
5831| 62980172 | Failed to encode icc. |
5832| 62980252 | Failed to create surface. |
5833
5834**示例:**
5835
5836```ts
5837import { BusinessError } from '@kit.BasicServicesKit';
5838import { fileIo as fs } from '@kit.CoreFileKit';
5839
5840const context: Context = getContext(this);
5841//此处'test.png'仅作示例,请开发者自行替换,否则imageSource会创建失败导致后续无法正常执行。
5842const path: string = context.filesDir + "/test.png";
5843const imageSourceApi: image.ImageSource = image.createImageSource(path);
5844let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 };
5845const filePath: string = context.filesDir + "/image_source.jpg";
5846let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
5847const imagePackerApi: image.ImagePacker = image.createImagePacker();
5848imagePackerApi.packToFile(imageSourceApi, file.fd, packOpts).then(() => {
5849  console.info('Succeeded in packing the image to file.');
5850}).catch((error: BusinessError) => {
5851  console.error(`Failed to pack the image to file.code ${error.code},message is ${error.message}`);
5852})
5853```
5854
5855### packToFile<sup>11+</sup>
5856
5857packToFile (source: PixelMap, fd: number, options: PackingOption,  callback: AsyncCallback\<void>): void;
5858
5859指定打包参数,将PixelMap图片源编码后直接打包进文件。使用callback形式返回结果。
5860
5861**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5862
5863**参数:**
5864
5865| 参数名   | 类型                            | 必填 | 说明                           |
5866| -------- | ------------------------------- | ---- | ------------------------------ |
5867| source   | [PixelMap](#pixelmap7)          | 是   | 打包的PixelMap资源。           |
5868| fd       | number                          | 是   | 文件描述符。                   |
5869| options   | [PackingOption](#packingoption) | 是   | 设置打包参数。                 |
5870| callback | AsyncCallback\<void>            | 是   | 回调函数,当打包图片进文件成功,err为undefined,否则为错误对象。  |
5871
5872**错误码:**
5873
5874以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5875
5876| 错误码ID | 错误信息 |
5877| ------- | --------------------------------------------|
5878| 62980096| The Operation failed.              |
5879| 62980101 | The image data is abnormal. |
5880| 62980106 | The image is too large. |
5881| 62980113 | Unknown image format. |
5882| 62980115 | If the parameter is invalid. |
5883| 62980119 | If encoder occur error during encoding.             |
5884| 62980120 | Add pixelmap out of range. |
5885| 62980172 | Failed to encode icc. |
5886| 62980252 | Failed to create surface. |
5887
5888**示例:**
5889
5890```ts
5891import { BusinessError } from '@kit.BasicServicesKit';
5892import { fileIo as fs } from '@kit.CoreFileKit';
5893
5894const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
5895let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } }
5896const context: Context = getContext(this);
5897const path: string = context.filesDir + "/pixel_map.jpg";
5898image.createPixelMap(color, opts).then((pixelmap: image.PixelMap) => {
5899  let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }
5900  let file = fs.openSync(path, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
5901  const imagePackerApi: image.ImagePacker = image.createImagePacker();
5902  imagePackerApi.packToFile(pixelmap, file.fd, packOpts, (err: BusinessError) => {
5903    if (err) {
5904      console.error(`Failed to pack the image to file.code ${err.code},message is ${err.message}`);
5905    } else {
5906      console.info('Succeeded in packing the image to file.');
5907    }
5908  })
5909})
5910```
5911
5912### packToFile<sup>11+</sup>
5913
5914packToFile (source: PixelMap, fd: number, options: PackingOption): Promise\<void>
5915
5916指定打包参数,将PixelMap图片源编码后直接打包进文件。使用Promise形式返回结果。
5917
5918**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5919
5920**参数:**
5921
5922| 参数名 | 类型                            | 必填 | 说明                 |
5923| ------ | ------------------------------- | ---- | -------------------- |
5924| source | [PixelMap](#pixelmap7)          | 是   | 打包的PixelMap资源。 |
5925| fd     | number                          | 是   | 文件描述符。         |
5926| options | [PackingOption](#packingoption) | 是   | 设置打包参数。       |
5927
5928**返回值:**
5929
5930| 类型           | 说明                              |
5931| -------------- | --------------------------------- |
5932| Promise\<void> |  Promise对象。无返回结果的Promise对象。|
5933
5934**错误码:**
5935
5936以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5937
5938| 错误码ID | 错误信息 |
5939| ------- | --------------------------------------------|
5940| 62980096| The Operation failed.              |
5941| 62980101 | The image data is abnormal. |
5942| 62980106 | The image is too large. |
5943| 62980113 | Unknown image format. |
5944| 62980115 | If the parameter is invalid. |
5945| 62980119 | If encoder occur error during encoding.             |
5946| 62980120 | Add pixelmap out of range. |
5947| 62980172 | Failed to encode icc. |
5948| 62980252 | Failed to create surface. |
5949
5950**示例:**
5951
5952```ts
5953import { BusinessError } from '@kit.BasicServicesKit';
5954import { fileIo as fs } from '@kit.CoreFileKit';
5955
5956const color: ArrayBuffer = new ArrayBuffer(96); // 96为需要创建的像素buffer大小,取值为:height * width *4
5957let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } }
5958const context: Context = getContext(this);
5959const path: string = context.filesDir + "/pixel_map.jpg";
5960image.createPixelMap(color, opts).then((pixelmap: image.PixelMap) => {
5961  let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }
5962  let file = fs.openSync(path, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
5963  const imagePackerApi: image.ImagePacker = image.createImagePacker();
5964  imagePackerApi.packToFile(pixelmap, file.fd, packOpts)
5965    .then(() => {
5966      console.info('Succeeded in packing the image to file.');
5967    }).catch((error: BusinessError) => {
5968    console.error(`Failed to pack the image to file.code ${error.code},message is ${error.message}`);
5969  })
5970})
5971```
5972
5973### packToFile<sup>13+</sup>
5974
5975packToFile(picture: Picture, fd: number, options: PackingOption): Promise\<void>
5976
5977指定打包参数,将Picture图片源编码后直接打包进文件。使用Promise形式返回结果。
5978
5979**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
5980
5981**参数:**
5982
5983| 参数名  | 类型                         | 必填 | 说明                 |
5984| ------- | ---------------------------- | ---- | -------------------- |
5985| picture  | [Picture](#picture13)          | 是   | 打包的Picture资源。 |
5986| fd      | number                       | 是   | 文件描述符。         |
5987| options | [PackingOption](#packingoption) | 是   | 设置打包参数。       |
5988
5989**返回值:**
5990
5991| 类型           | 说明                      |
5992| -------------- | ------------------------- |
5993| Promise\<void> | 无返回结果的Promise对象。 |
5994
5995**错误码:**
5996
5997以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
5998
5999| 错误码ID | 错误信息                                                     |
6000| -------- | ------------------------------------------------------------ |
6001| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
6002| 7800301  | Encode failed.                                         |
6003
6004**示例:**
6005
6006```ts
6007import { BusinessError } from '@kit.BasicServicesKit';
6008import { image } from '@kit.ImageKit';
6009import { fileIo as fs } from '@kit.CoreFileKit';
6010
6011async function PackToFile() {
6012  const context = getContext();
6013  const resourceMgr = context.resourceManager;
6014  const rawFile = await resourceMgr.getRawFileContent("test.jpg");
6015  let ops: image.SourceOptions = {
6016    sourceDensity: 98,
6017  }
6018  let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops);
6019  let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap();
6020  let pictureObj: image.Picture = image.createPicture(commodityPixelMap);
6021
6022  let funcName = "PackToFile";
6023  if (imagePackerApi != null) {
6024    const context: Context = getContext();
6025    const filePath: string = context.filesDir + "/test.jpg";
6026    let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
6027    let packOpts: image.PackingOption = {
6028      format: "image/jpeg",
6029      quality: 98,
6030      bufferSize: 10,
6031      desiredDynamicRange: image.PackingDynamicRange.AUTO,
6032      needsPackProperties: true};
6033    await imagePackerApi.packToFile(pictureObj, file.fd, packOpts).then(() => {
6034      console.info(funcName, 'Succeeded in packing the image to file.');
6035    }).catch((error: BusinessError) => {
6036      console.error(funcName, 'Failed to pack the image to file.code ${error.code},message is ${error.message}');
6037    });
6038  }
6039}
6040```
6041
6042## image.createAuxiliaryPicture<sup>13+</sup>
6043
6044createAuxiliaryPicture(buffer: ArrayBuffer, size: Size, type: AuxiliaryPictureType): AuxiliaryPicture
6045
6046通过ArrayBuffer图片数据、辅助图尺寸、辅助图类型创建AuxiliaryPicture实例。
6047
6048**系统能力:** SystemCapability.Multimedia.Image.Core
6049
6050**参数:**
6051
6052| 参数名 | 类型                                            | 必填 | 说明                         |
6053| ------ | ----------------------------------------------- | ---- | ---------------------------- |
6054| buffer | ArrayBuffer                                     | 是   | 以buffer形式存放的图像数据。 |
6055| size   | [Size](#size)                                   | 是   | 辅助图的尺寸。               |
6056| type   | [AuxiliaryPictureType](#auxiliarypicturetype13) | 是   | 辅助图类型。                 |
6057
6058**返回值:**
6059
6060| 类型                                    | 说明                                       |
6061| --------------------------------------- | ------------------------------------------ |
6062| [AuxiliaryPicture](#auxiliarypicture13) | 如果操作成功,则返回AuxiliaryPicture实例。 |
6063
6064**错误码:**
6065
6066以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
6067
6068| 错误码ID | 错误信息                                                     |
6069| -------- | ------------------------------------------------------------ |
6070| 401      | Parameter error.Possible causes:1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
6071
6072**示例:**
6073
6074```ts
6075import { image } from '@kit.ImageKit';
6076
6077async function CreateAuxiliaryPicture() {
6078  let funcName = "CreateAuxiliaryPicture";
6079  const context = getContext();
6080  const resourceMgr = context.resourceManager;
6081  const rawFile = await resourceMgr.getRawFileContent("hdr.jpg"); //需要支持hdr的图片
6082  let auxBuffer: ArrayBuffer = rawFile.buffer as ArrayBuffer;
6083  let auxSize: Size = {
6084    height: 180,
6085    width: 240
6086  };
6087  let auxType: image.AuxiliaryPictureType = image.AuxiliaryPictureType.GAINMAP;
6088  let auxPictureObj: image.AuxiliaryPicture | null = image.createAuxiliaryPicture(auxBuffer, auxSize, auxType);
6089  if(auxPictureObj != null) {
6090    let type: image.AuxiliaryPictureType = auxPictureObj.getType();
6091    console.info(funcName, 'CreateAuxiliaryPicture succeeded this.Aux_picture.type.' + JSON.stringify(type));
6092  } else {
6093    console.error(funcName, 'CreateAuxiliaryPicture failed');
6094  }
6095}
6096```
6097
6098## AuxiliaryPicture<sup>13+</sup>
6099
6100辅助图一般用于辅助主图进行特殊信息的展示,使图像包含更丰富的信息。辅助图图像类,用于读取或写入图像的辅助图数据以及获取图像的辅助图信息。在调用AuxiliaryPicture的方法前,需要先通过[createAuxiliaryPicture](#imagecreateauxiliarypicture13)创建一个AuxiliaryPicture实例。
6101
6102### 属性
6103
6104**系统能力:** SystemCapability.Multimedia.Image.Core
6105
6106### writePixelsFromBuffer<sup>13+</sup>
6107
6108writePixelsFromBuffer(data: ArrayBuffer): Promise\<void>
6109
6110读取ArrayBuffer中的辅助图片数据,并将数据写入AuxiliaryPicture对象,使用Promise形式返回。
6111
6112**系统能力:** SystemCapability.Multimedia.Image.Core
6113
6114**参数:**
6115
6116| 参数名 | 类型        | 必填 | 说明             |
6117| ------ | ----------- | ---- | ---------------- |
6118| data   | ArrayBuffer | 是   | 辅助图像素数据。 |
6119
6120**返回值:**
6121
6122| 类型           | 说明                                   |
6123| -------------- | -------------------------------------- |
6124| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
6125
6126**错误码:**
6127
6128以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
6129
6130| 错误码ID | 错误信息                                                     |
6131| -------- | ------------------------------------------------------------ |
6132| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
6133| 7600301  | Memory alloc failed.                                         |
6134| 7600302  | Memory copy failed.                                          |
6135
6136**示例:**
6137
6138```ts
6139import { image } from '@kit.ImageKit';
6140
6141async function WritePixelsFromBuffer() {
6142  const context = getContext();
6143  const resourceMgr = context.resourceManager;
6144  const rawFile = await resourceMgr.getRawFileContent("hdr.jpg"); //需要支持hdr的图片
6145  let ops: image.SourceOptions = {
6146    sourceDensity: 98,
6147  }
6148  let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops);
6149  let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap();
6150  let pictureObj: image.Picture = image.createPicture(commodityPixelMap);
6151  let auxPictureObj: image.AuxiliaryPicture | null = pictureObj.getAuxiliaryPicture(image.AuxiliaryPictureType.GAINMAP);
6152  if(auxPictureObj != null) {
6153    let auxBuffer: ArrayBuffer = await auxPictureObj.readPixelsToBuffer();
6154    await auxPictureObj.writePixelsFromBuffer(auxBuffer);
6155    console.info('Write pixels from buffer success.');
6156  } else {
6157    console.error('AuxPictureObj is null.');
6158  }
6159}
6160```
6161
6162### readPixelsToBuffer<sup>13+</sup>
6163
6164readPixelsToBuffer(): Promise\<ArrayBuffer>
6165
6166读取图像像素映射数据并将数据写入ArrayBuffer,使用Promise形式返回。
6167
6168**系统能力:** SystemCapability.Multimedia.Image.Core
6169
6170**返回值:**
6171
6172| 类型                  | 说明                              |
6173| --------------------- | --------------------------------- |
6174| Promise\<ArrayBuffer> | Promise对象。返回辅助图像素数据。 |
6175
6176**错误码:**
6177
6178以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
6179
6180| 错误码ID | 错误信息             |
6181| -------- | -------------------- |
6182| 7600301  | Memory alloc failed. |
6183| 7600302  | Memory copy failed.  |
6184
6185**示例:**
6186
6187```ts
6188import { BusinessError } from '@kit.BasicServicesKit';
6189import { image } from '@kit.ImageKit';
6190
6191async function ReadPixelsToBuffer() {
6192  const context = getContext();
6193  const resourceMgr = context.resourceManager;
6194  const rawFile = await resourceMgr.getRawFileContent("hdr.jpg"); //需要支持hdr的图片
6195  let ops: image.SourceOptions = {
6196    sourceDensity: 98,
6197  }
6198  let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops);
6199  let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap();
6200  let pictureObj: image.Picture = image.createPicture(commodityPixelMap);
6201  let auxPictureObj: image.AuxiliaryPicture | null = pictureObj.getAuxiliaryPicture(image.AuxiliaryPictureType.GAINMAP);
6202  if(auxPictureObj != null) {
6203    await auxPictureObj.readPixelsToBuffer().then((pixelsBuffer: ArrayBuffer) => {
6204      console.info('Read pixels to buffer success.' );
6205    }).catch((error: BusinessError) => {
6206      console.error('Read pixels to buffer failed error.code: ' + JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message));
6207    });
6208  } else {
6209    console.error('AuxPictureObj is null.');
6210  }
6211}
6212```
6213
6214### getType<sup>13+</sup>
6215
6216getType(): AuxiliaryPictureType
6217
6218获取辅助图的类型。
6219
6220**系统能力:** SystemCapability.Multimedia.Image.Core
6221
6222**返回值:**
6223
6224| 类型                                            | 说明                         |
6225| ----------------------------------------------- | ---------------------------- |
6226| [AuxiliaryPictureType](#auxiliarypicturetype13) | 操作成功,返回辅助图的类型。 |
6227
6228**示例:**
6229
6230```ts
6231import { image } from '@kit.ImageKit';
6232
6233async function GetAuxiliaryPictureType() {
6234  if (auxPictureObj != null) {
6235    let type: image.AuxiliaryPictureType = auxPictureObj.getType();
6236    console.info('Success get auxiliary picture type ' +  JSON.stringify(type));
6237  } else {
6238    console.info('Failed get auxiliary picture type ');
6239  }
6240}
6241```
6242
6243### setMetadata<sup>13+</sup>
6244
6245setMetadata(metadataType: MetadataType, metadata: Metadata): Promise\<void>
6246
6247设置辅助图元数据。
6248
6249**系统能力:** SystemCapability.Multimedia.Image.Core
6250
6251**参数:**
6252
6253| 参数名       | 类型                            | 必填 | 说明                                 |
6254| ------------ | ------------------------------- | ---- | ------------------------------------ |
6255| metadataType | [MetadataType](#metadatatype13) | 是   | 元数据的类型,用于设置对应的元数据。 |
6256| metadata     | [Metadata](#metadata13)         | 是   | 元数据对象。                         |
6257
6258**返回值:**
6259
6260| 类型           | 说明                                   |
6261| -------------- | -------------------------------------- |
6262| Promise\<void> | Promise对象,无返回结果的Promise对象。 |
6263
6264**错误码:**
6265
6266以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
6267
6268| 错误码ID | 错误信息                                                     |
6269| -------- | ------------------------------------------------------------ |
6270| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
6271| 7600202  | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. |
6272
6273**示例:**
6274
6275```ts
6276import { BusinessError } from '@kit.BasicServicesKit';
6277import { image } from '@kit.ImageKit';
6278
6279async function SetAuxPictureObjMetadata() {
6280  const exifContext = getContext();
6281  const exifResourceMgr = exifContext.resourceManager;
6282  const exifRawFile = await exifResourceMgr.getRawFileContent("exif.jpg");//图片包含exif metadata
6283  let exifOps: image.SourceOptions = {
6284    sourceDensity: 98,
6285  }
6286  let exifImageSource: image.ImageSource = image.createImageSource(exifRawFile.buffer as ArrayBuffer, exifOps);
6287  let exifCommodityPixelMap: image.PixelMap = await exifImageSource.createPixelMap();
6288  let exifPictureObj: image.Picture = image.createPicture(exifCommodityPixelMap);
6289  if (exifPictureObj != null) {
6290    console.info('Create picture succeeded');
6291  } else {
6292    console.info('Create picture failed');
6293  }
6294
6295  if (auxPictureObj != null) {
6296    let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA;
6297    let exifMetaData: image.Metadata = await exifPictureObj.getMetadata(metadataType);
6298    auxPictureObj.setMetadata(metadataType, exifMetaData).then(() => {
6299      console.info('Set metadata success');
6300    }).catch((error: BusinessError) => {
6301      console.error('Set metadata failed.error.code: ${error.code}, error.message: ${error.message}');
6302    });
6303  } else {
6304    console.info('AuxPictureObjMetaData is null');
6305  }
6306}
6307```
6308
6309### getMetadata<sup>13+</sup>
6310
6311getMetadata(metadataType: MetadataType): Promise\<Metadata>
6312
6313从辅助图中获取元数据。
6314
6315**系统能力:** SystemCapability.Multimedia.Image.Core
6316
6317**参数:**
6318
6319| 参数名       | 类型                            | 必填 | 说明                                   |
6320| ------------ | ------------------------------- | ---- | -------------------------------------- |
6321| metadataType | [MetadataType](#metadatatype13) | 是   | 元数据类型,用于获取对应类型的元数据。 |
6322
6323**返回值:**
6324
6325| 类型                             | 说明             |
6326| -------------------------------- | ---------------- |
6327| Promise<[Metadata](#metadata13)> | 返回元数据对象。 |
6328
6329**错误码:**
6330
6331以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
6332
6333| 错误码ID | 错误信息                                                     |
6334| -------- | ------------------------------------------------------------ |
6335| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
6336| 7600202  | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. |
6337
6338**示例:**
6339
6340```ts
6341import { image } from '@kit.ImageKit';
6342
6343async function GetAuxPictureObjMetadata() {
6344  if (auxPictureObj != null) {
6345    let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA;
6346    let auxPictureObjMetaData: image.Metadata | null = await auxPictureObj.getMetadata(metadataType);
6347    if (auxPictureObjMetaData != null) {
6348      console.info('Get auxpictureobj Metadata success' );
6349    } else {
6350      console.info('Get auxpictureobj Metadata failed');
6351    }
6352  } else {
6353    console.info('Get auxpictureobj is null.');
6354  }
6355}
6356```
6357
6358### getAuxiliaryPictureinfo<sup>13+</sup>
6359
6360getAuxiliaryPictureInfo(): AuxiliaryPictureInfo
6361
6362获取有关此辅助图的图像信息。
6363
6364**系统能力:** SystemCapability.Multimedia.Image.Core
6365
6366**返回值:**
6367
6368| 类型                                            | 说明                              |
6369| ----------------------------------------------- | --------------------------------- |
6370| [AuxiliaryPictureInfo](#auxiliarypictureinfo13) | Promise对象,返回辅助图图像信息。 |
6371
6372**示例:**
6373
6374```ts
6375import { image } from '@kit.ImageKit';
6376
6377async function GetAuxiliaryPictureInfo() {
6378  if(auxPictureObj != null) {
6379    let auxinfo: image.AuxiliaryPictureInfo = auxPictureObj.getAuxiliaryPictureInfo();
6380    console.info('GetAuxiliaryPictureInfo Type: ' + auxinfo.auxiliaryPictureType +
6381      ' height: ' + auxinfo.size.height + ' width: ' + auxinfo.size.width +
6382      ' rowStride: ' +  auxinfo.rowStride +  ' pixelFormat: ' + auxinfo.pixelFormat +
6383      ' colorSpace: ' +  auxinfo.colorSpace);
6384  } else {
6385    console.info('Get auxiliary picture information failed');
6386  }
6387}
6388```
6389
6390### setAuxiliaryPictureinfo<sup>13+</sup>
6391
6392setAuxiliaryPictureInfo(info: AuxiliaryPictureInfo): void
6393
6394设置辅助图的图像信息。
6395
6396**系统能力:** SystemCapability.Multimedia.Image.Core
6397
6398**参数:**
6399
6400| 参数名 | 类型                                            | 必填 | 说明               |
6401| ------ | ----------------------------------------------- | ---- | ------------------ |
6402| info   | [AuxiliaryPictureInfo](#auxiliarypictureinfo13) | 是   | 辅助图的图像信息。 |
6403
6404**错误码:**
6405
6406以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
6407
6408| 错误码ID | 错误信息                                                     |
6409| -------- | :----------------------------------------------------------- |
6410| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
6411
6412**示例:**
6413
6414```ts
6415import { colorSpaceManager } from '@kit.ArkGraphics2D';
6416import { image } from '@kit.ImageKit';
6417
6418async function SetAuxiliaryPictureInfo() {
6419  if(auxPictureObj != null) {
6420    let colorSpaceName = colorSpaceManager.ColorSpace.SRGB;
6421    let info: image.AuxiliaryPictureInfo = {
6422      auxiliaryPictureType: image.AuxiliaryPictureType.GAINMAP,
6423      size: {height: 100, width: 200},
6424      pixelFormat: image.PixelMapFormat.RGBA_8888,
6425      rowStride: 0,
6426      colorSpace: colorSpaceManager.create(colorSpaceName),
6427    };
6428    auxPictureObj.setAuxiliaryPictureInfo(info);
6429  }
6430}
6431```
6432
6433### release<sup>13+</sup>
6434
6435release():void
6436
6437释放辅助图对象,无返回值。
6438
6439**系统能力:** SystemCapability.Multimedia.Image.Core
6440
6441**示例:**
6442
6443```ts
6444import { image } from '@kit.ImageKit';
6445
6446async function Release() {
6447  let funcName = "Release";
6448  if (auxPictureObj != null) {
6449    auxPictureObj.release();
6450    if (auxPictureObj.getType() == null) {
6451      console.info(funcName, 'Success !');
6452    } else {
6453      console.info(funcName, 'Failed !');
6454    }
6455  } else {
6456    console.info('PictureObj is null');
6457  }
6458}
6459```
6460
6461## Metadata<sup>13+</sup>
6462
6463图像元数据类,用于存储图像的元数据。目前支持的元数据类型可参考[MetadataType](#metadatatype13)。
6464
6465### 属性
6466
6467**系统能力:** SystemCapability.Multimedia.Image.Core
6468
6469### getProperties<sup>13+</sup>
6470
6471getProperties(key: Array\<string>): Promise\<Record\<string, string | null>>
6472
6473获取图像中属性的值,使用Promise形式返回。如要查询属性值信息请参考[PropertyKey](#propertykey7)和[FragmentMapPropertyKey](#fragmentmappropertykey13)。
6474
6475**系统能力:** SystemCapability.Multimedia.Image.Core
6476
6477**参数:**
6478
6479| 参数名 | 类型           | 必填 | 说明                     |
6480| ------ | -------------- | ---- | ------------------------ |
6481| key    | Array\<string> | 是   | 要获取其值的属性的名称。 |
6482
6483**返回值:**
6484
6485| 类型                                     | 说明                                                         |
6486| ---------------------------------------- | ------------------------------------------------------------ |
6487| Promise\<Record<string, string \| null>> | Promise对象,返回元数据要获取的属性的值,如获取失败则返回错误码。 |
6488
6489**错误码:**
6490
6491以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
6492
6493| 错误码ID | 错误信息                                                     |
6494| -------- | ------------------------------------------------------------ |
6495| 401      | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; |
6496| 7600202  | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. |
6497
6498**示例:**
6499
6500```ts
6501import { BusinessError } from '@kit.BasicServicesKit';
6502import { image } from '@kit.ImageKit';
6503
6504async function GetProperties() {
6505  const context = getContext();
6506  const resourceMgr = context.resourceManager;
6507  const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); //图片包含exif metadata
6508  let ops: image.SourceOptions = {
6509    sourceDensity: 98,
6510  }
6511  let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops);
6512  let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap();
6513  let pictureObj: image.Picture = image.createPicture(commodityPixelMap);
6514  let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA;
6515  let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType);
6516  if (metaData != null) {
6517    await metaData.getProperties(["ImageWidth", "ImageLength"]).then((data2) => {
6518      console.info('Get properties ',JSON.stringify(data2));
6519    }).catch((error: BusinessError) => {
6520      console.info('Get properties failed error.code: ' +JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message));
6521    });
6522  } else {
6523    console.info('Metadata is null.');
6524  }
6525}
6526```
6527
6528### setProperties<sup>13+</sup>
6529
6530setProperties(records: Record\<string, string | null>): Promise\<void>
6531
6532批量设置图片元数据中的指定属性的值,使用Promise形式返回。如要查询属性值信息请参考[PropertyKey](#propertykey7)和[FragmentMapPropertyKey](#fragmentmappropertykey13)。
6533
6534**系统能力:** SystemCapability.Multimedia.Image.Core
6535
6536**参数:**
6537
6538| 参数名  | 类型                           | 必填 | 说明                     |
6539| ------- | ------------------------------ | ---- | ------------------------ |
6540| records | Record<string, string \| null> | 是   | 要修改的属性和值的数组。 |
6541
6542**返回值:**
6543
6544| 类型           | 说明                                  |
6545| -------------- | ------------------------------------- |
6546| Promise\<void> | Promise对象,如获取失败则返回错误码。 |
6547
6548**错误码:**
6549
6550以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
6551
6552| 错误码ID | 错误信息                                                     |
6553| -------- | ------------------------------------------------------------ |
6554| 401      | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; |
6555| 7600202  | Unsupported metadata. Possible causes: 1. Unsupported metadata type. 2. The metadata type does not match the auxiliary picture type. |
6556
6557**示例:**
6558
6559```ts
6560import { BusinessError } from '@kit.BasicServicesKit';
6561import { image } from '@kit.ImageKit';
6562
6563async function SetProperties() {
6564  const context = getContext();
6565  const resourceMgr = context.resourceManager;
6566  const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); //图片包含exif metadata
6567  let ops: image.SourceOptions = {
6568    sourceDensity: 98,
6569  }
6570  let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops);
6571  let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap();
6572  let pictureObj: image.Picture = image.createPicture(commodityPixelMap);
6573  let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA;
6574  let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType);
6575  if (metaData != null) {
6576    let setkey: Record<string, string | null> = {
6577      "ImageWidth": "200",
6578      "ImageLength": "300"
6579    };
6580    await metaData.setProperties(setkey).then(async () => {
6581      console.info('Set auxpictureobj properties success.');
6582    }).catch((error: BusinessError) => {
6583      console.error('Failed to set metadata Properties. code is ${error.code}, message is ${error.message}');
6584    })
6585  } else {
6586    console.info('AuxPictureObj metadata is null. ');
6587  }
6588}
6589```
6590
6591### getAllProperties<sup>13+</sup>
6592
6593getAllProperties(): Promise\<Record<string, string | null>>
6594
6595获取图片中所有元数据的属性和值,使用Promise形式返回。如要查询属性值信息请参考[PropertyKey](#propertykey7)和[FragmentMapPropertyKey](#fragmentmappropertykey13)。
6596
6597**系统能力:** SystemCapability.Multimedia.Image.Core
6598
6599**返回值:**
6600
6601| 类型                                     | 说明                                        |
6602| ---------------------------------------- | ------------------------------------------- |
6603| Promise\<Record<string, string \| null>> | Promise对象,返回元数据拥有的所有属性的值。 |
6604
6605**示例:**
6606
6607```ts
6608import { BusinessError } from '@kit.BasicServicesKit';
6609import { image } from '@kit.ImageKit';
6610
6611async function GetAllProperties() {
6612  const context = getContext();
6613  const resourceMgr = context.resourceManager;
6614  const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); //图片包含exif metadata
6615  let ops: image.SourceOptions = {
6616    sourceDensity: 98,
6617  }
6618  let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops);
6619  let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap();
6620  let pictureObj: image.Picture = image.createPicture(commodityPixelMap);
6621  let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA;
6622  let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType);
6623  if (metaData != null) {
6624    await metaData.getAllProperties().then((data2) => {
6625      const count = Object.keys(data2).length;
6626      console.info('Metadata have ', count, ' properties');
6627      console.info('Get metadata all properties: ', JSON.stringify(data2));
6628    }).catch((error: BusinessError) => {
6629      console.error('Get metadata all properties failed error.code: ' +JSON.stringify(error.code) + ' ,error.message:' + JSON.stringify(error.message));
6630    });
6631  } else {
6632    console.info('Metadata is null.');
6633  }
6634}
6635```
6636
6637### clone<sup>13+</sup>
6638
6639clone(): Promise\<Metadata>
6640
6641对元数据进行克隆,用Promise形式返回结果。
6642
6643**系统能力:** SystemCapability.Multimedia.Image.Core
6644
6645**返回值:**
6646
6647| 类型                              | 说明                              |
6648| --------------------------------- | --------------------------------- |
6649| Promise\<[Metadata](#metadata13)> | Promise对象,成功返回元数据实例。 |
6650
6651**错误码:**
6652
6653以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
6654
6655| 错误码ID | 错误信息             |
6656| -------- | -------------------- |
6657| 7600301  | Memory alloc failed. |
6658| 7600302  | Memory copy failed.  |
6659
6660**示例:**
6661
6662```ts
6663import { BusinessError } from '@kit.BasicServicesKit';
6664import { image } from '@kit.ImageKit';
6665
6666async function clone() {
6667  const context = getContext();
6668  const resourceMgr = context.resourceManager;
6669  const rawFile = await resourceMgr.getRawFileContent("exif.jpg"); //图片包含exif metadata
6670  let ops: image.SourceOptions = {
6671    sourceDensity: 98,
6672  }
6673  let imageSource: image.ImageSource = image.createImageSource(rawFile.buffer as ArrayBuffer, ops);
6674  let commodityPixelMap: image.PixelMap = await imageSource.createPixelMap();
6675  let pictureObj: image.Picture = image.createPicture(commodityPixelMap);
6676  let metadataType: image.MetadataType = image.MetadataType.EXIF_METADATA;
6677  let metaData: image.Metadata | null = await pictureObj.getMetadata(metadataType);
6678  if (metaData != null) {
6679    let new_metadata: image.Metadata = await metaData.clone();
6680    new_metadata.getProperties(["ImageWidth"]).then((data1) => {
6681      console.info('Clone new_metadata and get Properties.', JSON.stringify(data1));
6682    }).catch((err: BusinessError) => {
6683      console.error('Clone new_metadata failed.', JSON.stringify(err));
6684    });
6685  } else {
6686    console.info('Metadata is null.');
6687  }
6688}
6689```
6690
6691## image.createImageReceiver<sup>11+</sup>
6692
6693createImageReceiver(size: Size, format: ImageFormat, capacity: number): ImageReceiver
6694
6695通过图片大小、图片格式、容量创建ImageReceiver实例。
6696
6697**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6698
6699**参数:**
6700
6701| 参数名   | 类型   | 必填 | 说明                   |
6702| -------- | ------ | ---- | ---------------------- |
6703| size    | [Size](#size)  | 是   | 图像的默认大小。       |
6704| format   | [ImageFormat](#imageformat9) | 是   | 图像格式,取值为[ImageFormat](#imageformat9)常量(目前仅支持 ImageFormat:JPEG,实际返回格式由生产者决定,如相机)。             |
6705| capacity | number | 是   | 同时访问的最大图像数。 |
6706
6707**返回值:**
6708
6709| 类型                             | 说明                                    |
6710| -------------------------------- | --------------------------------------- |
6711| [ImageReceiver](#imagereceiver9) | 如果操作成功,则返回ImageReceiver实例。 |
6712
6713**错误码:**
6714
6715以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
6716
6717| 错误码ID | 错误信息 |
6718| ------- | --------------------------------------------|
6719| 401| Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;   |
6720
6721**示例:**
6722
6723```ts
6724let size: image.Size = {
6725  height: 8192,
6726  width: 8
6727}
6728let receiver: image.ImageReceiver = image.createImageReceiver(size, image.ImageFormat.JPEG, 8);
6729```
6730
6731## image.createImageReceiver<sup>(deprecated)</sup>
6732
6733createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver
6734
6735通过宽、高、图片格式、容量创建ImageReceiver实例。
6736
6737> **说明:**
6738>
6739> 从API version 11开始不再维护,建议使用[createImageReceiver](#imagecreateimagereceiver11)代替。
6740
6741**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6742
6743**参数:**
6744
6745| 参数名   | 类型   | 必填 | 说明                   |
6746| -------- | ------ | ---- | ---------------------- |
6747| width    | number | 是   | 图像的默认宽度。       |
6748| height   | number | 是   | 图像的默认高度。       |
6749| format   | number | 是   | 图像格式,取值为[ImageFormat](#imageformat9)常量(目前仅支持 ImageFormat:JPEG,实际返回格式由生产者决定,如相机)。  |
6750| capacity | number | 是   | 同时访问的最大图像数。 |
6751
6752**返回值:**
6753
6754| 类型                             | 说明                                    |
6755| -------------------------------- | --------------------------------------- |
6756| [ImageReceiver](#imagereceiver9) | 如果操作成功,则返回ImageReceiver实例。 |
6757
6758**示例:**
6759
6760```ts
6761let receiver: image.ImageReceiver = image.createImageReceiver(8192, 8, image.ImageFormat.JPEG, 8);
6762```
6763
6764## ImageReceiver<sup>9+</sup>
6765
6766图像接收类,用于获取组件surface id,接收最新的图片和读取下一张图片,以及释放ImageReceiver实例。
6767
6768在调用以下方法前需要先创建ImageReceiver实例。
6769
6770### 属性
6771
6772**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6773
6774| 名称     | 类型                         | 可读 | 可写 | 说明               |
6775| -------- | ---------------------------- | ---- | ---- | ------------------ |
6776| size     | [Size](#size)                | 是   | 否   | 图片大小。         |
6777| capacity | number                       | 是   | 否   | 同时访问的图像数。 |
6778| format   | [ImageFormat](#imageformat9) | 是   | 否   | 图像格式。         |
6779
6780### getReceivingSurfaceId<sup>9+</sup>
6781
6782getReceivingSurfaceId(callback: AsyncCallback\<string>): void
6783
6784用于获取一个surface id供Camera或其他组件使用。使用callback返回结果。
6785
6786**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6787
6788**参数:**
6789
6790| 参数名   | 类型                   | 必填 | 说明                       |
6791| -------- | ---------------------- | ---- | -------------------------- |
6792| callback | AsyncCallback\<string> | 是   | 回调函数,当获取surface id成功,err为undefined,data为获取到的surface id;否则为错误对象。 |
6793
6794**示例:**
6795
6796```ts
6797import { BusinessError } from '@kit.BasicServicesKit';
6798
6799receiver.getReceivingSurfaceId((err: BusinessError, id: string) => {
6800  if (err) {
6801    console.error(`Failed to get the ReceivingSurfaceId.code ${err.code},message is ${err.message}`);
6802  } else {
6803    console.info('Succeeded in getting the ReceivingSurfaceId.');
6804  }
6805});
6806```
6807
6808### getReceivingSurfaceId<sup>9+</sup>
6809
6810getReceivingSurfaceId(): Promise\<string>
6811
6812用于获取一个surface id供Camera或其他组件使用。使用promise返回结果。
6813
6814**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6815
6816**返回值:**
6817
6818| 类型             | 说明                 |
6819| ---------------- | -------------------- |
6820| Promise\<string> | Promise对象,返回surface id。 |
6821
6822**示例:**
6823
6824```ts
6825import { BusinessError } from '@kit.BasicServicesKit';
6826
6827receiver.getReceivingSurfaceId().then((id: string) => {
6828  console.info('Succeeded in getting the ReceivingSurfaceId.');
6829}).catch((error: BusinessError) => {
6830  console.error(`Failed to get the ReceivingSurfaceId.code ${error.code},message is ${error.message}`);
6831})
6832```
6833
6834### readLatestImage<sup>9+</sup>
6835
6836readLatestImage(callback: AsyncCallback\<Image>): void
6837
6838从ImageReceiver读取最新的图片,并使用callback返回结果。
6839
6840**注意**:此接口需要在[on](#on9)回调触发后调用,才能正常的接收到数据。且此接口返回的[Image](#image9)对象使用完毕后需要调用[release](#release9-4)方法释放,释放后才可以继续接收新的数据。
6841
6842**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6843
6844**参数:**
6845
6846| 参数名     | 类型                            | 必填 | 说明                     |
6847| -------- | ------------------------------- | ---- | ------------------------ |
6848| callback | AsyncCallback<[Image](#image9)> | 是   | 回调函数,当读取最新图片成功,err为undefined,data为获取到的最新图片;否则为错误对象。  |
6849
6850**示例:**
6851
6852```ts
6853import { BusinessError } from '@kit.BasicServicesKit';
6854
6855receiver.readLatestImage((err: BusinessError, img: image.Image) => {
6856  if (err) {
6857    console.error(`Failed to read the latest Image.code ${err.code},message is ${err.message}`);
6858  } else {
6859    console.info('Succeeded in reading the latest Image.');
6860  }
6861});
6862```
6863
6864### readLatestImage<sup>9+</sup>
6865
6866readLatestImage(): Promise\<Image>
6867
6868从ImageReceiver读取最新的图片,并使用promise返回结果。
6869
6870**注意**:此接口需要在[on](#on9)回调触发后调用,才能正常的接收到数据。且此接口返回的[Image](#image9)对象使用完毕后需要调用[release](#release9-4)方法释放,释放后才可以继续接收新的数据。
6871
6872**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6873
6874**返回值:**
6875
6876| 类型                      | 说明               |
6877| ------------------------- | ------------------ |
6878| Promise<[Image](#image9)> | Promise对象,返回最新图片。 |
6879
6880**示例:**
6881
6882```ts
6883import { BusinessError } from '@kit.BasicServicesKit';
6884
6885receiver.readLatestImage().then((img: image.Image) => {
6886  console.info('Succeeded in reading the latest Image.');
6887}).catch((error: BusinessError) => {
6888  console.error(`Failed to read the latest Image.code ${error.code},message is ${error.message}`);
6889})
6890```
6891
6892### readNextImage<sup>9+</sup>
6893
6894readNextImage(callback: AsyncCallback\<Image>): void
6895
6896从ImageReceiver读取下一张图片,并使用callback返回结果。
6897
6898**注意**:此接口需要在[on](#on9)回调触发后调用,才能正常的接收到数据。且此接口返回的[Image](#image9)对象使用完毕后需要调用[release](#release9-4)方法释放,释放后才可以继续接收新的数据。
6899
6900**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6901
6902**参数:**
6903
6904| 参数名   | 类型                            | 必填 | 说明                       |
6905| -------- | ------------------------------- | ---- | -------------------------- |
6906| callback | AsyncCallback<[Image](#image9)> | 是   | 回调函数,当获取下一张图片成功,err为undefined,data为获取到的下一张图片;否则为错误对象。  |
6907
6908**示例:**
6909
6910```ts
6911import { BusinessError } from '@kit.BasicServicesKit';
6912
6913receiver.readNextImage((err: BusinessError, img: image.Image) => {
6914  if (err) {
6915    console.error(`Failed to read the next Image.code ${err.code},message is ${err.message}`);
6916  } else {
6917    console.info('Succeeded in reading the next Image.');
6918  }
6919});
6920```
6921
6922### readNextImage<sup>9+</sup>
6923
6924readNextImage(): Promise\<Image>
6925
6926从ImageReceiver读取下一张图片,并使用promise返回结果。
6927
6928**注意**:此接口需要在[on](#on9)回调触发后调用,才能正常的接收到数据。且此接口返回的[Image](#image9)对象使用完毕后需要调用[release](#release9-4)方法释放,释放后才可以继续接收新的数据。
6929
6930**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6931
6932**返回值:**
6933
6934| 类型                      | 说明                 |
6935| ------------------------- | -------------------- |
6936| Promise<[Image](#image9)> | Promise对象,返回下一张图片。 |
6937
6938**示例:**
6939
6940```ts
6941import { BusinessError } from '@kit.BasicServicesKit';
6942
6943receiver.readNextImage().then((img: image.Image) => {
6944  console.info('Succeeded in reading the next Image.');
6945}).catch((error: BusinessError) => {
6946  console.error(`Failed to read the next Image.code ${error.code},message is ${error.message}`);
6947})
6948```
6949
6950### on<sup>9+</sup>
6951
6952on(type: 'imageArrival', callback: AsyncCallback\<void>): void
6953
6954接收图片时注册回调。
6955
6956**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6957
6958**参数:**
6959
6960| 参数名   | 类型                 | 必填 | 说明                                                   |
6961| -------- | -------------------- | ---- | ------------------------------------------------------ |
6962| type     | string               | 是   | 注册事件的类型,固定为'imageArrival',接收图片时触发。 |
6963| callback | AsyncCallback\<void> | 是   | 回调函数,当注册事件触发成功,err为undefined,否则为错误对象。                                        |
6964
6965**示例:**
6966
6967```ts
6968receiver.on('imageArrival', () => {
6969  // image arrival, do something.
6970})
6971```
6972
6973### off<sup>13+</sup>
6974
6975off(type: 'imageArrival', callback?: AsyncCallback\<void>): void
6976
6977释放buffer时移除注册回调。
6978
6979**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
6980
6981**参数:**
6982
6983| 参数名   | 类型                 | 必填 | 说明                                     |
6984| -------- | -------------------- |----|----------------------------------------|
6985| type     | string               | 是  | 注册事件的类型,固定为'imageArrival',释放buffer时触发。 |
6986| callback | AsyncCallback\<void> | 否  | 移除的回调函数。         |
6987
6988**示例:**
6989
6990```ts
6991let callbackFunc = ()=>{
6992    // do something
6993}
6994receiver.on('imageArrival', callbackFunc)
6995receiver.off('imageArrival', callbackFunc)
6996```
6997
6998### release<sup>9+</sup>
6999
7000release(callback: AsyncCallback\<void>): void
7001
7002释放ImageReceiver实例并使用回调返回结果。
7003
7004ArkTS有内存回收机制,ImageReceiver对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
7005
7006**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
7007
7008**参数:**
7009
7010| 参数名   | 类型                 | 必填 | 说明                     |
7011| -------- | -------------------- | ---- | ------------------------ |
7012| callback | AsyncCallback\<void> | 是   | 回调函数,当释放ImageReceiver实例成功,err为undefined,否则为错误对象。  |
7013
7014**示例:**
7015
7016```ts
7017import { BusinessError } from '@kit.BasicServicesKit';
7018
7019receiver.release((err: BusinessError) => {
7020  if (err) {
7021    console.error(`Failed to release the receiver.code ${err.code},message is ${err.message}`);
7022  } else {
7023    console.info('Succeeded in releasing the receiver.');
7024  }
7025})
7026```
7027
7028### release<sup>9+</sup>
7029
7030release(): Promise\<void>
7031
7032释放ImageReceiver实例并使用promise返回结果。
7033
7034ArkTS有内存回收机制,ImageReceiver对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
7035
7036**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
7037
7038**返回值:**
7039
7040| 类型           | 说明               |
7041| -------------- | ------------------ |
7042| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
7043
7044**示例:**
7045
7046```ts
7047import { BusinessError } from '@kit.BasicServicesKit';
7048
7049receiver.release().then(() => {
7050  console.info('Succeeded in releasing the receiver.');
7051}).catch((error: BusinessError) => {
7052  console.error(`Failed to release the receiver.code ${error.code},message is ${error.message}`);
7053})
7054```
7055
7056## image.createImageCreator<sup>11+</sup>
7057
7058createImageCreator(size: Size, format: ImageFormat, capacity: number): ImageCreator
7059
7060通过图片大小、图片格式、容量创建ImageCreator实例。
7061
7062**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
7063
7064**参数:**
7065
7066| 参数名   | 类型   | 必填 | 说明                   |
7067| -------- | ------ | ---- | ---------------------- |
7068| size    | [Size](#size)  | 是   | 图像的默认大小。       |
7069| format   | [ImageFormat](#imageformat9) | 是   | 图像格式,如YCBCR_422_SP,JPEG。             |
7070| capacity | number | 是   | 同时访问的最大图像数。 |
7071
7072**返回值:**
7073
7074| 类型                           | 说明                                    |
7075| ------------------------------ | --------------------------------------- |
7076| [ImageCreator](#imagecreator9) | 如果操作成功,则返回ImageCreator实例。 |
7077
7078
7079**错误码:**
7080
7081以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。
7082
7083| 错误码ID | 错误信息 |
7084| ------- | --------------------------------------------|
7085| 401| Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;          |
7086
7087**示例:**
7088
7089```ts
7090let size: image.Size = {
7091  height: 8192,
7092  width: 8
7093}
7094let creator: image.ImageCreator = image.createImageCreator(size, image.ImageFormat.JPEG, 8);
7095```
7096
7097## image.createImageCreator<sup>(deprecated)</sup>
7098
7099createImageCreator(width: number, height: number, format: number, capacity: number): ImageCreator
7100
7101通过宽、高、图片格式、容量创建ImageCreator实例。
7102
7103> **说明:**
7104>
7105> 从API version 11开始不再维护,建议使用[createImageCreator](#imagecreateimagecreator11)代替。
7106
7107**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
7108
7109**参数:**
7110
7111| 参数名   | 类型   | 必填 | 说明                   |
7112| -------- | ------ | ---- | ---------------------- |
7113| width    | number | 是   | 图像的默认宽度。       |
7114| height   | number | 是   | 图像的默认高度。       |
7115| format   | number | 是   | 图像格式,如YCBCR_422_SP,JPEG。             |
7116| capacity | number | 是   | 同时访问的最大图像数。 |
7117
7118**返回值:**
7119
7120| 类型                           | 说明                                    |
7121| ------------------------------ | --------------------------------------- |
7122| [ImageCreator](#imagecreator9) | 如果操作成功,则返回ImageCreator实例。 |
7123
7124**示例:**
7125
7126```ts
7127let creator: image.ImageCreator = image.createImageCreator(8192, 8, image.ImageFormat.JPEG, 8);
7128```
7129
7130## ImageCreator<sup>9+</sup>
7131
7132图像创建模块,用于请求图像原生数据区域,并开放给应用编译原生图像数据的能力。
7133在调用以下方法前需要先创建[ImageCreator](#imagecreator9)实例,ImageCreator不支持多线程。
7134
7135### 属性
7136
7137**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
7138
7139| 名称     | 类型                         | 可读 | 可写 | 说明               |
7140| -------- | ---------------------------- | ---- | ---- | ------------------ |
7141| capacity | number                       | 是   | 否   | 同时访问的图像数。 |
7142| format   | [ImageFormat](#imageformat9) | 是   | 否   | 图像格式。         |
7143
7144### dequeueImage<sup>9+</sup>
7145
7146dequeueImage(callback: AsyncCallback\<Image>): void
7147
7148从空闲队列中获取buffer图片,用于绘制UI内容,并使用callback返回结果。
7149
7150**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
7151
7152**参数:**
7153
7154| 参数名        | 类型                                    | 必填 | 说明                 |
7155| ------------- | ---------------------------------------| ---- | -------------------- |
7156| callback      | AsyncCallback\<[Image](#image9)>  | 是   | 回调函数,当获取最新图片成功,err为undefined,data为获取到的最新图片;否则为错误对象。  |
7157
7158**示例:**
7159
7160```ts
7161import { BusinessError } from '@kit.BasicServicesKit';
7162
7163creator.dequeueImage((err: BusinessError, img: image.Image) => {
7164  if (err) {
7165    console.error(`Failed to dequeue the Image.code ${err.code},message is ${err.message}`);
7166  } else {
7167    console.info('Succeeded in dequeuing the Image.');
7168  }
7169});
7170```
7171
7172### dequeueImage<sup>9+</sup>
7173
7174dequeueImage(): Promise\<Image>
7175
7176从空闲队列中获取buffer图片,用于绘制UI内容,并使用promise返回结果。
7177
7178**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
7179
7180**返回值:**
7181
7182| 类型             | 说明           |
7183| --------------- | ------------- |
7184| Promise\<[Image](#image9)> | Promise对象,返回最新图片。 |
7185
7186**示例:**
7187
7188```ts
7189import { BusinessError } from '@kit.BasicServicesKit';
7190
7191creator.dequeueImage().then((img: image.Image) => {
7192  console.info('Succeeded in dequeuing the Image.');
7193}).catch((error: BusinessError) => {
7194  console.error(`Failed to dequeue the Image.code ${error.code},message is ${error.message}`);
7195})
7196```
7197
7198### queueImage<sup>9+</sup>
7199
7200queueImage(interface: Image, callback: AsyncCallback\<void>): void
7201
7202将绘制好的图片放入Dirty队列,并使用callback返回结果。
7203
7204**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
7205
7206**参数:**
7207
7208| 参数名        | 类型                     | 必填 | 说明                 |
7209| ------------- | -------------------------| ---- | -------------------- |
7210| interface     | [Image](#image9)                    | 是   | 绘制好的buffer图像。 |
7211| callback      | AsyncCallback\<void>     | 是   | 回调函数,当将图片放入Dirty队列成功,err为undefined,否则为错误对象。  |
7212
7213**示例:**
7214
7215```ts
7216import { BusinessError } from '@kit.BasicServicesKit';
7217
7218creator.dequeueImage().then((img: image.Image) => {
7219  //绘制图片
7220  img.getComponent(4).then((component : image.Component) => {
7221    let bufferArr: Uint8Array = new Uint8Array(component.byteBuffer);
7222    for (let i = 0; i < bufferArr.length; i += 4) {
7223      bufferArr[i] = 0; //B
7224      bufferArr[i + 1] = 0; //G
7225      bufferArr[i + 2] = 255; //R
7226      bufferArr[i + 3] = 255; //A
7227    }
7228  })
7229  creator.queueImage(img, (err: BusinessError) => {
7230    if (err) {
7231      console.error(`Failed to queue the Image.code ${err.code},message is ${err.message}`);
7232    } else {
7233      console.info('Succeeded in queuing the Image.');
7234    }
7235  })
7236})
7237
7238```
7239
7240### queueImage<sup>9+</sup>
7241
7242queueImage(interface: Image): Promise\<void>
7243
7244将绘制好的图片放入Dirty队列,并使用promise返回结果。
7245
7246**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
7247
7248**参数:**
7249
7250| 参数名          | 类型     | 必填 | 说明                |
7251| ------------- | --------| ---- | ------------------- |
7252| interface     | [Image](#image9)   | 是   | 绘制好的buffer图像。 |
7253
7254**返回值:**
7255
7256| 类型            | 说明           |
7257| -------------- | ------------- |
7258| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
7259
7260**示例:**
7261
7262```ts
7263import { BusinessError } from '@kit.BasicServicesKit';
7264
7265creator.dequeueImage().then((img: image.Image) => {
7266  //绘制图片
7267  img.getComponent(4).then((component: image.Component) => {
7268    let bufferArr: Uint8Array = new Uint8Array(component.byteBuffer);
7269    for (let i = 0; i < bufferArr.length; i += 4) {
7270      bufferArr[i] = 0; //B
7271      bufferArr[i + 1] = 0; //G
7272      bufferArr[i + 2] = 255; //R
7273      bufferArr[i + 3] = 255; //A
7274    }
7275  })
7276  creator.queueImage(img).then(() => {
7277    console.info('Succeeded in queuing the Image.');
7278  }).catch((error: BusinessError) => {
7279    console.error(`Failed to queue the Image.code ${error.code},message is ${error.message}`);
7280  })
7281})
7282
7283```
7284
7285### on<sup>9+</sup>
7286
7287on(type: 'imageRelease', callback: AsyncCallback\<void>): void
7288
7289监听imageRelease事件,并使用callback返回结果。
7290
7291**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
7292
7293**参数:**
7294
7295| 参数名        | 类型                     | 必填 | 说明                 |
7296| ------------- | -------------------------| ---- | -------------------- |
7297| type          | string                   | 是   | 监听事件类型,如'imageRelease'。 |
7298| callback      | AsyncCallback\<void>     | 是   | 回调函数,当监听事件触发成功,err为undefined,否则为错误对象。  |
7299
7300**示例:**
7301
7302```ts
7303import { BusinessError } from '@kit.BasicServicesKit';
7304
7305creator.on('imageRelease', (err: BusinessError) => {
7306  if (err) {
7307    console.error(`Failed to get the imageRelease callback.code ${err.code},message is ${err.message}`);
7308  } else {
7309    console.info('Succeeded in getting imageRelease callback.');
7310  }
7311})
7312```
7313
7314### off<sup>13+</sup>
7315
7316off(type: 'imageRelease', callback?: AsyncCallback\<void>): void
7317
7318释放buffer时,移除注册的回调函数。
7319
7320**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
7321
7322**参数:**
7323
7324| 参数名        | 类型                     | 必填 | 说明                                         |
7325| ------------- | -------------------------|----|--------------------------------------------|
7326| type          | string                   | 是  | 监听事件类型,如'imageRelease'。                    |
7327| callback      | AsyncCallback\<void>     | 否  | 将被移除的回调函数。 |
7328
7329**示例:**
7330
7331```ts
7332let callbackFunc = ()=>{
7333    // do something
7334}
7335creator.on('imageRelease', callbackFunc)
7336creator.off('imageRelease', callbackFunc)
7337```
7338
7339### release<sup>9+</sup>
7340
7341release(callback: AsyncCallback\<void>): void
7342
7343释放当前图像,并使用callback返回结果。
7344
7345ArkTS有内存回收机制,ImageCreator对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
7346
7347**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
7348
7349**参数:**
7350
7351| 参数名           | 类型                     | 必填 | 说明                 |
7352| ------------- | -------------------------| ---- | -------------------- |
7353| callback      | AsyncCallback\<void>     | 是   | 回调函数,当图像释放成功,err为undefined,否则为错误对象。 |
7354
7355**示例:**
7356
7357```ts
7358import { BusinessError } from '@kit.BasicServicesKit';
7359
7360creator.release((err: BusinessError) => {
7361  if (err) {
7362    console.error(`Failed to release the creator.code ${err.code},message is ${err.message}`);
7363  } else {
7364    console.info('Succeeded in releasing creator.');
7365  }
7366});
7367```
7368### release<sup>9+</sup>
7369
7370release(): Promise\<void>
7371
7372释放当前图像,并使用promise返回结果。
7373
7374ArkTS有内存回收机制,ImageCreator对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
7375
7376**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
7377
7378**返回值:**
7379
7380| 类型            | 说明           |
7381| -------------- | ------------- |
7382| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
7383
7384**示例:**
7385
7386```ts
7387import { BusinessError } from '@kit.BasicServicesKit';
7388
7389creator.release().then(() => {
7390  console.info('Succeeded in releasing creator.');
7391}).catch((error: BusinessError) => {
7392  console.error(`Failed to release the creator.code ${error.code},message is ${error.message}`);
7393})
7394```
7395
7396## Image<sup>9+</sup>
7397
7398提供基本的图像操作,包括获取图像信息、读写图像数据。调用[readNextImage](#readnextimage9)和[readLatestImage](#readlatestimage9)接口时会返回image。
7399
7400### 属性
7401
7402**系统能力:** SystemCapability.Multimedia.Image.Core
7403
7404| 名称     | 类型               | 可读 | 可写 | 说明                                               |
7405| -------- | ------------------ | ---- | ---- | -------------------------------------------------- |
7406| clipRect | [Region](#region8) | 是   | 是   | 要裁剪的图像区域。                                 |
7407| size     | [Size](#size)      | 是   | 否   | 图像大小。如果image对象所存储的是相机预览流数据,即YUV图像数据,那么获取到的size中的宽高分别对应YUV图像的宽高; 如果image对象所存储的是相机拍照流数据,即JPEG图像,由于已经是编码后的文件,size中的宽等于JPEG文件大小,高等于1。image对象所存储的数据是预览流还是拍照流,取决于应用将receiver中的surfaceId传给相机的previewOutput还是captureOutput。相机预览与拍照最佳实践请参考[双路预览(ArkTS)](../../media/camera/camera-dual-channel-preview.md)与[拍照实现方案(ArkTS)](../../media/camera/camera-shooting-case.md)。                                |
7408| format   | number             | 是   | 否   | 图像格式,参考[OH_NativeBuffer_Format](../apis-arkgraphics2d/_o_h___native_buffer.md#oh_nativebuffer_format)。 |
7409| timestamp<sup>12+</sup> | number         | 是      | 否   | 图像时间戳。时间戳以纳秒为单位,通常是单调递增的。时间戳的具体含义和基准取决于图像的生产者,在相机预览/拍照场景,生产者就是相机。来自不同生产者的图像的时间戳可能有不同的含义和基准,因此可能无法进行比较。如果要获取某张照片的生成时间,可以通过[getImageProperty](#getimageproperty11)接口读取相关的EXIF信息。|
7410
7411### getComponent<sup>9+</sup>
7412
7413getComponent(componentType: ComponentType, callback: AsyncCallback\<Component>): void
7414
7415根据图像的组件类型从图像中获取组件缓存并使用callback返回结果。
7416
7417**系统能力:** SystemCapability.Multimedia.Image.Core
7418
7419**参数:**
7420
7421| 参数名        | 类型                                    | 必填 | 说明                 |
7422| ------------- | --------------------------------------- | ---- | -------------------- |
7423| componentType | [ComponentType](#componenttype9)        | 是   | 图像的组件类型。(目前仅支持 ComponentType:JPEG,实际返回格式由生产者决定,如相机)    |
7424| callback      | AsyncCallback<[Component](#component9)> | 是   | 回调函数,当返回组件缓冲区成功,err为undefined,data为获取到的组件缓冲区;否则为错误对象。  |
7425
7426**示例:**
7427
7428```ts
7429import { BusinessError } from '@kit.BasicServicesKit';
7430
7431img.getComponent(4, (err: BusinessError, component: image.Component) => {
7432  if (err) {
7433    console.error(`Failed to get the component.code ${err.code},message is ${err.message}`);
7434  } else {
7435    console.info('Succeeded in getting component.');
7436  }
7437})
7438```
7439
7440### getComponent<sup>9+</sup>
7441
7442getComponent(componentType: ComponentType): Promise\<Component>
7443
7444根据图像的组件类型从图像中获取组件缓存并使用Promise方式返回结果。
7445
7446**系统能力:** SystemCapability.Multimedia.Image.Core
7447
7448**参数:**
7449
7450| 参数名        | 类型                             | 必填 | 说明             |
7451| ------------- | -------------------------------- | ---- | ---------------- |
7452| componentType | [ComponentType](#componenttype9) | 是   | 图像的组件类型。(目前仅支持 ComponentType:JPEG,实际返回格式由生产者决定,如相机) |
7453
7454**返回值:**
7455
7456| 类型                              | 说明                              |
7457| --------------------------------- | --------------------------------- |
7458| Promise<[Component](#component9)> | Promise对象,返回组件缓冲区。 |
7459
7460**示例:**
7461
7462```ts
7463import { BusinessError } from '@kit.BasicServicesKit';
7464
7465img.getComponent(4).then((component: image.Component) => {
7466  console.info('Succeeded in getting component.');
7467}).catch((error: BusinessError) => {
7468  console.error(`Failed to get the component.code ${error.code},message is ${error.message}`);
7469})
7470```
7471
7472### release<sup>9+</sup>
7473
7474release(callback: AsyncCallback\<void>): void
7475
7476释放当前图像并使用callback返回结果。
7477
7478在接收另一个图像前必须先释放对应资源。
7479
7480ArkTS有内存回收机制,Image对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
7481
7482**系统能力:** SystemCapability.Multimedia.Image.Core
7483
7484**参数:**
7485
7486| 参数名   | 类型                 | 必填 | 说明           |
7487| -------- | -------------------- | ---- | -------------- |
7488| callback | AsyncCallback\<void> | 是   | 回调函数,当图像释放成功,err为undefined,否则为错误对象。  |
7489
7490**示例:**
7491
7492```ts
7493import { BusinessError } from '@kit.BasicServicesKit';
7494
7495img.release((err: BusinessError) => {
7496  if (err) {
7497    console.error(`Failed to release the image instance.code ${err.code},message is ${err.message}`);
7498  } else {
7499    console.info('Succeeded in releasing the image instance.');
7500  }
7501})
7502```
7503
7504### release<sup>9+</sup>
7505
7506release(): Promise\<void>
7507
7508释放当前图像并使用Promise方式返回结果。
7509
7510在接收另一个图像前必须先释放对应资源。
7511
7512ArkTS有内存回收机制,Image对象不调用release方法,内存最终也会由系统统一释放。但图片使用的内存往往较大,为尽快释放内存,建议应用在使用完成后主动调用release方法提前释放内存。
7513
7514**系统能力:** SystemCapability.Multimedia.Image.Core
7515
7516**返回值:**
7517
7518| 类型           | 说明                  |
7519| -------------- | --------------------- |
7520| Promise\<void> |  Promise对象。无返回结果的Promise对象。 |
7521
7522**示例:**
7523
7524```ts
7525import { BusinessError } from '@kit.BasicServicesKit';
7526
7527img.release().then(() => {
7528  console.info('Succeeded in releasing the image instance.');
7529}).catch((error: BusinessError) => {
7530  console.error(`Failed to release the image instance.code ${error.code},message is ${error.message}`);
7531})
7532```
7533
7534## PositionArea<sup>7+</sup>
7535
7536表示图片指定区域内的数据。
7537
7538**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
7539
7540**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
7541
7542**系统能力:** SystemCapability.Multimedia.Image.Core
7543
7544| 名称   | 类型               | 只读|  可选| 说明                                                         |
7545| ------ | ------------------ | ---| -----|------------------------------------------------------- |
7546| pixels | ArrayBuffer        | 否 |   否   | 像素。                                                       |
7547| offset | number             | 否 |   否  |  偏移量。                                                     |
7548| stride | number             | 否 |   否  | 跨距,内存中每行像素所占的空间。stride >= region.size.width*4。                   |
7549| region | [Region](#region8) | 否 |   否  |区域,按照区域读写。写入的区域宽度加X坐标不能大于原图的宽度,写入的区域高度加Y坐标不能大于原图的高度。 |
7550
7551## ImageInfo
7552
7553表示图片信息。
7554
7555**系统能力:** SystemCapability.Multimedia.Image.Core
7556
7557| 名称 | 类型          | 只读 | 可选 | 说明       |
7558| ---- | ------------- | --- |-----|---------- |
7559| size<sup>6+</sup> | [Size](#size) | 否 |  否  |图片大小。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 |
7560| density<sup>9+</sup> | number | 否  | 否 |像素密度,单位为ppi。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 |
7561| stride<sup>11+</sup> | number | 否  | 否  | 跨距,内存中每行像素所占的空间。stride >= region.size.width*4 <br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 |
7562| pixelFormat<sup>12+</sup> | [PixelMapFormat](#pixelmapformat7) | 否  |  否 | 像素格式。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 |
7563| alphaType<sup>12+</sup> | [AlphaType](#alphatype9)  | 否  |  否  |透明度。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 |
7564| mimeType<sup>12+</sup> | string  |  否  |   否  |图片真实格式(MIME type)。  |
7565| isHdr<sup>12+</sup> | boolean  |  否  | 否  | 图片是否为高动态范围(HDR)。对于[ImageSource](#imagesource),代表源图片是否为HDR;对于[PixelMap](#pixelmap7),代表解码后的pixelmap是否为HDR。 |
7566
7567## Size
7568
7569表示图片尺寸。
7570
7571**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
7572
7573**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
7574
7575**系统能力:** SystemCapability.Multimedia.Image.Core
7576
7577| 名称   | 类型   | 只读 |  可选  |说明           |
7578| ------ | ------ | -- |-----| -------------- |
7579| height | number | 否  |  否  |输出图片的高,单位:像素。 |
7580| width  | number | 否  |  否 | 输出图片的宽,单位:像素。 |
7581
7582## PixelMapFormat<sup>7+</sup>
7583
7584枚举,图片像素格式。
7585
7586**系统能力:** SystemCapability.Multimedia.Image.Core
7587
7588| 名称                   |   值   | 说明              |
7589| ---------------------- | ------ | ----------------- |
7590| UNKNOWN                | 0      | 未知格式。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。        |
7591| RGB_565                | 2      | 格式为RGB_565。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。     |
7592| RGBA_8888              | 3      | 格式为RGBA_8888。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 |
7593| BGRA_8888<sup>9+</sup> | 4      | 格式为BGRA_8888。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 |
7594| RGB_888<sup>9+</sup>   | 5      | 格式为RGB_888。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。   |
7595| ALPHA_8<sup>9+</sup>   | 6      | 格式为ALPHA_8。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。   |
7596| RGBA_F16<sup>9+</sup>  | 7      | 格式为RGBA_F16。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。  |
7597| NV21<sup>9+</sup>      | 8      | 格式为NV21。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。      |
7598| NV12<sup>9+</sup>      | 9      | 格式为NV12。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。      |
7599| RGBA_1010102<sup>12+</sup> | 10 | 格式为RGBA_1010102 |
7600| YCBCR_P010<sup>12+</sup> | 11 | 格式为YCBCR_P010 |
7601| YCRCB_P010<sup>12+</sup> | 12 | 格式为YCRCB_P010 |
7602
7603## AlphaType<sup>9+</sup>
7604
7605枚举,图像的透明度类型。
7606
7607**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
7608
7609**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
7610
7611**系统能力:** SystemCapability.Multimedia.Image.Core
7612
7613| 名称     |   值   | 说明                    |
7614| -------- | ------ | ----------------------- |
7615| UNKNOWN  | 0      | 未知透明度。            |
7616| OPAQUE   | 1      | 没有alpha或图片不透明。 |
7617| PREMUL   | 2      | RGB预乘alpha。         |
7618| UNPREMUL | 3      | RGB非预乘alpha。       |
7619
7620## AuxiliaryPictureType<sup>13+</sup>
7621
7622枚举,辅助图的图像类型。
7623
7624**系统能力:** SystemCapability.Multimedia.Image.Core
7625
7626| 名称          | 值   | 说明         |
7627| ------------- | ---- | ------------ |
7628| GAINMAP       | 1    | 增益图,代表了一种增强SDR图像以产生具有可变显示调整能力的HDR图像的机制。它是一组描述如何应用gainmap元数据的组合。     |
7629| DEPTH_MAP     | 2    | 深度图,储存图像的深度数据,通过捕捉每个像素与摄像机之间的距离,提供场景的三维结构信息,通常用于3D重建和场景理解。     |
7630| UNREFOCUS_MAP | 3    | 人像未对焦的原图,提供了一种在人像拍摄中突出背景模糊效果的方式,能够帮助用户在后期处理中选择焦点区域,增加创作自由度。   |
7631| LINEAR_MAP    | 4    | 线性图,用于提供额外的数据视角或补充信息,通常用于视觉效果的增强,它可以包含场景中光照、颜色或其他视觉元素的线性表示。     |
7632| FRAGMENT_MAP  | 5    | 水印裁剪图,表示在原图中被水印覆盖的区域,该图像用于修复或移除水印影响,恢复图像的完整性和可视性。 |
7633
7634## AuxiliaryPictureInfo<sup>13+</sup>
7635
7636表示辅助图图像信息。
7637
7638**系统能力:** SystemCapability.Multimedia.Image.Core
7639
7640| 名称                      | 类型                                                         | 只读 | 可选 | 说明                                                         |
7641| ------------------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ |
7642| auxiliaryPictureType      | [AuxiliaryPictureType](#auxiliarypicturetype13)              | 否   | 否   | 辅助图的图像类型。                                           |
7643| size         | [Size](#size)                                                | 否   | 否   | 图片大小。 |
7644| rowStride                 | number                                                       | 否   | 否   | 行距。                                                       |
7645| pixelFormat | [PixelMapFormat](#pixelmapformat7)                           | 否   | 否   | 像素格式。 |
7646| colorSpace                | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | 否   | 否   | 目标色彩空间。                                               |
7647
7648## MetadataType<sup>13+</sup>
7649
7650枚举,图片元数据类型。
7651
7652**系统能力:** SystemCapability.Multimedia.Image.Core
7653
7654| 名称              | 值   | 说明               |
7655| ----------------- | ---- | ------------------ |
7656| EXIF_METADATA     | 1    | exif数据。         |
7657| FRAGMENT_METADATA | 2    | 水印裁剪图元数据。 |
7658
7659## ScaleMode<sup>9+</sup>
7660
7661枚举,图像的缩放模式。
7662
7663**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
7664
7665**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
7666
7667**系统能力:** SystemCapability.Multimedia.Image.Core
7668
7669| 名称            |   值   | 说明                                               |
7670| --------------- | ------ | -------------------------------------------------- |
7671| CENTER_CROP     | 1      | 缩放图像以填充目标图像区域并居中裁剪区域外的效果。 |
7672| FIT_TARGET_SIZE | 0      | 图像适合目标尺寸的效果。                           |
7673
7674## SourceOptions<sup>9+</sup>
7675
7676ImageSource的初始化选项。
7677
7678**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
7679
7680**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
7681
7682**系统能力:** SystemCapability.Multimedia.Image.Core
7683
7684| 名称              | 类型                               | 只读 | 可选 | 说明               |
7685| ----------------- | ---------------------------------- | ---- | ---- | ------------------ |
7686| sourceDensity     | number                             | 否   | 否   | 图片资源像素密度,单位DPI。<br>在解码参数[DecodingOptions](#decodingoptions7)未设置desiredSize的前提下,当前参数SourceOptions.sourceDensityDecodingOptions.fitDensity非零时将对解码输出的pixelmap进行缩放。<br>缩放后宽计算公式如下(高同理):(width * fitDensity + (sourceDensity >> 1)) / sourceDensity。|
7687| sourcePixelFormat | [PixelMapFormat](#pixelmapformat7) | 否   | 是   | 图片像素格式,默认值为UNKNOWN。     |
7688| sourceSize        | [Size](#size)                      | 否   | 是   | 图像像素大小,默认值为空。     |
7689
7690
7691## InitializationOptions<sup>8+</sup>
7692
7693PixelMap的初始化选项。
7694
7695**系统能力:** SystemCapability.Multimedia.Image.Core
7696
7697| 名称                     | 类型                               | 只读 |可选 |  说明           |
7698| ------------------------ | ---------------------------------- | ----| -----|  -------------- |
7699| alphaType<sup>9+</sup>   | [AlphaType](#alphatype9)           | 否   | 是| 透明度。默认值为IMAGE_ALPHA_TYPE_PREMUL。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。      |
7700| editable                 | boolean                            | 否   | 是| 是否可编辑。默认值为false。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。|
7701| srcPixelFormat<sup>12+</sup>  | [PixelMapFormat](#pixelmapformat7) | 否 | 是 | 传入的buffer数据的像素格式。默认值为BGRA_8888。|
7702| pixelFormat              | [PixelMapFormat](#pixelmapformat7) | 否 | 是| 生成的pixelMap的像素格式。默认值为RGBA_8888。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。     |
7703| scaleMode<sup>9+</sup>   | [ScaleMode](#scalemode9)           | 否  | 是 | 缩略值。默认值为0。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。       |
7704| size                     | [Size](#size)                      | 否  | 否|创建图片大小。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 |
7705
7706## DecodingOptions<sup>7+</sup>
7707
7708图像解码设置选项。
7709
7710**系统能力:** SystemCapability.Multimedia.Image.ImageSource
7711
7712| 名称               | 类型                               | 只读 | 可选 | 说明             |
7713| ------------------ | ---------------------------------- | ---- | ---- | ---------------- |
7714| sampleSize         | number                             | 否   | 是   | 缩略图采样大小,默认值为1。当前只能取1。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 |
7715| rotate             | number                             | 否   | 是   | 旋转角度。默认值为0。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。       |
7716| editable           | boolean                            | 否   | 是   | 是否可编辑。默认值为false。当取值为false时,图片不可二次编辑,如writepixels操作将失败。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。  |
7717| desiredSize        | [Size](#size)                      | 否   | 是   | 期望输出大小。默认值为空。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。   |
7718| desiredRegion      | [Region](#region8)                 | 否   | 是   | 解码区域。默认值为空。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。       |
7719| 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卡片中使用。 |
7720| index              | number                             | 否   | 是   | 解码图片序号。默认值为0。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。   |
7721| fitDensity<sup>9+</sup> | number                        | 否   | 是   | 图像像素密度,单位为ppi。默认值为0。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。   |
7722| desiredColorSpace<sup>11+</sup> | [colorSpaceManager.ColorSpaceManager](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspacemanager) | 否   | 是   | 目标色彩空间。默认值为UNKNOWN。 |
7723| desiredDynamicRange<sup>12+</sup> | [DecodingDynamicRange](#decodingdynamicrange12) | 否   | 是   | 目标动态范围,默认值为SDR。<br>通过[CreateIncrementalSource](#imagecreateincrementalsource9)创建的imagesource不支持设置此属性,默认解码为SDR内容。<br>如果平台不支持HDR,设置无效,默认解码为SDR内容。 |
7724
7725## DecodingOptionsForPicture<sup>13+</sup>
7726
7727图像解码设置选项。
7728
7729**系统能力:** SystemCapability.Multimedia.Image.ImageSource
7730
7731| 名称                     | 类型                                                    | 只读 | 可选 | 说明                                                         |
7732| ------------------------ | ------------------------------------------------------- | ---- | ---- | ------------------------------------------------------------ |
7733| desiredAuxiliaryPictures | Array\<[AuxiliaryPictureType](#auxiliarypicturetype13)> | 否   | 否   | 设置AuxiliaryPicture类型,默认解码所有AuxiliaryPicture类型。 |
7734
7735## Region<sup>8+</sup>
7736
7737表示区域信息。
7738
7739**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。
7740
7741**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
7742
7743**系统能力:** SystemCapability.Multimedia.Image.Core
7744
7745| 名称 | 类型          | 只读 | 可选| 说明         |
7746| ---- | ------------- | ---- | ---- | ------------ |
7747| size | [Size](#size) | 否   | 否   | 区域大小。   |
7748| x    | number        | 否   | 否  | 区域横坐标。 |
7749| y    | number        | 否  | 否  | 区域纵坐标。 |
7750
7751## PackingOption
7752
7753表示图片打包选项。
7754
7755**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
7756
7757| 名称    | 类型   | 只读 | 可选 | 说明                                                |
7758| ------- | ------ | ---- | ---- | --------------------------------------------------- |
7759| format  | string | 否   | 否   | 目标格式。</br>当前只支持"image/jpeg"、"image/webp"、"image/png"和"image/heif"<sup>12+</sup>(不同硬件设备支持情况不同)。<br>**说明:** 因为jpeg不支持透明通道,若使用带透明通道的数据编码jpeg格式,透明色将变为黑色。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
7760| quality | number | 否   | 否   | JPEG编码中设定输出图片质量的参数,取值范围为0-100。0质量最低,100质量最高,质量越高生成图片所占空间越大。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
7761| bufferSize<sup>9+</sup> | number | 否   | 是   | 接收编码数据的缓冲区大小,单位为Byte。如果不设置大小,默认为25M。如果编码图片超过25M,需要指定大小。bufferSize需大于编码后图片大小。使用[packToFile](#packtofile11)不受此参数限制。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
7762| desiredDynamicRange<sup>12+</sup> | [PackingDynamicRange](#packingdynamicrange12) | 否   | 是   | 目标动态范围。默认值为SDR。 |
7763| needsPackProperties<sup>12+</sup> | boolean | 否   | 是   | 是否需要编码图片属性信息,例如EXIF。默认值为false。 |
7764
7765## ImagePropertyOptions<sup>11+</sup>
7766
7767表示查询图片属性的索引。
7768
7769**系统能力:** SystemCapability.Multimedia.Image.ImageSource
7770
7771| 名称         | 类型   | 只读 | 可选 | 说明         |
7772| ------------ | ------ | ---- | ---- | ------------ |
7773| index        | number | 是   | 是   | 图片序号。默认值为0。   |
7774| defaultValue | string | 是   | 是   | 默认属性值。默认值为空。 |
7775
7776## GetImagePropertyOptions<sup>(deprecated)</sup>
7777
7778表示查询图片属性的索引。
7779
7780> **说明:**
7781>
7782> 从API version 11开始不再维护,建议使用[ImagePropertyOptions](#imagepropertyoptions11)代替。
7783
7784**系统能力:** SystemCapability.Multimedia.Image.ImageSource
7785
7786| 名称         | 类型   | 只读 | 可选 | 说明         |
7787| ------------ | ------ | ---- | ---- | ------------ |
7788| index        | number | 否   | 是   | 图片序号。默认值为0。   |
7789| defaultValue | string | 否   | 是   | 默认属性值。默认值为空。 |
7790
7791## PropertyKey<sup>7+</sup>
7792
7793枚举,Exif(Exchangeable image file format)图片信息。
7794
7795**系统能力:** SystemCapability.Multimedia.Image.Core
7796
7797| 名称               |   值                    |   说明                    |
7798| ----------------- | ----------------------- |---------------------------|
7799| NEW_SUBFILE_TYPE <sup>12+</sup>           | "NewSubfileType"            | **读写能力:** 可读写<br> 在Exif中,"NewSubfileType"字段用于标识子文件的数据类型,如全分辨率图像、缩略图或多帧图像的一部分。其值是位掩码,0代表全分辨率图像,1代表缩略图,2代表多帧图像的一部分。|
7800| SUBFILE_TYPE <sup>12+</sup>               | "SubfileType"               | **读写能力:** 可读写<br> 此标签指示此子文件中的数据类型。标签已弃用,请使用NewSubfileType替代。|
7801| IMAGE_WIDTH                               | "ImageWidth"                | **读写能力:** 可读写<br> 图片宽度。|
7802| IMAGE_LENGTH                              | "ImageLength"               | **读写能力:** 可读写<br> 图片长度。|
7803| BITS_PER_SAMPLE                           | "BitsPerSample"             | **读写能力:** 可读写<br> 每个像素比特数。|
7804| COMPRESSION <sup>12+</sup>                | "Compression"               | **读写能力:** 可读写<br> 图像压缩方案。|
7805| PHOTOMETRIC_INTERPRETATION <sup>12+</sup> | "PhotometricInterpretation" | **读写能力:** 可读写<br> 像素构成,例如 RGB 或 YCbCr。|
7806| IMAGE_DESCRIPTION<sup>10+</sup>           | "ImageDescription"          | **读写能力:** 可读写<br> 图像信息描述。|
7807| MAKE<sup>10+</sup>                        | "Make"                      | **读写能力:** 可读写<br> 生产商。|
7808| MODEL<sup>10+</sup>                       | "Model"                     | **读写能力:** 可读写<br> 设备型号。|
7809| STRIP_OFFSETS <sup>12+</sup>              | "StripOffsets"              | **读写能力:** 可读写<br> 每个strip的字节偏移量。|
7810| 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。|
7811| SAMPLES_PER_PIXEL <sup>12+</sup>          | "SamplesPerPixel"           | **读写能力:** 可读写<br> 每个像素的分量数。由于该标准适用于 RGB 和 YCbCr 图像,因此该标签的值设置为 3。在 JPEG 压缩数据中,使用 JPEG 标记代替该标签。|
7812| ROWS_PER_STRIP <sup>12+</sup>             | "RowsPerStrip"              | **读写能力:** 可读写<br> 每个strip的图像数据行数。|
7813| STRIP_BYTE_COUNTS <sup>12+</sup>          | "StripByteCounts"           | **读写能力:** 可读写<br> 每个图像数据带的总字节数。|
7814| X_RESOLUTION <sup>12+</sup>               | "XResolution"               | **读写能力:** 可读写<br> 图像宽度方向的分辨率。|
7815| Y_RESOLUTION <sup>12+</sup>               | "YResolution"               | **读写能力:** 可读写<br> 图像高度方向的分辨率。|
7816| PLANAR_CONFIGURATION <sup>12+</sup>       | "PlanarConfiguration"       | **读写能力:** 可读写<br> 表示像素组件的记录格式,chunky格式或是planar格式。|
7817| RESOLUTION_UNIT <sup>12+</sup>            | "ResolutionUnit"            | **读写能力:** 可读写<br> 用于测量XResolution和YResolution的单位。|
7818| TRANSFER_FUNCTION <sup>12+</sup>          | "TransferFunction"          | **读写能力:** 可读写<br> 图像的传递函数,通常用于颜色校正。|
7819| SOFTWARE <sup>12+</sup>                   | "Software"                  | **读写能力:** 可读写<br> 用于生成图像的软件的名称和版本。|
7820| DATE_TIME<sup>10+</sup>                   | "DateTime"                  | **读写能力:** 可读写<br> 日期时间。|
7821| ARTIST <sup>12+</sup>                     | "Artist"                    | **读写能力:** 可读写<br> 创建图像的用户名称。|
7822| WHITE_POINT <sup>12+</sup>                | "WhitePoint"                | **读写能力:** 可读写<br> 图像的白点色度。|
7823| PRIMARY_CHROMATICITIES <sup>12+</sup>     | "PrimaryChromaticities"     | **读写能力:** 可读写<br> 图像的主要颜色的色度。|
7824| PHOTO_MODE<sup>10+</sup>                  | "PhotoMode"                 | **读写能力:** 可读写<br> 拍照模式。|
7825| JPEG_INTERCHANGE_FORMAT <sup>12+</sup>    | "JPEGInterchangeFormat"     | **读写能力:** 可读写<br> JPEG压缩缩略图数据开始字节(SOI)的偏移。|
7826| JPEG_INTERCHANGE_FORMAT_LENGTH <sup>12+</sup> | "JPEGInterchangeFormatLength" | **读写能力:** 可读写<br> JPEG压缩缩略图数据的字节数。|
7827| YCBCR_COEFFICIENTS <sup>12+</sup>         | "YCbCrCoefficients"         | **读写能力:** 可读写<br> 从RGB到YCbCr图像数据的转换矩阵系数。|
7828| YCBCR_SUB_SAMPLING <sup>12+</sup>         | "YCbCrSubSampling"          | **读写能力:** 可读写<br> 色度分量与亮度分量的采样比率。|
7829| YCBCR_POSITIONING <sup>12+</sup>          | "YCbCrPositioning"          | **读写能力:** 可读写<br> 色度分量相对于亮度分量的位置。|
7830| REFERENCE_BLACK_WHITE <sup>12+</sup>      | "ReferenceBlackWhite"       | **读写能力:** 可读写<br> 参考黑点值和参考白点值。|
7831| COPYRIGHT <sup>12+</sup>                  | "Copyright"                 | **读写能力:** 可读写<br> 图像的版权信息。|
7832| EXPOSURE_TIME<sup>9+</sup>                | "ExposureTime"              | **读写能力:** 可读写<br> 曝光时间,例如1/33 sec。|
7833| F_NUMBER<sup>9+</sup>                     | "FNumber"                   | **读写能力:** 可读写<br> 光圈值,例如f/1.8。|
7834| EXPOSURE_PROGRAM <sup>12+</sup>           | "ExposureProgram"           | **读写能力:** 可读写<br> 拍照时相机用来设置曝光的程序的类别。|
7835| SPECTRAL_SENSITIVITY <sup>12+</sup>       | "SpectralSensitivity"       | **读写能力:** 可读写<br> 表示所用相机的每个通道的光谱灵敏度。|
7836| GPS_VERSION_ID <sup>12+</sup>             | "GPSVersionID"              | **读写能力:** 可读写<br> GPSInfoIFD的版本。|
7837| GPS_LATITUDE_REF                          | "GPSLatitudeRef"            | **读写能力:** 可读写<br> 纬度引用,例如N或S。|
7838| GPS_LATITUDE                              | "GPSLatitude"               | **读写能力:** 可读写<br> 图片纬度。修改时应按"度,分,秒"格式传入,如"39,54,7.542"|
7839| GPS_LONGITUDE_REF                         | "GPSLongitudeRef"           | **读写能力:** 可读写<br> 经度引用,例如W或E。|
7840| GPS_LONGITUDE                             | "GPSLongitude"              | **读写能力:** 可读写<br> 图片经度。修改时应按"度,分,秒"格式传入,如"116,19,42.16"|
7841| GPS_ALTITUDE_REF <sup>12+</sup>           | "GPSAltitudeRef"            | **读写能力:** 可读写<br> 用于GPS高度的参照高度。|
7842| GPS_ALTITUDE <sup>12+</sup>               | "GPSAltitude"               | **读写能力:** 可读写<br> 基于GPSAltitudeRef的高度。|
7843| GPS_TIME_STAMP<sup>10+</sup>              | "GPSTimeStamp"              | **读写能力:** 可读写<br> GPS时间戳。|
7844| GPS_SATELLITES <sup>12+</sup>             | "GPSSatellites"             | **读写能力:** 可读写<br> 用于测量的GPS卫星。|
7845| GPS_STATUS <sup>12+</sup>                 | "GPSStatus"                 | **读写能力:** 可读写<br> 录制图像时GPS接收器的状态。|
7846| GPS_MEASURE_MODE <sup>12+</sup>           | "GPSMeasureMode"            | **读写能力:** 可读写<br> GPS测量模式。|
7847| GPS_DOP <sup>12+</sup>                    | "GPSDOP"                    | **读写能力:** 可读写<br> GPS DOP(数据精度等级)。|
7848| GPS_SPEED_REF <sup>12+</sup>              | "GPSSpeedRef"               | **读写能力:** 可读写<br> 用来表示GPS接收器移动速度的单位。|
7849| GPS_SPEED <sup>12+</sup>                  | "GPSSpeed"                  | **读写能力:** 可读写<br> GPS接收器的移动速度。|
7850| GPS_TRACK_REF <sup>12+</sup>              | "GPSTrackRef"               | **读写能力:** 可读写<br> GPS接收机移动方向的参照。|
7851| GPS_TRACK <sup>12+</sup>                  | "GPSTrack"                  | **读写能力:** 可读写<br> GPS接收机的移动方向。|
7852| GPS_IMG_DIRECTION_REF <sup>12+</sup>      | "GPSImgDirectionRef"        | **读写能力:** 可读写<br> 图像方向的参照。|
7853| GPS_IMG_DIRECTION <sup>12+</sup>          | "GPSImgDirection"           | **读写能力:** 可读写<br> 拍摄时图像的方向。|
7854| GPS_MAP_DATUM <sup>12+</sup>              | "GPSMapDatum"               | **读写能力:** 可读写<br> GPS接收器使用的大地测量数据。|
7855| GPS_DEST_LATITUDE_REF <sup>12+</sup>      | "GPSDestLatitudeRef"        | **读写能力:** 可读写<br> 目的地点的纬度参照。|
7856| GPS_DEST_LATITUDE <sup>12+</sup>          | "GPSDestLatitude"           | **读写能力:** 可读写<br> 目的地点的纬度。|
7857| GPS_DEST_LONGITUDE_REF <sup>12+</sup>     | "GPSDestLongitudeRef"       | **读写能力:** 可读写<br> 目的地点的经度参照。|
7858| GPS_DEST_LONGITUDE <sup>12+</sup>         | "GPSDestLongitude"          | **读写能力:** 可读写<br> 目的地点的经度。|
7859| GPS_DEST_BEARING_REF <sup>12+</sup>       | "GPSDestBearingRef"         | **读写能力:** 可读写<br> 指向目的地点的方位参照。|
7860| GPS_DEST_BEARING <sup>12+</sup>           | "GPSDestBearing"            | **读写能力:** 可读写<br> 目的地方位。|
7861| GPS_DEST_DISTANCE_REF <sup>12+</sup>      | "GPSDestDistanceRef"        | **读写能力:** 可读写<br> 目标点距离的测量单位。|
7862| GPS_DEST_DISTANCE <sup>12+</sup>          | "GPSDestDistance"           | **读写能力:** 可读写<br> 到目的地点的距离。|
7863| GPS_PROCESSING_METHOD <sup>12+</sup>      | "GPSProcessingMethod"       | **读写能力:** 可读写<br> 记录定位方法名的字符字符串。|
7864| GPS_AREA_INFORMATION <sup>12+</sup>       | "GPSAreaInformation"        | **读写能力:** 可读写<br> 记录GPS区域名的字符字符串。|
7865| GPS_DATE_STAMP<sup>10+</sup>              | "GPSDateStamp"              | **读写能力:** 可读写<br> GPS日期戳。|
7866| GPS_DIFFERENTIAL <sup>12+</sup>           | "GPSDifferential"           | **读写能力:** 可读写<br> 此字段表示GPS数据是否应用了差分校正,对于精确的位置准确性至关重要。|
7867| GPS_H_POSITIONING_ERROR <sup>12+</sup>    | "GPSHPositioningError"      | **读写能力:** 可读写<br> 此标签指示水平定位误差,单位为米。|
7868| ISO_SPEED_RATINGS<sup>9+</sup>            | "ISOSpeedRatings"           | **读写能力:** 可读写<br> ISO感光度,例如400。|
7869| PHOTOGRAPHIC_SENSITIVITY <sup>12+</sup>   | "PhotographicSensitivity"   | **读写能力:** 可读写<br> 此标签指示拍摄图像时相机或输入设备的灵敏度。|
7870| OECF <sup>12+</sup>                       | "OECF"                      | **读写能力:** 可读写<br> 表示ISO 14524中规定的光电转换函数(OECF)。|
7871| SENSITIVITY_TYPE<sup>10+</sup>            | "SensitivityType"           | **读写能力:** 可读写<br> 灵敏度类型。|
7872| STANDARD_OUTPUT_SENSITIVITY<sup>10+</sup> | "StandardOutputSensitivity" | **读写能力:** 可读写<br> 标准输出灵敏度。|
7873| RECOMMENDED_EXPOSURE_INDEX<sup>10+</sup>  | "RecommendedExposureIndex"  | **读写能力:** 可读写<br> 推荐曝光指数。|
7874| ISO_SPEED<sup>10+</sup>                   | "ISOSpeedRatings"           | **读写能力:** 可读写<br> ISO速度等级。|
7875| ISO_SPEED_LATITUDE_YYY <sup>12+</sup>     | "ISOSpeedLatitudeyyy"       | **读写能力:** 可读写<br> 该标签指示摄像机或输入设备的ISO速度纬度yyy值,该值在ISO 12232中定义。|
7876| ISO_SPEED_LATITUDE_ZZZ <sup>12+</sup>     | "ISOSpeedLatitudezzz"       | **读写能力:** 可读写<br> 该标签指示摄像机或输入设备的ISO速度纬度zzz值,该值在ISO 12232中定义。|
7877| EXIF_VERSION <sup>12+</sup>               | "ExifVersion"               | **读写能力:** 可读写<br> 支持的Exif标准版本。|
7878| DATE_TIME_ORIGINAL<sup>9+</sup>           | "DateTimeOriginal"          | **读写能力:** 可读写<br> 拍摄时间,例如2022:09:06 15:48:00。|
7879| DATE_TIME_DIGITIZED <sup>12+</sup>        | "DateTimeDigitized"         | **读写能力:** 可读写<br> 图像作为数字数据存储的日期和时间,格式为YYYY:MM:DD HH:MM:SS|
7880| OFFSET_TIME <sup>12+</sup>                | "OffsetTime"                | **读写能力:** 可读写<br> 在Exif中,OffsetTime字段表示与UTC(协调世界时)的时间偏移,格式为±HH:MM,用于确定照片拍摄的本地时间。|
7881| OFFSET_TIME_ORIGINAL <sup>12+</sup>       | "OffsetTimeOriginal"        | **读写能力:** 可读写<br> 此标签记录原始图像创建时的UTC偏移量,对于时间敏感的应用至关重要。|
7882| OFFSET_TIME_DIGITIZED <sup>12+</sup>      | "OffsetTimeDigitized"       | **读写能力:** 可读写<br> 此标签记录图像数字化时的UTC偏移量,有助于准确调整时间戳。|
7883| COMPONENTS_CONFIGURATION <sup>12+</sup>   | "ComponentsConfiguration"   | **读写能力:** 可读写<br> 压缩数据的特定信息。|
7884| COMPRESSED_BITS_PER_PIXEL <sup>12+</sup>  | "CompressedBitsPerPixel"    | **读写能力:** 可读写<br> 用于压缩图像的压缩模式,单位为每像素位数。|
7885| SHUTTER_SPEED <sup>12+</sup>              | "ShutterSpeedValue"         | **读写能力:** 可读写<br> 快门速度,以APEX(摄影曝光的加法系统)值表示。|
7886| APERTURE_VALUE<sup>10+</sup>              | "ApertureValue"             | **读写能力:** 可读写<br> 光圈值。|
7887| BRIGHTNESS_VALUE <sup>12+</sup>           | "BrightnessValue"           | **读写能力:** 可读写<br> 图像的亮度值,以APEX单位表示。|
7888| EXPOSURE_BIAS_VALUE<sup>10+</sup>         | "ExposureBiasValue"         | **读写能力:** 可读写<br> 曝光偏差值。|
7889| MAX_APERTURE_VALUE <sup>12+</sup>         | "MaxApertureValue"          | **读写能力:** 可读写<br> 最小F数镜头。|
7890| SUBJECT_DISTANCE <sup>12+</sup>           | "SubjectDistance"           | **读写能力:** 可读写<br> 测量单位为米的主体距离。|
7891| METERING_MODE<sup>10+</sup>               | "MeteringMode"              | **读写能力:** 可读写<br> 测光模式。|
7892| LIGHT_SOURCE<sup>10+</sup>                | "LightSource"               | **读写能力:** 可读写<br> 光源。|
7893| FLASH <sup>10+</sup>                      | "Flash"                     | **读写能力:** 可读写<br> 闪光灯,记录闪光灯状态。|
7894| FOCAL_LENGTH <sup>10+</sup>               | "FocalLength"               | **读写能力:** 可读写<br> 焦距。|
7895| SUBJECT_AREA <sup>12+</sup>               | "SubjectArea"               | **读写能力:** 可读写<br> 该标签指示整个场景中主要主体的位置和区域。|
7896| MAKER_NOTE <sup>12+</sup>                 | "MakerNote"                 | **读写能力:** 只读<br> Exif/DCF制造商使用的标签,用于记录任何所需信息。|
7897| SCENE_POINTER <sup>12+</sup>              | "HwMnoteScenePointer"       | **读写能力:** 只读<br> 场景指针。|
7898| SCENE_VERSION <sup>12+</sup>              | "HwMnoteSceneVersion"       | **读写能力:** 只读<br> 场景算法版本信息。|
7899| SCENE_FOOD_CONF<sup>11+</sup>             | "HwMnoteSceneFoodConf"      | **读写能力:** 只读<br> 拍照场景:食物。|
7900| SCENE_STAGE_CONF<sup>11+</sup>            | "HwMnoteSceneStageConf"     | **读写能力:** 只读<br> 拍照场景:舞台。|
7901| SCENE_BLUE_SKY_CONF<sup>11+</sup>         | "HwMnoteSceneBlueSkyConf"   | **读写能力:** 只读<br> 拍照场景:蓝天。|
7902| SCENE_GREEN_PLANT_CONF<sup>11+</sup>      | "HwMnoteSceneGreenPlantConf" | **读写能力:** 只读<br> 拍照场景:绿植。|
7903| SCENE_BEACH_CONF<sup>11+</sup>            | "HwMnoteSceneBeachConf"     | **读写能力:** 只读<br> 拍照场景:沙滩。|
7904| SCENE_SNOW_CONF<sup>11+</sup>             | "HwMnoteSceneSnowConf"      | **读写能力:** 只读<br> 拍照场景:下雪。|
7905| SCENE_SUNSET_CONF<sup>11+</sup>           | "HwMnoteSceneSunsetConf"    | **读写能力:** 只读<br> 拍照场景:日落。|
7906| SCENE_FLOWERS_CONF<sup>11+</sup>          | "HwMnoteSceneFlowersConf"   | **读写能力:** 只读<br> 拍照场景:花。|
7907| SCENE_NIGHT_CONF<sup>11+</sup>            | "HwMnoteSceneNightConf"     | **读写能力:** 只读<br> 拍照场景:夜晚。|
7908| SCENE_TEXT_CONF<sup>11+</sup>             | "HwMnoteSceneTextConf"      | **读写能力:** 只读<br> 拍照场景:文本。|
7909| FACE_POINTER <sup>12+</sup>               | "HwMnoteFacePointer"        | **读写能力:** 只读<br> 脸部指针。|
7910| FACE_VERSION <sup>12+</sup>               | "HwMnoteFaceVersion"        | **读写能力:** 只读<br> 人脸算法版本信息。|
7911| FACE_COUNT<sup>11+</sup>                  | "HwMnoteFaceCount"          | **读写能力:** 只读<br> 人脸数量。|
7912| FACE_CONF <sup>12+</sup>                  | "HwMnoteFaceConf"           | **读写能力:** 只读<br> 人脸置信度。|
7913| FACE_SMILE_SCORE <sup>12+</sup>           | "HwMnoteFaceSmileScore"     | **读写能力:** 只读<br> FaceCount张人脸的笑脸分数。|
7914| FACE_RECT <sup>12+</sup>                  | "HwMnoteFaceRect"           | **读写能力:** 只读<br> 脸部矩形。|
7915| FACE_LEYE_CENTER <sup>12+</sup>           | "HwMnoteFaceLeyeCenter"     | **读写能力:** 只读<br> 左眼中心。|
7916| FACE_REYE_CENTER <sup>12+</sup>           | "HwMnoteFaceReyeCenter"     | **读写能力:** 只读<br> 右眼中心。|
7917| FACE_MOUTH_CENTER <sup>12+</sup>          | "HwMnoteFaceMouthCenter"    | **读写能力:** 只读<br> 嘴中心。|
7918| CAPTURE_MODE <sup>10+</sup>               | "HwMnoteCaptureMode"        | **读写能力:** 可读写<br> 捕获模式。|
7919| BURST_NUMBER <sup>12+</sup>               | "HwMnoteBurstNumber"        | **读写能力:** 只读<br> 连拍次数。|
7920| FRONT_CAMERA <sup>12+</sup>               | "HwMnoteFrontCamera"        | **读写能力:** 只读<br> 是否是前置相机自拍。|
7921| ROLL_ANGLE <sup>11+</sup>                 | "HwMnoteRollAngle"          | **读写能力:** 只读<br> 滚动角度。|
7922| PITCH_ANGLE<sup>11+</sup>                 | "HwMnotePitchAngle"         | **读写能力:** 只读<br> 俯仰角度。|
7923| PHYSICAL_APERTURE <sup>10+</sup>          | "HwMnotePhysicalAperture"   | **读写能力:** 只读<br> 物理孔径,光圈大小。|
7924| FOCUS_MODE<sup>11+</sup>                  | "HwMnoteFocusMode"          | **读写能力:** 只读<br> 对焦模式。|
7925| USER_COMMENT <sup>10+</sup>               | "UserComment"               | **读写能力:** 可读写<br> 用户注释。|
7926| SUBSEC_TIME <sup>12+</sup>                | "SubsecTime"                | **读写能力:** 可读写<br> 用于为DateTime标签记录秒的分数的标签。|
7927| SUBSEC_TIME_ORIGINAL <sup>12+</sup>       | "SubsecTimeOriginal"        | **读写能力:** 可读写<br> 用于为DateTimeOriginal标签记录秒的分数的标签。|
7928| SUBSEC_TIME_DIGITIZED <sup>12+</sup>      | "SubsecTimeDigitized"       | **读写能力:** 可读写<br> 用于为DateTimeDigitized标签记录秒的分数的标签。|
7929| FLASHPIX_VERSION <sup>12+</sup>           | "FlashpixVersion"           | **读写能力:** 可读写<br> 该标签表示FPXR文件支持的Flashpix格式版本,增强了设备兼容性。|
7930| COLOR_SPACE <sup>12+</sup>                | "ColorSpace"                | **读写能力:** 可读写<br> 色彩空间信息标签,通常记录为色彩空间指定符。|
7931| PIXEL_X_DIMENSION <sup>10+</sup>          | "PixelXDimension"           | **读写能力:** 可读写<br> 像素X尺寸。|
7932| PIXEL_Y_DIMENSION<sup>10+</sup>           | "PixelYDimension"           | **读写能力:** 可读写<br> 像素Y尺寸。|
7933| RELATED_SOUND_FILE <sup>12+</sup>         | "RelatedSoundFile"          | **读写能力:** 可读写<br> 与图像数据相关的音频文件的名称。|
7934| FLASH_ENERGY <sup>12+</sup>               | "FlashEnergy"               | **读写能力:** 可读写<br> 图像捕获时的闪光能量,以BCPS表示。|
7935| SPATIAL_FREQUENCY_RESPONSE <sup>12+</sup> | "SpatialFrequencyResponse"  | **读写能力:** 可读写<br> 相机或输入设备的空间频率表。|
7936| FOCAL_PLANE_X_RESOLUTION <sup>12+</sup>   | "FocalPlaneXResolution"     | **读写能力:** 可读写<br> 图像宽度中每FocalPlaneResolutionUnit的像素。|
7937| FOCAL_PLANE_Y_RESOLUTION <sup>12+</sup>   | "FocalPlaneYResolution"     | **读写能力:** 可读写<br> 图像高度中每FocalPlaneResolutionUnit的像素。|
7938| FOCAL_PLANE_RESOLUTION_UNIT <sup>12+</sup> | "FocalPlaneResolutionUnit"  | **读写能力:** 可读写<br> 测量FocalPlaneXResolution和FocalPlaneYResolution的单位。|
7939| SUBJECT_LOCATION <sup>12+</sup>           | "SubjectLocation"           | **读写能力:** 可读写<br> 主要对象相对于左边缘的位置。|
7940| EXPOSURE_INDEX <sup>12+</sup>             | "ExposureIndex"             | **读写能力:** 可读写<br> 捕获时选定的曝光指数。|
7941| SENSING_METHOD <sup>12+</sup>             | "SensingMethod"             | **读写能力:** 可读写<br> 相机上的图像传感器类型。|
7942| FILE_SOURCE <sup>12+</sup>                | "FileSource"                | **读写能力:** 可读写<br> 表明图像来源。|
7943| SCENE_TYPE<sup>9+</sup>                   | "SceneType"                 | **读写能力:** 可读写<br> 拍摄场景模式,例如人像、风光、运动、夜景等。|
7944| CFA_PATTERN <sup>12+</sup>                | "CFAPattern"                | **读写能力:** 可读写<br> 图像传感器的色彩滤光片(CFA)几何图案。|
7945| CUSTOM_RENDERED <sup>12+</sup>            | "CustomRendered"            | **读写能力:** 可读写<br> 指示图像数据上的特殊处理。|
7946| EXPOSURE_MODE <sup>12+</sup>              | "ExposureMode"              | **读写能力:** 可读写<br> 拍摄时设置的曝光模式。|
7947| WHITE_BALANCE <sup>10+</sup>              | "WhiteBalance"              | **读写能力:** 可读写<br> 白平衡。|
7948| DIGITAL_ZOOM_RATIO <sup>12+</sup>         | "DigitalZoomRatio"          | **读写能力:** 可读写<br> 捕获时的数字变焦比率。|
7949| FOCAL_LENGTH_IN_35_MM_FILM <sup>10+</sup> | "FocalLengthIn35mmFilm"     | **读写能力:** 可读写<br> 焦距35毫米胶片。|
7950| SCENE_CAPTURE_TYPE <sup>12+</sup>         | "SceneCaptureType"          | **读写能力:** 可读写<br> 捕获的场景类型。|
7951| GAIN_CONTROL <sup>12+</sup>               | "GainControl"               | **读写能力:** 可读写<br> 整体图像增益调整的程度。|
7952| CONTRAST <sup>12+</sup>                   | "Contrast"                  | **读写能力:** 可读写<br> 相机应用的对比度处理方向。|
7953| SATURATION <sup>12+</sup>                 | "Saturation"                | **读写能力:** 可读写<br> 相机应用的饱和度处理方向。|
7954| SHARPNESS <sup>12+</sup>                  | "Sharpness"                 | **读写能力:** 可读写<br> 相机应用的锐度处理方向。|
7955| DEVICE_SETTING_DESCRIPTION <sup>12+</sup> | "DeviceSettingDescription"  | **读写能力:** 可读写<br> 特定相机模型的拍照条件信息。|
7956| SUBJECT_DISTANCE_RANGE <sup>12+</sup>     | "SubjectDistanceRange"      | **读写能力:** 可读写<br> 表示主体到相机的距离范围。|
7957| IMAGE_UNIQUE_ID <sup>12+</sup>            | "ImageUniqueID"             | **读写能力:** 可读写<br> 为每张图片唯一分配的标识符。|
7958| CAMERA_OWNER_NAME <sup>12+</sup>          | "CameraOwnerName"           | **读写能力:** 可读写<br> 相机所有者的姓名。|
7959| BODY_SERIAL_NUMBER <sup>12+</sup>         | "BodySerialNumber"          | **读写能力:** 可读写<br> 相机机身的序列号。|
7960| LENS_SPECIFICATION <sup>12+</sup>         | "LensSpecification"         | **读写能力:** 可读写<br> 使用的镜头规格。|
7961| LENS_MAKE <sup>12+</sup>                  | "LensMake"                  | **读写能力:** 可读写<br> 镜头的制造商。|
7962| LENS_MODEL <sup>12+</sup>                 | "LensModel"                 | **读写能力:** 可读写<br> 镜头的型号名称。|
7963| LENS_SERIAL_NUMBER <sup>12+</sup>         | "LensSerialNumber"          | **读写能力:** 可读写<br> 镜头的序列号。|
7964| COMPOSITE_IMAGE <sup>12+</sup>            | "CompositeImage"            | **读写能力:** 可读写<br> 表示图像是否为合成图像。|
7965| SOURCE_IMAGE_NUMBER_OF_COMPOSITE_IMAGE <sup>12+</sup>   | "SourceImageNumberOfCompositeImage"       | **读写能力:** 可读写<br> 用于合成图像的源图像数量。|
7966| SOURCE_EXPOSURE_TIMES_OF_COMPOSITE_IMAGE <sup>12+</sup> | "SourceExposureTimesOfCompositeImage"     | **读写能力:** 可读写<br> 合成图像的源图像曝光时间。|
7967| GAMMA <sup>12+</sup>                      | "Gamma"                     | **读写能力:** 可读写<br> 表示系数伽马的值。|
7968| DNG_VERSION <sup>12+</sup>                | "DNGVersion"                | **读写能力:** 可读写<br> DNG版本标签编码了符合DNG规范的四级版本号。|
7969| DEFAULT_CROP_SIZE <sup>12+</sup>          | "DefaultCropSize"           | **读写能力:** 可读写<br> DefaultCropSize指定了原始坐标中的最终图像大小,考虑了额外的边缘像素。|
7970| GIF_LOOP_COUNT <sup>12+</sup>             | "GIFLoopCount"              | **读写能力:** 只读<br> GIF图片循环次数。0表示无限循环,其他值表示循环次数。|
7971| IS_XMAGE_SUPPORTED <sup>12+</sup> | "HwMnoteIsXmageSupported" | **读写能力:** 可读写<br>是否支持XMAGE。 |
7972| XMAGE_MODE <sup>12+</sup> | "HwMnoteXmageMode" | **读写能力:** 可读写<br>XMAGE水印模式。 |
7973| XMAGE_LEFT <sup>12+</sup> | "HwMnoteXmageLeft" | **读写能力:** 可读写<br>水印区域X1坐标。 |
7974| XMAGE_TOP <sup>12+</sup> | "HwMnoteXmageTop" | **读写能力:** 可读写<br>水印区域Y1坐标。 |
7975| XMAGE_RIGHT <sup>12+</sup> | "HwMnoteXmageRight" | **读写能力:** 可读写<br>水印区域X2坐标。 |
7976| XMAGE_BOTTOM <sup>12+</sup> | "HwMnoteXmageBottom" | **读写能力:** 可读写<br>水印区域Y2坐标。 |
7977| CLOUD_ENHANCEMENT_MODE <sup>12+</sup> | "HwMnoteCloudEnhancementMode" | **读写能力:** 可读写<br>云增强模式。 |
7978| WIND_SNAPSHOT_MODE <sup>12+</sup> | "HwMnoteWindSnapshotMode" | **读写能力:** 只读<br>运动快拍模式。 |
7979
7980## FragmentMapPropertyKey<sup>13+</sup>
7981
7982枚举,水印裁剪图图片信息。
7983
7984**系统能力:** SystemCapability.Multimedia.Image.Core
7985
7986| 名称          | 值                    | 说明                                |
7987| ------------- | --------------------- | ----------------------------------- |
7988| X_IN_ORIGINAL | "XInOriginal"         | 水印裁剪图左上角在原始图中的X坐标。 |
7989| Y_IN_ORIGINAL | "YInOriginal"         | 水印裁剪图左上角在原始图中的Y坐标。 |
7990| WIDTH         | "FragmentImageWidth"  | 水印裁剪图的宽。                    |
7991| HEIGHT        | "FragmentImageHeight" | 水印裁剪图的高。                    |
7992
7993## ImageFormat<sup>9+</sup>
7994
7995枚举,图片格式。
7996
7997**系统能力:** SystemCapability.Multimedia.Image.Core
7998
7999| 名称         |   值   | 说明                 |
8000| ------------ | ------ | -------------------- |
8001| YCBCR_422_SP | 1000   | YCBCR422半平面格式。 |
8002| JPEG         | 2000   | JPEG编码格式。       |
8003
8004## ComponentType<sup>9+</sup>
8005
8006枚举,图像的组件类型。
8007
8008**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
8009
8010| 名称  |   值   | 说明        |
8011| ----- | ------ | ----------- |
8012| YUV_Y | 1      | 亮度信息。  |
8013| YUV_U | 2      | 色度信息。  |
8014| YUV_V | 3      | 色度信息。  |
8015| JPEG  | 4      | JPEG 类型。 |
8016
8017## Component<sup>9+</sup>
8018
8019描述图像颜色分量。
8020
8021**系统能力:** SystemCapability.Multimedia.Image.Core
8022
8023| 名称          | 类型                             | 只读 | 可选 | 说明         |
8024| ------------- | -------------------------------- | ---- | ---- | ------------ |
8025| componentType | [ComponentType](#componenttype9) | 是   | 否   | 组件类型。   |
8026| rowStride     | number                           | 是   | 否   | 行距。读取相机预览流数据时,需要考虑按stride进行读取,具体用法见[ArkTS双路预览示例](../../media/camera/camera-dual-channel-preview.md)。       |
8027| pixelStride   | number                           | 是   | 否   | 像素间距。   |
8028| byteBuffer    | ArrayBuffer                      | 是   | 否   | 组件缓冲区。 |
8029
8030## DecodingDynamicRange<sup>12+</sup>
8031
8032描述解码时期望的图像动态范围。
8033
8034**系统能力:** SystemCapability.Multimedia.Image.Core
8035
8036| 名称          | 值       | 说明         |
8037| ------------- | ----------| ------------ |
8038| AUTO          | 0    | 自适应,根据图片信息处理。即如果图片本身为HDR图片,则会按照HDR内容解码;反之按照SDR内容解码。通过[CreateIncrementalSource](#imagecreateincrementalsource9)创建的imagesource会解码为SDR内容。  |
8039| SDR           | 1    | 按照标准动态范围处理图片。   |
8040| HDR           | 2    | 按照高动态范围处理图片。通过[CreateIncrementalSource](#imagecreateincrementalsource9)创建的imagesource会解码为SDR内容。     |
8041
8042## PackingDynamicRange<sup>12+</sup>
8043
8044描述编码时期望的图像动态范围。
8045
8046**系统能力:** SystemCapability.Multimedia.Image.Core
8047
8048| 名称          | 值       | 说明         |
8049| ------------- | ----------| ------------ |
8050| AUTO          | 0    | 自适应,根据[pixelmap](#pixelmap7)内容处理。即如果pixelmap本身为HDR,则会按照HDR内容进行编码;反之按照SDR内容编码。  |
8051| SDR           | 1    | 按照标准动态范围处理图片。   |
8052
8053## HdrMetadataKey<sup>12+</sup>
8054
8055枚举,[pixelmap](#pixelmap7)使用的HDR相关元数据信息的关键字。
8056
8057**系统能力:** SystemCapability.Multimedia.Image.Core
8058
8059| 名称          | 值       | 说明         |
8060| ------------- | ----------| ------------ |
8061| HDR_METADATA_TYPE    | 0    | [pixelmap](#pixelmap7)使用的元数据类型。  |
8062| HDR_STATIC_METADATA  | 1    | 静态元数据。   |
8063| HDR_DYNAMIC_METADATA | 2    | 动态元数据。   |
8064| HDR_GAINMAP_METADATA | 3    | Gainmap使用的元数据。   |
8065
8066## HdrMetadataType<sup>12+</sup>
8067
8068枚举,[HdrMetadataKey](#hdrmetadatakey12)中HDR_METADATA_TYPE关键字对应的值。
8069
8070**系统能力:** SystemCapability.Multimedia.Image.Core
8071
8072| 名称          | 值       | 说明         |
8073| ------------- | ----------| ------------ |
8074| NONE     | 0    | 无元数据内容。  |
8075| BASE     | 1    | 表示用于基础图的元数据。   |
8076| GAINMAP  | 2    | 表示用于Gainmap图的元数据。   |
8077| ALTERNATE| 3    | 表示用于合成后HDR图的元数据。   |
8078
8079## HdrStaticMetadata<sup>12+</sup>
8080
8081静态元数据值,[HdrMetadataKey](#hdrmetadatakey12)中HDR_STATIC_METADATA关键字对应的值。
8082
8083**系统能力:** SystemCapability.Multimedia.Image.Core
8084
8085| 名称          | 类型       | 只读 | 可选 | 说明         |
8086| ------------- | ----------| -- | -- | ------------ |
8087| displayPrimariesX     | Array\<number>  | 否 | 否 | 归一化后显示设备三基色的X坐标,数组的长度为3,以0.00002为单位,范围[0.0, 1.0]。  |
8088| displayPrimariesY     | Array\<number>  | 否 | 否 | 归一化后显示设备三基色的Y坐标,数组的长度为3,以0.00002为单位,范围[0.0, 1.0]。  |
8089| whitePointX  | number  | 否 | 否 | 归一化后白点值的X坐标,以0.00002为单位,范围[0.0, 1.0]。   |
8090| whitePointY  | number   | 否 | 否 | 归一化后白点值的Y坐标,以0.00002为单位,范围[0.0, 1.0]。   |
8091| maxLuminance  | number  | 否 | 否 | 图像主监视器最大亮度。以1为单位,最大值为65535。   |
8092| minLuminance  | number   | 否 | 否 | 图像主监视器最小亮度。以0.0001为单位,最大值6.55535。   |
8093| maxContentLightLevel  | number  | 否 | 否 | 显示内容的最大亮度。以1为单位,最大值为65535。   |
8094| maxFrameAverageLightLevel  | number  | 否 | 否 | 显示内容的最大平均亮度,以1为单位,最大值为65535。 |
8095
8096## GainmapChannel<sup>12+</sup>
8097
8098Gainmap图单个通道的数据内容,参考ISO 21496-1。
8099
8100**系统能力:** SystemCapability.Multimedia.Image.Core
8101
8102| 名称          | 类型       | 只读 | 可选 | 说明         |
8103| ------------- | ----------| -- | -- | ------------ |
8104| gainmapMax     | number   | 否 | 否 | 增强图像的最大值,参考ISO 21496-1。  |
8105| gainmapMin     | number   | 否 | 否 | 增强图像的最小值,参考ISO 21496-1。  |
8106| gamma  | number    | 否 | 否 | gamma值,参考ISO 21496-1。   |
8107| baseOffset  | number     | 否 | 否 | 基础图的偏移,参考ISO 21496-1。   |
8108| alternateOffset  | number    | 否 | 否 | 提取的可选择图像偏移量,参考ISO 21496-1。    |
8109
8110## HdrGainmapMetadata<sup>12+</sup>
8111
8112Gainmap使用的元数据值,[HdrMetadataKey](#hdrmetadatakey12)中HDR_GAINMAP_METADATA关键字对应的值,参考ISO 21496-1。
8113
8114**系统能力:** SystemCapability.Multimedia.Image.Core
8115
8116| 名称          | 类型       | 只读 | 可选 | 说明         |
8117| ------------- | ----------| -- | -- | ------------ |
8118| writerVersion     | number   | 否 | 否 | 元数据编写器使用的版本。  |
8119| miniVersion     | number   | 否 | 否 | 元数据解析需要理解的最小版本。  |
8120| gainmapChannelCount  | number    | 否 | 否 | Gainmap的颜色通道数,值为3时RGB通道的元数据值不同,值为1时各通道元数据值相同,参考ISO 21496-1。  |
8121| useBaseColorFlag  | boolean     | 否 | 否 | 是否使用基础图的色彩空间,参考ISO 21496-1。   |
8122| baseHeadroom  | number    | 否 | 否 |  基础图提亮比,参考ISO 21496-1。   |
8123| alternateHeadroom  | number     | 否 | 否 |  提取的可选择图像提亮比,参考ISO 21496-1。  |
8124| channels  | Array<[GainmapChannel](#gainmapchannel12)> | 否 | 否 | 各通道的数据,长度为3,参考ISO 21496-1。 |
8125
8126## HdrMetadataValue<sup>12+</sup>
8127
8128type HdrMetadataValue = HdrMetadataType | HdrStaticMetadata | ArrayBuffer | HdrGainmapMetadata
8129
8130PixelMap使用的HDR元数据值类型,和[HdrMetadataKey](#hdrmetadatakey12)关键字相对应。
8131
8132**系统能力:** SystemCapability.Multimedia.Image.Core
8133
8134| 类型                | 说明                                            |
8135| ------------------- | ----------------------------------------------- |
8136| [HdrMetadataType](#hdrmetadatatype12) | [HdrMetadataKey](#hdrmetadatakey12)中HDR_GAINMAP_METADATA关键字对应的元数据值类型。 |
8137| [HdrStaticMetadata](#hdrstaticmetadata12) | [HdrMetadataKey](#hdrmetadatakey12)中HDR_STATIC_METADATA关键字对应的元数据值类型。 |
8138| ArrayBuffer | [HdrMetadataKey](#hdrmetadatakey12)中HDR_DYNAMIC_METADATA关键字对应的元数据值类型。 |
8139| [HdrGainmapMetadata](#hdrgainmapmetadata12) | [HdrMetadataKey](#hdrmetadatakey12)中HDR_GAINMAP_METADATA关键字对应的元数据值类型。 |
8140
8141## AntiAliasingLevel<sup>12+</sup>
8142
8143缩放时的缩放算法。
8144
8145**系统能力:** SystemCapability.Multimedia.Image.Core
8146
8147| 名称                   |   值   | 说明              |
8148| ---------------------- | ------ | ----------------- |
8149| NONE                | 0      | 默认为最近邻缩放算法。        |
8150| LOW                 | 1      | 双线性缩放算法。     |
8151| MEDIUM              | 2      | 双线性缩放算法,同步开启mipmap。|
8152| HIGH                | 3      | cubic缩放算法。 |
8153
8154## 补充说明
8155### SVG标签说明
8156
8157从API version 10开始支持SVG标签,使用版本为(SVG) 1.1,SVG文件需添加xml声明,应以“<?xml”开头,并且SVG标签需设置width,height。当前支持的标签列表有:
8158- a
8159- circla
8160- clipPath
8161- defs
8162- ellipse
8163- feBlend
8164- feColorMatrix
8165- feComposite
8166- feDiffuseLighting
8167- feDisplacementMap
8168- feDistantLight
8169- feFlood
8170- feGaussianBlur
8171- feImage
8172- feMorphology
8173- feOffset
8174- fePointLight
8175- feSpecularLighting
8176- feSpotLight
8177- feTurbulence
8178- filter
8179- g
8180- image
8181- line
8182- linearGradient
8183- mask
8184- path
8185- pattern
8186- polygon
8187- polyline
8188- radialGradient
8189- rect
8190- stop
8191- svg
8192- text
8193- textPath
8194- tspan
8195- use