• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Image
2
3The **Image** component is usually used to display images in applications. It supports images in PNG, JPG, JPEG, BMP, SVG, WEBP, GIF, or HEIF format from the following data sources: [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7), [ResourceStr](ts-types.md#resourcestr), or [DrawableDescriptor](#drawabledescriptor10).
4
5> **NOTE**
6>
7> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
8>
9> To use shortcut keys to copy the **Image** component, the component must be [in focus](../../../ui/arkts-common-events-focus-event.md#setting-whether-a-component-is-focusable). By default, the **Image** component is not focusable. To enable it to gain focus, set both the [focusable](ts-universal-attributes-focus.md#focusable) and [focusOnTouch](ts-universal-attributes-focus.md#focusontouch9) attributes to **true**.
10>
11> The **Image** component supports SVG image sources. For details about SVG tags, see [SVG Tags](./ts-basic-svg.md).
12>
13> For animated images, animation playback is disabled by default and depends on the visibility of the **Image** component. When the component is visible, the animation is started through the callback. When the component is invisible, the animation is stopped. The visibility status of the **Image** component can be identified through the [onVisibleAreaChange](./ts-universal-component-visible-area-change-event.md#onvisibleareachange) event. If the value of **ratios** is greater than 0, the component is visible.
14
15## Required Permissions
16
17The **ohos.permission.INTERNET** permission is required for using online images. For details about how to apply for a permission, see [Declaring Permissions](../../../security/AccessToken/declare-permissions.md).
18
19
20## Child Components
21
22Not supported
23
24
25## APIs
26
27### Image
28
29Image(src: PixelMap | ResourceStr | DrawableDescriptor)
30
31Obtains an image from the specified source for subsequent rendering and display.
32
33If the **Image** component fails to obtain the image or the obtained image size is 0, the **Image** component is automatically resized to 0 and does not follow the layout constraints of its parent component.
34
35By default, the **Image** component crops images to keep their center. For example, if the component has the same width and height, it crops any image whose width and height are different, so as to keep its center.
36
37If the **Image** component does not have its width and height set, its size adapts to that of its parent component once the image is successfully loaded.
38
39**Widget capability**: This API can be used in ArkTS widgets since API version 9.
40
41**Atomic service API**: This API can be used in atomic services since API version 11.
42
43**System capability**: SystemCapability.ArkUI.ArkUI.Full
44
45**Parameters**
46
47| Name | Type                                    | Mandatory  | Description                                    |
48| ---- | ---------------------------------------- | ---- | ---------------------------------------- |
49| src  | [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7) \| [ResourceStr](ts-types.md#resourcestr)\| [DrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#drawabledescriptor) | Yes   | Data source of the image. Local and online sources are supported. For details about how to reference an image, see [Loading Image Resources](../../../ui/arkts-graphics-display.md#loading-image-resources).<br>1. **PixelMap**: an array of pixels storing graphical information. This type is usually used in image editing scenarios.<br>2. **ResourceStr**: a string or a **Resource** object.<br>The string format can be used to load local images and, more frequently, online images. When using an image referenced using a relative path, for example, **Image("common/test.jpg")**, the **Image** component cannot be called across bundles or modules. If an image needs to be used globally, you are advised to use the **Resource** format. The following types of strings are supported:<br>- Base64 strings in the format of data:image/[png\|jpeg\|bmp\|webp\|heif];base64,[base64 data], where *[base64 data]* is a Base64 string.<br>- Strings with the **file://** prefix, that is, [application sandbox URIs](../../apis-core-file-kit/js-apis-file-fileuri.md#constructor10): **file://\<bundleName>/\<sandboxPath>**, When accessing a path that contains special characters, use [fileUri.getUriFromPath(path)](../../apis-core-file-kit/js-apis-file-fileuri.md#fileurigeturifrompath) to transform the path into a URI that can handle special symbols. In addition, ensure that the application has the read permission to the files in the specified path.<br>The **Resource** format allows for access across bundles and modules. It is recommended for accessing local images.<br>3. **DrawableDescriptor**: an object created when the passed resource ID or name belongs to a common image. If the [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12) type is passed in, the PixelMap array animation can be played.<br>**NOTE**<br>- ArkTS widgets support GIF animations, but the animations only play once on display.<br>- ArkTS widgets do not support the strings with the **http:/\/** or **file:/\/** prefix.<br>- ArkTS widgets do not support the [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7) type.<br>- When a local image is being loaded, any modification or replacement of it may cause application crash. Therefore, to overwrite an image file, delete the file first and then create one with the same name.<br>- Online images must support the RFC 9113 standard to be successfully loaded.<br>- If images to download are greater than 10 MB or in large number, consider using [HTTP](../../../network/http-request.md) to preload them to improve the image loading performance and facilitate data management on the application side.<br> - Directly passing a URL to the **Image** component can lead to potential performance issues, such as: (1) Large images cannot be preloaded, resulting in longer display times for white blocks; (2) Small images set to load synchronously can block the UI thread in weak network environments, causing screen freezing issues; (3) In fast-scrolling water flow layouts, images that are about to be displayed could not be preloaded, leading to more white blocks during scrolling. Performance issues manifest differently in different scenarios. To address these issues, decouple the network downloading part from the display of the **Image** component, which allows for preloading or asynchronous downloading.<br>- To display an SVG image that does not have the native size, you must set the width and height for the **Image** component.<br>- If an SVG image references another local image through the Image tag, the referenced image cannot be in .svg or .gif format.<br>- When the **src** attribute changes from a valid value to an invalid one, the image remains unchanged.<br>- If this parameter is of the [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7) type, the **Image** component can detect data changes only when the reference to the **PixelMap** object is updated to point to a new instance. If modifications are made to the content of the **PixelMap** object, such as pixel values, but the reference to the object remains the same, the **Image** component will not recognize these modifications as a data change.|
50
51### Image<sup>12+</sup>
52
53Image(src: PixelMap | ResourceStr | DrawableDescriptor | ImageContent)
54
55Obtains an image. The [ImageContent](#imagecontent12) type allows you to specify the image content.
56
57**Widget capability**: This API can be used in ArkTS widgets since API version 12.
58
59**Atomic service API**: This API can be used in atomic services since API version 12.
60
61**System capability**: SystemCapability.ArkUI.ArkUI.Full
62
63**Parameters**
64
65| Name | Type                                    | Mandatory  | Description                                    |
66| ---- | ---------------------------------------- | ---- | ---------------------------------------- |
67| src  | [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7) \| [ResourceStr](ts-types.md#resourcestr)\| [DrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#drawabledescriptor)\| [ImageContent](#imagecontent12) | Yes   | Data source of the image. Local and online sources are supported. For details about how to reference an image, see [Loading Image Resources](../../../ui/arkts-graphics-display.md#loading-image-resources).<br>1. **PixelMap**: an array of pixels storing graphical information. This type is usually used in image editing scenarios.<br>2. **ResourceStr**: a string or a **Resource** object.<br>The string format can be used to load local images and, more frequently, online images. When using an image referenced using a relative path, for example, **Image("common/test.jpg")**, the **Image** component cannot be called across bundles or modules. If an image needs to be used globally, you are advised to use the **Resource** format. The following types of strings are supported:<br>- Base64 strings in the format of data:image/[png\|jpeg\|bmp\|webp\|heif];base64,[base64 data], where *[base64 data]* is a Base64 string.<br>- Strings with the **file://** prefix, that is, [application sandbox URIs](../../apis-core-file-kit/js-apis-file-fileuri.md#constructor10): **file://\<bundleName>/\<sandboxPath>**, When accessing a path that contains special characters, use [fileUri.getUriFromPath(path)](../../apis-core-file-kit/js-apis-file-fileuri.md#fileurigeturifrompath) to transform the path into a URI that can handle special symbols. In addition, ensure that the application has the read permission to the files in the specified path.<br>The **Resource** format allows for access across bundles and modules. It is recommended for accessing local images.<br>3. **DrawableDescriptor**: an object created when the passed resource ID or name belongs to a common image. If the [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12) type is passed in, the PixelMap array animation can be played.<br>4. [ImageContent](#imagecontent12): image content.<br>**NOTE**<br>- ArkTS widgets support GIF animations, but the animations only play once on display.<br>- ArkTS widgets do not support the strings with the **http:/\/** or **file:/\/** prefix.<br>- ArkTS widgets do not support the [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7) type.<br>- When a local image is being loaded, any modification or replacement of it may cause application crash. Therefore, to overwrite an image file, delete the file first and then create one with the same name.<br>- Online images must support the RFC 9113 standard to be successfully loaded.<br>- If images to download are greater than 10 MB or in large number, consider using [HTTP](../../../network/http-request.md) to preload them to improve the image loading performance and facilitate data management on the application side.<br> - Directly passing a URL to the **Image** component can lead to potential performance issues, such as: (1) Large images cannot be preloaded, resulting in longer display times for white blocks; (2) Small images set to load synchronously can block the UI thread in weak network environments, causing screen freezing issues; (3) In fast-scrolling water flow layouts, images that are about to be displayed could not be preloaded, leading to more white blocks during scrolling. Performance issues manifest differently in different scenarios. To address these issues, decouple the network downloading part from the display of the **Image** component, which allows for preloading or asynchronous downloading.<br>- To display an SVG image that does not have the native size, you must set the width and height for the **Image** component.<br>- If an SVG image references another local image through the Image tag, the referenced image cannot be in .svg or .gif format.<br>- When the **src** attribute changes from a valid value to an invalid one, the image remains unchanged.<br>- If this parameter is of the [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7) type, the **Image** component can detect data changes only when the reference to the **PixelMap** object is updated to point to a new instance. If modifications are made to the content of the **PixelMap** object, such as pixel values, but the reference to the object remains the same, the **Image** component will not recognize these modifications as a data change.|
68
69### Image<sup>12+</sup>
70
71Image(src: PixelMap | ResourceStr | DrawableDescriptor, imageAIOptions: ImageAIOptions)
72
73Obtains an image. The [imageAIOptions](ts-image-common.md#imageaioptions) parameter allows you to set AI image analysis options.
74
75**Atomic service API**: This API can be used in atomic services since API version 12.
76
77**System capability**: SystemCapability.ArkUI.ArkUI.Full
78
79**Parameters**
80
81| Name | Type                                    | Mandatory  | Description                                    |
82| ---- | ---------------------------------------- | ---- | ---------------------------------------- |
83| src  | [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7) \| [ResourceStr](ts-types.md#resourcestr)\| [DrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#drawabledescriptor) | Yes   | Data source of the image. Local and online sources are supported. For details about how to reference an image, see [Loading Image Resources](../../../ui/arkts-graphics-display.md#loading-image-resources).<br>1. **PixelMap**: an array of pixels storing graphical information. This type is usually used in image editing scenarios.<br>2. **ResourceStr**: a string or a **Resource** object.<br>The string format can be used to load local images and, more frequently, online images. When using an image referenced using a relative path, for example, **Image("common/test.jpg")**, the **Image** component cannot be called across bundles or modules. If an image needs to be used globally, you are advised to use the **Resource** format. The following types of strings are supported:<br>- Base64 strings in the format of data:image/[png\|jpeg\|bmp\|webp\|heif];base64,[base64 data], where *[base64 data]* is a Base64 string.<br>- Strings with the **file://** prefix, that is, [application sandbox URIs](../../apis-core-file-kit/js-apis-file-fileuri.md#constructor10): **file://\<bundleName>/\<sandboxPath>**, When accessing a path that contains special characters, use [fileUri.getUriFromPath(path)](../../apis-core-file-kit/js-apis-file-fileuri.md#fileurigeturifrompath) to transform the path into a URI that can handle special symbols. In addition, ensure that the application has the read permission to the files in the specified path.<br>The **Resource** format allows for access across bundles and modules. It is recommended for accessing local images.<br>3. **DrawableDescriptor**: an object created when the passed resource ID or name belongs to a common image. If the [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12) type is passed in, the PixelMap array animation can be played.<br>**NOTE**<br>- ArkTS widgets support GIF animations, but the animations only play once on display.<br>- ArkTS widgets do not support the strings with the **http:/\/** or **file:/\/** prefix.<br>- ArkTS widgets do not support the [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7) type.<br>- When a local image is being loaded, any modification or replacement of it may cause application crash. Therefore, to overwrite an image file, delete the file first and then create one with the same name.<br>- Online images must support the RFC 9113 standard to be successfully loaded.<br>- If images to download are greater than 10 MB or in large number, consider using [HTTP](../../../network/http-request.md) to preload them to improve the image loading performance and facilitate data management on the application side.<br> - Directly passing a URL to the **Image** component can lead to potential performance issues, such as: (1) Large images cannot be preloaded, resulting in longer display times for white blocks; (2) Small images set to load synchronously can block the UI thread in weak network environments, causing screen freezing issues; (3) In fast-scrolling water flow layouts, images that are about to be displayed could not be preloaded, leading to more white blocks during scrolling. Performance issues manifest differently in different scenarios. To address these issues, decouple the network downloading part from the display of the **Image** component, which allows for preloading or asynchronous downloading.<br>- To display an SVG image that does not have the native size, you must set the width and height for the **Image** component.<br>- If an SVG image references another local image through the Image tag, the referenced image cannot be in .svg or .gif format.<br>- When the **src** attribute changes from a valid value to an invalid one, the image remains unchanged.<br>- If this parameter is of the [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7) type, the **Image** component can detect data changes only when the reference to the **PixelMap** object is updated to point to a new instance. If modifications are made to the content of the **PixelMap** object, such as pixel values, but the reference to the object remains the same, the **Image** component will not recognize these modifications as a data change.|
84| imageAIOptions  | [ImageAIOptions](ts-image-common.md#imageaioptions) | Yes  | AI image analysis options. You can configure the analysis type or bind an analyzer controller through this parameter.|
85
86## Attributes
87
88For details about how to use the attributes, see [Setting Attributes](../../../ui/arkts-graphics-display.md#setting-attributes). In addition to the [universal attributes](ts-component-general-attributes.md), the following attributes are supported.
89
90> **NOTE**
91>
92> The **Image** component does not support the universal attribute [foregroundColor](./ts-universal-attributes-foreground-color.md#foregroundcolor). Instead, you can set the fill color using the component's [fillColor](#fillcolor) attribute.
93
94### alt
95
96alt(value: string | Resource  | PixelMap)
97
98Sets the placeholder image displayed during loading.
99
100This attribute does not take effect when the parameter type of the component is [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12).
101
102**Widget capability**: This API can be used in ArkTS widgets since API version 9.
103
104**Atomic service API**: This API can be used in atomic services since API version 11.
105
106**System capability**: SystemCapability.ArkUI.ArkUI.Full
107
108**Parameters**
109
110| Name| Type                                                    | Mandatory| Description                                                        |
111| ------ | -------------------------------------------------------- | ---- | ------------------------------------------------------------ |
112| value  | string \| [Resource](ts-types.md#resource) \| [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7)<sup>12+</sup> | Yes  | Placeholder image displayed during loading. Local images (in PNG, JPG, BMP, SVG, GIF, or HEIF format) and [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7) objects are supported, but online images are not.<br>Default value: **null**|
113
114### objectFit
115
116objectFit(value: ImageFit)
117
118Sets how the image is resized to fit its container.
119
120**Widget capability**: This API can be used in ArkTS widgets since API version 9.
121
122**Atomic service API**: This API can be used in atomic services since API version 11.
123
124**System capability**: SystemCapability.ArkUI.ArkUI.Full
125
126**Parameters**
127
128| Name| Type                                     | Mandatory| Description                                       |
129| ------ | ----------------------------------------- | ---- | ------------------------------------------- |
130| value  | [ImageFit](ts-appendix-enums.md#imagefit) | Yes  | How the image is resized to fit its container.<br>Default value: **ImageFit.Cover**|
131
132### imageMatrix<sup>15+</sup>
133
134imageMatrix(matrix: ImageMatrix)
135
136Sets the transformation matrix for the image, which covers parameters for translation, rotation, and scaling to achieve the optimal display of grid thumbnails. This attribute is not applicable to SVG images.
137
138This attribute does not take effect when the **resizable** or **objectRepeat** attributes are set.
139
140This attribute only processes the image source and does not trigger any callback events of the **Image** component.
141
142**Atomic service API**: This API can be used in atomic services since API version 15.
143
144**System capability**: SystemCapability.ArkUI.ArkUI.Full
145
146**Parameters**
147
148| Name| Type                                                | Mandatory| Description          |
149| ------ | --------------------------------------------------- | ---- | -------------- |
150| matrix  | ImageMatrix | Yes  | Transformation matrix of the image.|
151
152### objectRepeat
153
154objectRepeat(value: ImageRepeat)
155
156Sets how the image is repeated. When set to repeat, the image is repeated from the center to edges, and the last image will be clipped if it does not fit in the component. This attribute is not applicable to SVG images.
157
158This attribute does not take effect when the parameter type of the component is [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12).
159
160**Widget capability**: This API can be used in ArkTS widgets since API version 9.
161
162**Atomic service API**: This API can be used in atomic services since API version 11.
163
164**System capability**: SystemCapability.ArkUI.ArkUI.Full
165
166**Parameters**
167
168| Name| Type                                           | Mandatory| Description                                             |
169| ------ | ----------------------------------------------- | ---- | ------------------------------------------------- |
170| value  | [ImageRepeat](ts-appendix-enums.md#imagerepeat) | Yes  | How the image is repeated.<br>Default value: **ImageRepeat.NoRepeat**|
171
172### interpolation
173
174interpolation(value: ImageInterpolation)
175
176Sets the interpolation effect of the image, which can alleviate aliasing that occurs when the image is zoomed. This attribute is not applicable to SVG images.
177
178This attribute does not take effect when the parameter type of the component is [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12).
179
180**Widget capability**: This API can be used in ArkTS widgets since API version 9.
181
182**Atomic service API**: This API can be used in atomic services since API version 11.
183
184**System capability**: SystemCapability.ArkUI.ArkUI.Full
185
186**Parameters**
187
188| Name| Type                                     | Mandatory| Description                                               |
189| ------ | ----------------------------------------- | ---- | --------------------------------------------------- |
190| value  | [ImageInterpolation](#imageinterpolation) | Yes  | Interpolation effect of the image.<br>Default value: **ImageInterpolation.Low**|
191
192### renderMode
193
194renderMode(value: ImageRenderMode)
195
196Sets the rendering mode of the image. This attribute is not applicable to SVG images.
197
198When [ColorFilter](#colorfilter9) is set, this attribute is not effective.
199
200This attribute does not take effect when the parameter type of the component is [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12).
201
202**Widget capability**: This API can be used in ArkTS widgets since API version 9.
203
204**Atomic service API**: This API can be used in atomic services since API version 11.
205
206**System capability**: SystemCapability.ArkUI.ArkUI.Full
207
208**Parameters**
209
210| Name| Type                               | Mandatory| Description                                                        |
211| ------ | ----------------------------------- | ---- | ------------------------------------------------------------ |
212| value  | [ImageRenderMode](#imagerendermode) | Yes  | Rendering mode of the image, which can be **Original** or **Template** (monochrome).<br>Default value: **ImageRenderMode.Original**|
213
214### sourceSize
215
216sourceSize(value: { width: number; height: number })
217
218Sets the decoding size of the image. This attribute works only when the target size is smaller than the source size. This attribute is not applicable to SVG images or **PixelMap** objects.
219
220This attribute does not take effect when the parameter type of the component is [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12).
221
222**Widget capability**: This API can be used in ArkTS widgets since API version 9.
223
224**Atomic service API**: This API can be used in atomic services since API version 11.
225
226**System capability**: SystemCapability.ArkUI.ArkUI.Full
227
228**Parameters**
229
230| Name| Type                                                   | Mandatory| Description                                                        |
231| ------ | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
232| value  | {<br/>width: number,<br/>height: number<br/>} | Yes  | Decoding size of the image. This parameter can be used to reduce the image resolution when the image display size needs to be smaller than the component size. When used together with **ImageFit.None**, it can display a small image in the component.<br>Unit: vp|
233
234
235### matchTextDirection
236
237matchTextDirection(value: boolean)
238
239Specifies whether to display the image in the system language direction. When **value** is set to **true**, the image is horizontally flipped in the right-to-left (RTL) language context.
240
241This attribute does not take effect when the parameter type of the component is [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12).
242
243**Widget capability**: This API can be used in ArkTS widgets since API version 9.
244
245**Atomic service API**: This API can be used in atomic services since API version 11.
246
247**System capability**: SystemCapability.ArkUI.ArkUI.Full
248
249**Parameters**
250
251| Name| Type   | Mandatory| Description                                        |
252| ------ | ------- | ---- | -------------------------------------------- |
253| value  | boolean | Yes  | Whether to display the image in the system language direction.<br>Default value: **false**|
254
255### fitOriginalSize
256
257fitOriginalSize(value: boolean)
258
259Specifies whether to fit the component to the size of the image source when the component size is not set.
260
261This attribute does not take effect when the parameter type of the component is [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12).
262
263**Widget capability**: This API can be used in ArkTS widgets since API version 9.
264
265**Atomic service API**: This API can be used in atomic services since API version 11.
266
267**System capability**: SystemCapability.ArkUI.ArkUI.Full
268
269**Parameters**
270
271| Name| Type   | Mandatory| Description                                            |
272| ------ | ------- | ---- | ------------------------------------------------ |
273| value  | boolean | Yes  | Whether to fit the image to the size of the image source.<br>Default value: **false**<br>**NOTE**<br>If **fitOriginalSize** is set to **false** or is not set, the component does not fit the image to the size of the image source.<br> If **fitOriginalSize** is set to true, the component fits the image to the size of the image source.|
274
275### fillColor
276
277fillColor(value: ResourceColor)
278
279Sets the fill color to be superimposed on the image. This attribute applies only to SVG images. Once set, the fill color will replace the fill colors of all drawable elements within the SVG image. To set the fill color for a PNG image, use [colorFilter](#colorfilter9).
280
281This attribute does not take effect when the parameter type of the component is [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12).
282
283**Widget capability**: This API can be used in ArkTS widgets since API version 9.
284
285**Atomic service API**: This API can be used in atomic services since API version 11.
286
287**System capability**: SystemCapability.ArkUI.ArkUI.Full
288
289**Parameters**
290
291| Name| Type                                      | Mandatory| Description          |
292| ------ | ------------------------------------------ | ---- | -------------- |
293| value  | [ResourceColor](ts-types.md#resourcecolor) | Yes  | Fill color to be superimposed on the image.<br>**NOTE**<br> By default, no fill color is applied. If an invalid value is passed, the system uses the default theme color: black in light mode and white in dark mode.|
294
295### fillColor<sup>15+</sup>
296
297fillColor(color: ResourceColor|ColorContent)
298
299Sets the fill color to be superimposed on the image. This attribute applies only to SVG images. Once set, the fill color will replace the fill colors of all drawable elements within the SVG image. To set the fill color for a PNG image, use [colorFilter](#colorfilter9). To reset the fill color, pass a value of the [ColorContent](#colorcontent15) type.
300
301This attribute does not take effect when the parameter type of the component is [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12).
302
303**Atomic service API**: This API can be used in atomic services since API version 15.
304
305**System capability**: SystemCapability.ArkUI.ArkUI.Full
306
307**Parameters**
308
309| Name| Type                                      | Mandatory| Description          |
310| ------ | ------------------------------------------ | ---- | -------------- |
311| color  | [ResourceColor](ts-types.md#resourcecolor)\|[ColorContent](#colorcontent15) | Yes  | Fill color to be superimposed on the image.<br>**NOTE**<br> By default, no fill color is applied. If an invalid value is passed, the system uses the default theme color: black in light mode and white in dark mode.|
312
313### autoResize
314
315autoResize(value: boolean)
316
317Specifies whether to resize the image source based on the size of the display area during image decoding. As downsampling images results in some loss of information, it may reduce the image quality, causing issues such as aliasing. To retain the original image quality, set **autoResize** to **false**, but this may increase the memory usage.
318
319If the original image size does not match the display size, the image may be distorted or blurred. Recommended configuration for the optimal definition:
320
321When the image is scaled down: .autoResize(false) + .interpolation(.Medium)
322
323When the image is scaled up: .interpolation(.High)
324
325This attribute does not take effect when the parameter type of the component is [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12) or SVG.
326
327**Widget capability**: This API can be used in ArkTS widgets since API version 9.
328
329**Atomic service API**: This API can be used in atomic services since API version 11.
330
331**System capability**: SystemCapability.ArkUI.ArkUI.Full
332
333**Parameters**
334
335| Name| Type   | Mandatory| Description                                                        |
336| ------ | ------- | ---- | ------------------------------------------------------------ |
337| value  | boolean | Yes  | Whether to resize the image source based on the size of the display area during image decoding. This resizing can help reduce the memory usage. For example, if the size of the original image is 1920 x 1080 and the size of the display area is 200 x 200, you can set this attribute to **true** so that the image is downsampled to 200 x 200.<br>Default value: **false**|
338
339### syncLoad<sup>8+</sup>
340
341syncLoad(value: boolean)
342
343Specifies whether to load the image synchronously. When loading a small image, you are advised to set **syncLoad** to **true** so that the image loading can be quickly completed on the main thread.
344
345This attribute does not take effect when the parameter type of the component is [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12).
346
347**Widget capability**: This API can be used in ArkTS widgets since API version 9.
348
349**Atomic service API**: This API can be used in atomic services since API version 11.
350
351**System capability**: SystemCapability.ArkUI.ArkUI.Full
352
353**Parameters**
354
355| Name| Type   | Mandatory| Description                                                        |
356| ------ | ------- | ---- | ------------------------------------------------------------ |
357| value  | boolean | Yes  | Whether to load the image synchronously. By default, the image is loaded asynchronously. During synchronous loading, the UI thread is blocked and the placeholder image is not displayed.<br>Default value: **false**|
358
359### copyOption<sup>9+</sup>
360
361copyOption(value: CopyOptions)
362
363Whether the image can be copied. When **copyOption** is set to a value other than **CopyOptions.None**, the image can be copied in various manners, such as long pressing, right-clicking, or pressing Ctrl+C. SVG images cannot be copied.
364
365This attribute does not take effect when the parameter type of the component is [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12).
366
367**Widget capability**: This API can be used in ArkTS widgets since API version 9.
368
369**Atomic service API**: This API can be used in atomic services since API version 11.
370
371**System capability**: SystemCapability.ArkUI.ArkUI.Full
372
373**Parameters**
374
375| Name| Type                                            | Mandatory| Description                                         |
376| ------ | ------------------------------------------------ | ---- | --------------------------------------------- |
377| value  | [CopyOptions](ts-appendix-enums.md#copyoptions9) | Yes  | Specifies whether the image can be copied.<br>Default value: **CopyOptions.None**|
378
379### colorFilter<sup>9+</sup>
380
381colorFilter(value: ColorFilter | DrawingColorFilter)
382
383Sets the color filter for the image.
384
385When this attribute is set, [renderMode](#rendermode) is not effective.
386
387**Widget capability**: This API can be used in ArkTS widgets since API version 9.
388
389**Atomic service API**: This API can be used in atomic services since API version 11.
390
391**System capability**: SystemCapability.ArkUI.ArkUI.Full
392
393**Parameters**
394
395| Name| Type                                   | Mandatory| Description                                                        |
396| ------ | --------------------------------------- | ---- | ------------------------------------------------------------ |
397| value  | [ColorFilter](ts-types.md#colorfilter9) \| [DrawingColorFilter](#drawingcolorfilter12) | Yes  | 1. Color filter of the image. The input parameter is a 4 x 5 RGBA transformation matrix.<br>The first row of the matrix represents a vector value of R (red), the second row represents a vector value of G (green), the third row represents a vector value of B (blue), and the fourth row represents a vector value of A (alpha). The four rows represent different RGBA vector values.<br>If the matrix contains entries of 1 on the diagonal and entries of 0 in other places, the original color of the image is retained.<br> **Calculation rule:**<br>If the input filter matrix is as follows:<br>![image-matrix-1](figures/image-matrix-1.jpg)<br>Wherein the color is [R, G, B, A].<br>Then the color after filtering is [R', G', B', A'].<br>![image-matrix-2](figures/image-matrix-2.jpg)<br>2. The ColorFilter type of **@ohos.graphics.drawing** can be used as the input parameter since API Version 12.<br>**NOTE**<br>This parameter is not available for SVG images in API version 11 and earlier versions.<br>The DrawingColorfilter type can be used in atomic services since API version 12. The SVG image to set as the source must have the **stroke** attribute.|
398
399### draggable<sup>9+</sup>
400
401draggable(value: boolean)
402
403Specifies whether the image is draggable. This attribute cannot be used together with the [onDragStart](ts-universal-events-drag-drop.md#ondragstart) event.
404
405**Atomic service API**: This API can be used in atomic services since API version 11.
406
407**System capability**: SystemCapability.ArkUI.ArkUI.Full
408
409**Parameters**
410
411| Name| Type   | Mandatory| Description                                                        |
412| ------ | ------- | ---- | ------------------------------------------------------------ |
413| value  | boolean | Yes  | Whether the image is draggable. The value **true** means that the image is draggable, in which case the bound long press gesture will not take effect.<br>Default value:<br>API version 9 and earlier: **false**<br> Since API version 10: **true**<br> To bind custom gestures to the component, set **draggable** to **false**.|
414
415### enableAnalyzer<sup>11+</sup>
416
417enableAnalyzer(enable: boolean)
418
419Sets whether to enable the AI analyzer, which supports subject recognition, text recognition, and object lookup.<!--RP3--><!--RP3End-->
420
421This attribute cannot be used together with the [overlay](ts-universal-attributes-overlay.md) attribute. If they are set at the same time, the **CustomBuilder** attribute in **overlay** has no effect. This attribute depends on device capabilities.
422
423Images to be analyzed must be static, non-vector images. That is, SVG and GIF images cannot be analyzed. [Pixel maps](../../apis-image-kit/js-apis-image.md#pixelmap7) in [RGBA_8888](../../apis-image-kit/js-apis-image.md#pixelmapformat7) format can be passed in for analysis. For details, see [Example 4](#example-4-enabling-the-ai-analyzer).
424
425The placeholder images (specified by **alt**) cannot be analyzed. An image can be analyzed only when **objectRepeat** is set to **ImageRepeat.NoRepeat** and [obscured](ts-universal-attributes-obscured.md) is disabled.
426
427Analysis is performed based on the complete original image. If the **clip**, **margin**, **borderRadius**, **position**, or **objectFit** attribute is set, the image is not displayed completely. If **renderMode** is used to apply a mask, analysis is still performed based on the complete original image. The **copyOption** attribute does not affect the AI analyzer.
428
429This attribute does not take effect when the parameter type of the component is [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12).
430
431> **NOTE**
432>
433> The ohos.permission.INTERNET permission must be declared.
434
435**Atomic service API**: This API can be used in atomic services since API version 12.
436
437**System capability**: SystemCapability.ArkUI.ArkUI.Full
438
439**Parameters**
440
441| Name| Type   | Mandatory| Description                                                        |
442| ------ | ------- | ---- | ------------------------------------------------------------ |
443| enable  | boolean | Yes  | Whether to enable the AI analyzer. The value **true** means to enable the AI analyzer.<br>Default value: **false**|
444
445### resizable<sup>11+</sup>
446
447resizable(value: ResizableOptions)
448
449Sets the resizable image options. Resizing is effective for drag previews and placeholder images.
450
451When [ResizableOptions](#resizableoptions11) is set to a valid value, the **objectRepeat** attribute does not take effect.
452
453When the sum of the values of **top** and **bottom** is greater than the source image height, or the sum of the values of **left** and **right** is greater than the source image width, the [ResizableOptions](#resizableoptions11) attribute does not take effect.
454
455This attribute does not take effect when the parameter type of the component is [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12) or SVG.
456
457**Atomic service API**: This API can be used in atomic services since API version 12.
458
459**System capability**: SystemCapability.ArkUI.ArkUI.Full
460
461**Parameters**
462
463| Name| Type                                   | Mandatory| Description                            |
464| ------ | --------------------------------------- | ---- | -------------------------------- |
465| value  | [ResizableOptions](#resizableoptions11) | Yes  | Resizable image options.|
466
467### privacySensitive<sup>12+</sup>
468
469privacySensitive(supported: boolean)
470
471Sets whether to secure sensitive information on widgets.
472
473**Widget capability**: This API can be used in ArkTS widgets since API version 12.
474
475**Atomic service API**: This API can be used in atomic services since API version 12.
476
477**System capability**: SystemCapability.ArkUI.ArkUI.Full
478
479**Parameters**
480
481| Name   | Type   | Mandatory| Description                    |
482| --------- | ------- | ---- | ------------------------ |
483| supported | boolean | Yes  | Whether to secure sensitive information on widgets.<br>Default value: **false**.<br>If this parameter is set to **true**, the image is obscured with a translucent background.<br>**NOTE**<br>If this parameter is set to **null**, the image is not obscured.<br>Obscuring requires [widget framework support](./ts-universal-attributes-obscured.md).|
484
485### dynamicRangeMode<sup>12+</sup>
486
487dynamicRangeMode(value: DynamicRangeMode)
488
489Sets the dynamic range of the image to be displayed. This attribute is not applicable to SVG images.
490
491<!--RP1--><!--RP1End-->
492
493**Atomic service API**: This API can be used in atomic services since API version 12.
494
495**System capability**: SystemCapability.ArkUI.ArkUI.Full
496
497**Parameters**
498
499| Name| Type                                   | Mandatory| Description                            |
500| ------ | --------------------------------------- | ---- | -------------------------------- |
501| value  | [DynamicRangeMode](#dynamicrangemode12) | Yes  | Dynamic range of the image.<br>Default value: **dynamicRangeMode.Standard**|
502
503### orientation<sup>14+</sup>
504
505orientation(orientation: ImageRotateOrientation)
506
507Sets the display orientation of the image content.
508
509**Atomic service API**: This API can be used in atomic services since API version 14.
510
511**System capability**: SystemCapability.ArkUI.ArkUI.Full
512
513**Parameters**
514
515| Name| Type                                   | Mandatory| Description                            |
516| ------ | --------------------------------------- | ---- | -------------------------------- |
517| orientation  | [ImageRotateOrientation](#imagerotateorientation14) | Yes  | Display orientation of the image content.<br>Default value: **ImageRotateOrientation.UP**|
518
519## ImageContent<sup>12+</sup>
520
521Defines the image content.
522
523**Widget capability**: This API can be used in ArkTS widgets since API version 12.
524
525**Atomic service API**: This API can be used in atomic services since API version 12.
526
527**System capability**: SystemCapability.ArkUI.ArkUI.Full
528
529| Name    | Description                   |
530| ------ | -------------------------- |
531| EMPTY   | Empty image.                  |
532
533## ImageInterpolation
534
535**Widget capability**: This API can be used in ArkTS widgets since API version 9.
536
537**Atomic service API**: This API can be used in atomic services since API version 11.
538
539**System capability**: SystemCapability.ArkUI.ArkUI.Full
540
541| Name    | Description                      |
542| ------ | -------------------------- |
543| None   | Nearest neighbor interpolation.                  |
544| High   | Cubic interpolation. This mode produces scaled images of the highest possible quality, but may require more image rendering time.|
545| Medium | MipMap interpolation.                    |
546| Low    | Bilinear interpolation.                    |
547
548## ImageRenderMode
549
550**Widget capability**: This API can be used in ArkTS widgets since API version 9.
551
552**Atomic service API**: This API can be used in atomic services since API version 11.
553
554**System capability**: SystemCapability.ArkUI.ArkUI.Full
555
556| Name    | Description          |
557| -------- | -------------- |
558| Original | Render image pixels as they are in the original source image.|
559| Template | Render image pixels to create a monochrome template image.|
560
561## ResizableOptions<sup>11+</sup>
562
563Defines the resizable image options.
564
565**Atomic service API**: This API can be used in atomic services since API version 12.
566
567**System capability**: SystemCapability.ArkUI.ArkUI.Full
568
569| Name| Type| Mandatory| Description|
570| --------- |-----------|-----------|-----------|
571| slice | [EdgeWidths](#edgewidths) |  No | Edge widths in different directions of a component.<br>**NOTE**<br>This parameter takes effect only when values of **bottom** and **right** are both greater than 0.<br> When a number is passed, the default unit is vp.|
572| lattice<sup>12+</sup> | [DrawingLattice](#drawinglattice12) |  No | Lattice object, which is used to divide the image by lattice.<br>**NOTE**<br> A lattice object can be created through the **createImageLattice** API of the **@ohos.graphics.drawing** module. The lattices on both even columns and even rows are fixed.<br>This parameter does not take effect for the [backgroundImageResizable](ts-universal-attributes-background.md#backgroundimageresizable12) API.<br> When a number is passed, the default unit is px.|
573
574## EdgeWidths
575
576**Atomic service API**: This API can be used in atomic services since API version 11.
577
578**System capability**: SystemCapability.ArkUI.ArkUI.Full
579
580| Name| Type| Mandatory| Description|
581| --------- |-----------|-----------|-----------|
582|  top    |  [Length](ts-types.md#length)  |  No | Width of the top edge.<br>Default value: **0**<br>Unit: vp|
583|  right  |  [Length](ts-types.md#length)  |  No | Width of the right edge.<br>Default value: **0**<br>Unit: vp|
584|  bottom |  [Length](ts-types.md#length)  |  No | Width of the bottom edge.<br>Default value: **0**<br>Unit: vp|
585|  left   |  [Length](ts-types.md#length)  |  No | Width of the left edge.<br>Default value: **0**<br>Unit: vp|
586
587![edgewidths](figures/edgewidths.png)
588
589## DynamicRangeMode<sup>12+</sup>
590
591Describes the dynamic range of the image to be displayed.
592
593**Atomic service API**: This API can be used in atomic services since API version 12.
594
595**System capability**: SystemCapability.ArkUI.ArkUI.Full
596
597| Name    | Value   | Description                   |
598| ------ | -------------------------- | -------------------------- |
599| HIGH   | 0  | Unrestricted dynamic range, which allows for the maximum brightening of an image.             |
600| CONSTRAINT | 1 | Restricted dynamic range, which brightens an image within certain constraints.         |
601| STANDARD | 2 | Standard dynamic range, which does not brighten an image.        |
602
603## ImageRotateOrientation<sup>14+</sup>
604
605Describes the desired display orientation for image content.
606
607**Atomic service API**: This API can be used in atomic services since API version 14.
608
609**System capability**: SystemCapability.ArkUI.ArkUI.Full
610
611| Name    | Value   | Description                   |
612| ------ | -------------------------- | -------------------------- |
613| AUTO   | 0  | Use the EXIF metadata of the image to determine the display orientation.             |
614| UP | 1 | Display the image in its original orientation without any EXIF processing. Default value.         |
615| RIGHT | 2 | Rotate the image 90 degrees clockwise before displaying it.        |
616| DOWN | 3| Rotate the image 180 degrees before displaying it.        |
617| LEFT | 4 | Rotate the image 90 degrees counterclockwise before displaying it.        |
618
619## DrawableDescriptor<sup>10+<sup>
620
621type DrawableDescriptor = DrawableDescriptor
622
623Represents a parameter object for the **Image** component.
624
625**Atomic service API**: This API can be used in atomic services since API version 11.
626
627**System capability**: SystemCapability.ArkUI.ArkUI.Full
628
629| Type    | Description      |
630| ------ | ---------- |
631| [DrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#drawabledescriptor)  | **DrawableDescriptor** object.|
632
633## DrawingColorFilter<sup>12+<sup>
634
635type DrawingColorFilter = ColorFilter
636
637Represents a color filter object.
638
639**Atomic service API**: This API can be used in atomic services since API version 12.
640
641**System capability**: SystemCapability.ArkUI.ArkUI.Full
642
643| Type    | Description      |
644| ------ | ---------- |
645| [ColorFilter](../../apis-arkgraphics2d/js-apis-graphics-drawing.md#colorfilter)  | Color filter created.|
646
647## DrawingLattice<sup>12+<sup>
648
649type DrawingLattice = Lattice
650
651Represents a matrix grid object that divides an image into a rectangular grid.
652
653**Atomic service API**: This API can be used in atomic services since API version 12.
654
655**System capability**: SystemCapability.ArkUI.ArkUI.Full
656
657| Type    | Description      |
658| ------ | ---------- |
659| [Lattice](../../apis-arkgraphics2d/js-apis-graphics-drawing.md#lattice12) | Matrix grid object used to divide the image into a rectangular grid.|
660
661## ImageMatrix<sup>15+<sup>
662
663type ImageMatrix = Matrix4Transit
664
665Represents the current matrix object.
666
667**Atomic service API**: This API can be used in atomic services since API version 15.
668
669**System capability**: SystemCapability.ArkUI.ArkUI.Full
670
671| Type    | Description      |
672| ------ | ---------- |
673| [Matrix4Transit](../js-apis-matrix4.md#matrix4transit) | Current matrix object.|
674
675## ColorContent<sup>15+</sup>
676
677Defines the content for color filling.
678
679**Atomic service API**: This API can be used in atomic services since API version 15.
680
681**System capability**: SystemCapability.ArkUI.ArkUI.Full
682
683| Name| Type      | Read-Only| Mandatory| Description          |
684| ------ | --------- | ---- | --- | ------------- |
685| ORIGIN  | ColorContent | Yes| No| Resets the [fillColor](#fillcolor) API, effectively the same as not setting [fillColor](#fillcolor).|
686
687## Events
688
689In addition to the [universal events](ts-component-general-events.md), the following events are supported.
690
691### onComplete
692
693onComplete(callback: (event?: { width: number, height: number, componentWidth: number, componentHeight: number, loadingStatus: number,contentWidth: number, contentHeight: number, contentOffsetX: number, contentOffsetY: number }) =&gt; void)
694
695Triggered when an image is successfully loaded or decoded. The size of the loaded image is returned.
696
697This event is not triggered if the parameter type of the component is [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12).
698
699**Widget capability**: This API can be used in ArkTS widgets since API version 9.
700
701**Atomic service API**: This API can be used in atomic services since API version 11.
702
703**System capability**: SystemCapability.ArkUI.ArkUI.Full
704
705**Parameters**
706
707| Name                      | Type  | Mandatory| Description                                                        |
708| ---------------------------- | ------ | ---- | ------------------------------------------------------------ |
709| width                        | number | Yes  | Width of the image.<br>Unit: pixel                                   |
710| height                       | number | Yes  | Height of the image.<br>Unit: pixel                                   |
711| componentWidth               | number | Yes  | Width of the component.<br>Unit: pixel                                   |
712| componentHeight              | number | Yes  | Height of the component.<br>Unit: pixel                                   |
713| loadingStatus                | number | Yes  | Loading status of the image.<br>**NOTE**<br>If the return value is **0**, the image is successfully loaded. If the return value is **1**, the image is successfully decoded.|
714| contentWidth<sup>10+</sup>   | number | Yes  | Actual rendered width of the image.<br>Unit: pixel<br>**NOTE**<br>This parameter is valid only when the return value of **loadingStatus** is **1**.|
715| contentHeight<sup>10+</sup>  | number | Yes  | Actual rendered height of the image.<br>Unit: pixel<br>**NOTE**<br>This parameter is valid only when the return value of **loadingStatus** is **1**.|
716| contentOffsetX<sup>10+</sup> | number | Yes  | Offset of the rendered content relative to the component on the x-axis.<br>Unit: pixel<br>**NOTE**<br>This parameter is valid only when the return value of **loadingStatus** is **1**.|
717| contentOffsetY<sup>10+</sup> | number | Yes  | Offset of the rendered content relative to the component on the y-axis<br>Unit: pixel<br>**NOTE**<br>This parameter is valid only when the return value of **loadingStatus** is **1**.|
718
719### onError<sup>9+</sup>
720
721onError(callback: ImageErrorCallback)
722
723Triggered when an error occurs during image loading.
724
725This event is not triggered if the parameter type of the component is [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12).
726
727**Widget capability**: This API can be used in ArkTS widgets since API version 9.
728
729**Atomic service API**: This API can be used in atomic services since API version 11.
730
731**System capability**: SystemCapability.ArkUI.ArkUI.Full
732
733**Parameters**
734
735| Name  | Type                                      | Mandatory| Description                      |
736| -------- | ------------------------------------------ | ---- | -------------------------- |
737| callback | [ImageErrorCallback](#imageerrorcallback9) | Yes  | Callback triggered when an error occurs during image loading.<br>**NOTE**<br> - You are advised to use this callback to quickly identify the specific causes for image loading failures.|
738
739### onFinish
740
741onFinish(event: () =&gt; void)
742
743Triggered when the animation playback in the loaded SVG image is complete. If the animation is an infinite loop, this callback is not triggered.
744
745Only SVG images are supported. This event is not triggered if the parameter type of the component is [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12).
746
747**Widget capability**: This API can be used in ArkTS widgets since API version 9.
748
749**Atomic service API**: This API can be used in atomic services since API version 11.
750
751**System capability**: SystemCapability.ArkUI.ArkUI.Full
752
753## ImageErrorCallback<sup>9+</sup>
754
755type ImageErrorCallback = (error: ImageError) => void
756
757Represents the callback triggered when an error occurs during image loading.
758
759The callback is not triggered if the parameter type of the component is [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12).
760
761**Widget capability**: This API can be used in ArkTS widgets since API version 9.
762
763**Atomic service API**: This API can be used in atomic services since API version 11.
764
765**System capability**: SystemCapability.ArkUI.ArkUI.Full
766
767| Name| Type                      | Mandatory| Description                              |
768| ------ | -------------------------- | ---- | ---------------------------------- |
769| error  | [ImageError](#imageerror9) | Yes  | Return object that triggers the callback for when an error occurs during image loading.|
770
771## ImageError<sup>9+</sup>
772
773Describes the return object that triggers the callback for when an error occurs during image loading.
774
775This event is not triggered if the parameter type of the component is [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12).
776
777**Atomic service API**: This API can be used in atomic services since API version 11.
778
779**System capability**: SystemCapability.ArkUI.ArkUI.Full
780
781| Name         | Type  | Mandatory| Description                     |
782| --------------- | ------ | ---- | ------------------------- |
783| componentWidth  | number | Yes  | Width of the component.<br>Unit: pixel<br>**Widget capability**: This API can be used in ArkTS widgets since API version 9.|
784| componentHeight | number | Yes  | Height of the component.<br>Unit: pixel<br>**Widget capability**: This API can be used in ArkTS widgets since API version 9.|
785| message<sup>10+</sup>         | string | Yes  | Error information.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 10.|
786
787## Example
788
789### Example 1: Loading Images of Basic Types
790
791This example demonstrates how to load images of basic types, such as PNG, GIF, SVG, and JPG.
792
793```ts
794@Entry
795@Component
796struct ImageExample1 {
797  build() {
798    Column() {
799      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) {
800        Row() {
801          // Load a PNG image.
802          Image($r('app.media.ic_camera_master_ai_leaf'))
803            .width(110).height(110).margin(15)
804            .overlay('png', { align: Alignment.Bottom, offset: { x: 0, y: 20 } })
805          // Load a GIF image.
806          Image($r('app.media.loading'))
807            .width(110).height(110).margin(15)
808            .overlay('gif', { align: Alignment.Bottom, offset: { x: 0, y: 20 } })
809        }
810        Row() {
811          // Load an SVG image.
812          Image($r('app.media.ic_camera_master_ai_clouded'))
813            .width(110).height(110).margin(15)
814            .overlay('svg', { align: Alignment.Bottom, offset: { x: 0, y: 20 } })
815          // Load a JPG image.
816          Image($r('app.media.ic_public_favor_filled'))
817            .width(110).height(110).margin(15)
818            .overlay('jpg', { align: Alignment.Bottom, offset: { x: 0, y: 20 } })
819        }
820      }
821    }.height(320).width(360).padding({ right: 10, top: 10 })
822  }
823}
824```
825
826![en-us_image_0000001592882500](figures/en-us_image_0000001592882500.gif)
827
828### Example 2: Downloading and Displaying Online Images
829
830The default timeout is 5 minutes for loading online images. When using an online image, you are advised to use **alt** to configure a placeholder image displayed during loading. You can use [HTTP](../../../network/http-request.md) to send a network request, and then decode the returned data into a **PixelMap** object in the **Image** component. For details about image development, see [Introduction to Image Kit](../../../media/image/image-overview.md).
831
832The **ohos.permission.INTERNET** permission is required for using online images. For details about how to apply for a permission, see [Declaring Permissions](../../../security/AccessToken/declare-permissions.md).
833
834```ts
835import { http } from '@kit.NetworkKit';
836import { BusinessError } from '@kit.BasicServicesKit';
837import { image } from '@kit.ImageKit';
838
839@Entry
840@Component
841struct ImageExample2 {
842  @State pixelMapImg: PixelMap | undefined = undefined;
843
844  aboutToAppear() {
845    this.requestImageUrl('https://www.example.com/xxx.png');// Enter a specific online image URL.
846  }
847
848  requestImageUrl(url: string) {
849    http.createHttp().request(url, (error: BusinessError, data: http.HttpResponse)=> {
850      if (error) {
851        console.error(`request image failed: url: ${url}, code: ${error.code}, message: ${error.message}`);
852      } else {
853        let imgData: ArrayBuffer = data.result as ArrayBuffer;
854        console.info(`request image success, size: ${imgData.byteLength}`);
855        let imgSource: image.ImageSource = image.createImageSource(imgData);
856        class sizeTmp {
857          height: number = 100
858          width: number = 100
859        }
860        let options: Record<string, number | boolean | sizeTmp> = {
861          'alphaType': 0,
862          'editable': false,
863          'pixelFormat': 3,
864          'scaleMode': 1,
865          'size': { height: 100, width: 100 }
866        }
867        imgSource.createPixelMap(options).then((pixelMap: PixelMap) => {
868          console.error('image createPixelMap success');
869          this.pixelMapImg = pixelMap;
870        })
871      }
872    })
873  }
874
875  build() {
876    Column() {
877      Image(this.pixelMapImg)
878        .alt($r('app.media.img'))
879        .objectFit(ImageFit.None)
880        .width('100%')
881        .height('100%')
882    }
883  }
884}
885```
886
887![en-us_image_0000001607845173](figures/en-us_image_view2.gif)
888
889### Example 3: Adding Events to an Image
890
891This example shows how to add **onClick** and **onFinish** events to an image.
892
893```ts
894@Entry
895@Component
896struct ImageExample3 {
897  private imageOne: Resource = $r('app.media.earth');
898  private imageTwo: Resource = $r('app.media.star');
899  private imageThree: Resource = $r('app.media.moveStar');
900  @State src: Resource = this.imageOne
901  @State src2: Resource = this.imageThree
902  build(){
903    Column(){
904      // Add a click event so that a specific image is loaded upon clicking.
905      Image(this.src)
906        .width(100)
907        .height(100)
908        .onClick(() => {
909          this.src = this.imageTwo
910        })
911
912      // When the image to be loaded is in SVG format:
913      Image(this.src2)
914        .width(100)
915        .height(100)
916        .onFinish(() => {
917          // Load another image when the SVG image has finished its animation.
918          this.src2 = this.imageOne
919        })
920    }.width('100%').height('100%')
921  }
922}
923```
924
925![en-us_image_0000001607845173](figures/en-us_image_0000001607845173.gif)
926
927### Example 4: Enabling the AI Analyzer
928<!--RP2-->
929This example shows how to use **enableAnalyzer** to enable the AI analyzer.
930
931```ts
932import { image } from '@kit.ImageKit'
933
934@Entry
935@Component
936struct ImageExample4 {
937  @State imagePixelMap: image.PixelMap | undefined = undefined
938  private aiController: ImageAnalyzerController = new ImageAnalyzerController()
939  private options: ImageAIOptions = {
940    types: [ImageAnalyzerType.SUBJECT, ImageAnalyzerType.TEXT],
941    aiController: this.aiController
942  }
943
944  async aboutToAppear() {
945    this.imagePixelMap = await this.getPixmapFromMedia($r('app.media.app_icon'))
946  }
947
948  build() {
949    Column() {
950      Image(this.imagePixelMap, this.options)
951        .enableAnalyzer(true)
952        .width(200)
953        .height(200)
954        .margin({bottom:10})
955      Button('getTypes')
956        .width(80)
957        .height(80)
958        .onClick(() => {
959          this.aiController.getImageAnalyzerSupportTypes()
960        })
961    }
962  }
963  private async getPixmapFromMedia(resource: Resource) {
964    let unit8Array = await getContext(this)?.resourceManager?.getMediaContent({
965      bundleName: resource.bundleName,
966      moduleName: resource.moduleName,
967      id: resource.id
968    })
969    let imageSource = image.createImageSource(unit8Array.buffer.slice(0, unit8Array.buffer.byteLength))
970    let createPixelMap: image.PixelMap = await imageSource.createPixelMap({
971      desiredPixelFormat: image.PixelMapFormat.RGBA_8888
972    })
973    await imageSource.release()
974    return createPixelMap
975  }
976}
977```
978
979![en-us_image_0000001607845173](figures/en-us_image_view4.gif)
980<!--RP2End-->
981### Example 5: Resizing an Image
982
983This example shows how to resize an image in different directions.
984
985```ts
986@Entry
987@Component
988struct Index {
989  @State top: number = 10
990  @State bottom: number = 10
991  @State left: number = 10
992  @State right: number = 10
993
994  build() {
995    Column({ space: 5 }) {
996      // Original image effect
997      Image($r("app.media.landscape"))
998        .width(200).height(200)
999        .border({ width: 2, color: Color.Pink })
1000        .objectFit(ImageFit.Contain)
1001
1002      // Set the resizable attribute to resize the image in different directions.
1003      Image($r("app.media.landscape"))
1004        .resizable({
1005          slice: {
1006            left: this.left,
1007            right: this.right,
1008            top: this.top,
1009            bottom: this.bottom
1010          }
1011        })
1012        .width(200)
1013        .height(200)
1014        .border({ width: 2, color: Color.Pink })
1015        .objectFit(ImageFit.Contain)
1016
1017      Row() {
1018        Button("add top to " + this.top).fontSize(10)
1019          .onClick(() => {
1020            this.top += 10
1021          })
1022        Button("add bottom to " + this.bottom).fontSize(10)
1023          .onClick(() => {
1024            this.bottom += 10
1025          })
1026      }
1027
1028      Row() {
1029        Button("add left to " + this.left).fontSize(10)
1030          .onClick(() => {
1031            this.left += 10
1032          })
1033        Button("add right to " + this.right).fontSize(10)
1034          .onClick(() => {
1035            this.right += 10
1036          })
1037      }
1038
1039    }
1040    .justifyContent(FlexAlign.Start).width('100%').height('100%')
1041  }
1042}
1043```
1044
1045![imageResizable](figures/imageResizable.gif)
1046
1047### Example 6: Playing a PixelMap Array Animation
1048
1049This example demonstrates how to play an animation of a **PixelMap** array using [AnimatedDrawableDescriptor](../js-apis-arkui-drawableDescriptor.md#animateddrawabledescriptor12).
1050
1051```ts
1052import {AnimationOptions, AnimatedDrawableDescriptor} from '@kit.ArkUI'
1053import { image } from '@kit.ImageKit'
1054
1055@Entry
1056@Component
1057struct ImageExample {
1058  pixelmaps: Array<PixelMap>  = [];
1059  options: AnimationOptions = {duration:2000, iterations:1};
1060  @State animated: AnimatedDrawableDescriptor | undefined = undefined;
1061
1062  async aboutToAppear() {
1063    this.pixelmaps = await this.getPixelMaps();
1064    this.animated = new AnimatedDrawableDescriptor(this.pixelmaps, this.options);
1065  }
1066
1067  build() {
1068    Column() {
1069      Row() {
1070        Image(this.animated)
1071          .width('500px').height('500px')
1072          .onFinish(() => {
1073            console.info("finish")
1074          })
1075      }.height('50%')
1076      Row() {
1077        Button('once').width(100).padding(5).onClick(() => {
1078          this.options = {duration:2000, iterations:1};
1079          this.animated = new AnimatedDrawableDescriptor(this.pixelmaps, this.options);
1080        }).margin(5)
1081        Button('infinite').width(100).padding(5).onClick(() => {
1082          this.options = {duration:2000, iterations:-1};
1083          this.animated = new AnimatedDrawableDescriptor(this.pixelmaps, this.options);
1084        }).margin(5)
1085      }
1086    }.width('50%')
1087  }
1088
1089  private async getPixmapListFromMedia(resource: Resource) {
1090    let unit8Array = await getContext(this)?.resourceManager?.getMediaContent({
1091      bundleName: resource.bundleName,
1092      moduleName: resource.moduleName,
1093      id: resource.id
1094    })
1095    let imageSource = image.createImageSource(unit8Array.buffer.slice(0, unit8Array.buffer.byteLength))
1096    let createPixelMap: Array<image.PixelMap> = await imageSource.createPixelMapList({
1097      desiredPixelFormat: image.PixelMapFormat.RGBA_8888
1098    })
1099    await imageSource.release()
1100    return createPixelMap
1101  }
1102
1103  private async getPixmapFromMedia(resource: Resource) {
1104    let unit8Array = await getContext(this)?.resourceManager?.getMediaContent({
1105      bundleName: resource.bundleName,
1106      moduleName: resource.moduleName,
1107      id: resource.id
1108    })
1109    let imageSource = image.createImageSource(unit8Array.buffer.slice(0, unit8Array.buffer.byteLength))
1110    let createPixelMap: image.PixelMap = await imageSource.createPixelMap({
1111      desiredPixelFormat: image.PixelMapFormat.RGBA_8888
1112    })
1113    await imageSource.release()
1114    return createPixelMap
1115  }
1116
1117  private async getPixelMaps() {
1118    let Mypixelmaps:Array<PixelMap> = await this.getPixmapListFromMedia($r('app.media.view'))// A GIF image, when processed, can generate multiple PixelMap instances.
1119    Mypixelmaps.push(await this.getPixmapFromMedia($r('app.media.icon'))) // Add an image.
1120    return Mypixelmaps;
1121  }
1122}
1123```
1124
1125![en-us_image_0000001607845173](figures/en-us_image_view6.gif)
1126
1127### Example 7: Setting a Color Filter for an Image
1128
1129This example shows how to set a color filter for an image using [colorFilter](#colorfilter9).
1130
1131```ts
1132import { drawing, common2D } from '@kit.ArkGraphics2D';
1133
1134@Entry
1135@Component
1136struct ImageExample3 {
1137  private imageOne: Resource = $r('app.media.1');
1138  private imageTwo: Resource = $r('app.media.2');
1139  @State src: Resource = this.imageOne
1140  @State src2: Resource = this.imageTwo
1141  private ColorFilterMatrix: number[] = [1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0]
1142  private color: common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
1143  @State DrawingColorFilterFirst: ColorFilter | undefined = undefined
1144  @State DrawingColorFilterSecond: ColorFilter | undefined = undefined
1145  @State DrawingColorFilterThird: ColorFilter | undefined = undefined
1146
1147  build() {
1148    Column() {
1149      Image(this.src)
1150        .width(100)
1151        .height(100)
1152        .colorFilter(this.DrawingColorFilterFirst)
1153        .onClick(()=>{
1154          this.DrawingColorFilterFirst = drawing.ColorFilter.createBlendModeColorFilter(this.color, drawing.BlendMode.SRC_IN);
1155        })
1156
1157      Image(this.src2)
1158        .width(100)
1159        .height(100)
1160        .colorFilter(this.DrawingColorFilterSecond)
1161        .onClick(()=>{
1162          this.DrawingColorFilterSecond = new ColorFilter(this.ColorFilterMatrix);
1163        })
1164
1165      // When the image to be loaded is in SVG format:
1166      Image($r('app.media.test_self'))
1167        .width(110).height(110).margin(15)
1168        .colorFilter(this.DrawingColorFilterThird)
1169        .onClick(()=>{
1170          this.DrawingColorFilterThird = drawing.ColorFilter.createBlendModeColorFilter(this.color, drawing.BlendMode.SRC_IN);
1171        })
1172    }
1173  }
1174}
1175```
1176![imageSetColorFilter](figures/imageSetColorFilter.gif)
1177
1178### Example 8: Setting the Fill Effect for an Image
1179
1180This example shows how to [objectFit](#objectfit) to specify how an image is resized to fit its container.
1181
1182```ts
1183@Entry
1184@Component
1185struct ImageExample{
1186  build() {
1187    Column() {
1188      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) {
1189        Row() {
1190          // Load a PNG image.
1191          Image($r('app.media.sky'))
1192            .width(110).height(110).margin(15)
1193            .overlay('png', { align: Alignment.Bottom, offset: { x: 0, y: 20 } })
1194            .border({ width: 2, color: Color.Pink })
1195            .objectFit(ImageFit.TOP_START)
1196          // Load a GIF image.
1197          Image($r('app.media.loading'))
1198            .width(110).height(110).margin(15)
1199            .overlay('gif', { align: Alignment.Bottom, offset: { x: 0, y: 20 } })
1200            .border({ width: 2, color: Color.Pink })
1201            .objectFit(ImageFit.BOTTOM_START)
1202        }
1203        Row() {
1204          // Load an SVG image.
1205          Image($r('app.media.svg'))
1206            .width(110).height(110).margin(15)
1207            .overlay('svg', { align: Alignment.Bottom, offset: { x: 0, y: 20 } })
1208            .border({ width: 2, color: Color.Pink })
1209            .objectFit(ImageFit.TOP_END)
1210          // Load a JPG image.
1211          Image($r('app.media.jpg'))
1212            .width(110).height(110).margin(15)
1213            .overlay('jpg', { align: Alignment.Bottom, offset: { x: 0, y: 20 } })
1214            .border({ width: 2, color: Color.Pink })
1215            .objectFit(ImageFit.CENTER)
1216        }
1217      }
1218    }.height(320).width(360).padding({ right: 10, top: 10 })
1219  }
1220}
1221```
1222
1223![imageResizable](figures/imageSetFit.gif)
1224
1225### Example 9: Switching Between Different Types of Images
1226
1227This example demonstrates the display effects of images when using ResourceStr type and ImageContent type as data sources.
1228
1229```ts
1230@Entry
1231@Component
1232struct ImageContentExample {
1233  @State imageSrcIndex: number = 0;
1234  @State imageSrcList: (ResourceStr | ImageContent)[] = [$r('app.media.app_icon'), ImageContent.EMPTY]
1235
1236  build() {
1237    Column({ space: 10 }) {
1238      Image(this.imageSrcList[this.imageSrcIndex])
1239        .width(100)
1240        .height(100)
1241      Button('Change Image src')
1242        .padding(20)
1243        .onClick(() => {
1244          this.imageSrcIndex = (this.imageSrcIndex + 1) % this.imageSrcList.length
1245        })
1246    }.width('100%')
1247    .padding(20)
1248  }
1249}
1250```
1251
1252![imageContent](figures/en-us_image_view9.gif)
1253
1254### Example 10: Securing Sensitive Information
1255
1256This example shows how to secure sensitive information on widgets using [privacySensitive](#privacysensitive12). The display requires widget framework support.
1257
1258```ts
1259@Entry
1260@Component
1261struct ImageExample {
1262  build() {
1263    Column({ space: 10 }) {
1264      Image($r("app.media.startIcon"))
1265        .width(50)
1266        .height(50)
1267        .margin({top :30})
1268        .privacySensitive(true)
1269    }
1270    .alignItems(HorizontalAlign.Center)
1271    .width("100%")
1272  }
1273}
1274```
1275
1276![imageContent](figures/en-us_image_view10.gif)
1277
1278### Example 11: Setting the Scan Effect for an Image
1279
1280This example shows how to enable the scan effect for an image using [linearGradient](./ts-basic-components-datapanel.md#lineargradient10) and [animateTo()](./ts-explicit-animation.md).
1281
1282```ts
1283import { curves } from '@kit.ArkUI';
1284
1285@Entry
1286@Component
1287struct ImageExample11 {
1288  private curve = curves.cubicBezier(0.33, 0, 0.67, 1);
1289  @State moveImg: string[] = ['imageScanEffect'];
1290  @State moveImgVisible: Visibility = Visibility.Visible;
1291  @State durationTime: number = 1500;
1292  @State iterationsTimes: number = -1;
1293  @State private opacityValue: number = 0.5;
1294  @State imageWidth: number = 450;
1295  @State visible: Visibility = Visibility.Hidden;
1296  @State stackBackgroundColor: string = '#E1E4E9';
1297  @State linePositionX: number = 0 - this.imageWidth;
1298  @State linePositionY: number = 0;
1299  @State imgResource: Resource | undefined = undefined;
1300
1301  startupAnimate() {
1302    this.moveImg.pop();
1303    this.moveImg.push('imageScanEffect');
1304    setTimeout(() => {
1305      this.imgResource = $r('app.media.img');
1306    }, 3000);
1307    animateTo({
1308      duration: this.durationTime,
1309      curve: this.curve,
1310      tempo: 1,
1311      iterations: this.iterationsTimes,
1312      delay: 0
1313    }, () => {
1314      this.linePositionX = this.imageWidth;
1315    })
1316  }
1317
1318  build() {
1319    Column() {
1320      Row() {
1321        Stack() {
1322          Image(this.imgResource)
1323            .width(this.imageWidth)
1324            .height(200)
1325            .objectFit(ImageFit.Contain)
1326            .visibility(this.visible)
1327            .onComplete(() => {
1328              this.visible = Visibility.Visible;
1329              this.moveImg.pop();
1330            })
1331            .onError(() =>{
1332              setTimeout(() => {
1333                this.visible = Visibility.Visible;
1334                this.moveImg.pop();
1335              }, 2600)
1336            })
1337          ForEach(this.moveImg, (item: string) => {
1338            Row()
1339              .width(this.imageWidth)
1340              .height(200)
1341              .visibility(this.moveImgVisible)
1342              .position({ x: this.linePositionX, y: this.linePositionY })
1343              .linearGradient({
1344                direction: GradientDirection.Right,
1345                repeating: false,
1346                colors: [[0xE1E4E9, 0], [0xFFFFFF, 0.75], [0xE1E4E9, 1]]
1347              })
1348              .opacity(this.opacityValue)
1349          })
1350        }
1351        .backgroundColor(this.visible ? this.stackBackgroundColor : undefined)
1352        .margin({top: 20, left: 20, right: 20})
1353        .borderRadius(20)
1354        .clip(true)
1355        .onAppear(() => {
1356          this.startupAnimate();
1357        })
1358      }
1359    }
1360  }
1361}
1362```
1363
1364![imageContent](figures/imageScanEffect.gif)
1365
1366### Example 12: Setting the Image Decoding Size Using sourceSize
1367
1368This example uses the [sourceSize](ts-basic-components-image.md#sourcesize) API to customize the decoding size of the image.
1369
1370```ts
1371@Entry
1372@Component
1373struct Index {
1374  @State borderRadiusValue: number = 10;
1375  build() {
1376    Column() {
1377      Image($r("app.media.sky"))
1378        .sourceSize({width:1393, height:1080})
1379        .height(300)
1380        .width(300)
1381        .objectFit(ImageFit.Contain)
1382        .borderWidth(1)
1383      Image($r("app.media.sky"))
1384        .sourceSize({width:13, height:10})
1385        .height(300)
1386        .width(300)
1387        .objectFit(ImageFit.Contain)
1388        .borderWidth(1)
1389    }
1390    .height('100%')
1391    .width('100%')
1392  }
1393}
1394```
1395
1396![sourceSizeExample](figures/sourceSizeExample.png)
1397
1398### Example 13: Setting the Image Rendering Mode Using renderMode
1399
1400This example uses the [renderMode](ts-basic-components-image.md#rendermode) API to set the image rendering mode to grayscale.
1401
1402```ts
1403@Entry
1404@Component
1405struct Index {
1406  @State borderRadiusValue: number = 10;
1407  build() {
1408    Column() {
1409      Image($r("app.media.sky"))
1410        .renderMode(ImageRenderMode.Template)
1411        .height(300)
1412        .width(300)
1413        .objectFit(ImageFit.Contain)
1414        .borderWidth(1)
1415    }
1416    .height('100%')
1417    .width('100%')
1418  }
1419}
1420```
1421
1422![renderModeExample](figures/renderModeExample.png)
1423
1424### Example 14: Setting the Image Repeat Pattern Using objectRepeat
1425
1426This example uses the [objectRepeat](ts-basic-components-image.md#objectrepeat) API to repeat the image along the vertical axis.
1427
1428```ts
1429@Entry
1430@Component
1431struct Index {
1432  @State borderRadiusValue: number = 10;
1433  build() {
1434    Column() {
1435      Image($r("app.media.sky"))
1436        .objectRepeat(ImageRepeat.Y)
1437        .height(300)
1438        .width(300)
1439        .objectFit(ImageFit.Contain)
1440        .borderWidth(1)
1441    }
1442    .height('100%')
1443    .width('100%')
1444  }
1445}
1446```
1447
1448![objectRepeatExample](figures/objectRepeatExample.png)
1449
1450### Example 15: Setting the Fill Color for SVG Images
1451
1452This example shows how to use [fillColor](#fillcolor15) to set different fill colors for SVG images.
1453
1454```ts
1455@Entry
1456@Component
1457struct Index {
1458  build() {
1459    Column() {
1460      Text("FillColor not set")
1461      Image($r("app.media.svgExample"))
1462        .height(100)
1463        .width(100)
1464        .objectFit(ImageFit.Contain)
1465        .borderWidth(1)
1466      Text("fillColor set to ColorContent.ORIGIN")
1467      Image($r("app.media.svgExample"))
1468        .height(100)
1469        .width(100)
1470        .objectFit(ImageFit.Contain)
1471        .borderWidth(1)
1472        .fillColor(ColorContent.ORIGIN)
1473      Text("fillColor set to Color.Blue")
1474      Image($r("app.media.svgExample"))
1475        .height(100)
1476        .width(100)
1477        .objectFit(ImageFit.Contain)
1478        .borderWidth(1)
1479        .fillColor(Color.Blue)
1480      Text("fillColor set to undefined")
1481      Image($r("app.media.svgExample"))
1482        .height(100)
1483        .width(100)
1484        .objectFit(ImageFit.Contain)
1485        .borderWidth(1)
1486        .fillColor(undefined)
1487    }
1488    .height('100%')
1489    .width('100%')
1490  }
1491}
1492```
1493
1494![fillColorExample](figures/fillColorExample.png)
1495
1496### Example 16: Adding Transform Effects to Images
1497
1498This example demonstrates how to apply rotation and translation effects to images using [imageMatrix](#imagematrix15) and [objectFit](#objectfit).
1499
1500```ts
1501import { matrix4 } from '@kit.ArkUI'
1502
1503@Entry
1504@Component
1505struct Test {
1506  private matrix1 = matrix4.identity()
1507    .translate({ x: -400, y: -750 })
1508    .scale({ x: 0.5, y: 0.5 })
1509    .rotate({
1510      x: 2,
1511      y: 0.5,
1512      z: 3,
1513      centerX: 10,
1514      centerY: 10,
1515      angle: -10
1516    })
1517
1518  build() {
1519    Row() {
1520      Column({ space: 50 }) {
1521        Column({ space: 5 }) {
1522          Image($r("app.media.example"))
1523            .border({ width:2, color: Color.Black })
1524            .objectFit(ImageFit.Contain)
1525            .width(150)
1526            .height(150)
1527          Text("No transformation")
1528            .fontSize('25px')
1529        }
1530        Column({ space: 5 }) {
1531          Image($r("app.media.example"))
1532            .border({ width:2, color: Color.Black })
1533            .objectFit(ImageFit.None)
1534            .translate({ x: 10, y: 10 })
1535            .scale({ x: 0.5, y: 0.5 })
1536            .width(100)
1537            .height(100)
1538          Text("Direct transformation on the image, with the upper left corner of the image source displayed by default")
1539            .fontSize('25px')
1540        }
1541        Column({ space: 5 }) {
1542          Image($r("app.media.example"))
1543            .objectFit(ImageFit.MATRIX)
1544            .imageMatrix(this.matrix1)
1545            .border({ width:2, color: Color.Black })
1546            .width(150)
1547            .height(150)
1548          Text("Transformation using imageMatrix to adjust the source position for optimal display")
1549            .fontSize('25px')
1550        }
1551      }
1552      .width('100%')
1553    }
1554  }
1555}
1556```
1557
1558![imageMatrix](figures/imageMatrix.jpeg)
1559