js-apis-image.md 91.6 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 83 84 85

图像像素类,用于读取或写入图像数据以及获取图像信息。在调用PixelMap的方法前,需要先通过createPixelMap创建一个PixelMap实例。

 ### 属性

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
Z
zhang-xiaobo1997 已提交
950 951
let path = this.context.getApplicationContext().fileDirs + "test.jpg";
const imageSourceApi = image.createImageSource(path);
X
xiaok 已提交
952 953
```

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

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

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

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

**参数:**

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

**返回值:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**返回值:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**返回值:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**返回值:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**返回值:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**返回值:**

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

**示例:**

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

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

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

### 属性

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

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

### getImageInfo

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

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

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

**参数:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**返回值:**

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

**示例:**

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

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

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

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

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

 **参数:**

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

**返回值:**

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

**示例:**

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

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

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

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

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

 **参数:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**返回值:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**返回值:**

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

**示例:**

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


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

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

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

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

**参数:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**返回值:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**示例:**

```js
F
fengzewu 已提交
1502 1503 1504 1505 1506 1507 1508 1509 1510
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 已提交
1511
imageSourceApi.createPixelMap(decodingOptions, pixelmap => { 
X
xu-rui-w 已提交
1512 1513
    console.log('Succeeded in creating pixelmap object.');
})
X
xiaok 已提交
1514 1515
```

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

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

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

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

**参数:**

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

**示例:**

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

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

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

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

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

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

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

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

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

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

createImagePacker(): ImagePacker

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

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

**返回值:**

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

**示例:**

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

Z
zengyawen 已提交
1582 1583
## ImagePacker

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

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

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

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

### packing

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

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

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

**参数:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**返回值:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**示例:**

```js
X
xu-rui-w 已提交
1671
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
F
fengzewu 已提交
1672 1673 1674 1675
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 }
冯泽悟 已提交
1676
    imagePackerApi.packing(pixelmap, packOpts, data => { 
F
fengzewu 已提交
1677 1678
        console.log('Succeeded in packing the image.');
    })
X
xu-rui-w 已提交
1679
})
1680 1681
```

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

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

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

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

**参数:**

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

**返回值:**

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

**示例:**

```js
X
xu-rui-w 已提交
1706
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
F
fengzewu 已提交
1707 1708 1709 1710
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 }
冯泽悟 已提交
1711
    imagePackerApi.packing(pixelmap, packOpts)
F
fengzewu 已提交
1712
        .then( data => {
F
fengzewu 已提交
1713 1714 1715 1716
            console.log('Succeeded in packing the image.');
        }).catch(error => {
            console.log('Failed to pack the image..');
        })
F
fengzewu 已提交
1717
})
X
xiaok 已提交
1718 1719
```

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

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

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

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

**参数:**

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

**示例:**

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

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

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

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

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

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

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

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

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

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

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

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

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

**参数:**

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

**返回值:**

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

**示例:**

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

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

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

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

### 属性

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

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

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

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

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

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

**参数:**

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

**示例:**

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

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

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

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

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

**返回值:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**示例:**

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

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

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

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

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

**返回值:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**示例:**

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

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

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

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

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

**返回值:**

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

**示例:**

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

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

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

接收图片时注册回调。

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

**参数:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**示例:**

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

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

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

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

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

**返回值:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**返回值:**

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

**示例:**

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

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

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

### 属性

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

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

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

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

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

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

**参数:**

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

**示例:**

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

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

dequeueImage(): Promise\<Image>

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

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

**返回值:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**示例:**

```js
2136 2137
creator.dequeueImage().then(img => {
    //绘制图片
2138 2139 2140 2141 2142 2143 2144 2145 2146
    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
        }
    })
2147 2148 2149 2150 2151 2152
    creator.queueImage(img, (err) => {
        if (err) {
            console.info('queueImage failed: ' + err);
        }
        console.info('queueImage succeeded');
    })
2153 2154
})

R
renhongwei 已提交
2155 2156
```

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

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

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

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

**参数:**

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

**返回值:**

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

**示例:**

```js
2180 2181
creator.dequeueImage().then(img => {
    //绘制图片
2182 2183 2184 2185 2186 2187 2188 2189 2190
    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
        }
    })
2191 2192 2193 2194 2195
    creator.queueImage(img).then(() => {
        console.info('queueImage succeeded.');
    }).catch(error => {
        console.info('queueImage failed: ' + error);
    })
X
xu-rui-w 已提交
2196
})
2197

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

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

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

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

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

**参数:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**示例:**

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

release(): Promise\<void>

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

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

**返回值:**

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

**示例:**

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

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

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

### 属性

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

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

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

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

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

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

**参数:**

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

**示例:**

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

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

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

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

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

**参数:**

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

**返回值:**

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

**示例:**

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

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

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

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

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

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

**参数:**

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

**示例:**

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

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

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

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

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

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

**返回值:**

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

**示例:**

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2432
| 名称                   |   值   | 说明              |
X
xu-rui-w 已提交
2433 2434 2435
| ---------------------- | ------ | ----------------- |
| UNKNOWN                | 0      | 未知格式。        |
| RGB_565                | 2      | 格式为RGB_565     |
X
xu-rui-w 已提交
2436 2437 2438 2439 2440 2441 2442
| 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 已提交
2443

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

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

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

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

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

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

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

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

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

ImageSource的初始化选项。

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

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


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

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

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

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

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

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

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

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

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

表示区域信息。

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

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

## PackingOption

表示图片打包选项。

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

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

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

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

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

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

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

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

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

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

2569

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

枚举,图片格式。

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

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

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

枚举,图像的组件类型。

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

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

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

描述图像颜色分量。

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

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

X
xu-rui-w 已提交
2607
## ResponseCode
X
xu-rui-w 已提交
2608 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

编译错误返回的响应码。

| 名称                                | 值       | 说明                                                |
| ----------------------------------- | -------- | --------------------------------------------------- |
| 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 | 配置错误。                                          |