1e41f4b71Sopenharmony_ci# ImageBitmap
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciAn **ImageBitmap** object stores pixel data rendered on a canvas.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci>  **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci>  The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci## APIs
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ciImageBitmap(src: string, unit?: LengthMetricsUnit)
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci**Parameters**
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description                                   |
22e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ---------------------------------------- |
23e41f4b71Sopenharmony_ci| src  | string | Yes | Image source. Local images are supported.<br>1. The string format is used to load local images, for example, **ImageBitmap("common/images/example.jpg")**. For entry and feature modules, the start point of the image path for loading is the **ets** folder of the module. For HAR and shared modules, the start point is the **ets** folder of the entry or feature module into which they are built.<br>2. Supported image formats: bmp, jpg, png, svg, and webp.<br>**NOTE**<br>- ArkTS widgets do not support the strings with the **http://**, **datashare://**, or **file://data/storage**. |
24e41f4b71Sopenharmony_ci| unit<sup>12+</sup>  | [LengthMetricsUnit](../js-apis-arkui-graphics.md#lengthmetricsunit12) | No | Unit mode of the **ImageBitmap** object. The value cannot be dynamically changed once set. The configuration method is the same as that of [CanvasRenderingContext2D](ts-canvasrenderingcontext2d.md#lengthmetricsunit12).<br>Default value: **DEFAULT** |
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci## Attributes
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci| Name    | Type | Read Only | Optional | Description |
36e41f4b71Sopenharmony_ci| ------ | ------ | ----- | -------- | --------------------------- |
37e41f4b71Sopenharmony_ci| width | number | Yes | No | Pixel width of the **ImageBitmap** object.<br>Default unit: vp |
38e41f4b71Sopenharmony_ci| height | number | Yes | No | Pixel height of the **ImageBitmap** object.<br>Default unit: vp |
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci**Example**
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci  ```ts
43e41f4b71Sopenharmony_ci  // xxx.ets
44e41f4b71Sopenharmony_ci  @Entry
45e41f4b71Sopenharmony_ci  @Component
46e41f4b71Sopenharmony_ci  struct ImageExample {
47e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
48e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
49e41f4b71Sopenharmony_ci    private img:ImageBitmap = new ImageBitmap("common/images/example.jpg")
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci    build() {
52e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
53e41f4b71Sopenharmony_ci        Canvas(this.context)
54e41f4b71Sopenharmony_ci          .width('100%')
55e41f4b71Sopenharmony_ci          .height('100%')
56e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
57e41f4b71Sopenharmony_ci          .onReady(() => {
58e41f4b71Sopenharmony_ci            this.context.drawImage(this.img, 0, 0, 500, 500, 0, 0, 400, 200)
59e41f4b71Sopenharmony_ci            this.img.close()
60e41f4b71Sopenharmony_ci          })
61e41f4b71Sopenharmony_ci      }
62e41f4b71Sopenharmony_ci      .width('100%')
63e41f4b71Sopenharmony_ci      .height('100%')
64e41f4b71Sopenharmony_ci    }
65e41f4b71Sopenharmony_ci  }
66e41f4b71Sopenharmony_ci  ```
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci  ![en-us_image_0000001194352442](figures/en-us_image_0000001194352442.png)
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci## Methods
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci### close
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ciclose(): void
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ciReleases all graphics resources associated with this **ImageBitmap** object and sets its width and height to **0**. For the sample code, see the code for creating an **ImageBitmap** object.
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
85