1e41f4b71Sopenharmony_ci# image
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ciThe **\<image>** component is used to render and display images.
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci> **NOTE**
7e41f4b71Sopenharmony_ci>
8e41f4b71Sopenharmony_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.
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## Child Components
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ciNot supported
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## Attributes
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ciIn addition to the [universal attributes](js-service-widget-common-attributes.md), the following attributes are supported.
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci| Name| Type| Default Value| Mandatory| Description|
20e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
21e41f4b71Sopenharmony_ci| src | string | - | No| Image path.<br>- The local path is supported. Supported formats are as follows: PNG, JPG, BMP, SVG, and GIF.<br>- The path to the in-memory image is also supported in the scheme format of **memory://**.<br>**NOTE**<br>To display an online image, download it and then access it with its in-memory path. Do not use URLs.|
22e41f4b71Sopenharmony_ci| alt | string | - | No| Placeholder image displayed during image loading.|
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci## Styles
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ciIn addition to the [universal styles](js-service-widget-common-styles.md), the following styles are supported.
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci| Name| Type| Default Value| Mandatory| Description|
30e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
31e41f4b71Sopenharmony_ci| object-fit | string | cover | No| Image scale type. For details about available values, see **object-fit**. This style is not supported for SVG images.|
32e41f4b71Sopenharmony_ci| match-text-direction | boolean | false | No| Whether image orientation changes with the text direction. This style is not supported for SVG images.|
33e41f4b71Sopenharmony_ci| fit-original-size | boolean | false | No| Whether the **\<image>** component adapts to the image source size when its width and height are not set. If this style is set to **true**, **object-fit** will not take effect. This style is not supported for SVG images.|
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci**Table 1** object-fit
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci| Type| Description|
38e41f4b71Sopenharmony_ci| -------- | -------- |
39e41f4b71Sopenharmony_ci| cover | The image is scaled with its aspect ratio retained for both sides to be greater than or equal to the display boundaries and displayed in the middle.|
40e41f4b71Sopenharmony_ci| contain | The image is scaled with the aspect ratio retained for the image to be completely displayed within the display boundaries and displayed in the middle.|
41e41f4b71Sopenharmony_ci| fill | The image is scaled to fill the display area, and its aspect ratio is not retained.|
42e41f4b71Sopenharmony_ci| none | The image is displayed in the middle with its aspect ratio and size retained.|
43e41f4b71Sopenharmony_ci| scale-down | The image is displayed in the middle with its aspect ratio retained, in the size equal to or smaller than the original size.|
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci>  **NOTE**
46e41f4b71Sopenharmony_ci>
47e41f4b71Sopenharmony_ci>  When using an SVG image, note that:
48e41f4b71Sopenharmony_ci>
49e41f4b71Sopenharmony_ci>  - The SVG image will not be drawn if the length or width of the parent component is infinity. Therefore, you are advised to set the length and width for the **\<image>** component.
50e41f4b71Sopenharmony_ci>
51e41f4b71Sopenharmony_ci>  - If the image length and width are not specified in the SVG description, the SVG image fills the **\<image>** component area.
52e41f4b71Sopenharmony_ci>
53e41f4b71Sopenharmony_ci>  - If the image length and width are specified in the SVG description, the following rules are adopted to decide the final display effect:
54e41f4b71Sopenharmony_ci>
55e41f4b71Sopenharmony_ci>    - If the **\<image>** component is too small to afford the SVG image, the SVG image is cropped and only its upper left part is displayed in the component.
56e41f4b71Sopenharmony_ci>
57e41f4b71Sopenharmony_ci>    - If the **\<image>** component is big enough to afford the SVG image, the SVG image is displayed in the upper left corner of the component.
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci## Events
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci| Name| Parameter| Description|
63e41f4b71Sopenharmony_ci| -------- | -------- | -------- |
64e41f4b71Sopenharmony_ci| click | - | Triggered when the component is clicked.|
65e41f4b71Sopenharmony_ci| complete | - | Triggered when the image is successfully loaded.|
66e41f4b71Sopenharmony_ci| error | - | Triggered when an exception occurs during image loading.|
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci## Example
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci```html
73e41f4b71Sopenharmony_ci<!-- xxx.hml -->
74e41f4b71Sopenharmony_ci<stack class="content">
75e41f4b71Sopenharmony_ci    <image src="/common/bg3.jpg" class="img"></image>
76e41f4b71Sopenharmony_ci</stack>
77e41f4b71Sopenharmony_ci```
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci```css
81e41f4b71Sopenharmony_ci/* xxx.css */
82e41f4b71Sopenharmony_ci.img{  
83e41f4b71Sopenharmony_ci  object-fit: contain
84e41f4b71Sopenharmony_ci}
85e41f4b71Sopenharmony_ci```
86e41f4b71Sopenharmony_ci**4 x 4 widget**
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci![image.jpg](figures/image.jpg)
89