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