js-apis-image.md 91.7 KB
Newer Older
Z
zengyawen 已提交
1
# @ohos.multimedia.image (图片处理)
X
xiaok 已提交
2

X
xu-rui-w 已提交
3 4
本模块提供图片处理效果,包括通过属性创建PixelMap、读取图像像素数据、读取区域内的图片数据等。

Z
zengyawen 已提交
5
> **说明:**
H
update  
HelloCrease 已提交
6
> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
Z
zengyawen 已提交
7

Z
zengyawen 已提交
8
## 导入模块
X
xiaok 已提交
9

Z
zengyawen 已提交
10
```js
Z
zengyawen 已提交
11
import image from '@ohos.multimedia.image';
X
xiaok 已提交
12 13
```

Z
zengyawen 已提交
14
## image.createPixelMap<sup>8+</sup>
X
xu-rui-w 已提交
15

16
createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<PixelMap>
X
xiaok 已提交
17

X
xu-rui-w 已提交
18
通过属性创建PixelMap,默认采用BGRA_8888格式处理数据,通过Promise返回结果。
X
xiaok 已提交
19

X
xu-rui-w 已提交
20
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
21 22 23

**参数:**

24
| 参数名  | 类型                                             | 必填 | 说明                                                             |
X
xu-rui-w 已提交
25 26
| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- |
| colors  | ArrayBuffer                                      | 是   | BGRA_8888格式的颜色数组。                                        |
27
| options | [InitializationOptions](#initializationoptions8) | 是   | 创建像素的属性,包括透明度,尺寸,缩略值,像素格式和是否可编辑。 |
X
xiaok 已提交
28 29 30

**返回值:**

X
xu-rui-w 已提交
31 32 33 34
| 类型                             | 说明                                                                    |
| -------------------------------- | ----------------------------------------------------------------------- |
| Promise\<[PixelMap](#pixelmap7)> | 返回Pixelmap。<br>当创建的pixelmap大小超过原图大小时,返回原图pixelmap大小。|

X
xiaok 已提交
35 36 37 38

**示例:**

```js
X
xu-rui-w 已提交
39
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
X
xu-rui-w 已提交
40
let bufferArr = new Uint8Array(color);
X
xu-rui-w 已提交
41
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
F
fengzewu 已提交
42 43 44 45 46
image.createPixelMap(color, opts).then((pixelmap) => {
    console.log('Succeeded in creating pixelmap.');
}).catch(error => {
    console.log('Failed to create pixelmap.');
})
X
xiaok 已提交
47 48
```

Z
zengyawen 已提交
49
## image.createPixelMap<sup>8+</sup>
X
xiaok 已提交
50

51
createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: AsyncCallback\<PixelMap>): void
X
xiaok 已提交
52

X
xu-rui-w 已提交
53
通过属性创建PixelMap,默认采用BGRA_8888格式处理数据,通过回调函数返回结果。
X
xiaok 已提交
54

X
xu-rui-w 已提交
55
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
56 57 58

**参数:**

59
| 参数名   | 类型                                             | 必填 | 说明                       |
Z
zengyawen 已提交
60
| -------- | ------------------------------------------------ | ---- | -------------------------- |
X
xu-rui-w 已提交
61
| colors   | ArrayBuffer                                      | 是   | BGRA_8888格式的颜色数组。  |
62
| options  | [InitializationOptions](#initializationoptions8) | 是   | 属性。                     |
Z
zengyawen 已提交
63
| callback | AsyncCallback\<[PixelMap](#pixelmap7)>           | 是   | 通过回调返回PixelMap对象。 |
X
xiaok 已提交
64 65 66 67

**示例:**

```js
X
xu-rui-w 已提交
68
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
X
xu-rui-w 已提交
69
let bufferArr = new Uint8Array(color);
X
xu-rui-w 已提交
70
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
X
xu-rui-w 已提交
71 72 73 74 75 76 77
image.createPixelMap(color, opts, (error, pixelmap) => {
    if(error) {
        console.log('Failed to create pixelmap.');
    } else {
        console.log('Succeeded in creating pixelmap.');
    }
})
X
xiaok 已提交
78 79
```

Z
zengyawen 已提交
80
## PixelMap<sup>7+</sup>
Z
zengyawen 已提交
81

82
图像像素类,用于读取或写入图像数据以及获取图像信息。在调用PixelMap的方法前,需要先通过createPixelMap创建一个PixelMap实例。目前pixelmap序列化大小最大128MB,超过会送显失败。大小计算方式为(宽\*\*每像素占用字节数)。
Z
zengyawen 已提交
83 84 85

 ### 属性

X
xu-rui-w 已提交
86
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
87

X
xu-rui-w 已提交
88 89 90
| 名称       | 类型    | 可读 | 可写 | 说明                       |
| ---------- | ------- | ---- | ---- | -------------------------- |
| isEditable | boolean | 是   | 否   | 设定是否图像像素可被编辑。 |
Z
zengyawen 已提交
91

Z
zengyawen 已提交
92
### readPixelsToBuffer<sup>7+</sup>
X
xiaok 已提交
93

Z
zengyawen 已提交
94
readPixelsToBuffer(dst: ArrayBuffer): Promise\<void>
X
xiaok 已提交
95

X
xu-rui-w 已提交
96
读取图像像素数据,结果写入ArrayBuffer里,使用Promise形式返回。指定BGRA_8888格式创建pixelmap,读取的像素数据与原数据保持一致。
X
xiaok 已提交
97

X
xu-rui-w 已提交
98
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
99 100 101

**参数:**

X
xu-rui-w 已提交
102 103 104
| 参数名 | 类型        | 必填 | 说明                                                                                                  |
| ------ | ----------- | ---- | ----------------------------------------------------------------------------------------------------- |
| dst    | ArrayBuffer | 是   | 缓冲区,函数执行结束后获取的图像像素数据写入到该内存区域内。缓冲区大小由getPixelBytesNumber接口获取。 |
X
xiaok 已提交
105 106 107

**返回值:**

Z
zengyawen 已提交
108
| 类型           | 说明                                            |
X
xu-rui-w 已提交
109
| -------------- | ----------------------------------------------- |
Z
zengyawen 已提交
110
| Promise\<void> | Promise实例,用于获取结果,失败时返回错误信息。 |
X
xiaok 已提交
111 112 113 114

**示例:**

```js
X
xu-rui-w 已提交
115
const readBuffer = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
X
xu-rui-w 已提交
116 117
pixelmap.readPixelsToBuffer(readBuffer).then(() => {
    console.log('Succeeded in reading image pixel data.');  //符合条件则进入 
X
xu-rui-w 已提交
118
}).catch(error => {
X
xu-rui-w 已提交
119
    console.log('Failed to read image pixel data.');  //不符合条件则进入
X
xu-rui-w 已提交
120
})
X
xiaok 已提交
121 122
```

Z
zengyawen 已提交
123
### readPixelsToBuffer<sup>7+</sup>
X
xiaok 已提交
124

Z
zengyawen 已提交
125
readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\<void>): void
X
xiaok 已提交
126

X
xu-rui-w 已提交
127
读取图像像素数据,结果写入ArrayBuffer里,使用callback形式返回。指定BGRA_8888格式创建pixelmap,读取的像素数据与原数据保持一致。
X
xiaok 已提交
128

X
xu-rui-w 已提交
129
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
130 131 132

**参数:**

X
xu-rui-w 已提交
133 134 135 136
| 参数名   | 类型                 | 必填 | 说明                                                                                                  |
| -------- | -------------------- | ---- | ----------------------------------------------------------------------------------------------------- |
| dst      | ArrayBuffer          | 是   | 缓冲区,函数执行结束后获取的图像像素数据写入到该内存区域内。缓冲区大小由getPixelBytesNumber接口获取。 |
| callback | AsyncCallback\<void> | 是   | 获取回调,失败时返回错误信息。                                                                        |
X
xiaok 已提交
137 138 139 140

**示例:**

```js
X
xu-rui-w 已提交
141
const readBuffer = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
X
xu-rui-w 已提交
142
pixelmap.readPixelsToBuffer(readBuffer, (err, res) => {
X
xu-rui-w 已提交
143
    if(err) {
X
xu-rui-w 已提交
144
        console.log('Failed to read image pixel data.');  //不符合条件则进入
X
xu-rui-w 已提交
145
    } else {
X
xu-rui-w 已提交
146
        console.log('Succeeded in reading image pixel data.');  //符合条件则进入
X
xu-rui-w 已提交
147 148
    }
})
X
xiaok 已提交
149 150
```

Z
zengyawen 已提交
151
### readPixels<sup>7+</sup>
X
xiaok 已提交
152

Z
zengyawen 已提交
153
readPixels(area: PositionArea): Promise\<void>
X
xiaok 已提交
154 155 156

读取区域内的图片数据,使用Promise形式返回读取结果。

X
xu-rui-w 已提交
157
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
158 159 160

**参数:**

Z
zengyawen 已提交
161 162 163
| 参数名 | 类型                           | 必填 | 说明                     |
| ------ | ------------------------------ | ---- | ------------------------ |
| area   | [PositionArea](#positionarea7) | 是   | 区域大小,根据区域读取。 |
X
xiaok 已提交
164 165 166

**返回值:**

Z
zengyawen 已提交
167 168 169
| 类型           | 说明                                                |
| :------------- | :-------------------------------------------------- |
| Promise\<void> | Promise实例,用于获取读取结果,失败时返回错误信息。 |
X
xiaok 已提交
170 171 172 173

**示例:**

```js
X
xu-rui-w 已提交
174 175 176 177 178 179
const area = {
    pixels: new ArrayBuffer(8),
    offset: 0,
    stride: 8,
    region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
}
X
xu-rui-w 已提交
180 181
pixelmap.readPixels(area).then(() => {
    console.log('Succeeded in reading the image data in the area.'); //符合条件则进入
X
xu-rui-w 已提交
182
}).catch(error => {
X
xu-rui-w 已提交
183
    console.log('Failed to read the image data in the area.'); //不符合条件则进入
X
xu-rui-w 已提交
184
})
X
xiaok 已提交
185 186
```

Z
zengyawen 已提交
187
### readPixels<sup>7+</sup>
X
xiaok 已提交
188

Z
zengyawen 已提交
189
readPixels(area: PositionArea, callback: AsyncCallback\<void>): void
X
xiaok 已提交
190

Z
zengyawen 已提交
191
读取区域内的图片数据,使用callback形式返回读取结果。
X
xiaok 已提交
192

X
xu-rui-w 已提交
193
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
194 195 196

**参数:**

Z
zengyawen 已提交
197 198 199 200
| 参数名   | 类型                           | 必填 | 说明                           |
| -------- | ------------------------------ | ---- | ------------------------------ |
| area     | [PositionArea](#positionarea7) | 是   | 区域大小,根据区域读取。       |
| callback | AsyncCallback\<void>           | 是   | 获取回调,失败时返回错误信息。 |
X
xiaok 已提交
201 202 203 204

**示例:**

```js
X
xu-rui-w 已提交
205
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
X
xu-rui-w 已提交
206
let bufferArr = new Uint8Array(color);
207 208
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (err, pixelmap) => {
X
xu-rui-w 已提交
209 210 211 212 213 214 215 216 217 218 219
    if(pixelmap == undefined){
        console.info('createPixelMap failed.');
    } else {
        const area = { pixels: new ArrayBuffer(8),
            offset: 0,
            stride: 8,
            region: { size: { height: 1, width: 2 }, x: 0, y: 0 }};
        pixelmap.readPixels(area, () => {
            console.info('readPixels success');
        })
    }
220
})
X
xiaok 已提交
221 222
```

Z
zengyawen 已提交
223
### writePixels<sup>7+</sup>
X
xiaok 已提交
224

Z
zengyawen 已提交
225
writePixels(area: PositionArea): Promise\<void>
X
xiaok 已提交
226

227
将PixelMap写入指定区域内,使用Promise形式返回写入结果。
X
xiaok 已提交
228

X
xu-rui-w 已提交
229
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
230 231 232

**参数:** 

Z
zengyawen 已提交
233 234
| 参数名 | 类型                           | 必填 | 说明                 |
| ------ | ------------------------------ | ---- | -------------------- |
Z
zengyawen 已提交
235
| area   | [PositionArea](#positionarea7) | 是   | 区域,根据区域写入。 |
X
xiaok 已提交
236 237 238

**返回值:**

Z
zengyawen 已提交
239 240 241
| 类型           | 说明                                                |
| :------------- | :-------------------------------------------------- |
| Promise\<void> | Promise实例,用于获取写入结果,失败时返回错误信息。 |
X
xiaok 已提交
242 243 244 245

**示例:**

```js
X
xu-rui-w 已提交
246
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
X
xu-rui-w 已提交
247
let bufferArr = new Uint8Array(color);
248 249 250 251
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts)
    .then( pixelmap => {
        if (pixelmap == undefined) {
X
xu-rui-w 已提交
252
            console.info('createPixelMap failed.');
253 254 255 256 257 258
        }
        const area = { pixels: new ArrayBuffer(8),
            offset: 0,
            stride: 8,
            region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
        }
X
xu-rui-w 已提交
259
        let bufferArr = new Uint8Array(area.pixels);
260 261 262 263 264
        for (var i = 0; i < bufferArr.length; i++) {
            bufferArr[i] = i + 1;
        }

        pixelmap.writePixels(area).then(() => {
F
fengzewu 已提交
265
		    console.info('Succeeded to write pixelmap into the specified area.');
266
        })
X
xu-rui-w 已提交
267
    }).catch(error => {
268 269
        console.log('error: ' + error);
    })
X
xiaok 已提交
270 271
```

Z
zengyawen 已提交
272
### writePixels<sup>7+</sup>
X
xiaok 已提交
273

Z
zengyawen 已提交
274
writePixels(area: PositionArea, callback: AsyncCallback\<void>): void
X
xiaok 已提交
275

276
将PixelMap写入指定区域内,使用callback形式返回写入结果。
X
xiaok 已提交
277

X
xu-rui-w 已提交
278
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
279 280 281

**参数:** 

Z
zengyawen 已提交
282 283
| 参数名    | 类型                           | 必填 | 说明                           |
| --------- | ------------------------------ | ---- | ------------------------------ |
Z
zengyawen 已提交
284
| area      | [PositionArea](#positionarea7) | 是   | 区域,根据区域写入。           |
X
xu-rui-w 已提交
285
| callback  | AsyncCallback\<void>           | 是   | 获取回调,失败时返回错误信息。 |
X
xiaok 已提交
286 287 288 289

**示例:**

```js
F
fengzewu 已提交
290 291 292 293 294 295 296 297 298
const area = { pixels: new ArrayBuffer(8),
    offset: 0,
    stride: 8,
    region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
}
let bufferArr = new Uint8Array(area.pixels);
for (var i = 0; i < bufferArr.length; i++) {
    bufferArr[i] = i + 1;
}
X
xu-rui-w 已提交
299
pixelmap.writePixels(area, (error) => {
X
xu-rui-w 已提交
300
    if (error != undefined) {
X
xu-rui-w 已提交
301
		console.info('Failed to write pixelmap into the specified area.');
X
xu-rui-w 已提交
302
	} else {
F
fengzewu 已提交
303
		console.info('Succeeded to write pixelmap into the specified area.');
X
xu-rui-w 已提交
304
	}
X
xu-rui-w 已提交
305
})
X
xiaok 已提交
306 307
```

Z
zengyawen 已提交
308
### writeBufferToPixels<sup>7+</sup>
X
xiaok 已提交
309

Z
zengyawen 已提交
310
writeBufferToPixels(src: ArrayBuffer): Promise\<void>
X
xiaok 已提交
311

312
读取缓冲区中的图片数据,结果写入PixelMap中,使用Promise形式返回。
X
xiaok 已提交
313

X
xu-rui-w 已提交
314
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
315 316 317

**参数:**

Z
zengyawen 已提交
318 319 320
| 参数名 | 类型        | 必填 | 说明           |
| ------ | ----------- | ---- | -------------- |
| src    | ArrayBuffer | 是   | 图像像素数据。 |
X
xiaok 已提交
321 322 323

**返回值:**

Z
zengyawen 已提交
324 325 326
| 类型           | 说明                                            |
| -------------- | ----------------------------------------------- |
| Promise\<void> | Promise实例,用于获取结果,失败时返回错误信息。 |
X
xiaok 已提交
327 328 329 330

**示例:**

```js
X
xu-rui-w 已提交
331
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
X
xu-rui-w 已提交
332
let bufferArr = new Uint8Array(color);
F
fengzewu 已提交
333 334 335 336
for (var i = 0; i < bufferArr.length; i++) {
    bufferArr[i] = i + 1;
}
pixelmap.writeBufferToPixels(color).then(() => {
X
xiaok 已提交
337 338 339
    console.log("Succeeded in writing data from a buffer to a PixelMap.");
}).catch((err) => {
    console.error("Failed to write data from a buffer to a PixelMap.");
X
xu-rui-w 已提交
340
})
X
xiaok 已提交
341 342
```

Z
zengyawen 已提交
343
### writeBufferToPixels<sup>7+</sup>
X
xiaok 已提交
344

Z
zengyawen 已提交
345
writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\<void>): void
X
xiaok 已提交
346

347
读取缓冲区中的图片数据,结果写入PixelMap中,使用callback形式返回。
X
xiaok 已提交
348

X
xu-rui-w 已提交
349
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
350 351 352

**参数:**

Z
zengyawen 已提交
353 354 355 356
| 参数名   | 类型                 | 必填 | 说明                           |
| -------- | -------------------- | ---- | ------------------------------ |
| src      | ArrayBuffer          | 是   | 图像像素数据。                 |
| callback | AsyncCallback\<void> | 是   | 获取回调,失败时返回错误信息。 |
X
xiaok 已提交
357 358 359 360

**示例:**

```js
X
xu-rui-w 已提交
361
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
X
xu-rui-w 已提交
362
let bufferArr = new Uint8Array(color);
F
fengzewu 已提交
363 364 365 366
for (var i = 0; i < bufferArr.length; i++) {
    bufferArr[i] = i + 1;
}
pixelmap.writeBufferToPixels(color, function(err) {
X
xiaok 已提交
367 368 369
    if (err) {
        console.error("Failed to write data from a buffer to a PixelMap.");
        return;
X
xu-rui-w 已提交
370 371 372
    } else {
		console.log("Succeeded in writing data from a buffer to a PixelMap.");
	}
X
xiaok 已提交
373 374 375
});
```

Z
zengyawen 已提交
376
### getImageInfo<sup>7+</sup>
X
xiaok 已提交
377

Z
zengyawen 已提交
378
getImageInfo(): Promise\<ImageInfo>
X
xiaok 已提交
379 380 381

获取图像像素信息,使用Promise形式返回获取的图像像素信息。

X
xu-rui-w 已提交
382
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
383 384 385

**返回值:**

Z
zengyawen 已提交
386 387 388
| 类型                              | 说明                                                        |
| --------------------------------- | ----------------------------------------------------------- |
| Promise\<[ImageInfo](#imageinfo)> | Promise实例,用于异步获取图像像素信息,失败时返回错误信息。 |
X
xiaok 已提交
389 390 391 392

**示例:**

```js
X
xu-rui-w 已提交
393
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
F
fengzewu 已提交
394 395 396 397 398 399 400 401 402 403 404 405 406 407
let opts = { editable: true, pixelFormat: 2, size: { height: 6, width: 8 } }
image.createPixelMap(color, opts).then(pixelmap => {
    if (pixelmap == undefined) {
        console.error("Failed to obtain the image pixel map information.");
    }
    pixelmap.getImageInfo().then(imageInfo => {
        if (imageInfo == undefined) {
            console.error("Failed to obtain the image pixel map information.");
        }
        if (imageInfo.size.height == 4 && imageInfo.size.width == 6) {
            console.log("Succeeded in obtaining the image pixel map information.");
        }
    })
})
X
xiaok 已提交
408 409
```

Z
zengyawen 已提交
410
### getImageInfo<sup>7+</sup>
X
xiaok 已提交
411

Z
zengyawen 已提交
412
getImageInfo(callback: AsyncCallback\<ImageInfo>): void
X
xiaok 已提交
413 414 415

获取图像像素信息,使用callback形式返回获取的图像像素信息。

X
xu-rui-w 已提交
416
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
417 418 419

**参数:**

Z
zengyawen 已提交
420 421 422
| 参数名   | 类型                                    | 必填 | 说明                                                         |
| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback\<[ImageInfo](#imageinfo)> | 是   | 获取图像像素信息回调,异步返回图像像素信息,失败时返回错误信息。 |
X
xiaok 已提交
423 424 425 426

**示例:**

```js
X
xu-rui-w 已提交
427
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
F
fengzewu 已提交
428 429 430 431 432 433 434 435 436 437 438 439 440
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (err, pixelmap) => {
    if (pixelmap == undefined) {
        console.error("Failed to obtain the image pixel map information.");
    }
    pixelmap.getImageInfo((err, imageInfo) => {
        if (imageInfo == undefined) {
            console.error("Failed to obtain the image pixel map information.");
        }
        if (imageInfo.size.height == 4 && imageInfo.size.width == 6) {
            console.log("Succeeded in obtaining the image pixel map information.");
        }
    })
X
xu-rui-w 已提交
441
})
X
xiaok 已提交
442 443
```

Z
zengyawen 已提交
444
### getBytesNumberPerRow<sup>7+</sup>
X
xiaok 已提交
445

Z
zengyawen 已提交
446
getBytesNumberPerRow(): number
X
xiaok 已提交
447 448 449

获取图像像素每行字节数。

X
xu-rui-w 已提交
450
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
451 452 453

**返回值:**

Z
zengyawen 已提交
454 455 456
| 类型   | 说明                 |
| ------ | -------------------- |
| number | 图像像素的行字节数。 |
X
xiaok 已提交
457 458 459 460

**示例:**

```js
X
xu-rui-w 已提交
461
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
X
xu-rui-w 已提交
462
let bufferArr = new Uint8Array(color);
X
xu-rui-w 已提交
463
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
X
xu-rui-w 已提交
464
image.createPixelMap(color, opts, (err,pixelmap) => {
X
xu-rui-w 已提交
465 466
    let rowCount = pixelmap.getBytesNumberPerRow();
})
X
xiaok 已提交
467 468
```

Z
zengyawen 已提交
469
### getPixelBytesNumber<sup>7+</sup>
X
xiaok 已提交
470

Z
zengyawen 已提交
471
getPixelBytesNumber(): number
X
xiaok 已提交
472 473 474

获取图像像素的总字节数。

X
xu-rui-w 已提交
475
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
476 477 478

**返回值:**

Z
zengyawen 已提交
479 480 481
| 类型   | 说明                 |
| ------ | -------------------- |
| number | 图像像素的总字节数。 |
X
xiaok 已提交
482 483 484 485

**示例:**

```js
X
xu-rui-w 已提交
486
let pixelBytesNumber = pixelmap.getPixelBytesNumber();
X
xiaok 已提交
487 488
```

X
xu-rui-w 已提交
489 490 491 492
### getDensity<sup>9+</sup>

getDensity():number

X
xu-rui-w 已提交
493
获取当前图像像素的密度。
X
xu-rui-w 已提交
494 495 496 497 498

**系统能力:** SystemCapability.Multimedia.Image.Core

**返回值:**

X
xu-rui-w 已提交
499 500 501
| 类型   | 说明            |
| ------ | --------------- |
| number | 图像像素的密度。|
X
xu-rui-w 已提交
502 503 504 505 506 507 508 509 510 511 512

**示例:**

```js
let getDensity = pixelmap.getDensity();
```

### opacity<sup>9+</sup>

opacity(rate: number, callback: AsyncCallback\<void>): void

X
xu-rui-w 已提交
513
通过设置透明比率来让PixelMap达到对应的透明效果,使用callback形式返回。
X
xu-rui-w 已提交
514 515 516 517 518 519 520 521 522 523 524 525 526

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

| 参数名   | 类型                 | 必填 | 说明                           |
| -------- | -------------------- | ---- | ------------------------------ |
| rate     | number               | 是   | 透明比率的值,取值范围:0-1。   |
| callback | AsyncCallback\<void> | 是   | 获取回调,失败时返回错误信息。 |

**示例:**

```js
F
fengzewu 已提交
527 528 529 530 531 532 533 534 535
var rate = 0.5;
pixelmap.opacity(rate, (err) => {
	if (err) {
        console.error("Failed to set opacity.");
        return;
    } else {
        console.log("Succeeded in setting opacity.");
	}
})
X
xu-rui-w 已提交
536 537 538 539 540 541
```

### opacity<sup>9+</sup>

opacity(rate: number): Promise\<void>

X
xu-rui-w 已提交
542
通过设置透明比率来让PixelMap达到对应的透明效果,使用Promise形式返回。
X
xu-rui-w 已提交
543 544 545 546 547 548 549

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

| 参数名 | 类型   | 必填 | 说明                        |
| ------ | ------ | ---- | --------------------------- |
X
xu-rui-w 已提交
550
| rate   | number | 是   | 透明比率的值,取值范围:0-1。|
X
xu-rui-w 已提交
551 552 553 554 555 556 557 558 559 560

**返回值:**

| 类型           | 说明                                            |
| -------------- | ----------------------------------------------- |
| Promise\<void> | Promise实例,用于获取结果,失败时返回错误信息。 |

**示例:**

```js
F
fengzewu 已提交
561
async function Demo() {
F
fengzewu 已提交
562
    await pixelmap.opacity(0.5);
X
xu-rui-w 已提交
563
}
X
xu-rui-w 已提交
564 565 566 567 568 569
```

### createAlphaPixelmap<sup>9+</sup>

createAlphaPixelmap(): Promise\<PixelMap>

X
xu-rui-w 已提交
570
根据Alpha通道的信息,来生成一个仅包含Alpha通道信息的pixelmap,可用于阴影效果,使用Promise形式返回。
X
xu-rui-w 已提交
571 572 573 574 575 576 577 578 579 580 581 582

**系统能力:** SystemCapability.Multimedia.Image.Core

**返回值:**

| 类型                             | 说明                        |
| -------------------------------- | --------------------------- |
| Promise\<[PixelMap](#pixelmap7)> | Promise实例,返回pixelmap。 |

**示例:**

```js
F
fengzewu 已提交
583
async function Demo() {
F
fengzewu 已提交
584 585
    await pixelmap.createAlphaPixelmap();
}   
X
xu-rui-w 已提交
586 587 588 589 590 591
```

### createAlphaPixelmap<sup>9+</sup>

createAlphaPixelmap(callback: AsyncCallback\<PixelMap>): void

X
xu-rui-w 已提交
592
根据Alpha通道的信息,来生成一个仅包含Alpha通道信息的pixelmap,可用于阴影效果,使用callback形式返回。
X
xu-rui-w 已提交
593 594 595 596 597

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

X
xu-rui-w 已提交
598 599 600
| 参数名   | 类型                     | 必填 | 说明                     |
| -------- | ------------------------ | ---- | ------------------------ |
| callback | AsyncCallback\<PixelMap> | 是   | 获取回调,异步返回结果。 |
X
xu-rui-w 已提交
601 602 603 604

**示例:**

```js
F
fengzewu 已提交
605 606 607 608 609 610 611
pixelmap.createAlphaPixelmap((err, alphaPixelMap) => {
    if (alphaPixelMap == undefined) {
        console.info('Failed to obtain new pixel map.');
    } else {
        console.info('Succeed in obtaining new pixel map.');
    }
})
X
xu-rui-w 已提交
612 613 614 615 616 617
```

### scale<sup>9+</sup>

scale(x: number, y: number, callback: AsyncCallback\<void>): void

X
xu-rui-w 已提交
618
根据输入的宽高对图片进行缩放,使用callback形式返回。
X
xu-rui-w 已提交
619 620 621 622 623

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

X
xu-rui-w 已提交
624 625 626 627 628
| 参数名   | 类型                 | 必填 | 说明                            |
| -------- | -------------------- | ---- | ------------------------------- |
| x        | number               | 是   | 宽度的缩放值,其值为输入的倍数。|
| y        | number               | 是   | 高度的缩放值,其值为输入的倍数。|
| callback | AsyncCallback\<void> | 是   | 获取回调,失败时返回错误信息。  |
X
xu-rui-w 已提交
629 630 631 632

**示例:**

```js
F
fengzewu 已提交
633
async function Demo() {
F
fengzewu 已提交
634
	await pixelmap.scale(2.0, 1.0);
X
xu-rui-w 已提交
635
}
X
xu-rui-w 已提交
636 637 638 639 640 641
```

### scale<sup>9+</sup>

scale(x: number, y: number): Promise\<void>

X
xu-rui-w 已提交
642
根据输入的宽高对图片进行缩放,使用Promise形式返回。
X
xu-rui-w 已提交
643 644 645 646 647

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

X
xu-rui-w 已提交
648 649 650 651
| 参数名 | 类型   | 必填 | 说明                            |
| ------ | ------ | ---- | ------------------------------- |
| x      | number | 是   | 宽度的缩放值,其值为输入的倍数。|
| y      | number | 是   | 高度的缩放值,其值为输入的倍数。|
X
xu-rui-w 已提交
652 653 654

**返回值:**

X
xu-rui-w 已提交
655 656 657
| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise\<void> | Promise实例,异步返回结果。 |
X
xu-rui-w 已提交
658 659 660 661

**示例:**

```js
F
fengzewu 已提交
662
async function Demo() {
F
fengzewu 已提交
663
	await pixelmap.scale(2.0, 1.0);
X
xu-rui-w 已提交
664
}
X
xu-rui-w 已提交
665 666 667 668 669 670
```

### translate<sup>9+</sup>

translate(x: number, y: number, callback: AsyncCallback\<void>): void

X
xu-rui-w 已提交
671
根据输入的坐标对图片进行位置变换,使用callback形式返回。
X
xu-rui-w 已提交
672 673 674 675 676 677 678 679 680 681 682 683 684 685

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

| 参数名   | 类型                 | 必填 | 说明                          |
| -------- | -------------------- | ---- | ----------------------------- |
| x        | number               | 是   | 区域横坐标。                  |
| y        | number               | 是   | 区域纵坐标。                  |
| callback | AsyncCallback\<void> | 是   | 获取回调,失败时返回错误信息。|

**示例:**

```js
F
fengzewu 已提交
686
async function Demo() {
F
fengzewu 已提交
687
	await pixelmap.translate(3.0, 1.0);
X
xu-rui-w 已提交
688
}
X
xu-rui-w 已提交
689 690 691 692 693 694
```

### translate<sup>9+</sup>

translate(x: number, y: number): Promise\<void>

X
xu-rui-w 已提交
695
根据输入的坐标对图片进行位置变换,使用Promise形式返回。
X
xu-rui-w 已提交
696 697 698 699 700 701 702 703 704 705 706 707

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

| 参数名 | 类型   | 必填 | 说明        |
| ------ | ------ | ---- | ----------- |
| x      | number | 是   | 区域横坐标。|
| y      | number | 是   | 区域纵坐标。|

**返回值:**

X
xu-rui-w 已提交
708 709 710
| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise\<void> | Promise实例,异步返回结果。 |
X
xu-rui-w 已提交
711 712 713 714

**示例:**

```js
F
fengzewu 已提交
715
async function Demo() {
F
fengzewu 已提交
716
	await pixelmap.translate(3.0, 1.0);
X
xu-rui-w 已提交
717
}
X
xu-rui-w 已提交
718 719 720 721 722 723
```

### rotate<sup>9+</sup>

rotate(angle: number, callback: AsyncCallback\<void>): void

X
xu-rui-w 已提交
724
根据输入的角度对图片进行旋转,使用callback形式返回。
X
xu-rui-w 已提交
725 726 727 728 729 730 731 732 733 734 735 736 737

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

| 参数名   | 类型                 | 必填 | 说明                          |
| -------- | -------------------- | ---- | ----------------------------- |
| angle    | number               | 是   | 图片旋转的角度。              |
| callback | AsyncCallback\<void> | 是   | 获取回调,失败时返回错误信息。|

**示例:**

```js
Y
yaozhupeng 已提交
738 739 740 741 742 743 744 745 746
var angle = 90.0;
pixelmap.rotate(angle, (err) => {
	if (err) {
        console.error("Failed to set rotation.");
        return;
    } else {
        console.log("Succeeded in setting rotation.");
	}
})
X
xu-rui-w 已提交
747 748 749 750 751 752
```

### rotate<sup>9+</sup>

rotate(angle: number): Promise\<void>

X
xu-rui-w 已提交
753
根据输入的角度对图片进行旋转,使用Promise形式返回。
X
xu-rui-w 已提交
754 755 756 757 758 759 760 761 762 763 764

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

| 参数名 | 类型   | 必填 | 说明                          |
| ------ | ------ | ---- | ----------------------------- |
| angle  | number | 是   | 图片旋转的角度。              |

**返回值:**

X
xu-rui-w 已提交
765 766 767
| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise\<void> | Promise实例,异步返回结果。 |
X
xu-rui-w 已提交
768 769 770 771

**示例:**

```js
F
fengzewu 已提交
772
async function Demo() {
F
fengzewu 已提交
773
	await pixelmap.rotate(90.0);
X
xu-rui-w 已提交
774
}
X
xu-rui-w 已提交
775 776 777 778 779 780
```

### flip<sup>9+</sup>

flip(horizontal: boolean, vertical: boolean, callback: AsyncCallback\<void>): void

X
xu-rui-w 已提交
781
根据输入的条件对图片进行翻转,使用callback形式返回。
X
xu-rui-w 已提交
782 783 784 785 786 787 788 789 790 791 792 793 794 795

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

| 参数名     | 类型                 | 必填 | 说明                          |
| ---------- | -------------------- | ---- | ----------------------------- |
| horizontal | boolean              | 是   | 水平翻转。                    |
| vertical   | boolean              | 是   | 垂直翻转。                    |
| callback   | AsyncCallback\<void> | 是   | 获取回调,失败时返回错误信息。|

**示例:**

```js
F
fengzewu 已提交
796
async function Demo() {
F
fengzewu 已提交
797
	await pixelmap.flip(false, true);
X
xu-rui-w 已提交
798
}
X
xu-rui-w 已提交
799 800 801 802 803 804
```

### flip<sup>9+</sup>

flip(horizontal: boolean, vertical: boolean): Promise\<void>

X
xu-rui-w 已提交
805
根据输入的条件对图片进行翻转,使用Promise形式返回。
X
xu-rui-w 已提交
806 807 808 809 810 811 812 813 814 815 816 817

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

| 参数名     | 类型    | 必填 | 说明      |
| ---------- | ------- | ---- | --------- |
| horizontal | boolean | 是   | 水平翻转。|
| vertical   | boolean | 是   | 垂直翻转。|

**返回值:**

X
xu-rui-w 已提交
818 819 820
| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise\<void> | Promise实例,异步返回结果。 |
X
xu-rui-w 已提交
821 822 823 824

**示例:**

```js
F
fengzewu 已提交
825
async function Demo() {
F
fengzewu 已提交
826
	await pixelmap.flip(false, true);
X
xu-rui-w 已提交
827
}
X
xu-rui-w 已提交
828 829 830 831 832 833
```

### crop<sup>9+</sup>

crop(region: Region, callback: AsyncCallback\<void>): void

X
xu-rui-w 已提交
834
根据输入的尺寸对图片进行裁剪,使用callback形式返回。
X
xu-rui-w 已提交
835 836 837 838 839 840 841

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

| 参数名   | 类型                 | 必填 | 说明                          |
| -------- | -------------------- | ---- | ----------------------------- |
X
xu-rui-w 已提交
842
| region   | [Region](#region7)   | 是   | 裁剪的尺寸。                  |
X
xu-rui-w 已提交
843 844 845 846 847
| callback | AsyncCallback\<void> | 是   | 获取回调,失败时返回错误信息。|

**示例:**

```js
F
fengzewu 已提交
848
async function Demo() {
F
fengzewu 已提交
849
	await pixelmap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } });
X
xu-rui-w 已提交
850
}
X
xu-rui-w 已提交
851 852 853 854 855 856
```

### crop<sup>9+</sup>

crop(region: Region): Promise\<void>

X
xu-rui-w 已提交
857
根据输入的尺寸对图片进行裁剪,使用Promise形式返回。
X
xu-rui-w 已提交
858 859 860 861 862

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

X
xu-rui-w 已提交
863 864 865
| 参数名 | 类型               | 必填 | 说明        |
| ------ | ------------------ | ---- | ----------- |
| region | [Region](#region7) | 是   | 裁剪的尺寸。|
X
xu-rui-w 已提交
866 867 868

**返回值:**

X
xu-rui-w 已提交
869 870 871
| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise\<void> | Promise实例,异步返回结果。 |
X
xu-rui-w 已提交
872 873 874 875

**示例:**

```js
F
fengzewu 已提交
876
async function Demo() {
F
fengzewu 已提交
877
	await pixelmap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } });
X
xu-rui-w 已提交
878
}
X
xu-rui-w 已提交
879 880
```

Z
zengyawen 已提交
881
### release<sup>7+</sup>
X
xiaok 已提交
882

Z
zengyawen 已提交
883
release():Promise\<void>
X
xiaok 已提交
884

885
释放PixelMap对象,使用Promise形式返回释放结果。
X
xiaok 已提交
886

X
xu-rui-w 已提交
887
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
888

Z
zengyawen 已提交
889
**返回值:**
X
xiaok 已提交
890

X
xu-rui-w 已提交
891 892 893
| 类型           | 说明                            |
| -------------- | ------------------------------- |
| Promise\<void> | Promise实例,异步返回释放结果。 |
X
xiaok 已提交
894 895 896 897

**示例:**

```js
F
fengzewu 已提交
898 899 900 901
pixelmap.release().then(() => {
	console.log('Succeeded in releasing pixelmap object.');
}).catch(error => {
	console.log('Failed to release pixelmap object.');
X
xu-rui-w 已提交
902
})
X
xiaok 已提交
903 904
```

Z
zengyawen 已提交
905
### release<sup>7+</sup>
X
xiaok 已提交
906

Z
zengyawen 已提交
907
release(callback: AsyncCallback\<void>): void
X
xiaok 已提交
908

909
释放PixelMap对象,使用callback形式返回释放结果。
X
xiaok 已提交
910

X
xu-rui-w 已提交
911
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
912 913 914

**参数:**

915
| 参数名   | 类型                 | 必填 | 说明               |
Z
zengyawen 已提交
916 917
| -------- | -------------------- | ---- | ------------------ |
| callback | AsyncCallback\<void> | 是   | 异步返回释放结果。 |
X
xiaok 已提交
918 919 920 921

**示例:**

```js
F
fengzewu 已提交
922 923
pixelmap.release(() => {
    console.log('Succeeded in releasing pixelmap object.');
X
xu-rui-w 已提交
924
})
X
xiaok 已提交
925 926
```

Z
zengyawen 已提交
927
## image.createImageSource
X
xiaok 已提交
928

Z
zengyawen 已提交
929
createImageSource(uri: string): ImageSource
X
xiaok 已提交
930

Z
zengyawen 已提交
931
通过传入的uri创建图片源实例。
X
xiaok 已提交
932

X
xu-rui-w 已提交
933
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
934 935 936

**参数:**

Z
zengyawen 已提交
937 938
| 参数名 | 类型   | 必填 | 说明                               |
| ------ | ------ | ---- | ---------------------------------- |
X
xu-rui-w 已提交
939
| uri    | string | 是   | 图片路径,当前仅支持应用沙箱路径。</br>当前支持格式有:.jpg .png .gif .bmp .webp RAW。 |
X
xiaok 已提交
940 941 942

**返回值:**

943 944 945
| 类型                        | 说明                                         |
| --------------------------- | -------------------------------------------- |
| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |
X
xiaok 已提交
946 947 948 949

**示例:**

```js
R
renhw 已提交
950
let context = featureAbility.getContext();
冯泽悟 已提交
951
let path = context.cacheDir() + "test.jpg";
Z
zhang-xiaobo1997 已提交
952
const imageSourceApi = image.createImageSource(path);
X
xiaok 已提交
953 954
```

X
xu-rui-w 已提交
955 956 957 958 959 960 961 962 963 964 965 966
## image.createImageSource<sup>9+</sup>

createImageSource(uri: string, options: SourceOptions): ImageSource

通过传入的uri创建图片源实例。

**系统能力:** SystemCapability.Multimedia.Image.ImageSource

**参数:**

| 参数名  | 类型                            | 必填 | 说明                                |
| ------- | ------------------------------- | ---- | ----------------------------------- |
X
xu-rui-w 已提交
967
| uri     | string                          | 是   | 图片路径,当前仅支持应用沙箱路径。</br>当前支持格式有:.jpg .png .gif .bmp .webp RAW。 |
968
| options | [SourceOptions](#sourceoptions9) | 是   | 图片属性,包括图片序号与默认属性值。|
X
xu-rui-w 已提交
969 970 971 972 973 974 975 976 977 978

**返回值:**

| 类型                        | 说明                                         |
| --------------------------- | -------------------------------------------- |
| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |

**示例:**

```js
X
xu-rui-w 已提交
979 980
var sourceOptions = { sourceDensity: 120 };
let imageSource = image.createImageSource('test.png', sourceOptions);
X
xu-rui-w 已提交
981 982
```

Z
zengyawen 已提交
983
## image.createImageSource<sup>7+</sup>
X
xiaok 已提交
984

Z
zengyawen 已提交
985
createImageSource(fd: number): ImageSource
X
xiaok 已提交
986

Z
zengyawen 已提交
987
通过传入文件描述符来创建图片源实例。
X
xiaok 已提交
988

X
xu-rui-w 已提交
989
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
990 991 992

**参数:**

X
xu-rui-w 已提交
993 994 995
| 参数名 | 类型   | 必填 | 说明          |
| ------ | ------ | ---- | ------------- |
| fd     | number | 是   | 文件描述符fd。|
X
xiaok 已提交
996 997 998

**返回值:**

999 1000 1001
| 类型                        | 说明                                         |
| --------------------------- | -------------------------------------------- |
| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |
X
xiaok 已提交
1002 1003 1004 1005

**示例:**

```js
X
xu-rui-w 已提交
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
const imageSourceApi = image.createImageSource(0);
```

## image.createImageSource<sup>9+</sup>

createImageSource(fd: number, options: SourceOptions): ImageSource

通过传入文件描述符来创建图片源实例。

**系统能力:** SystemCapability.Multimedia.Image.ImageSource

**参数:**

| 参数名  | 类型                            | 必填 | 说明                                |
| ------- | ------------------------------- | ---- | ----------------------------------- |
| fd      | number                          | 是   | 文件描述符fd。                      |
1022
| options | [SourceOptions](#sourceoptions9) | 是   | 图片属性,包括图片序号与默认属性值。|
X
xu-rui-w 已提交
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032

**返回值:**

| 类型                        | 说明                                         |
| --------------------------- | -------------------------------------------- |
| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |

**示例:**

```js
F
fengzewu 已提交
1033 1034
var sourceOptions = { sourceDensity: 120 };
const imageSourceApi = image.createImageSource(0, sourceOptions);
X
xu-rui-w 已提交
1035 1036 1037
```

## image.createImageSource<sup>9+</sup>
X
xiaok 已提交
1038

X
xu-rui-w 已提交
1039
createImageSource(buf: ArrayBuffer): ImageSource
X
xiaok 已提交
1040

X
xu-rui-w 已提交
1041
通过缓冲区创建图片源实例。
X
xiaok 已提交
1042

X
xu-rui-w 已提交
1043
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1044 1045 1046

**参数:**

X
xu-rui-w 已提交
1047 1048 1049
| 参数名 | 类型        | 必填 | 说明             |
| ------ | ----------- | ---- | ---------------- |
| buf    | ArrayBuffer | 是   | 图像缓冲区数组。 |
X
xiaok 已提交
1050 1051 1052 1053

**示例:**

```js
X
xu-rui-w 已提交
1054
const buf = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
X
xu-rui-w 已提交
1055
const imageSourceApi = image.createImageSource(buf);
X
xiaok 已提交
1056 1057
```

X
xu-rui-w 已提交
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
## image.createImageSource<sup>9+</sup>

createImageSource(buf: ArrayBuffer, options: SourceOptions): ImageSource

通过缓冲区创建图片源实例。

**系统能力:** SystemCapability.Multimedia.Image.ImageSource

**参数:**

| 参数名 | 类型                             | 必填 | 说明                                 |
| ------ | -------------------------------- | ---- | ------------------------------------ |
| buf    | ArrayBuffer                      | 是   | 图像缓冲区数组。                     |
1071
| options | [SourceOptions](#sourceoptions9) | 是   | 图片属性,包括图片序号与默认属性值。 |
X
xu-rui-w 已提交
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081

**返回值:**

| 类型                        | 说明                                         |
| --------------------------- | -------------------------------------------- |
| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |

**示例:**

```js
X
xu-rui-w 已提交
1082 1083
const data = new ArrayBuffer(112);
const imageSourceApi = image.createImageSource(data);
X
xu-rui-w 已提交
1084 1085
```

1086
## image.CreateIncrementalSource<sup>9+</sup>
X
xu-rui-w 已提交
1087

1088
CreateIncrementalSource(buf: ArrayBuffer): ImageSource
X
xu-rui-w 已提交
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108

通过缓冲区以增量的方式创建图片源实例。

**系统能力:** SystemCapability.Multimedia.Image.ImageSource

**参数:**

| 参数名  | 类型        | 必填 | 说明      |
| ------- | ------------| ---- | ----------|
| buf     | ArrayBuffer | 是   | 增量数据。|

**返回值:**

| 类型                        | 说明                              |
| --------------------------- | --------------------------------- |
| [ImageSource](#imagesource) | 返回图片源,失败时返回undefined。 |

**示例:**

```js
X
xu-rui-w 已提交
1109
const buf = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
1110
const imageSourceIncrementalSApi = image.CreateIncrementalSource(buf);
X
xu-rui-w 已提交
1111 1112
```

1113
## image.CreateIncrementalSource<sup>9+</sup>
X
xu-rui-w 已提交
1114

1115
CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource
X
xu-rui-w 已提交
1116

X
xu-rui-w 已提交
1117
通过缓冲区以增量的方式创建图片源实例。
X
xu-rui-w 已提交
1118

X
xu-rui-w 已提交
1119
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xu-rui-w 已提交
1120 1121 1122 1123 1124

**参数:**

| 参数名  | 类型                            | 必填 | 说明                                 |
| ------- | ------------------------------- | ---- | ------------------------------------ |
X
xu-rui-w 已提交
1125
| buf     | ArrayBuffer                     | 是   | 增量数据。                           |
1126
| options | [SourceOptions](#sourceoptions9) | 否   | 图片属性,包括图片序号与默认属性值。 |
X
xu-rui-w 已提交
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136

**返回值:**

| 类型                        | 说明                              |
| --------------------------- | --------------------------------- |
| [ImageSource](#imagesource) | 返回图片源,失败时返回undefined。 |

**示例:**

```js
X
xu-rui-w 已提交
1137
const buf = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
1138
const imageSourceIncrementalSApi = image.CreateIncrementalSource(buf);
X
xiaok 已提交
1139 1140
```

Z
zengyawen 已提交
1141
## ImageSource
X
xiaok 已提交
1142

Z
zengyawen 已提交
1143 1144 1145 1146
图片源类,用于获取图片相关信息。在调用ImageSource的方法前,需要先通过createImageSource构建一个ImageSource实例。

### 属性

X
xu-rui-w 已提交
1147
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
Z
zhang-xiaobo1997 已提交
1148

Z
zengyawen 已提交
1149 1150
| 名称             | 类型           | 可读 | 可写 | 说明                                                         |
| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
X
xu-rui-w 已提交
1151
| supportedFormats | Array\<string> | 是   | 否   | 支持的图片格式,包括:png,jpeg,bmp,gif,webp,RAW。 |
Z
zengyawen 已提交
1152 1153 1154 1155

### getImageInfo

getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void
X
xiaok 已提交
1156 1157 1158

获取指定序号的图片信息,使用callback形式返回图片信息。

X
xu-rui-w 已提交
1159
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1160 1161 1162

**参数:**

Z
zengyawen 已提交
1163 1164 1165 1166
| 参数名   | 类型                                   | 必填 | 说明                                     |
| -------- | -------------------------------------- | ---- | ---------------------------------------- |
| index    | number                                 | 是   | 创建图片源时的序号。                     |
| callback | AsyncCallback<[ImageInfo](#imageinfo)> | 是   | 获取图片信息回调,异步返回图片信息对象。 |
X
xiaok 已提交
1167 1168 1169 1170

**示例:**

```js
X
xu-rui-w 已提交
1171 1172 1173 1174 1175 1176 1177
imageSourceApi.getImageInfo(0,(error, imageInfo) => { 
    if(error) {
        console.log('getImageInfo failed.');
    } else {
        console.log('getImageInfo succeeded.');
    }
})
X
xiaok 已提交
1178 1179
```

Z
zengyawen 已提交
1180
### getImageInfo
X
xiaok 已提交
1181

Z
zengyawen 已提交
1182
getImageInfo(callback: AsyncCallback\<ImageInfo>): void
X
xiaok 已提交
1183

Z
zengyawen 已提交
1184
获取图片信息,使用callback形式返回图片信息。
X
xiaok 已提交
1185

X
xu-rui-w 已提交
1186
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1187 1188 1189

**参数:**

1190
| 参数名   | 类型                                   | 必填 | 说明                                     |
X
xiaok 已提交
1191
| -------- | -------------------------------------- | ---- | ---------------------------------------- |
Z
zengyawen 已提交
1192
| callback | AsyncCallback<[ImageInfo](#imageinfo)> | 是   | 获取图片信息回调,异步返回图片信息对象。 |
X
xiaok 已提交
1193 1194 1195 1196

**示例:**

```js
X
xu-rui-w 已提交
1197
imageSourceApi.getImageInfo(imageInfo => { 
X
xu-rui-w 已提交
1198
    console.log('Succeeded in obtaining the image information.');
X
xu-rui-w 已提交
1199
})
X
xiaok 已提交
1200 1201
```

Z
zengyawen 已提交
1202
### getImageInfo
X
xiaok 已提交
1203

Z
zengyawen 已提交
1204
getImageInfo(index?: number): Promise\<ImageInfo>
X
xiaok 已提交
1205 1206 1207

获取图片信息,使用Promise形式返回图片信息。

X
xu-rui-w 已提交
1208
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1209 1210 1211

**参数:**

1212
| 参数名| 类型   | 必填 | 说明                                  |
Z
zengyawen 已提交
1213 1214
| ----- | ------ | ---- | ------------------------------------- |
| index | number | 否   | 创建图片源时的序号,不选择时默认为0。 |
X
xiaok 已提交
1215 1216 1217

**返回值:**

Z
zengyawen 已提交
1218 1219 1220
| 类型                             | 说明                   |
| -------------------------------- | ---------------------- |
| Promise<[ImageInfo](#imageinfo)> | 返回获取到的图片信息。 |
X
xiaok 已提交
1221 1222 1223 1224 1225

**示例:**

```js
imageSourceApi.getImageInfo(0)
X
xu-rui-w 已提交
1226
    .then(imageInfo => {
X
xu-rui-w 已提交
1227
		console.log('Succeeded in obtaining the image information.');
X
xu-rui-w 已提交
1228
	}).catch(error => {
X
xu-rui-w 已提交
1229
		console.log('Failed to obtain the image information.');
X
xu-rui-w 已提交
1230
	})
X
xiaok 已提交
1231 1232
```

Z
zengyawen 已提交
1233
### getImageProperty<sup>7+</sup>
X
xiaok 已提交
1234

Z
zengyawen 已提交
1235
getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\<string>
X
xiaok 已提交
1236

Z
zengyawen 已提交
1237
获取图片中给定索引处图像的指定属性键的值,用Promise形式返回结果。
X
xiaok 已提交
1238

X
xu-rui-w 已提交
1239
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1240 1241 1242

 **参数:**

1243
| 参数名  | 类型                                                 | 必填 | 说明                                 |
Z
zengyawen 已提交
1244 1245 1246
| ------- | ---------------------------------------------------- | ---- | ------------------------------------ |
| key     | string                                               | 是   | 图片属性名。                         |
| options | [GetImagePropertyOptions](#getimagepropertyoptions7) | 否   | 图片属性,包括图片序号与默认属性值。 |
X
xiaok 已提交
1247 1248 1249

**返回值:**

X
xu-rui-w 已提交
1250 1251
| 类型             | 说明                                                              |
| ---------------- | ----------------------------------------------------------------- |
Z
zengyawen 已提交
1252
| Promise\<string> | Promise实例,用于异步获取图片属性值,如获取失败则返回属性默认值。 |
X
xiaok 已提交
1253 1254 1255 1256

**示例:**

```js
1257
imageSourceApi.getImageProperty("BitsPerSample")
X
xu-rui-w 已提交
1258
    .then(data => {
X
xu-rui-w 已提交
1259
		console.log('Succeeded in getting the value of the specified attribute key of the image.');
X
xu-rui-w 已提交
1260
	})
X
xiaok 已提交
1261 1262
```

Z
zengyawen 已提交
1263
### getImageProperty<sup>7+</sup>
X
xiaok 已提交
1264

Z
zengyawen 已提交
1265
getImageProperty(key:string, callback: AsyncCallback\<string>): void
X
xiaok 已提交
1266

Z
zengyawen 已提交
1267
获取图片中给定索引处图像的指定属性键的值,用callback形式返回结果。
X
xiaok 已提交
1268

X
xu-rui-w 已提交
1269
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1270 1271 1272

 **参数:**

Z
zengyawen 已提交
1273 1274 1275 1276
| 参数名   | 类型                   | 必填 | 说明                                                         |
| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
| key      | string                 | 是   | 图片属性名。                                                 |
| callback | AsyncCallback\<string> | 是   | 获取图片属性回调,返回图片属性值,如获取失败则返回属性默认值。 |
X
xiaok 已提交
1277 1278 1279 1280

**示例:**

```js
X
xu-rui-w 已提交
1281 1282
imageSourceApi.getImageProperty("BitsPerSample",(error,data) => { 
    if(error) {
X
xu-rui-w 已提交
1283
        console.log('Failed to get the value of the specified attribute key of the image.');
X
xu-rui-w 已提交
1284
    } else {
X
xu-rui-w 已提交
1285
        console.log('Succeeded in getting the value of the specified attribute key of the image.');
X
xu-rui-w 已提交
1286 1287
    }
})
X
xiaok 已提交
1288 1289
```

Z
zengyawen 已提交
1290
### getImageProperty<sup>7+</sup>
X
xiaok 已提交
1291

Z
zengyawen 已提交
1292
getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCallback\<string>): void
X
xiaok 已提交
1293 1294 1295

获取图片指定属性键的值,callback形式返回结果。

X
xu-rui-w 已提交
1296
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1297 1298 1299

**参数:**

X
xu-rui-w 已提交
1300 1301 1302 1303 1304
| 参数名   | 类型                                                 | 必填 | 说明                                                          |
| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------- |
| key      | string                                               | 是   | 图片属性名。                                                  |
| options  | [GetImagePropertyOptions](#getimagepropertyoptions7) | 是   | 图片属性,包括图片序号与默认属性值。                          |
| callback | AsyncCallback\<string>                               | 是   | 获取图片属性回调,返回图片属性值,如获取失败则返回属性默认值。|
X
xiaok 已提交
1305 1306 1307 1308

**示例:**

```js
F
fengzewu 已提交
1309
let property = { index: 0, defaultValue: '9999' }
X
xu-rui-w 已提交
1310
imageSourceApi.getImageProperty("BitsPerSample",property,(error,data) => { 
X
xu-rui-w 已提交
1311
    if(error) {
X
xu-rui-w 已提交
1312
        console.log('Failed to get the value of the specified attribute key of the image.');
X
xu-rui-w 已提交
1313
    } else {
X
xu-rui-w 已提交
1314
        console.log('Succeeded in getting the value of the specified attribute key of the image.');
X
xu-rui-w 已提交
1315 1316
    }
})
X
xiaok 已提交
1317 1318
```

X
xu-rui-w 已提交
1319
### modifyImageProperty<sup>9+</sup>
X
xu-rui-w 已提交
1320

X
xu-rui-w 已提交
1321
modifyImageProperty(key: string, value: string): Promise\<void>
X
xu-rui-w 已提交
1322

X
xu-rui-w 已提交
1323
通过指定的键修改图片属性的值,使用Promise形式返回结果。
X
xu-rui-w 已提交
1324

X
xu-rui-w 已提交
1325
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xu-rui-w 已提交
1326 1327 1328 1329 1330 1331 1332 1333 1334 1335

**参数:**

| 参数名  | 类型   | 必填 | 说明         |
| ------- | ------ | ---- | ------------ |
| key     | string | 是   | 图片属性名。 |
| value   | string | 是   | 属性值。     |

**返回值:**

X
xu-rui-w 已提交
1336 1337 1338
| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise\<void> | Promise实例,异步返回结果。 |
X
xu-rui-w 已提交
1339 1340 1341 1342

**示例:**

```js
F
fengzewu 已提交
1343 1344 1345 1346
imageSourceApi.modifyImageProperty("ImageWidth", "120").then(() => {
    const w = imageSourceApi.getImageProperty("ImageWidth")
    console.info('w', w);
})
X
xu-rui-w 已提交
1347 1348
```

X
xu-rui-w 已提交
1349
### modifyImageProperty<sup>9+</sup>
X
xu-rui-w 已提交
1350

X
xu-rui-w 已提交
1351
modifyImageProperty(key: string, value: string, callback: AsyncCallback\<void>): void
X
xu-rui-w 已提交
1352

X
xu-rui-w 已提交
1353
通过指定的键修改图片属性的值,callback形式返回结果。
X
xu-rui-w 已提交
1354

X
xu-rui-w 已提交
1355
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xu-rui-w 已提交
1356 1357 1358 1359 1360 1361 1362

**参数:**

| 参数名   | 类型                | 必填 | 说明                           |
| -------- | ------------------- | ---- | ------------------------------ |
| key      | string              | 是   | 图片属性名。                   |
| value    | string              | 是   | 属性值。                       |
1363
| callback | AsyncCallback\<void> | 是   | 修改属性值,callback返回结果。 |
X
xu-rui-w 已提交
1364 1365 1366 1367

**示例:**

```js
X
xu-rui-w 已提交
1368
imageSourceApi.modifyImageProperty("ImageWidth", "120",() => {})
X
xu-rui-w 已提交
1369 1370
```

X
xu-rui-w 已提交
1371
### updateData<sup>9+</sup>
X
xu-rui-w 已提交
1372

X
xu-rui-w 已提交
1373
updateData(buf: ArrayBuffer, isFinished: boolean, value: number, length: number): Promise\<void>
X
xu-rui-w 已提交
1374

X
xu-rui-w 已提交
1375
更新增量数据,使用Promise形式返回结果。
X
xu-rui-w 已提交
1376

X
xu-rui-w 已提交
1377
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xu-rui-w 已提交
1378 1379 1380

**参数:**

1381
| 参数名     | 类型        | 必填 | 说明         |
X
xu-rui-w 已提交
1382 1383 1384
| ---------- | ----------- | ---- | ------------ |
| buf        | ArrayBuffer | 是   | 增量数据。   |
| isFinished | boolean     | 是   | 是否更新完。 |
1385 1386
| value      | number      | 是   | 偏移量。     |
| length     | number      | 是   | 数组长。     |
X
xu-rui-w 已提交
1387 1388 1389

**返回值:**

X
xu-rui-w 已提交
1390 1391 1392
| 类型           | 说明                       |
| -------------- | -------------------------- |
| Promise\<void> | Promise实例,异步返回结果。|
X
xu-rui-w 已提交
1393 1394 1395 1396 1397

**示例:**

```js
const array = new ArrayBuffer(100);
F
fengzewu 已提交
1398 1399 1400
imageSourceApi.updateData(array, false, 0, 10).then(data => {
    console.info('Succeeded in updating data.');
})
X
xu-rui-w 已提交
1401 1402 1403
```


X
xu-rui-w 已提交
1404
### updateData<sup>9+</sup>
X
xu-rui-w 已提交
1405

X
xu-rui-w 已提交
1406
updateData(buf: ArrayBuffer, isFinished: boolean, value: number, length: number, callback: AsyncCallback\<void>): void
X
xu-rui-w 已提交
1407

X
xu-rui-w 已提交
1408
更新增量数据,callback形式返回结果。
X
xu-rui-w 已提交
1409

X
xu-rui-w 已提交
1410
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xu-rui-w 已提交
1411 1412 1413

**参数:**

1414
| 参数名     | 类型                | 必填 | 说明                 |
X
xu-rui-w 已提交
1415 1416 1417
| ---------- | ------------------- | ---- | -------------------- |
| buf        | ArrayBuffer         | 是   | 增量数据。           |
| isFinished | boolean             | 是   | 是否更新完。         |
1418 1419
| value      | number              | 是   | 偏移量。             |
| length     | number              | 是   | 数组长。             |
1420
| callback   | AsyncCallback\<void> | 是   | 回调表示成功或失败。 |
X
xu-rui-w 已提交
1421 1422 1423 1424 1425

**示例:**

```js
const array = new ArrayBuffer(100);
F
fengzewu 已提交
1426 1427 1428 1429 1430
imageSourceApi.updateData(array, false, 0, 10,(error,data )=> {
    if(data !== undefined){
        console.info('Succeeded in updating data.');     
    }
})
X
xu-rui-w 已提交
1431 1432
```

Z
zengyawen 已提交
1433
### createPixelMap<sup>7+</sup>
X
xiaok 已提交
1434

Z
zengyawen 已提交
1435
createPixelMap(options?: DecodingOptions): Promise\<PixelMap>
X
xiaok 已提交
1436

1437
通过图片解码参数创建PixelMap对象。
X
xiaok 已提交
1438

X
xu-rui-w 已提交
1439
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1440 1441 1442

**参数:**

1443
| 参数名  | 类型                                 | 必填 | 说明       |
Z
zengyawen 已提交
1444 1445 1446 1447 1448 1449 1450 1451
| ------- | ------------------------------------ | ---- | ---------- |
| options | [DecodingOptions](#decodingoptions7) | 否   | 解码参数。 |

**返回值:**

| 类型                             | 说明                  |
| -------------------------------- | --------------------- |
| Promise\<[PixelMap](#pixelmap7)> | 异步返回Promise对象。 |
X
xiaok 已提交
1452 1453 1454 1455

**示例:**

```js
X
xu-rui-w 已提交
1456
imageSourceApi.createPixelMap().then(pixelmap => {
X
xu-rui-w 已提交
1457
    console.log('Succeeded in creating pixelmap object through image decoding parameters.');
X
xu-rui-w 已提交
1458
}).catch(error => {
X
xu-rui-w 已提交
1459
    console.log('Failed to create pixelmap object through image decoding parameters.');
X
xu-rui-w 已提交
1460
})
X
xiaok 已提交
1461 1462
```

Z
zengyawen 已提交
1463
### createPixelMap<sup>7+</sup>
X
xiaok 已提交
1464

Z
zengyawen 已提交
1465
createPixelMap(callback: AsyncCallback\<PixelMap>): void
X
xiaok 已提交
1466

1467
通过默认参数创建PixelMap对象,使用callback形式返回结果。
X
xiaok 已提交
1468

X
xu-rui-w 已提交
1469
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1470 1471 1472

**参数:**

1473
| 参数名     | 类型                                  | 必填 | 说明                       |
Z
zengyawen 已提交
1474 1475
| -------- | ------------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback<[PixelMap](#pixelmap7)> | 是   | 通过回调返回PixelMap对象。 |
X
xiaok 已提交
1476 1477 1478 1479

**示例:**

```js
X
xu-rui-w 已提交
1480
imageSourceApi.createPixelMap((err, pixelmap) => {
1481
                    console.info('Succeeded in creating pixelmap object.');
X
xu-rui-w 已提交
1482
                })
X
xiaok 已提交
1483 1484
```

Z
zengyawen 已提交
1485
### createPixelMap<sup>7+</sup>
X
xiaok 已提交
1486

Z
zengyawen 已提交
1487
createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): void
X
xiaok 已提交
1488

Z
zengyawen 已提交
1489
通过图片解码参数创建PixelMap对象。
X
xiaok 已提交
1490

X
xu-rui-w 已提交
1491
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1492 1493 1494

**参数:**

1495
| 参数名   | 类型                                  | 必填 | 说明                       |
Z
zengyawen 已提交
1496
| -------- | ------------------------------------- | ---- | -------------------------- |
1497
| options  | [DecodingOptions](#decodingoptions7)  | 是   | 解码参数。                 |
Z
zengyawen 已提交
1498
| callback | AsyncCallback<[PixelMap](#pixelmap7)> | 是   | 通过回调返回PixelMap对象。 |
X
xiaok 已提交
1499 1500 1501 1502

**示例:**

```js
F
fengzewu 已提交
1503 1504 1505 1506 1507 1508 1509 1510 1511
let decodingOptions = {
    sampleSize: 1,
    editable: true,
    desiredSize: { width: 1, height: 2 },
    rotate: 10,
    desiredPixelFormat: 3,
    desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 },
    index: 0
};
X
xu-rui-w 已提交
1512
imageSourceApi.createPixelMap(decodingOptions, pixelmap => { 
X
xu-rui-w 已提交
1513 1514
    console.log('Succeeded in creating pixelmap object.');
})
X
xiaok 已提交
1515 1516
```

Z
zengyawen 已提交
1517
### release
X
xiaok 已提交
1518

Z
zengyawen 已提交
1519
release(callback: AsyncCallback\<void>): void
X
xiaok 已提交
1520

Z
zengyawen 已提交
1521
释放图片源实例,使用callback形式返回结果。
X
xiaok 已提交
1522

X
xu-rui-w 已提交
1523
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1524 1525 1526

**参数:**

1527
| 参数名   | 类型                 | 必填 | 说明                               |
Z
zengyawen 已提交
1528 1529
| -------- | -------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<void> | 是   | 资源释放回调,失败时返回错误信息。 |
X
xiaok 已提交
1530 1531 1532 1533

**示例:**

```js
X
xu-rui-w 已提交
1534 1535 1536
imageSourceApi.release(() => { 
    console.log('release succeeded.');
})
X
xiaok 已提交
1537 1538
```

Z
zengyawen 已提交
1539
### release
X
xiaok 已提交
1540

Z
zengyawen 已提交
1541
release(): Promise\<void>
X
xiaok 已提交
1542

Z
zengyawen 已提交
1543
释放图片源实例,使用Promise形式返回结果。
X
xiaok 已提交
1544

X
xu-rui-w 已提交
1545
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1546

Z
zengyawen 已提交
1547 1548 1549 1550 1551 1552
**返回值:**

| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise\<void> | Promise实例,异步返回结果。 |

X
xiaok 已提交
1553 1554 1555
**示例:**

```js
X
xu-rui-w 已提交
1556
imageSourceApi.release().then(()=>{
X
xu-rui-w 已提交
1557
    console.log('Succeeded in releasing the image source instance.');
X
xu-rui-w 已提交
1558
}).catch(error => {
X
xu-rui-w 已提交
1559
    console.log('Failed to release the image source instance.');
X
xu-rui-w 已提交
1560
})
X
xiaok 已提交
1561 1562
```

Z
zengyawen 已提交
1563
## image.createImagePacker
X
xiaok 已提交
1564 1565 1566

createImagePacker(): ImagePacker

Z
zengyawen 已提交
1567
创建ImagePacker实例。
X
xiaok 已提交
1568

X
xu-rui-w 已提交
1569
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
X
xiaok 已提交
1570 1571 1572

**返回值:**

Z
zengyawen 已提交
1573 1574 1575
| 类型                        | 说明                  |
| --------------------------- | --------------------- |
| [ImagePacker](#imagepacker) | 返回ImagePacker实例。 |
X
xiaok 已提交
1576 1577 1578 1579 1580 1581 1582

**示例:**

```js
const imagePackerApi = image.createImagePacker();
```

Z
zengyawen 已提交
1583 1584
## ImagePacker

X
xu-rui-w 已提交
1585
图片打包器类,用于图片压缩和打包。在调用ImagePacker的方法前,需要先通过createImagePacker构建一个ImagePacker实例,当前支持格式有:jpeg webp。
X
xiaok 已提交
1586

Z
zengyawen 已提交
1587 1588
### 属性

X
xu-rui-w 已提交
1589
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
Z
zhang-xiaobo1997 已提交
1590 1591 1592 1593

| 名称             | 类型           | 可读 | 可写 | 说明                       |
| ---------------- | -------------- | ---- | ---- | -------------------------- |
| supportedFormats | Array\<string> | 是   | 否   | 图片打包支持的格式,jpeg。 |
Z
zengyawen 已提交
1594 1595 1596

### packing

1597
packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void
X
xiaok 已提交
1598 1599 1600

图片压缩或重新打包,使用callback形式返回结果。

X
xu-rui-w 已提交
1601
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
X
xiaok 已提交
1602 1603 1604

**参数:**

Z
zengyawen 已提交
1605 1606 1607
| 参数名   | 类型                               | 必填 | 说明                               |
| -------- | ---------------------------------- | ---- | ---------------------------------- |
| source   | [ImageSource](#imagesource)        | 是   | 打包的图片源。                     |
X
xu-rui-w 已提交
1608
| option   | [PackingOption](#packingoption)    | 是   | 设置打包参数。                      |
1609
| callback | AsyncCallback\<ArrayBuffer>        | 是   | 获取图片打包回调,返回打包后数据。 |
X
xiaok 已提交
1610 1611 1612 1613

**示例:**

```js
F
fengzewu 已提交
1614
const imageSourceApi = image.createImageSource(0);
X
xu-rui-w 已提交
1615
let packOpts = { format:"image/jpeg", quality:98 };
X
xu-rui-w 已提交
1616
imagePackerApi.packing(imageSourceApi, packOpts, data => {})
X
xiaok 已提交
1617 1618
```

Z
zengyawen 已提交
1619
### packing
X
xiaok 已提交
1620

1621
packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer>
X
xiaok 已提交
1622

Z
zengyawen 已提交
1623
图片压缩或重新打包,使用Promise形式返回结果。
X
xiaok 已提交
1624

X
xu-rui-w 已提交
1625
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
X
xiaok 已提交
1626 1627 1628 1629 1630

**参数:**

| 参数名 | 类型                            | 必填 | 说明           |
| ------ | ------------------------------- | ---- | -------------- |
Z
zengyawen 已提交
1631 1632
| source | [ImageSource](#imagesource)     | 是   | 打包的图片源。 |
| option | [PackingOption](#packingoption) | 是   | 设置打包参数。 |
X
xiaok 已提交
1633 1634 1635

**返回值:**

Z
zengyawen 已提交
1636
| 类型                         | 说明                                          |
X
xu-rui-w 已提交
1637 1638
| ---------------------------- | --------------------------------------------- |
| Promise\<ArrayBuffer>        | Promise实例,用于异步获取压缩或打包后的数据。 |
X
xiaok 已提交
1639 1640 1641 1642

**示例:**

```js
F
fengzewu 已提交
1643
const imageSourceApi = image.createImageSource(0);
X
xu-rui-w 已提交
1644
let packOpts = { format:"image/jpeg", quality:98 }
X
xu-rui-w 已提交
1645
imagePackerApi.packing(imageSourceApi, packOpts)
X
xu-rui-w 已提交
1646 1647 1648 1649 1650
    .then( data => {
        console.log('packing succeeded.');
	}).catch(error => {
	    console.log('packing failed.');
	})
1651 1652
```

1653
### packing<sup>8+</sup>
1654

Z
zengyawen 已提交
1655
packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void
1656 1657 1658

图片压缩或重新打包,使用callback形式返回结果。

X
xu-rui-w 已提交
1659
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
1660 1661 1662 1663 1664 1665 1666

**参数:**

| 参数名   | 类型                            | 必填 | 说明                               |
| -------- | ------------------------------- | ---- | ---------------------------------- |
| source   | [PixelMap](#pixelmap)           | 是   | 打包的PixelMap资源。               |
| option   | [PackingOption](#packingoption) | 是   | 设置打包参数。                     |
Z
zengyawen 已提交
1667
| callback | AsyncCallback\<ArrayBuffer>     | 是   | 获取图片打包回调,返回打包后数据。 |
1668 1669 1670 1671

**示例:**

```js
X
xu-rui-w 已提交
1672
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
F
fengzewu 已提交
1673 1674 1675 1676
let bufferArr = new Uint8Array(color);
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts).then((pixelmap) => {
    let packOpts = { format:"image/jpeg", quality:98 }
冯泽悟 已提交
1677
    imagePackerApi.packing(pixelmap, packOpts, data => { 
F
fengzewu 已提交
1678 1679
        console.log('Succeeded in packing the image.');
    })
X
xu-rui-w 已提交
1680
})
1681 1682
```

1683
### packing<sup>8+</sup>
1684

1685
packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer>
1686 1687 1688

图片压缩或重新打包,使用Promise形式返回结果。

X
xu-rui-w 已提交
1689
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
1690 1691 1692

**参数:**

Z
zhang-xiaobo1997 已提交
1693 1694
| 参数名 | 类型                            | 必填 | 说明               |
| ------ | ------------------------------- | ---- | ------------------ |
1695
| source | [PixelMap](#pixelmap)           | 是   | 打包的PixelMap源。 |
Z
zhang-xiaobo1997 已提交
1696
| option | [PackingOption](#packingoption) | 是   | 设置打包参数。     |
1697 1698 1699

**返回值:**

X
xu-rui-w 已提交
1700 1701 1702
| 类型                  | 说明                                         |
| --------------------- | -------------------------------------------- |
| Promise\<ArrayBuffer> | Promise实例,用于异步获取压缩或打包后的数据。|
1703 1704 1705 1706

**示例:**

```js
X
xu-rui-w 已提交
1707
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
F
fengzewu 已提交
1708 1709 1710 1711
let bufferArr = new Uint8Array(color);
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts).then((pixelmap) => {
    let packOpts = { format:"image/jpeg", quality:98 }
冯泽悟 已提交
1712
    imagePackerApi.packing(pixelmap, packOpts)
F
fengzewu 已提交
1713
        .then( data => {
F
fengzewu 已提交
1714 1715 1716 1717
            console.log('Succeeded in packing the image.');
        }).catch(error => {
            console.log('Failed to pack the image..');
        })
F
fengzewu 已提交
1718
})
X
xiaok 已提交
1719 1720
```

Z
zengyawen 已提交
1721
### release
X
xiaok 已提交
1722

Z
zengyawen 已提交
1723
release(callback: AsyncCallback\<void>): void
X
xiaok 已提交
1724

Z
zengyawen 已提交
1725
释放图片打包实例,使用callback形式返回结果。
X
xiaok 已提交
1726

X
xu-rui-w 已提交
1727
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
X
xiaok 已提交
1728 1729 1730

**参数:**

Z
zengyawen 已提交
1731 1732 1733
| 参数名   | 类型                 | 必填 | 说明                           |
| -------- | -------------------- | ---- | ------------------------------ |
| callback | AsyncCallback\<void> | 是   | 释放回调,失败时返回错误信息。 |
X
xiaok 已提交
1734 1735 1736 1737

**示例:**

```js
X
xu-rui-w 已提交
1738
imagePackerApi.release(()=>{ 
X
xu-rui-w 已提交
1739
    console.log('Succeeded in releasing image packaging.');
X
xu-rui-w 已提交
1740
})
X
xiaok 已提交
1741 1742
```

Z
zengyawen 已提交
1743
### release
X
xiaok 已提交
1744

Z
zengyawen 已提交
1745
release(): Promise\<void>
X
xiaok 已提交
1746

Z
zengyawen 已提交
1747
释放图片打包实例,使用Promise形式返回释放结果。
X
xiaok 已提交
1748

X
xu-rui-w 已提交
1749
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
X
xiaok 已提交
1750

Z
zengyawen 已提交
1751 1752
**返回值:**

X
xu-rui-w 已提交
1753 1754 1755
| 类型           | 说明                                                   |
| -------------- | ------------------------------------------------------ |
| Promise\<void> | Promise实例,用于异步获取释放结果,失败时返回错误信息。|
Z
zengyawen 已提交
1756

X
xiaok 已提交
1757 1758 1759
**示例:**

```js
X
xu-rui-w 已提交
1760
imagePackerApi.release().then(()=>{
X
xu-rui-w 已提交
1761
    console.log('Succeeded in releasing image packaging.');
X
xu-rui-w 已提交
1762
}).catch((error)=>{ 
X
xu-rui-w 已提交
1763
    console.log('Failed to release image packaging.'); 
X
xu-rui-w 已提交
1764
}) 
X
xiaok 已提交
1765 1766
```

Z
zhang-xiaobo1997 已提交
1767 1768
## image.createImageReceiver<sup>9+</sup>

Z
zengyawen 已提交
1769
createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver
Z
zhang-xiaobo1997 已提交
1770

Z
zengyawen 已提交
1771
通过宽、高、图片格式、容量创建ImageReceiver实例。
Z
zhang-xiaobo1997 已提交
1772

Z
zengyawen 已提交
1773
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1774 1775 1776

**参数:**

1777
| 参数名   | 类型   | 必填 | 说明                   |
Z
zengyawen 已提交
1778 1779 1780
| -------- | ------ | ---- | ---------------------- |
| width    | number | 是   | 图像的默认宽度。       |
| height   | number | 是   | 图像的默认高度。       |
Z
zhangqiang183 已提交
1781
| format   | number | 是   | 图像格式,取值为[ImageFormat](#imageformat9)常量(目前仅支持 ImageFormat:JPEG 和 4)。  |
Z
zengyawen 已提交
1782
| capacity | number | 是   | 同时访问的最大图像数。 |
Z
zhang-xiaobo1997 已提交
1783 1784 1785

**返回值:**

Z
zengyawen 已提交
1786 1787 1788
| 类型                             | 说明                                    |
| -------------------------------- | --------------------------------------- |
| [ImageReceiver](#imagereceiver9) | 如果操作成功,则返回ImageReceiver实例。 |
Z
zhang-xiaobo1997 已提交
1789 1790 1791 1792

**示例:**

```js
X
xu-rui-w 已提交
1793
var receiver = image.createImageReceiver(8192, 8, 2000, 8);
Z
zhang-xiaobo1997 已提交
1794
```
Z
zhang-xiaobo1997 已提交
1795

Z
zhang-xiaobo1997 已提交
1796 1797
## ImageReceiver<sup>9+</sup>

Z
zengyawen 已提交
1798 1799 1800
图像接收类,用于获取组件surface id,接收最新的图片和读取下一张图片,以及释放ImageReceiver实例。

在调用以下方法前需要先创建ImageReceiver实例。
Z
zhang-xiaobo1997 已提交
1801 1802 1803

### 属性

X
xu-rui-w 已提交
1804
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1805

X
xu-rui-w 已提交
1806 1807 1808 1809 1810
| 名称     | 类型                         | 可读 | 可写 | 说明               |
| -------- | ---------------------------- | ---- | ---- | ------------------ |
| size     | [Size](#size)                | 是   | 否   | 图片大小。         |
| capacity | number                       | 是   | 否   | 同时访问的图像数。 |
| format   | [ImageFormat](#imageformat9) | 是   | 否   | 图像格式。         |
Z
zhang-xiaobo1997 已提交
1811

Z
zhang-xiaobo1997 已提交
1812
### getReceivingSurfaceId<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1813

Z
zhang-xiaobo1997 已提交
1814
getReceivingSurfaceId(callback: AsyncCallback\<string>): void
Z
zhang-xiaobo1997 已提交
1815

Z
zengyawen 已提交
1816
用于获取一个surface id供Camera或其他组件使用。使用callback返回结果。
Z
zhang-xiaobo1997 已提交
1817

Z
zengyawen 已提交
1818
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1819 1820 1821

**参数:**

1822
| 参数名   | 类型                   | 必填 | 说明                       |
Z
zengyawen 已提交
1823 1824
| -------- | ---------------------- | ---- | -------------------------- |
| callback | AsyncCallback\<string> | 是   | 回调函数,返回surface id。 |
Z
zhang-xiaobo1997 已提交
1825 1826 1827 1828

**示例:**

```js
X
xu-rui-w 已提交
1829
receiver.getReceivingSurfaceId((err, id) => { 
X
xu-rui-w 已提交
1830 1831 1832 1833 1834 1835
    if(err) {
        console.log('getReceivingSurfaceId failed.');
    } else {
        console.log('getReceivingSurfaceId succeeded.');
    }
});
Z
zhang-xiaobo1997 已提交
1836 1837
```

Z
zhang-xiaobo1997 已提交
1838
### getReceivingSurfaceId<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1839

Z
zhang-xiaobo1997 已提交
1840
getReceivingSurfaceId(): Promise\<string>
Z
zhang-xiaobo1997 已提交
1841

Z
zengyawen 已提交
1842
用于获取一个surface id供Camera或其他组件使用。使用promise返回结果。
Z
zhang-xiaobo1997 已提交
1843

Z
zengyawen 已提交
1844
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1845 1846 1847

**返回值:**

Z
zhang-xiaobo1997 已提交
1848 1849 1850
| 类型             | 说明                 |
| ---------------- | -------------------- |
| Promise\<string> | 异步返回surface id。 |
Z
zhang-xiaobo1997 已提交
1851 1852 1853 1854 1855

**示例:**

```js
receiver.getReceivingSurfaceId().then( id => { 
X
xu-rui-w 已提交
1856 1857 1858 1859
    console.log('getReceivingSurfaceId succeeded.');
}).catch(error => {
    console.log('getReceivingSurfaceId failed.');
})
Z
zhang-xiaobo1997 已提交
1860 1861
```

Z
zhang-xiaobo1997 已提交
1862
### readLatestImage<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1863

Z
zhang-xiaobo1997 已提交
1864
readLatestImage(callback: AsyncCallback\<Image>): void
Z
zhang-xiaobo1997 已提交
1865

Z
zengyawen 已提交
1866
从ImageReceiver读取最新的图片,并使用callback返回结果。
Z
zhang-xiaobo1997 已提交
1867

Z
zengyawen 已提交
1868
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1869 1870 1871

**参数:**

1872
| 参数名     | 类型                            | 必填 | 说明                     |
Z
zengyawen 已提交
1873 1874
| -------- | ------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<[Image](#image9)> | 是   | 回调函数,返回最新图像。 |
Z
zhang-xiaobo1997 已提交
1875 1876 1877 1878

**示例:**

```js
X
xu-rui-w 已提交
1879 1880 1881 1882 1883 1884 1885
receiver.readLatestImage((err, img) => { 
    if(err) {
        console.log('readLatestImage failed.');
    } else {
        console.log('readLatestImage succeeded.');
    }
});
Z
zhang-xiaobo1997 已提交
1886 1887
```

Z
zhang-xiaobo1997 已提交
1888
### readLatestImage<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1889

Z
zhang-xiaobo1997 已提交
1890
readLatestImage(): Promise\<Image>
Z
zhang-xiaobo1997 已提交
1891

Z
zengyawen 已提交
1892
从ImageReceiver读取最新的图片,并使用promise返回结果。
Z
zhang-xiaobo1997 已提交
1893

Z
zengyawen 已提交
1894
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1895 1896 1897 1898 1899

**返回值:**

| 类型                      | 说明               |
| ------------------------- | ------------------ |
1900
| Promise<[Image](#image9)> | 异步返回最新图片。 |
Z
zhang-xiaobo1997 已提交
1901 1902 1903 1904

**示例:**

```js
X
xu-rui-w 已提交
1905 1906 1907 1908 1909
receiver.readLatestImage().then(img => {
    console.log('readLatestImage succeeded.');
}).catch(error => {
    console.log('readLatestImage failed.');
})
Z
zhang-xiaobo1997 已提交
1910 1911
```

Z
zhang-xiaobo1997 已提交
1912
### readNextImage<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1913

Z
zhang-xiaobo1997 已提交
1914
readNextImage(callback: AsyncCallback\<Image>): void
Z
zhang-xiaobo1997 已提交
1915

Z
zengyawen 已提交
1916
从ImageReceiver读取下一张图片,并使用callback返回结果。
Z
zhang-xiaobo1997 已提交
1917

Z
zengyawen 已提交
1918
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1919 1920 1921

**参数:**

1922
| 参数名   | 类型                            | 必填 | 说明                       |
Z
zengyawen 已提交
1923 1924
| -------- | ------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback<[Image](#image9)> | 是   | 回调函数,返回下一张图片。 |
Z
zhang-xiaobo1997 已提交
1925 1926 1927 1928

**示例:**

```js
X
xu-rui-w 已提交
1929 1930 1931 1932 1933 1934 1935
receiver.readNextImage((err, img) => { 
    if(err) {
        console.log('readNextImage failed.');
    } else {
        console.log('readNextImage succeeded.');
    }
});
Z
zhang-xiaobo1997 已提交
1936 1937
```

Z
zhang-xiaobo1997 已提交
1938
### readNextImage<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1939

Z
zhang-xiaobo1997 已提交
1940
readNextImage(): Promise\<Image>
Z
zhang-xiaobo1997 已提交
1941

Z
zengyawen 已提交
1942
从ImageReceiver读取下一张图片,并使用promise返回结果。
Z
zhang-xiaobo1997 已提交
1943

Z
zengyawen 已提交
1944
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1945 1946 1947 1948 1949

**返回值:**

| 类型                      | 说明                 |
| ------------------------- | -------------------- |
Z
zengyawen 已提交
1950
| Promise<[Image](#image9)> | 异步返回下一张图片。 |
Z
zhang-xiaobo1997 已提交
1951 1952 1953 1954

**示例:**

```js
X
xu-rui-w 已提交
1955 1956 1957 1958 1959
receiver.readNextImage().then(img => {
    console.log('readNextImage succeeded.');
}).catch(error => {
    console.log('readNextImage failed.');
})
Z
zhang-xiaobo1997 已提交
1960 1961
```

X
xu-rui-w 已提交
1962
### on<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1963

Z
zhang-xiaobo1997 已提交
1964
on(type: 'imageArrival', callback: AsyncCallback\<void>): void
Z
zhang-xiaobo1997 已提交
1965 1966 1967

接收图片时注册回调。

Z
zengyawen 已提交
1968
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1969 1970 1971

**参数:**

1972
| 参数名   | 类型                 | 必填 | 说明                                                   |
Z
zhang-xiaobo1997 已提交
1973
| -------- | -------------------- | ---- | ------------------------------------------------------ |
Z
zengyawen 已提交
1974
| type     | string               | 是   | 注册事件的类型,固定为'imageArrival',接收图片时触发。 |
Z
zhang-xiaobo1997 已提交
1975
| callback | AsyncCallback\<void> | 是   | 注册的事件回调。                                       |
Z
zhang-xiaobo1997 已提交
1976 1977 1978 1979

**示例:**

```js
X
xu-rui-w 已提交
1980
receiver.on('imageArrival', () => {})
Z
zhang-xiaobo1997 已提交
1981 1982
```

Z
zhang-xiaobo1997 已提交
1983
### release<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1984

Z
zengyawen 已提交
1985
release(callback: AsyncCallback\<void>): void
Z
zhang-xiaobo1997 已提交
1986 1987 1988

释放ImageReceiver实例并使用回调返回结果。

Z
zengyawen 已提交
1989
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1990 1991 1992

**参数:**

1993
| 参数名   | 类型                 | 必填 | 说明                     |
Z
zengyawen 已提交
1994 1995
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback\<void> | 是   | 回调函数,返回操作结果。 |
Z
zhang-xiaobo1997 已提交
1996 1997 1998 1999

**示例:**

```js
X
xu-rui-w 已提交
2000
receiver.release(() => {})
Z
zhang-xiaobo1997 已提交
2001 2002
```

Z
zhang-xiaobo1997 已提交
2003
### release<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2004

Z
zhang-xiaobo1997 已提交
2005
release(): Promise\<void>
Z
zhang-xiaobo1997 已提交
2006 2007 2008

释放ImageReceiver实例并使用promise返回结果。

Z
zengyawen 已提交
2009
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
2010 2011 2012

**返回值:**

Z
zengyawen 已提交
2013 2014 2015
| 类型           | 说明               |
| -------------- | ------------------ |
| Promise\<void> | 异步返回操作结果。 |
Z
zhang-xiaobo1997 已提交
2016 2017 2018 2019

**示例:**

```js
X
xu-rui-w 已提交
2020 2021 2022 2023 2024
receiver.release().then(() => {
    console.log('release succeeded.');
}).catch(error => {
    console.log('release failed.');
})
Z
zhang-xiaobo1997 已提交
2025 2026
```

R
renhongwei 已提交
2027 2028 2029 2030 2031 2032 2033 2034 2035 2036
## image.createImageCreator<sup>9+</sup>

createImageCreator(width: number, height: number, format: number, capacity: number): ImageCreator

通过宽、高、图片格式、容量创建ImageCreator实例。

**系统能力:** SystemCapability.Multimedia.Image.ImageCreator

**参数:**

2037
| 参数名   | 类型   | 必填 | 说明                   |
R
renhongwei 已提交
2038 2039 2040
| -------- | ------ | ---- | ---------------------- |
| width    | number | 是   | 图像的默认宽度。       |
| height   | number | 是   | 图像的默认高度。       |
X
xu-rui-w 已提交
2041
| format   | number | 是   | 图像格式,如YCBCR_422_SP,JPEG。             |
R
renhongwei 已提交
2042 2043 2044 2045 2046 2047
| capacity | number | 是   | 同时访问的最大图像数。 |

**返回值:**

| 类型                           | 说明                                    |
| ------------------------------ | --------------------------------------- |
X
xu-rui-w 已提交
2048
| [ImageCreator](#imagecreator9) | 如果操作成功,则返回ImageCreator实例。 |    
R
renhongwei 已提交
2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062

**示例:**

```js
var creator = image.createImageCreator(8192, 8, 4, 8);
```

## ImageCreator<sup>9+</sup>

图像创建模块,用于请求图像原生数据区域,并开放给应用编译原生图像数据的能力。
在调用以下方法前需要先创建ImageCreator实例。

### 属性

X
xu-rui-w 已提交
2063
**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
R
renhongwei 已提交
2064 2065 2066 2067 2068 2069 2070 2071 2072 2073

| 名称     | 类型                         | 可读 | 可写 | 说明               |
| -------- | ---------------------------- | ---- | ---- | ------------------ |
| capacity | number                       | 是   | 否   | 同时访问的图像数。 |
| format   | [ImageFormat](#imageformat9) | 是   | 否   | 图像格式。         |

### dequeueImage<sup>9+</sup>

dequeueImage(callback: AsyncCallback\<Image>): void

X
xu-rui-w 已提交
2074
从空闲队列中获取buffer图片,用于绘制UI内容,并使用callback返回结果。
R
renhongwei 已提交
2075

X
xu-rui-w 已提交
2076
**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
R
renhongwei 已提交
2077 2078 2079

**参数:**

2080
| 参数名        | 类型                                    | 必填 | 说明                 |
R
renhongwei 已提交
2081 2082 2083 2084 2085 2086
| ------------- | ---------------------------------------| ---- | -------------------- |
| callback      | AsyncCallback\<Image>                   | 是   | 回调函数,返回最新图片。 |

**示例:**

```js
X
xu-rui-w 已提交
2087 2088
creator.dequeueImage((err, img) => {
    if (err) {
2089
        console.info('dequeueImage failded.');
X
xu-rui-w 已提交
2090
    }
2091
    console.info('dequeueImage succeeded.');
X
xu-rui-w 已提交
2092
});
R
renhongwei 已提交
2093 2094 2095 2096 2097 2098
```

### dequeueImage<sup>9+</sup>

dequeueImage(): Promise\<Image>

X
xu-rui-w 已提交
2099
从空闲队列中获取buffer图片,用于绘制UI内容,并使用promise返回结果。
R
renhongwei 已提交
2100

X
xu-rui-w 已提交
2101
**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
R
renhongwei 已提交
2102 2103 2104 2105 2106 2107 2108 2109 2110 2111

**返回值:**

| 类型             | 说明           |
| --------------- | ------------- |
| Promise\<Image> | 返回绘制的图像。 |

**示例:**

```js
X
xu-rui-w 已提交
2112 2113 2114 2115 2116
creator.dequeueImage().then(img => {
    console.info('dequeueImage succeeded.');
}).catch(error => {
    console.log('dequeueImage failed: ' + error);
})
R
renhongwei 已提交
2117 2118
```

X
xu-rui-w 已提交
2119
### queueImage<sup>9+</sup>
R
renhongwei 已提交
2120 2121 2122

queueImage(interface: Image, callback: AsyncCallback\<void>): void

X
xu-rui-w 已提交
2123
将绘制好的图片放入Dirty队列,并使用callback返回结果。
R
renhongwei 已提交
2124

X
xu-rui-w 已提交
2125
**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
R
renhongwei 已提交
2126 2127 2128

**参数:**

2129
| 参数名        | 类型                     | 必填 | 说明                 |
R
renhongwei 已提交
2130 2131 2132 2133 2134 2135 2136
| ------------- | -------------------------| ---- | -------------------- |
| interface     | Image                    | 是   | 绘制好的buffer图像。 |
| callback      | AsyncCallback\<void>     | 是   | 获取回调,失败时返回错误信息。 |

**示例:**

```js
2137 2138
creator.dequeueImage().then(img => {
    //绘制图片
2139 2140 2141 2142 2143 2144 2145 2146 2147
    img.getComponent(4).then(component => {
        var bufferArr = new Uint8Array(component.byteBuffer);
        for (var i = 0; i < bufferArr.length; i += 4) {
            bufferArr[i] = 0; //B
            bufferArr[i + 1] = 0; //G
            bufferArr[i + 2] = 255; //R
            bufferArr[i + 3] = 255; //A
        }
    })
2148 2149 2150 2151 2152 2153
    creator.queueImage(img, (err) => {
        if (err) {
            console.info('queueImage failed: ' + err);
        }
        console.info('queueImage succeeded');
    })
2154 2155
})

R
renhongwei 已提交
2156 2157
```

X
xu-rui-w 已提交
2158
### queueImage<sup>9+</sup>
R
renhongwei 已提交
2159 2160 2161

queueImage(interface: Image): Promise\<void>

X
xu-rui-w 已提交
2162
将绘制好的图片放入Dirty队列,并使用promise返回结果。
R
renhongwei 已提交
2163

X
xu-rui-w 已提交
2164
**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
R
renhongwei 已提交
2165 2166 2167

**参数:**

2168
| 参数名          | 类型     | 必填 | 说明                |
R
renhongwei 已提交
2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180
| ------------- | --------| ---- | ------------------- |
| interface     | Image   | 是   | 绘制好的buffer图像。 |

**返回值:**

| 类型            | 说明           |
| -------------- | ------------- |
| Promise\<void> | 获取回调,失败时返回错误信息。 |

**示例:**

```js
2181 2182
creator.dequeueImage().then(img => {
    //绘制图片
2183 2184 2185 2186 2187 2188 2189 2190 2191
    img.getComponent(4).then(component => {
        var bufferArr = new Uint8Array(component.byteBuffer);
        for (var i = 0; i < bufferArr.length; i += 4) {
            bufferArr[i] = 0; //B
            bufferArr[i + 1] = 0; //G
            bufferArr[i + 2] = 255; //R
            bufferArr[i + 3] = 255; //A
        }
    })
2192 2193 2194 2195 2196
    creator.queueImage(img).then(() => {
        console.info('queueImage succeeded.');
    }).catch(error => {
        console.info('queueImage failed: ' + error);
    })
X
xu-rui-w 已提交
2197
})
2198

R
renhongwei 已提交
2199 2200 2201 2202 2203 2204 2205 2206
```

### on<sup>9+</sup>

on(type: 'imageRelease', callback: AsyncCallback\<void>): void

监听imageRelease事件,并使用callback返回结果。

X
xu-rui-w 已提交
2207
**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
R
renhongwei 已提交
2208 2209 2210

**参数:**

2211
| 参数名        | 类型                     | 必填 | 说明                 |
R
renhongwei 已提交
2212
| ------------- | -------------------------| ---- | -------------------- |
X
xu-rui-w 已提交
2213
| type          | string                   | 是   | 监听事件类型,如'imageRelease'。 |
R
renhongwei 已提交
2214 2215 2216 2217 2218
| callback      | AsyncCallback\<void>     | 是   | 获取回调,失败时返回错误信息。 |

**示例:**

```js
X
xu-rui-w 已提交
2219 2220 2221 2222 2223 2224
creator.on('imageRelease', (err) => {
    if (err) {
        console.info('on faild' + err);
    }
    console.info('on succeeded');
})
R
renhongwei 已提交
2225 2226 2227 2228 2229 2230 2231 2232
```

### release<sup>9+</sup>

release(callback: AsyncCallback\<void>): void

释放当前图像,并使用callback返回结果。

X
xu-rui-w 已提交
2233
**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
R
renhongwei 已提交
2234 2235 2236

**参数:**

2237
| 参数名           | 类型                     | 必填 | 说明                 |
R
renhongwei 已提交
2238 2239 2240 2241 2242 2243
| ------------- | -------------------------| ---- | -------------------- |
| callback      | AsyncCallback\<void>     | 是   | 获取回调,失败时返回错误信息。 |

**示例:**

```js
X
xu-rui-w 已提交
2244 2245 2246 2247 2248 2249
creator.release((err) => {
    if (err) {
        console.info('release failed: ' + err);
    }
    console.info('release succeeded');
});
R
renhongwei 已提交
2250 2251 2252 2253 2254
```
### release<sup>9+</sup>

release(): Promise\<void>

X
xu-rui-w 已提交
2255 2256 2257
释放当前图像,并使用promise返回结果。

**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
R
renhongwei 已提交
2258 2259 2260 2261 2262 2263 2264 2265 2266 2267

**返回值:**

| 类型            | 说明           |
| -------------- | ------------- |
| Promise\<void> | 获取回调,失败时返回错误信息。 |

**示例:**

```js
X
xu-rui-w 已提交
2268 2269 2270 2271 2272
creator.release().then(() => {
    console.info('release succeeded');
}).catch(error => {
    console.info('release failed');
})
R
renhongwei 已提交
2273 2274
```

Z
zhang-xiaobo1997 已提交
2275
## Image<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2276

Z
zengyawen 已提交
2277
提供基本的图像操作,包括获取图像信息、读写图像数据。调用[readNextImage](#readnextimage9)[readLatestImage](#readlatestimage9)接口时会返回image。
Z
zhang-xiaobo1997 已提交
2278 2279 2280

### 属性

X
xu-rui-w 已提交
2281
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
2282

X
xu-rui-w 已提交
2283 2284 2285
| 名称     | 类型               | 可读 | 可写 | 说明                                               |
| -------- | ------------------ | ---- | ---- | -------------------------------------------------- |
| clipRect | [Region](#region7) | 是   | 是   | 要裁剪的图像区域。                                 |
X
xu-rui-w 已提交
2286
| size     | [Size](#size)      | 是   | 否   | 图像大小。                                         |
X
xu-rui-w 已提交
2287
| format   | number             | 是   | 否   | 图像格式,参考[PixelMapFormat](#pixelmapformat7)。 |
Z
zhang-xiaobo1997 已提交
2288

Z
zhang-xiaobo1997 已提交
2289
### getComponent<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2290

Z
zhang-xiaobo1997 已提交
2291
getComponent(componentType: ComponentType, callback: AsyncCallback\<Component>): void
Z
zhang-xiaobo1997 已提交
2292

Z
zhang-xiaobo1997 已提交
2293
根据图像的组件类型从图像中获取组件缓存并使用callback返回结果。
Z
zhang-xiaobo1997 已提交
2294

Z
zengyawen 已提交
2295
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
2296 2297 2298

**参数:**

2299
| 参数名        | 类型                                    | 必填 | 说明                 |
Z
zhang-xiaobo1997 已提交
2300
| ------------- | --------------------------------------- | ---- | -------------------- |
Z
zengyawen 已提交
2301 2302
| componentType | [ComponentType](#componenttype9)        | 是   | 图像的组件类型。     |
| callback      | AsyncCallback<[Component](#component9)> | 是   | 用于返回组件缓冲区。 |
Z
zhang-xiaobo1997 已提交
2303 2304 2305 2306

**示例:**

```js
X
xu-rui-w 已提交
2307 2308 2309 2310 2311 2312 2313
img.getComponent(4, (err, component) => {
    if(err) {
        console.log('getComponent failed.');
    } else {
        console.log('getComponent succeeded.');
    }
})
Z
zhang-xiaobo1997 已提交
2314 2315
```

Z
zhang-xiaobo1997 已提交
2316
### getComponent<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2317

Z
zhang-xiaobo1997 已提交
2318
getComponent(componentType: ComponentType): Promise\<Component>
Z
zhang-xiaobo1997 已提交
2319

Z
zengyawen 已提交
2320
根据图像的组件类型从图像中获取组件缓存并使用Promise方式返回结果。
Z
zhang-xiaobo1997 已提交
2321

Z
zengyawen 已提交
2322
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
2323 2324 2325

**参数:**

2326
| 参数名        | 类型                             | 必填 | 说明             |
Z
zhang-xiaobo1997 已提交
2327
| ------------- | -------------------------------- | ---- | ---------------- |
Z
zengyawen 已提交
2328
| componentType | [ComponentType](#componenttype9) | 是   | 图像的组件类型。 |
Z
zhang-xiaobo1997 已提交
2329 2330 2331 2332 2333

**返回值:**

| 类型                              | 说明                              |
| --------------------------------- | --------------------------------- |
Z
zengyawen 已提交
2334
| Promise<[Component](#component9)> | 用于返回组件缓冲区的promise实例。 |
Z
zhang-xiaobo1997 已提交
2335 2336 2337 2338 2339 2340 2341

**示例:**

```js
img.getComponent(4).then(component => { })
```

Z
zhang-xiaobo1997 已提交
2342
### release<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2343

Z
zhang-xiaobo1997 已提交
2344
release(callback: AsyncCallback\<void>): void
Z
zhang-xiaobo1997 已提交
2345

Z
zengyawen 已提交
2346 2347 2348
释放当前图像并使用callback返回结果。

在接收另一个图像前必须先释放对应资源。
Z
zhang-xiaobo1997 已提交
2349

Z
zengyawen 已提交
2350
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
2351 2352 2353

**参数:**

2354
| 参数名   | 类型                 | 必填 | 说明           |
Z
zhang-xiaobo1997 已提交
2355 2356
| -------- | -------------------- | ---- | -------------- |
| callback | AsyncCallback\<void> | 是   | 返回操作结果。 |
Z
zhang-xiaobo1997 已提交
2357 2358 2359 2360

**示例:**

```js
X
xu-rui-w 已提交
2361 2362 2363
img.release(() =>{ 
    console.log('release succeeded.');
}) 
Z
zhang-xiaobo1997 已提交
2364 2365
```

Z
zhang-xiaobo1997 已提交
2366
### release<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2367

Z
zhang-xiaobo1997 已提交
2368
release(): Promise\<void>
Z
zhang-xiaobo1997 已提交
2369

Z
zengyawen 已提交
2370 2371 2372
释放当前图像并使用Promise方式返回结果。

在接收另一个图像前必须先释放对应资源。
Z
zhang-xiaobo1997 已提交
2373

Z
zengyawen 已提交
2374
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
2375 2376 2377

**返回值:**

Z
zhang-xiaobo1997 已提交
2378 2379 2380
| 类型           | 说明                  |
| -------------- | --------------------- |
| Promise\<void> | promise返回操作结果。 |
Z
zhang-xiaobo1997 已提交
2381 2382 2383 2384 2385

**示例:**

```js
img.release().then(() =>{
X
xu-rui-w 已提交
2386 2387 2388 2389
    console.log('release succeeded.');
}).catch(error => {
    console.log('release failed.');
})
Z
zhang-xiaobo1997 已提交
2390 2391
```

Z
zengyawen 已提交
2392 2393 2394 2395
## PositionArea<sup>7+</sup>

表示图片指定区域内的数据。

X
xu-rui-w 已提交
2396
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zengyawen 已提交
2397

2398 2399 2400 2401
| 名称   | 类型               | 可读 | 可写 | 说明                                                         |
| ------ | ------------------ | ---- | ---- | ------------------------------------------------------------ |
| pixels | ArrayBuffer        | 是   | 否   | 像素。                                                       |
| offset | number             | 是   | 否   | 偏移量。                                                     |
X
xu-rui-w 已提交
2402
| stride | number             | 是   | 否   | 像素间距,stride >= region.size.width*4。                   |
X
xu-rui-w 已提交
2403
| region | [Region](#region7) | 是   | 否   | 区域,按照区域读写。写入的区域宽度加X坐标不能大于原图的宽度,写入的区域高度加Y坐标不能大于原图的高度。 |
X
xiaok 已提交
2404

Z
zengyawen 已提交
2405
## ImageInfo
X
xiaok 已提交
2406

Z
zengyawen 已提交
2407
表示图片信息。
X
xiaok 已提交
2408

X
xu-rui-w 已提交
2409
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
2410

Z
zengyawen 已提交
2411 2412 2413
| 名称 | 类型          | 可读 | 可写 | 说明       |
| ---- | ------------- | ---- | ---- | ---------- |
| size | [Size](#size) | 是   | 是   | 图片大小。 |
X
xu-rui-w 已提交
2414
| density<sup>9+</sup> | number | 是   | 是   | 像素密度,单位为ppi。 |
X
xiaok 已提交
2415

Z
zengyawen 已提交
2416
## Size
X
xiaok 已提交
2417

Z
zengyawen 已提交
2418 2419
表示图片尺寸。

X
xu-rui-w 已提交
2420
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zengyawen 已提交
2421 2422 2423 2424 2425 2426 2427

| 名称   | 类型   | 可读 | 可写 | 说明           |
| ------ | ------ | ---- | ---- | -------------- |
| height | number | 是   | 是   | 输出图片的高。 |
| width  | number | 是   | 是   | 输出图片的宽。 |

## PixelMapFormat<sup>7+</sup>
X
xiaok 已提交
2428

Z
zengyawen 已提交
2429
枚举,图片像素格式。
X
xiaok 已提交
2430

X
xu-rui-w 已提交
2431
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zengyawen 已提交
2432

2433
| 名称                   |   值   | 说明              |
X
xu-rui-w 已提交
2434 2435 2436
| ---------------------- | ------ | ----------------- |
| UNKNOWN                | 0      | 未知格式。        |
| RGB_565                | 2      | 格式为RGB_565     |
X
xu-rui-w 已提交
2437 2438 2439 2440 2441 2442 2443
| RGBA_8888              | 3      | 格式为RGBA_8888 |
| BGRA_8888<sup>9+</sup> | 4      | 格式为BGRA_8888 |
| RGB_888<sup>9+</sup>   | 5      | 格式为RGB_888   |
| ALPHA_8<sup>9+</sup>   | 6      | 格式为ALPHA_8   |
| RGBA_F16<sup>9+</sup>  | 7      | 格式为RGBA_F16  |
| NV21<sup>9+</sup>      | 8      | 格式为NV21      |
| NV12<sup>9+</sup>      | 9      | 格式为NV12      |
Z
zengyawen 已提交
2444

2445
## AlphaType<sup>9+</sup>
X
xiaok 已提交
2446

Z
zengyawen 已提交
2447
枚举,图像的透明度类型。
X
xiaok 已提交
2448

X
xu-rui-w 已提交
2449
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zengyawen 已提交
2450

2451
| 名称     |   值   | 说明                    |
Z
zengyawen 已提交
2452 2453 2454
| -------- | ------ | ----------------------- |
| UNKNOWN  | 0      | 未知透明度。            |
| OPAQUE   | 1      | 没有alpha或图片全透明。 |
X
xu-rui-w 已提交
2455 2456
| PREMUL   | 2      | RGB前乘alpha。         |
| UNPREMUL | 3      | RGB不前乘alpha。       |
X
xiaok 已提交
2457

2458
## ScaleMode<sup>9+</sup>
X
xiaok 已提交
2459

Z
zengyawen 已提交
2460
枚举,图像的缩放模式。
X
xiaok 已提交
2461

X
xu-rui-w 已提交
2462
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
2463

2464
| 名称            |   值   | 说明                                               |
Z
zengyawen 已提交
2465 2466
| --------------- | ------ | -------------------------------------------------- |
| CENTER_CROP     | 1      | 缩放图像以填充目标图像区域并居中裁剪区域外的效果。 |
X
xu-rui-w 已提交
2467
| FIT_TARGET_SIZE | 0      | 图像适合目标尺寸的效果。                           |
X
xiaok 已提交
2468

X
xu-rui-w 已提交
2469 2470 2471 2472
## SourceOptions<sup>9+</sup>

ImageSource的初始化选项。

X
xu-rui-w 已提交
2473
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xu-rui-w 已提交
2474

X
xu-rui-w 已提交
2475 2476 2477 2478 2479
| 名称              | 类型                               | 可读 | 可写 | 说明               |
| ----------------- | ---------------------------------- | ---- | ---- | ------------------ |
| sourceDensity     | number                             | 是   | 是   | ImageSource的密度。|
| sourcePixelFormat | [PixelMapFormat](#pixelmapformat7) | 是   | 是   | 图片像素格式。     |
| sourceSize        | [Size](#size)                      | 是   | 是   | 图像像素大小。     |
X
xu-rui-w 已提交
2480 2481


Z
zengyawen 已提交
2482
## InitializationOptions<sup>8+</sup>
X
xiaok 已提交
2483

Z
zengyawen 已提交
2484 2485
PixelMap的初始化选项。

X
xu-rui-w 已提交
2486
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zengyawen 已提交
2487

X
xu-rui-w 已提交
2488 2489 2490
| 名称                     | 类型                               | 可读 | 可写 | 说明           |
| ------------------------ | ---------------------------------- | ---- | ---- | -------------- |
| alphaType<sup>9+</sup>   | [AlphaType](#alphatype9)           | 是   | 是   | 透明度。       |
X
xu-rui-w 已提交
2491 2492
| editable                 | boolean                            | 是   | 是   | 是否可编辑。   |
| pixelFormat              | [PixelMapFormat](#pixelmapformat7) | 是   | 是   | 像素格式。     |
X
xu-rui-w 已提交
2493
| scaleMode<sup>9+</sup>   | [ScaleMode](#scalemode9)           | 是   | 是   | 缩略值。       |
X
xu-rui-w 已提交
2494
| size                     | [Size](#size)                      | 是   | 是   | 创建图片大小。 |
Z
zengyawen 已提交
2495 2496

## DecodingOptions<sup>7+</sup>
X
xiaok 已提交
2497

Z
zengyawen 已提交
2498
图像解码设置选项。
X
xiaok 已提交
2499

X
xu-rui-w 已提交
2500
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
Z
zengyawen 已提交
2501 2502 2503 2504

| 名称               | 类型                               | 可读 | 可写 | 说明             |
| ------------------ | ---------------------------------- | ---- | ---- | ---------------- |
| sampleSize         | number                             | 是   | 是   | 缩略图采样大小。 |
Z
zengyawen 已提交
2505
| rotate             | number                             | 是   | 是   | 旋转角度。       |
Z
zengyawen 已提交
2506 2507
| editable           | boolean                            | 是   | 是   | 是否可编辑。     |
| desiredSize        | [Size](#size)                      | 是   | 是   | 期望输出大小。   |
2508
| desiredRegion      | [Region](#region7)                 | 是   | 是   | 解码区域。       |
Z
zengyawen 已提交
2509
| desiredPixelFormat | [PixelMapFormat](#pixelmapformat7) | 是   | 是   | 解码的像素格式。 |
X
xu-rui-w 已提交
2510
| index              | number                             | 是   | 是   | 解码图片序号。   |
X
xu-rui-w 已提交
2511
| fitDensity<sup>9+</sup> | number                        | 是   | 是   | 图像像素密度,单位为ppi。   |
Z
zengyawen 已提交
2512

2513
## Region<sup>7+</sup>
Z
zengyawen 已提交
2514 2515 2516

表示区域信息。

X
xu-rui-w 已提交
2517
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zengyawen 已提交
2518

2519 2520 2521 2522 2523
| 名称 | 类型          | 可读 | 可写 | 说明         |
| ---- | ------------- | ---- | ---- | ------------ |
| size | [Size](#size) | 是   | 是   | 区域大小。   |
| x    | number        | 是   | 是   | 区域横坐标。 |
| y    | number        | 是   | 是   | 区域纵坐标。 |
Z
zengyawen 已提交
2524 2525 2526 2527 2528

## PackingOption

表示图片打包选项。

X
xu-rui-w 已提交
2529
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
Z
zengyawen 已提交
2530

X
xu-rui-w 已提交
2531 2532
| 名称    | 类型   | 可读 | 可写 | 说明                                                |
| ------- | ------ | ---- | ---- | --------------------------------------------------- |
R
renhw 已提交
2533
| format  | string | 是   | 是   | 目标格式。</br>当前只支持jpg和webp 。 |
X
xu-rui-w 已提交
2534
| quality | number | 是   | 是   | JPEG编码中设定输出图片质量的参数,取值范围为1-100。 |
X
xu-rui-w 已提交
2535
| bufferSize<sup>9+</sup> | number | 是   | 是   | 用于设置图片大小,默认为10M |
Z
zengyawen 已提交
2536 2537 2538 2539 2540

## GetImagePropertyOptions<sup>7+</sup>

表示查询图片属性的索引。

X
xu-rui-w 已提交
2541
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
Z
zengyawen 已提交
2542 2543 2544 2545 2546 2547 2548 2549 2550 2551

| 名称         | 类型   | 可读 | 可写 | 说明         |
| ------------ | ------ | ---- | ---- | ------------ |
| index        | number | 是   | 是   | 图片序号。   |
| defaultValue | string | 是   | 是   | 默认属性值。 |

## PropertyKey<sup>7+</sup>

枚举,Exif(Exchangeable image file format)图片信息。

X
xu-rui-w 已提交
2552
**系统能力:** SystemCapability.Multimedia.Image.Core
2553

2554
| 名称              |   值                    | 说明                     |
X
xu-rui-w 已提交
2555 2556 2557 2558 2559 2560 2561
| ----------------- | ----------------------- | ------------------------ |
| BITS_PER_SAMPLE   | "BitsPerSample"         | 每个像素比特数。         |
| ORIENTATION       | "Orientation"           | 图片方向。               |
| IMAGE_LENGTH      | "ImageLength"           | 图片长度。               |
| IMAGE_WIDTH       | "ImageWidth"            | 图片宽度。               |
| GPS_LATITUDE      | "GPSLatitude"           | 图片纬度。               |
| GPS_LONGITUDE     | "GPSLongitude"          | 图片经度。               |
X
xu-rui-w 已提交
2562 2563
| GPS_LATITUDE_REF  | "GPSLatitudeRef"        | 纬度引用,例如N或S。    |
| GPS_LONGITUDE_REF | "GPSLongitudeRef"       | 经度引用,例如W或E。    |
X
xu-rui-w 已提交
2564 2565
| DATE_TIME_ORIGINAL<sup>9+</sup> | "DateTimeOriginal" | 拍摄时间,例如2022:09:06 15:48:00     |
| EXPOSURE_TIME<sup>9+</sup>      | "ExposureTime"     | 曝光时间,例如1/33 sec.|
X
xu-rui-w 已提交
2566
| SCENE_TYPE<sup>9+</sup>         | "SceneType"        | 拍摄场景模式,例如人像、风光、运动、夜景等。     |
X
xu-rui-w 已提交
2567 2568
| ISO_SPEED_RATINGS<sup>9+</sup>  | "ISOSpeedRatings"  | ISO感光度,例如400     |
| F_NUMBER<sup>9+</sup>           | "FNumber"          | 光圈值,例如f/1.8     |
R
renhongwei 已提交
2569

2570

Z
zhang-xiaobo1997 已提交
2571
## ImageFormat<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2572 2573 2574

枚举,图片格式。

X
xu-rui-w 已提交
2575
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
2576

2577
| 名称         |   值   | 说明                 |
Z
zengyawen 已提交
2578 2579 2580
| ------------ | ------ | -------------------- |
| YCBCR_422_SP | 1000   | YCBCR422半平面格式。 |
| JPEG         | 2000   | JPEG编码格式。       |
Z
zhang-xiaobo1997 已提交
2581

Z
zengyawen 已提交
2582
## ComponentType<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2583 2584 2585

枚举,图像的组件类型。

X
xu-rui-w 已提交
2586
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
2587

2588
| 名称  |   值   | 说明        |
Z
zhang-xiaobo1997 已提交
2589 2590 2591 2592
| ----- | ------ | ----------- |
| YUV_Y | 1      | 亮度信息。  |
| YUV_U | 2      | 色度信息。  |
| YUV_V | 3      | 色度信息。  |
X
xu-rui-w 已提交
2593
| JPEG  | 4      | JPEG 类型。 |
Z
zhang-xiaobo1997 已提交
2594

Z
zengyawen 已提交
2595
## Component<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2596 2597 2598

描述图像颜色分量。

X
xu-rui-w 已提交
2599
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
2600 2601 2602

| 名称          | 类型                             | 可读 | 可写 | 说明         |
| ------------- | -------------------------------- | ---- | ---- | ------------ |
Z
zengyawen 已提交
2603
| componentType | [ComponentType](#componenttype9) | 是   | 否   | 组件类型。   |
Z
zhang-xiaobo1997 已提交
2604 2605 2606 2607
| rowStride     | number                           | 是   | 否   | 行距。       |
| pixelStride   | number                           | 是   | 否   | 像素间距。   |
| byteBuffer    | ArrayBuffer                      | 是   | 否   | 组件缓冲区。 |

X
xu-rui-w 已提交
2608
## ResponseCode
X
xu-rui-w 已提交
2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648

编译错误返回的响应码。

| 名称                                | 值       | 说明                                                |
| ----------------------------------- | -------- | --------------------------------------------------- |
| ERR_MEDIA_INVALID_VALUE             | -1       | 无效大小。                                          |
| SUCCESS                             | 0        | 操作成功。                                          |
| ERROR                               | 62980096 | 操作失败。                                          |
| ERR_IPC                             | 62980097 | ipc错误。                                           |
| ERR_SHAMEM_NOT_EXIST                | 62980098 | 共享内存错误。                                      |
| ERR_SHAMEM_DATA_ABNORMAL            | 62980099 | 共享内存错误。                                      |
| ERR_IMAGE_DECODE_ABNORMAL           | 62980100 | 图像解码错误。                                      |
| ERR_IMAGE_DATA_ABNORMAL             | 62980101 | 图像输入数据错误。                                  |
| ERR_IMAGE_MALLOC_ABNORMAL           | 62980102 | 图像malloc错误。                                    |
| ERR_IMAGE_DATA_UNSUPPORT            | 62980103 | 不支持图像类型。                                    |
| ERR_IMAGE_INIT_ABNORMAL             | 62980104 | 图像初始化错误。                                    |
| ERR_IMAGE_GET_DATA_ABNORMAL         | 62980105 | 图像获取数据错误。                                  |
| ERR_IMAGE_TOO_LARGE                 | 62980106 | 图像数据太大。                                      |
| ERR_IMAGE_TRANSFORM                 | 62980107 | 图像转换错误。                                      |
| ERR_IMAGE_COLOR_CONVERT             | 62980108 | 图像颜色转换错误。                                  |
| ERR_IMAGE_CROP                      | 62980109 | 裁剪错误。                                          |
| ERR_IMAGE_SOURCE_DATA               | 62980110 | 图像源数据错误。                                    |
| ERR_IMAGE_SOURCE_DATA_INCOMPLETE    | 62980111 | 图像源数据不完整。                                  |
| ERR_IMAGE_MISMATCHED_FORMAT         | 62980112 | 图像格式不匹配。                                    |
| ERR_IMAGE_UNKNOWN_FORMAT            | 62980113 | 图像未知格式。                                      |
| ERR_IMAGE_SOURCE_UNRESOLVED         | 62980114 | 图像源未解析。                                      |
| ERR_IMAGE_INVALID_PARAMETER         | 62980115 | 图像无效参数。                                      |
| ERR_IMAGE_DECODE_FAILED             | 62980116 | 解码失败。                                          |
| ERR_IMAGE_PLUGIN_REGISTER_FAILED    | 62980117 | 注册插件失败。                                      |
| ERR_IMAGE_PLUGIN_CREATE_FAILED      | 62980118 | 创建插件失败。                                      |
| ERR_IMAGE_ENCODE_FAILED             | 62980119 | 图像编码失败。                                      |
| ERR_IMAGE_ADD_PIXEL_MAP_FAILED      | 62980120 | 图像添加像素映射失败。                              |
| ERR_IMAGE_HW_DECODE_UNSUPPORT       | 62980121 | 不支持图像硬件解码。                                |
| ERR_IMAGE_DECODE_HEAD_ABNORMAL      | 62980122 | 图像解码头错误。                                    |
| ERR_IMAGE_DECODE_EXIF_UNSUPPORT     | 62980123 | 图像解码exif取消支持。                              |
| ERR_IMAGE_PROPERTY_NOT_EXIST        | 62980124 | 图像属性不存在;错误代码被媒体占用,图像从150开始。 |
| ERR_IMAGE_READ_PIXELMAP_FAILED      | 62980246 | 读取像素地图失败。                                  |
| ERR_IMAGE_WRITE_PIXELMAP_FAILED     | 62980247 | 写入像素映射失败。                                  |
| ERR_IMAGE_PIXELMAP_NOT_ALLOW_MODIFY | 62980248 | pixelmap不允许修改。                                |
| ERR_IMAGE_CONFIG_FAILED             | 62980259 | 配置错误。                                          |