js-apis-image.md 51.1 KB
Newer Older
W
wusongqing 已提交
1
# Image Processing
W
wusongqing 已提交
2

W
wusongqing 已提交
3
> **NOTE**<br/>
W
wusongqing 已提交
4
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
W
wusongqing 已提交
5

W
wusongqing 已提交
6
## Modules to Import
W
wusongqing 已提交
7

W
wusongqing 已提交
8
```js
W
wusongqing 已提交
9 10 11 12
import image from '@ohos.multimedia.image';
```

## image.createPixelMap<sup>8+</sup>
W
wusongqing 已提交
13
createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<PixelMap>
W
wusongqing 已提交
14 15 16 17 18 19 20

Creates a **PixelMap** object. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

W
wusongqing 已提交
21 22 23
| Name   | Type                                            | Mandatory| Description                                                        |
| ------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ |
| colors  | ArrayBuffer                                      | Yes  | Color array.                                                  |
W
wusongqing 已提交
24
| options | [InitializationOptions](#initializationoptions8) | Yes  | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.|
W
wusongqing 已提交
25 26 27 28 29

**Return value**

| Type                            | Description          |
| -------------------------------- | -------------- |
W
wusongqing 已提交
30
| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.|
W
wusongqing 已提交
31 32 33 34 35 36 37 38 39 40 41

**Example**

```js
image.createPixelMap(Color, opts)
            .then((pixelmap) => {
            })
```

## image.createPixelMap<sup>8+</sup>

W
wusongqing 已提交
42
createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: AsyncCallback\<PixelMap>): void
W
wusongqing 已提交
43 44 45 46 47 48 49

Creates a **PixelMap** object. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

W
wusongqing 已提交
50 51 52
| Name    | Type                                            | Mandatory| Description                      |
| -------- | ------------------------------------------------ | ---- | -------------------------- |
| colors   | ArrayBuffer                                      | Yes  | Color array.                |
W
wusongqing 已提交
53
| options  | [InitializationOptions](#initializationoptions8) | Yes  | Pixel properties.                    |
W
wusongqing 已提交
54
| callback | AsyncCallback\<[PixelMap](#pixelmap7)>           | Yes  | Callback used to return the **PixelMap** object.|
W
wusongqing 已提交
55 56 57 58 59 60 61 62 63 64 65 66 67 68

**Example**

```js
image.createPixelMap(Color, opts, (pixelmap) => {
            })
```

## PixelMap<sup>7+</sup>

Provides APIs to read or write image pixel map data and obtain image pixel map information. Before calling any API in **PixelMap**, you must use **createPixelMap** to create a **PixelMap** object.

 ### Attributes

W
wusongqing 已提交
69 70 71 72 73
**System capability**: SystemCapability.Multimedia.Image

| Name                   | Type   | Readable| Writable| Description                      |
| ----------------------- | ------- | ---- | ---- | -------------------------- |
| isEditable<sup>7+</sup> | boolean | Yes  | No  | Whether the image pixel map is editable.|
W
wusongqing 已提交
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98

### readPixelsToBuffer<sup>7+</sup>

readPixelsToBuffer(dst: ArrayBuffer): Promise\<void>

Reads image pixel map data and writes the data to an **ArrayBuffer**. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

| Name| Type       | Mandatory| Description                                                        |
| ------ | ----------- | ---- | ------------------------------------------------------------ |
| dst    | ArrayBuffer | Yes  | Buffer to which the image pixel map data will be written.|

**Return value**

| Type          | Description                                           |
| :------------- | :---------------------------------------------- |
| Promise\<void> | Promise used to return the operation result. If the operation fails, an error message is returned.|

**Example**

```js
pixelmap.readPixelsToBuffer(readBuffer).then(() => {
W
wusongqing 已提交
99 100 101 102
                        // Called if the condition is met.
                }).catch(error => {
                // Called if no condition is met.
            })
W
wusongqing 已提交
103 104 105 106 107 108
```

### readPixelsToBuffer<sup>7+</sup>

readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\<void>): void

109
Reads image pixel map data and writes the data to an **ArrayBuffer**. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

| Name  | Type                | Mandatory| Description                                                        |
| -------- | -------------------- | ---- | ------------------------------------------------------------ |
| dst      | ArrayBuffer          | Yes  | Buffer to which the image pixel map data will be written.|
| callback | AsyncCallback\<void> | Yes  | Callback used to return the operation result. If the operation fails, an error message is returned.                              |

**Example**

```js
pixelmap.readPixelsToBuffer(readBuffer, () => {
            })
```

### readPixels<sup>7+</sup>

readPixels(area: PositionArea): Promise\<void>

131
Reads image pixel map data in an area. This API uses a promise to return the data read.
W
wusongqing 已提交
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

| Name| Type                          | Mandatory| Description                    |
| ------ | ------------------------------ | ---- | ------------------------ |
| area   | [PositionArea](#positionarea7) | Yes  | Area from which the image pixel map data will be read.|

**Return value**

| Type          | Description                                               |
| :------------- | :-------------------------------------------------- |
| Promise\<void> | Promise used to return the operation result. If the operation fails, an error message is returned.|

**Example**

```js
pixelmap.readPixels(area).then((data) => {
W
wusongqing 已提交
151 152 153 154
                  // Called if the condition is met.     
                }).catch(error => {
                // Called if no condition is met.
            })
W
wusongqing 已提交
155 156 157 158 159 160
```

### readPixels<sup>7+</sup>

readPixels(area: PositionArea, callback: AsyncCallback\<void>): void

161
Reads image pixel map data in an area. This API uses an asynchronous callback to return the data read.
W
wusongqing 已提交
162 163 164 165 166 167 168 169 170 171 172 173 174

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

| Name  | Type                          | Mandatory| Description                          |
| -------- | ------------------------------ | ---- | ------------------------------ |
| area     | [PositionArea](#positionarea7) | Yes  | Area from which the image pixel map data will be read.      |
| callback | AsyncCallback\<void>           | Yes  | Callback used to return the operation result. If the operation fails, an error message is returned.|

**Example**

```js
W
wusongqing 已提交
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (err, pixelmap) => {
     if(pixelmap == undefined){
          console.info('createPixelMap failed');
          expect(false).assertTrue();
          done();
      }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');
           })
      }
})
W
wusongqing 已提交
191 192 193 194 195 196 197 198 199 200 201 202 203 204
```

### writePixels<sup>7+</sup>

writePixels(area: PositionArea): Promise\<void>

Writes image pixel map data to an area. This API uses a promise to return the operation result.

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

| Name| Type                          | Mandatory| Description                |
| ------ | ------------------------------ | ---- | -------------------- |
205
| area   | [PositionArea](#positionarea7) | Yes  | Area to which the image pixel map data will be written.|
W
wusongqing 已提交
206 207 208 209 210 211 212 213 214 215

**Return value**

| Type          | Description                                               |
| :------------- | :-------------------------------------------------- |
| Promise\<void> | Promise used to return the operation result. If the operation fails, an error message is returned.|

**Example**

```js
W
wusongqing 已提交
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
const color = new ArrayBuffer(96);
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts)
    .then( pixelmap => {
        if (pixelmap == undefined) {
            console.info('createPixelMap failed');
            expect(false).assertTrue()
            done();
        }
        const area = { pixels: new ArrayBuffer(8),
            offset: 0,
            stride: 8,
            region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
        }
        var bufferArr = new Uint8Array(area.pixels);
        for (var i = 0; i < bufferArr.length; i++) {
            bufferArr[i] = i + 1;
        }

        pixelmap.writePixels(area).then(() => {
            const readArea = { pixels: new ArrayBuffer(8),
                offset: 0,
                stride: 8,
                // region.size.width + x < opts.width, region.size.height + y < opts.height
                region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
            }        
        })
    })
    .catch(error => {
        console.log('error: ' + error);
        expect().assertFail();
        done();
    })
W
wusongqing 已提交
249 250 251 252 253 254
```

### writePixels<sup>7+</sup>

writePixels(area: PositionArea, callback: AsyncCallback\<void>): void

255
Writes image pixel map data to an area. This API uses an asynchronous callback to return the operation result.
W
wusongqing 已提交
256 257 258 259 260 261 262

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

| Name   | Type                          | Mandatory| Description                          |
| --------- | ------------------------------ | ---- | ------------------------------ |
263
| area      | [PositionArea](#positionarea7) | Yes  | Area to which the image pixel map data will be written.          |
W
wusongqing 已提交
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
| callback: | AsyncCallback\<void>           | Yes  | Callback used to return the operation result. If the operation fails, an error message is returned.|

**Example**

```js
pixelmap.writePixels(area, () => {
                const readArea = {
                    pixels: new ArrayBuffer(20),
                    offset: 0,
                    stride: 8,
                    region: { size: { height: 1, width: 2 }, x: 0, y: 0 },
                }
            })
```

### writeBufferToPixels<sup>7+</sup>

writeBufferToPixels(src: ArrayBuffer): Promise\<void>

Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** object. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

| Name| Type       | Mandatory| Description          |
| ------ | ----------- | ---- | -------------- |
| src    | ArrayBuffer | Yes  | Buffer from which the image data will be read.|

**Return value**

| Type          | Description                                           |
| -------------- | ----------------------------------------------- |
| Promise\<void> | Promise used to return the operation result. If the operation fails, an error message is returned.|

**Example**

```js
pixelMap.writeBufferToPixels(colorBuffer).then(() => {
    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.");
});
```

### writeBufferToPixels<sup>7+</sup>

writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\<void>): void

313
Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** object. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

| Name  | Type                | Mandatory| Description                          |
| -------- | -------------------- | ---- | ------------------------------ |
| src      | ArrayBuffer          | Yes  | Buffer from which the image data will be read.                |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the operation result. If the operation fails, an error message is returned.|

**Example**

```js
pixelMap.writeBufferToPixels(colorBuffer, function(err) {
    if (err) {
        console.error("Failed to write data from a buffer to a PixelMap.");
        return;
    }
    console.log("Succeeded in writing data from a buffer to a PixelMap.");
});
```

### getImageInfo<sup>7+</sup>

getImageInfo(): Promise\<ImageInfo>

340
Obtains pixel map information of this image. This API uses a promise to return the information.
W
wusongqing 已提交
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363

**System capability**: SystemCapability.Multimedia.Image

**Return value**

| Type                             | Description                                                       |
| --------------------------------- | ----------------------------------------------------------- |
| Promise\<[ImageInfo](#imageinfo)> | Promise used to return the pixel map information. If the operation fails, an error message is returned.|

**Example**

```js
pixelMap.getImageInfo().then(function(info) {
    console.log("Succeeded in obtaining the image pixel map information.");
}).catch((err) => {
    console.error("Failed to obtain the image pixel map information.");
});
```

### getImageInfo<sup>7+</sup>

getImageInfo(callback: AsyncCallback\<ImageInfo>): void

364
Obtains pixel map information of this image. This API uses an asynchronous callback to return the information.
W
wusongqing 已提交
365 366 367 368 369 370 371 372 373 374 375 376

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

| Name  | Type                                   | Mandatory| Description                                                        |
| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback\<[ImageInfo](#imageinfo)> | Yes  | Callback used to return the pixel map information. If the operation fails, an error message is returned.|

**Example**

```js
W
wusongqing 已提交
377
pixelmap.getImageInfo((imageInfo) => {})
W
wusongqing 已提交
378 379 380 381 382 383
```

### getBytesNumberPerRow<sup>7+</sup>

getBytesNumberPerRow(): number

384
Obtains the number of bytes per line of the image pixel map.
W
wusongqing 已提交
385 386 387 388 389 390 391

**System capability**: SystemCapability.Multimedia.Image

**Return value**

| Type  | Description                |
| ------ | -------------------- |
392
| number | Number of bytes per line.|
W
wusongqing 已提交
393 394 395 396

**Example**

```js
W
wusongqing 已提交
397
rowCount = pixelmap.getBytesNumberPerRow()
W
wusongqing 已提交
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
```

### getPixelBytesNumber<sup>7+</sup>

getPixelBytesNumber(): number

Obtains the total number of bytes of the image pixel map.

**System capability**: SystemCapability.Multimedia.Image

**Return value**

| Type  | Description                |
| ------ | -------------------- |
| number | Total number of bytes.|

**Example**

```js
W
wusongqing 已提交
417
pixelBytesNumber = pixelmap.getPixelBytesNumber()
W
wusongqing 已提交
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
```

### release<sup>7+</sup>

release():Promise\<void>

Releases this **PixelMap** object. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Image

**Return value**

| Type          | Description              |
| -------------- | ------------------ |
| Promise\<void> | Promise used to return the operation result.|

**Example**

```js
W
wusongqing 已提交
437 438
 pixelmap.release().then(() => { })
            .catch(error => {})
W
wusongqing 已提交
439 440 441 442 443 444
```

### release<sup>7+</sup>

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

445
Releases this **PixelMap** object. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
446 447 448 449 450 451 452 453 454 455 456 457

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

| Name    | Type                | Mandatory| Description              |
| -------- | -------------------- | ---- | ------------------ |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the operation result.|

**Example**

```js
W
wusongqing 已提交
458
pixelmap.release(()=>{ })   
W
wusongqing 已提交
459 460 461 462 463 464 465 466 467 468 469 470 471 472
```

## image.createImageSource

createImageSource(uri: string): ImageSource

Creates an **ImageSource** instance based on the URI.

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

| Name| Type  | Mandatory| Description                              |
| ------ | ------ | ---- | ---------------------------------- |
W
wusongqing 已提交
473
| uri    | string | Yes  | Image path. Currently, only the application sandbox path is supported.|
W
wusongqing 已提交
474 475 476

**Return value**

W
wusongqing 已提交
477 478 479
| Type                       | Description                                        |
| --------------------------- | -------------------------------------------- |
| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.|
W
wusongqing 已提交
480 481 482 483

**Example**

```js
W
wusongqing 已提交
484 485
let path = this.context.getApplicationContext().fileDirs + "test.jpg";
const imageSourceApi = image.createImageSource(path);
W
wusongqing 已提交
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
```

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

createImageSource(fd: number): ImageSource

Creates an **ImageSource** instance based on the file descriptor.

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

| Name| Type  | Mandatory| Description          |
| ------ | ------ | ---- | -------------- |
| fd     | number | Yes  | File descriptor.|

**Return value**

W
wusongqing 已提交
504 505 506
| Type                       | Description                                        |
| --------------------------- | -------------------------------------------- |
| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.|
W
wusongqing 已提交
507 508 509 510 511 512 513 514 515 516 517 518 519

**Example**

```js
const imageSourceApi = image.createImageSource(0)
```

## ImageSource

Provides APIs to obtain image information. Before calling any API in **ImageSource**, you must use **createImageSource** to create an **ImageSource** instance.

### Attributes

W
wusongqing 已提交
520 521
**System capability**: SystemCapability.Multimedia.Image

W
wusongqing 已提交
522 523
| Name            | Type          | Readable| Writable| Description                                                        |
| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
524
| supportedFormats | Array\<string> | Yes  | No  | Supported image formats, including png, jpeg, wbmp, bmp, gif, webp, and heif.|
W
wusongqing 已提交
525 526 527 528 529

### getImageInfo

getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void

530
Obtains information about an image with the specified index. This API uses an asynchronous callback to return the information.
W
wusongqing 已提交
531 532 533 534 535 536 537 538 539 540 541 542 543

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

| Name  | Type                                  | Mandatory| Description                                    |
| -------- | -------------------------------------- | ---- | ---------------------------------------- |
| index    | number                                 | Yes  | Index of the image.                    |
| callback | AsyncCallback<[ImageInfo](#imageinfo)> | Yes  | Callback used to return the image information.|

**Example**

```js
W
wusongqing 已提交
544
imageSourceApi.getImageInfo(0,(error, imageInfo) => {})
W
wusongqing 已提交
545 546 547 548 549 550
```

### getImageInfo

getImageInfo(callback: AsyncCallback\<ImageInfo>): void

551
Obtains information about this image. This API uses an asynchronous callback to return the information.
W
wusongqing 已提交
552 553 554 555 556 557 558 559 560 561 562 563

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

| Name    | Type                                  | Mandatory| Description                                    |
| -------- | -------------------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback<[ImageInfo](#imageinfo)> | Yes  | Callback used to return the image information.|

**Example**

```js
W
wusongqing 已提交
564
imageSourceApi.getImageInfo(imageInfo => {})
W
wusongqing 已提交
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
```

### getImageInfo

getImageInfo(index?: number): Promise\<ImageInfo>

Obtains information about an image with the specified index. This API uses a promise to return the image information.

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

| Name | Type  | Mandatory| Description                                 |
| ----- | ------ | ---- | ------------------------------------- |
| index | number | No  | Index of the image. If this parameter is not set, the default value **0** is used.|

**Return value**

| Type                            | Description                  |
| -------------------------------- | ---------------------- |
| Promise<[ImageInfo](#imageinfo)> | Promise used to return the image information.|

**Example**

```js
imageSourceApi.getImageInfo(0)
W
wusongqing 已提交
591 592
            .then(imageInfo => {})
			.catch(error => {})
W
wusongqing 已提交
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
```

### getImageProperty<sup>7+</sup>

getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\<string>

Obtains the value of a property with the specified index in this image. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Image

 **Parameters**

| Name   | Type                                                | Mandatory| Description                                |
| ------- | ---------------------------------------------------- | ---- | ------------------------------------ |
| key     | string                                               | Yes  | Name of the property.                        |
| options | [GetImagePropertyOptions](#getimagepropertyoptions7) | No  | Image properties, including the image index and default property value.|

**Return value**

| Type            | Description                                                        |
| ---------------- | ------------------------------------------------------------ |
| Promise\<string> | Promise used to return the property value. If the operation fails, the default value is returned.|

**Example**

```js
W
wusongqing 已提交
619 620 621
imageSourceApi.getImageProperty("BitsPerSample")
            .then(data => {})
            .catch(error => {})
W
wusongqing 已提交
622 623 624 625 626 627
```

### getImageProperty<sup>7+</sup>

getImageProperty(key:string, callback: AsyncCallback\<string>): void

628
Obtains the value of a property with the specified index in this image. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
629 630 631 632 633 634 635 636 637 638 639 640 641

**System capability**: SystemCapability.Multimedia.Image

 **Parameters**

| Name  | Type                  | Mandatory| Description                                                        |
| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
| key      | string                 | Yes  | Name of the property.                                                |
| callback | AsyncCallback\<string> | Yes  | Callback used to return the property value. If the operation fails, the default value is returned.|

**Example**

```js
W
wusongqing 已提交
642
imageSourceApi.getImageProperty("BitsPerSample",(error,data) => {})
W
wusongqing 已提交
643 644 645 646 647 648
```

### getImageProperty<sup>7+</sup>

getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCallback\<string>): void

649
Obtains the value of a property in this image. This API uses an asynchronous callback to return the property value in a string.
W
wusongqing 已提交
650 651 652 653 654 655 656 657 658 659 660 661 662 663

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

| Name  | Type                                                | Mandatory| Description                                                        |
| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
| key      | string                                               | Yes  | Name of the property.                                                |
| options  | [GetImagePropertyOptions](#getimagepropertyoptions7) | Yes  | Image properties, including the image index and default property value.                        |
| callback | AsyncCallback\<string>                               | Yes  | Callback used to return the property value. If the operation fails, the default value is returned.|

**Example**

```js
W
wusongqing 已提交
664
imageSourceApi.getImageProperty("BitsPerSample",property,(error,data) => {})
W
wusongqing 已提交
665 666 667 668
```

### createPixelMap<sup>7+</sup>

W
wusongqing 已提交
669
createPixelMap(options?: DecodingOptions): Promise\<PixelMap>
W
wusongqing 已提交
670

671
Creates a **PixelMap** object based on image decoding parameters. This API uses a promise to return the result.
W
wusongqing 已提交
672 673 674 675 676

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

W
wusongqing 已提交
677 678 679 680 681 682 683 684 685
| Name   | Type                                | Mandatory| Description      |
| ------- | ------------------------------------ | ---- | ---------- |
| options | [DecodingOptions](#decodingoptions7) | No  | Image decoding parameters.|

**Return value**

| Type                            | Description                 |
| -------------------------------- | --------------------- |
| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.|
W
wusongqing 已提交
686 687 688 689

**Example**

```js
W
wusongqing 已提交
690 691
imageSourceApi.createPixelMap().then(pixelmap => {})
    						.catch(error => {})
W
wusongqing 已提交
692 693 694 695
```

### createPixelMap<sup>7+</sup>

W
wusongqing 已提交
696
createPixelMap(callback: AsyncCallback\<PixelMap>): void
W
wusongqing 已提交
697

698
Creates a **PixelMap** object based on the default parameters. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
699 700 701 702 703

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

W
wusongqing 已提交
704 705 706
| Name    | Type                                 | Mandatory| Description                      |
| -------- | ------------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback<[PixelMap](#pixelmap7)> | Yes  | Callback used to return the **PixelMap** object.|
W
wusongqing 已提交
707 708 709 710

**Example**

```js
W
wusongqing 已提交
711
imageSourceApi.createPixelMap(pixelmap => {})
W
wusongqing 已提交
712 713 714 715
```

### createPixelMap<sup>7+</sup>

W
wusongqing 已提交
716
createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): void
W
wusongqing 已提交
717

718
Creates a **PixelMap** object based on image decoding parameters. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
719 720 721 722 723

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

W
wusongqing 已提交
724 725 726 727
| Name    | Type                                 | Mandatory| Description                      |
| -------- | ------------------------------------- | ---- | -------------------------- |
| options  | [DecodingOptions](#decodingoptions7)  | Yes  | Image decoding parameters.                |
| callback | AsyncCallback<[PixelMap](#pixelmap7)> | Yes  | Callback used to return the **PixelMap** object.|
W
wusongqing 已提交
728 729 730 731

**Example**

```js
W
wusongqing 已提交
732
imageSourceApi.createPixelMap(decodingOptions, pixelmap => {})    
W
wusongqing 已提交
733 734 735 736 737 738
```

### release

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

739
Releases this **ImageSource** instance. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
740 741 742 743 744 745 746 747 748 749 750 751

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

| Name    | Type                | Mandatory| Description                              |
| -------- | -------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<void> | Yes  | Callback invoked for instance release. If the operation fails, an error message is returned.|

**Example**

```js
W
wusongqing 已提交
752
imageSourceApi.release(() => {})
W
wusongqing 已提交
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
```

### release

release(): Promise\<void>

Releases this **ImageSource** instance. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Image

**Return value**

| Type          | Description                       |
| -------------- | --------------------------- |
| Promise\<void> | Promise used to return the operation result.|

**Example**

```js
W
wusongqing 已提交
772
imageSourceApi.release().then(()=>{ }).catch(error => {})
W
wusongqing 已提交
773 774 775 776 777 778 779 780 781 782 783 784
```

## image.createImagePacker

createImagePacker(): ImagePacker

Creates an **ImagePacker** instance.

**System capability**: SystemCapability.Multimedia.Image

**Return value**

W
wusongqing 已提交
785 786 787
| Type                       | Description                 |
| --------------------------- | --------------------- |
| [ImagePacker](#imagepacker) | **ImagePacker** instance created.|
W
wusongqing 已提交
788 789 790 791 792 793 794 795 796 797 798 799 800

**Example**

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

## ImagePacker

Provide APIs to pack images. Before calling any API in **ImagePacker**, you must use **createImagePacker** to create an **ImagePacker** instance.

### Attributes

W
wusongqing 已提交
801 802 803 804 805
**System capability**: SystemCapability.Multimedia.Image

| Name            | Type          | Readable| Writable| Description                      |
| ---------------- | -------------- | ---- | ---- | -------------------------- |
| supportedFormats | Array\<string> | Yes  | No  | Supported image format, which can be jpeg.|
W
wusongqing 已提交
806 807 808

### packing

W
wusongqing 已提交
809
packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void
W
wusongqing 已提交
810

811
Packs an image. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
812 813 814 815 816 817 818 819 820

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

| Name  | Type                              | Mandatory| Description                              |
| -------- | ---------------------------------- | ---- | ---------------------------------- |
| source   | [ImageSource](#imagesource)        | Yes  | Image to pack.                    |
| option   | [PackingOption](#packingoption)    | Yes  | Option for image packing.                    |
W
wusongqing 已提交
821
| callback | AsyncCallback\<ArrayBuffer>        | Yes  | Callback used to return the packed data.|
W
wusongqing 已提交
822 823 824 825 826 827 828 829 830 831

**Example**

```js
let packOpts = { format:["image/jpeg"], quality:98 }
imagePackerApi.packing(imageSourceApi, packOpts, data => {})
```

### packing

W
wusongqing 已提交
832
packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer>
W
wusongqing 已提交
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848

Packs an image. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

| Name| Type                           | Mandatory| Description          |
| ------ | ------------------------------- | ---- | -------------- |
| source | [ImageSource](#imagesource)     | Yes  | Image to pack.|
| option | [PackingOption](#packingoption) | Yes  | Option for image packing.|

**Return value**

| Type                        | Description                                         |
| :--------------------------- | :-------------------------------------------- |
W
wusongqing 已提交
849
| Promise\<ArrayBuffer> | Promise used to return the packed data.|
W
wusongqing 已提交
850 851 852 853 854 855 856 857 858 859

**Example**

```js
let packOpts = { format:["image/jpeg"], quality:98 }
imagePackerApi.packing(imageSourceApi, packOpts)
    .then( data => { })
	.catch(error => {})
```

W
wusongqing 已提交
860
### packing<sup>8+</sup>
W
wusongqing 已提交
861 862

packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void
W
wusongqing 已提交
863

864
Packs an image. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
865 866 867 868 869 870 871

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

| Name  | Type                           | Mandatory| Description                              |
| -------- | ------------------------------- | ---- | ---------------------------------- |
W
wusongqing 已提交
872
| source   | [PixelMap](#pixelmap)           | Yes  | **PixelMap** object to pack.              |
W
wusongqing 已提交
873
| option   | [PackingOption](#packingoption) | Yes  | Option for image packing.                    |
W
wusongqing 已提交
874
| callback | AsyncCallback\<ArrayBuffer>     | Yes  | Callback used to return the packed data.|
W
wusongqing 已提交
875 876 877 878 879

**Example**

```js
let packOpts = { format:["image/jpeg"], quality:98 }
W
wusongqing 已提交
880
imagePackerApi.packing(pixelMapApi, packOpts, data => {})
W
wusongqing 已提交
881 882
```

W
wusongqing 已提交
883
### packing<sup>8+</sup>
W
wusongqing 已提交
884

W
wusongqing 已提交
885
packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer>
W
wusongqing 已提交
886 887 888 889 890 891 892

Packs an image. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

W
wusongqing 已提交
893 894
| Name| Type                           | Mandatory| Description              |
| ------ | ------------------------------- | ---- | ------------------ |
W
wusongqing 已提交
895
| source | [PixelMap](#pixelmap)           | Yes  | **PixelMap** object to pack.|
W
wusongqing 已提交
896
| option | [PackingOption](#packingoption) | Yes  | Option for image packing.    |
W
wusongqing 已提交
897 898 899

**Return value**

W
wusongqing 已提交
900 901
| Type                        | Description                                         |
| :--------------------------- | :-------------------------------------------- |
W
wusongqing 已提交
902
| Promise\<ArrayBuffer> | Promise used to return the packed data.|
W
wusongqing 已提交
903 904 905 906 907

**Example**

```js
let packOpts = { format:["image/jpeg"], quality:98 }
W
wusongqing 已提交
908 909 910
imagePackerApi.packing(pixelMapApi, packOpts)
    .then( data => { })
	.catch(error => {})
W
wusongqing 已提交
911 912 913 914 915 916
```

### release

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

917
Releases this **ImagePacker** instance. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
918 919 920 921 922 923 924 925 926 927 928 929

**System capability**: SystemCapability.Multimedia.Image

**Parameters**

| Name  | Type                | Mandatory| Description                          |
| -------- | -------------------- | ---- | ------------------------------ |
| callback | AsyncCallback\<void> | Yes  | Callback invoked for instance release. If the operation fails, an error message is returned.|

**Example**

```js
W
wusongqing 已提交
930
imagePackerApi.release(()=>{})
W
wusongqing 已提交
931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949
```

### release

release(): Promise\<void>

Releases this **ImagePacker** instance. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Image

**Return value**

| Type          | Description                                                   |
| :------------- | :------------------------------------------------------ |
| Promise\<void> | Promise used to return the instance release result. If the operation fails, an error message is returned.|

**Example**

```js
W
wusongqing 已提交
950 951
 imagePackerApi.release().then(()=>{
            }).catch((error)=>{}) 
W
wusongqing 已提交
952 953
```

W
wusongqing 已提交
954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292
## image.createImageReceiver<sup>9+</sup>

createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver

Create an **ImageReceiver** instance by specifying the image width, height, format, and capacity.

**System capability**: SystemCapability.Multimedia.Image.ImageReceiver

**Parameters**

| Name    | Type  | Mandatory| Description                  |
| -------- | ------ | ---- | ---------------------- |
| width    | number | Yes  | Default image width.      |
| height   | number | Yes  | Default image height.      |
| format   | number | Yes  | Image format.            |
| capacity | number | Yes  | Maximum number of images that can be accessed at the same time.|

**Return value**

| Type                            | Description                                   |
| -------------------------------- | --------------------------------------- |
| [ImageReceiver](#imagereceiver9) | Returns an **ImageReceiver** instance if the operation is successful.|

**Example**

```js
var receiver = image.createImageReceiver(8192, 8, 4, 8)
```

## ImageReceiver<sup>9+</sup>

Provides APIs to obtain the surface ID of a component, read the latest image, read the next image, and release the **ImageReceiver** instance.

Before calling any APIs in **ImageReceiver**, you must create an **ImageReceiver** instance.

### Attributes

**System capability**: SystemCapability.Multimedia.Image.ImageReceiver

| Name                 | Type                        | Readable| Writable| Description              |
| --------------------- | ---------------------------- | ---- | ---- | ------------------ |
| size<sup>9+</sup>     | [Size](#size)                | Yes  | No  | Image size.        |
| capacity<sup>9+</sup> | number                       | Yes  | No  | Maximum number of images that can be accessed at the same time.|
| format<sup>9+</sup>   | [ImageFormat](#imageformat9) | Yes  | No  | Image format.        |

### getReceivingSurfaceId<sup>9+</sup>

getReceivingSurfaceId(callback: AsyncCallback\<string>): void

Obtains a surface ID for the camera or other components. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.Image.ImageReceiver

**Parameters**

| Name    | Type                  | Mandatory| Description                      |
| -------- | ---------------------- | ---- | -------------------------- |
| callback | AsyncCallback\<string> | Yes  | Callback used to return the surface ID.|

**Example**

```js
 receiver.getReceivingSurfaceId((err, id) => {});
```

### getReceivingSurfaceId<sup>9+</sup>

getReceivingSurfaceId(): Promise\<string>

Obtains a surface ID for the camera or other components. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Image.ImageReceiver

**Return value**

| Type            | Description                |
| ---------------- | -------------------- |
| Promise\<string> | Promise used to return the surface ID.|

**Example**

```js
receiver.getReceivingSurfaceId().then( id => { 
            }).catch(error => {
            })
```

### readLatestImage<sup>9+</sup>

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

Reads the latest image from the **ImageReceiver** instance. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.Image.ImageReceiver

**Parameters**

| Name    | Type                           | Mandatory| Description                    |
| -------- | ------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<[Image](#image9)> | Yes  | Callback used to return the latest image.|

**Example**

```js
 receiver.readLatestImage((err, img) => { });
```

### readLatestImage<sup>9+</sup>

readLatestImage(): Promise\<Image>

Reads the latest image from the **ImageReceiver** instance. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Image.ImageReceiver

**Return value**

| Type                     | Description              |
| ------------------------- | ------------------ |
| Promise<[Image](#image8)> | Promise used to return the latest image.|

**Example**

```js
receiver.readLatestImage().then(img => {})
	.catch(error => {})
```

### readNextImage<sup>9+</sup>

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

Reads the next image from the **ImageReceiver** instance. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.Image.ImageReceiver

**Parameters**

| Name    | Type                           | Mandatory| Description                      |
| -------- | ------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback<[Image](#image9)> | Yes  | Callback used to return the next image.|

**Example**

```js
receiver.readNextImage((err, img) => {});
```

### readNextImage<sup>9+</sup>

readNextImage(): Promise\<Image>

Reads the next image from the **ImageReceiver** instance. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Image.ImageReceiver

**Return value**

| Type                     | Description                |
| ------------------------- | -------------------- |
| Promise<[Image](#image9)> | Promise used to return the next image.|

**Example**

```js
 receiver.readNextImage().then(img => {
            }).catch(error => {
            })
```

### on('imageArrival')<sup>9+</sup>

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

Listens for image arrival events.

**System capability**: SystemCapability.Multimedia.Image.ImageReceiver

**Parameters**

| Name    | Type                | Mandatory| Description                                                  |
| -------- | -------------------- | ---- | ------------------------------------------------------ |
| type     | string               | Yes  | Type of event to listen for. The value is fixed at **imageArrival**, which is triggered when an image is received.|
| callback | AsyncCallback\<void> | Yes  | Callback invoked for the event.                                      |

**Example**

```js
 receiver.on('imageArrival', () => {})
```

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

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

Releases this **ImageReceiver** instance. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.Image.ImageReceiver

**Parameters**

| Name    | Type                | Mandatory| Description                    |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|

**Example**

```js
 receiver.release(() => {})
```

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

release(): Promise\<void>

Releases this **ImageReceiver** instance. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Image.ImageReceiver

**Return value**

| Type          | Description              |
| -------------- | ------------------ |
| Promise\<void> | Promise used to return the result.|

**Example**

```js
 receiver.release().then(() => {})
 	.catch(error => {})
```

## Image<sup>9+</sup>

Provides APIs for basic image operations, including obtaining image information and reading and writing image data. An **Image** instance is returned when [readNextImage](#readnextimage9) and [readLatestImage](#readlatestimage9) are called.

### Attributes

**System capability**: SystemCapability.Multimedia.Image.Core

| Name                 | Type              | Readable| Writable| Description                                              |
| --------------------- | ------------------ | ---- | ---- | -------------------------------------------------- |
| clipRect<sup>9+</sup> | [Region](#region7) | Yes  | Yes  | Image area to be cropped.                                |
| size<sup>9+</sup>     | [Size](#size)      | Yes  | No  | Image size.                                        |
| format<sup>9+</sup>   | number             | Yes  | No  | Image format. For details, see [PixelMapFormat](#pixelmapformat7).|

### getComponent<sup>9+</sup>

getComponent(componentType: ComponentType, callback: AsyncCallback\<Component>): void

Obtains the component buffer from the **Image** instance based on the color component type. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.Image.Core

**Parameters**

| Name         | Type                                   | Mandatory| Description                |
| ------------- | --------------------------------------- | ---- | -------------------- |
| componentType | [ComponentType](#componenttype9)        | Yes  | Color component type of the image.    |
| callback      | AsyncCallback<[Component](#component9)> | Yes  | Callback used to return the component buffer.|

**Example**

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

### getComponent<sup>9+</sup>

getComponent(componentType: ComponentType): Promise\<Component>

Obtains the component buffer from the **Image** instance based on the color component type. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Image.Core

**Parameters**

| Name         | Type                            | Mandatory| Description            |
| ------------- | -------------------------------- | ---- | ---------------- |
| componentType | [ComponentType](#componenttype9) | Yes  | Color component type of the image.|

**Return value**

| Type                             | Description                             |
| --------------------------------- | --------------------------------- |
| Promise<[Component](#component9)> | Promise used to return the component buffer.|

**Example**

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

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

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

Releases this **Image** instance. This API uses an asynchronous callback to return the result.

The corresponding resources must be released before another image arrives.

**System capability**: SystemCapability.Multimedia.Image.Core

**Parameters**

| Name    | Type                | Mandatory| Description          |
| -------- | -------------------- | ---- | -------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|

**Example**

```js
img.release(() =>{ }) 
```

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

release(): Promise\<void>

Releases this **Image** instance. This API uses a promise to return the result.

The corresponding resources must be released before another image arrives.

**System capability**: SystemCapability.Multimedia.Image.Core

**Return value**

| Type          | Description                 |
| -------------- | --------------------- |
| Promise\<void> | Promise used to return the result.|

**Example**

```js
img.release().then(() =>{
            }).catch(error => {
            })  
```

W
wusongqing 已提交
1293 1294 1295 1296 1297 1298
## PositionArea<sup>7+</sup>

Describes area information in an image.

**System capability**: SystemCapability.Multimedia.Image

W
wusongqing 已提交
1299 1300 1301 1302
| Name  | Type              | Readable| Writable| Description                                                        |
| ------ | ------------------ | ---- | ---- | ------------------------------------------------------------ |
| pixels | ArrayBuffer        | Yes  | No  | Pixels of the image.                                                      |
| offset | number             | Yes  | No  | Offset for data reading.                                                    |
W
wusongqing 已提交
1303 1304
| stride | number             | Yes  | No  | Number of bytes from one row of pixels in memory to the next row of pixels in memory. The value of **stride** must be greater than or equal to the value of **region.size.width** multiplied by 4.                   |
| region | [Region](#region7) | Yes  | No  | Region to read or write. The width of the region to write plus the X coordinate cannot be greater than the width of the original image. The height of the region to write plus the Y coordinate cannot be greater than the height of the original image.|
W
wusongqing 已提交
1305

W
wusongqing 已提交
1306
## ImageInfo
W
wusongqing 已提交
1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328

Describes image information.

**System capability**: SystemCapability.Multimedia.Image

| Name| Type         | Readable| Writable| Description      |
| ---- | ------------- | ---- | ---- | ---------- |
| size | [Size](#size) | Yes  | Yes  | Image size.|

## Size

Describes the size of an image.

**System capability**: SystemCapability.Multimedia.Image

| Name  | Type  | Readable| Writable| Description          |
| ------ | ------ | ---- | ---- | -------------- |
| height | number | Yes  | Yes  | Image height.|
| width  | number | Yes  | Yes  | Image width.|

## PixelMapFormat<sup>7+</sup>

W
wusongqing 已提交
1329
Enumerates the pixel formats of images.
W
wusongqing 已提交
1330 1331 1332 1333 1334 1335 1336 1337 1338

**System capability**: SystemCapability.Multimedia.Image

| Name     | Default Value| Description             |
| --------- | ------ | ----------------- |
| UNKNOWN   | 0      | Unknown format.       |
| RGBA_8888 | 3      | RGBA_8888.|
| RGB_565   | 2      | RGB_565.  |

W
wusongqing 已提交
1339
## AlphaType<sup>9+</sup>
W
wusongqing 已提交
1340

W
wusongqing 已提交
1341
Enumerates the alpha types of images.
W
wusongqing 已提交
1342 1343 1344 1345 1346 1347

**System capability**: SystemCapability.Multimedia.Image

| Name    | Default Value| Description                   |
| -------- | ------ | ----------------------- |
| UNKNOWN  | 0      | Unknown alpha type.           |
1348
| OPAQUE   | 1      | There is no alpha or the image is opaque.|
W
wusongqing 已提交
1349 1350 1351
| PREMUL   | 2      | Premultiplied alpha.         |
| UNPREMUL | 3      | Unpremultiplied alpha, that is, straight alpha.       |

W
wusongqing 已提交
1352
## ScaleMode<sup>9+</sup>
W
wusongqing 已提交
1353

W
wusongqing 已提交
1354
Enumerates the scale modes of images.
W
wusongqing 已提交
1355 1356 1357 1358 1359 1360 1361 1362 1363 1364

**System capability**: SystemCapability.Multimedia.Image

| Name           | Default Value| Description                                              |
| --------------- | ------ | -------------------------------------------------- |
| CENTER_CROP     | 1      | Scales the image so that it fills the requested bounds of the target and crops the extra.|
| FIT_TARGET_SIZE | 2      | Reduces the image size to the dimensions of the target.                          |

## InitializationOptions<sup>8+</sup>

W
wusongqing 已提交
1365 1366
Defines pixel map initialization options.

W
wusongqing 已提交
1367 1368
**System capability**: SystemCapability.Multimedia.Image

W
wusongqing 已提交
1369 1370 1371 1372 1373 1374 1375
| Name                  | Type                              | Readable| Writable| Description          |
| ---------------------- | ---------------------------------- | ---- | ---- | -------------- |
| alphaType<sup>9+</sup> | [AlphaType](#alphatype9)           | Yes  | Yes  | Alpha type.      |
| editable               | boolean                            | Yes  | Yes  | Whether the image is editable.  |
| pixelFormat            | [PixelMapFormat](#pixelmapformat7) | Yes  | Yes  | Pixel map format.    |
| scaleMode<sup>9+</sup> | [ScaleMode](#scalemode9)           | Yes  | Yes  | Scale mode.      |
| size                   | [Size](#size)                      | Yes  | Yes  | Image size.|
W
wusongqing 已提交
1376 1377 1378

## DecodingOptions<sup>7+</sup>

W
wusongqing 已提交
1379
Defines image decoding options.
W
wusongqing 已提交
1380 1381 1382 1383 1384 1385

**System capability**: SystemCapability.Multimedia.Image

| Name              | Type                              | Readable| Writable| Description            |
| ------------------ | ---------------------------------- | ---- | ---- | ---------------- |
| sampleSize         | number                             | Yes  | Yes  | Thumbnail sampling size.|
W
wusongqing 已提交
1386
| rotate             | number                             | Yes  | Yes  | Rotation angle.      |
W
wusongqing 已提交
1387 1388
| editable           | boolean                            | Yes  | Yes  | Whether the image is editable.    |
| desiredSize        | [Size](#size)                      | Yes  | Yes  | Expected output size.  |
W
wusongqing 已提交
1389
| desiredRegion      | [Region](#region7)                 | Yes  | Yes  | Region to decode.      |
W
wusongqing 已提交
1390
| desiredPixelFormat | [PixelMapFormat](#pixelmapformat7) | Yes  | Yes  | Pixel map format for decoding.|
N
Neil Chen 已提交
1391
| index              | number                              | Yes  | Yes  | Index of the image to decode.    |
W
wusongqing 已提交
1392

W
wusongqing 已提交
1393
## Region<sup>7+</sup>
W
wusongqing 已提交
1394 1395 1396 1397 1398

Describes region information.

**System capability**: SystemCapability.Multimedia.Image

W
wusongqing 已提交
1399 1400 1401
| Name| Type         | Readable| Writable| Description        |
| ---- | ------------- | ---- | ---- | ------------ |
| size | [Size](#size) | Yes  | Yes  | Region size.  |
W
wusongqing 已提交
1402 1403 1404 1405 1406
| x    | number        | Yes  | Yes  | X coordinate of the region.|
| y    | number        | Yes  | Yes  | Y coordinate of the region.|

## PackingOption

W
wusongqing 已提交
1407
Defines the option for image packing.
W
wusongqing 已提交
1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430

**System capability**: SystemCapability.Multimedia.Image

| Name   | Type  | Readable| Writable| Description          |
| ------- | ------ | ---- | ---- | -------------- |
| format  | string | Yes  | Yes  | Format of the packed image.    |
| quality | number | Yes  | Yes  | Quality of the packed image.|

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

Describes image properties.

**System capability**: SystemCapability.Multimedia.Image

| Name        | Type  | Readable| Writable| Description        |
| ------------ | ------ | ---- | ---- | ------------ |
| index        | number | Yes  | Yes  | Index of an image.  |
| defaultValue | string | Yes  | Yes  | Default property value.|

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

Describes the exchangeable image file format (Exif) information of an image.

W
wusongqing 已提交
1431 1432
**System capability**: SystemCapability.Multimedia.Image

W
wusongqing 已提交
1433 1434
| Name             | Default Value           | Description                |
| ----------------- | ----------------- | -------------------- |
1435
| BITS_PER_SAMPLE   | "BitsPerSample"   | Number of bits per pixel.    |
W
wusongqing 已提交
1436 1437 1438 1439 1440 1441 1442
| ORIENTATION       | "Orientation"     | Image orientation.          |
| IMAGE_LENGTH      | "ImageLength"     | Image length.          |
| IMAGE_WIDTH       | "ImageWidth"      | Image width.          |
| GPS_LATITUDE      | "GPSLatitude"     | Image latitude.          |
| GPS_LONGITUDE     | "GPSLongitude"    | Image longitude.          |
| GPS_LATITUDE_REF  | "GPSLatitudeRef"  | Latitude reference, for example, N or S.|
| GPS_LONGITUDE_REF | "GPSLongitudeRef" | Longitude reference, for example, W or E.|
W
wusongqing 已提交
1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479

## ImageFormat<sup>9+</sup>

Enumerates the image formats.

**System capability**: SystemCapability.Multimedia.Image.Core

| Name        | Default Value| Description                |
| ------------ | ------ | -------------------- |
| YCBCR_422_SP | 1000   | YCBCR422 semi-planar format.|
| JPEG         | 2000   | JPEG encoding format.      |

## ComponentType<sup>9+</sup>

Enumerates the color component types of images.

**System capability**: SystemCapability.Multimedia.Image.ImageReceiver

| Name | Default Value| Description       |
| ----- | ------ | ----------- |
| YUV_Y | 1      | Luminance component. |
| YUV_U | 2      | Chrominance component. |
| YUV_V | 3      | Chrominance component. |
| JPEG  | 4      | JPEG type.|

## Component<sup>9+</sup>

Describes the color components of an image.

**System capability**: SystemCapability.Multimedia.Image.Core

| Name         | Type                            | Readable| Writable| Description        |
| ------------- | -------------------------------- | ---- | ---- | ------------ |
| componentType | [ComponentType](#componenttype9) | Yes  | No  | Color component type.  |
| rowStride     | number                           | Yes  | No  | Row stride.      |
| pixelStride   | number                           | Yes  | No  | Pixel stride.  |
| byteBuffer    | ArrayBuffer                      | Yes  | No  | Component buffer.|