1e41f4b71Sopenharmony_ci# ImageSpan
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciAs a child of the [Text](ts-basic-components-text.md) and [ContainerSpan](ts-basic-components-containerspan.md) components, the **ImageSpan** component is used to display inline images.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci>  **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci>  This component is supported since API version 10. Updates will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## Child Components
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ciNot supported
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## APIs
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ciImageSpan(value: ResourceStr | PixelMap)
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci**Parameters**
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description|
26e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
27e41f4b71Sopenharmony_ci| value | [ResourceStr](ts-types.md#resourcestr) \| [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7)  | Yes| Image source. Both local and online images are supported.<br>When using an image referenced using a relative path, for example, **ImageSpan("common/test.jpg")**, the **ImageSpan** component cannot be called across bundles or modules. Therefore, you are advised to use **\$r** to reference image resources that need to be used globally.<br>\- The supported formats include PNG, JPG, BMP, SVG, GIF, and HEIF.<br>\- Base64 strings are supported. The value format is data:image/[png\|jpeg\|bmp\|webp\|heif];base64,[base64 data], where *[base64 data]* is a Base64 string.<br>\- Strings with the **file:///data/storage** prefix are supported, which are used to read image resources in the **files** folder in the installation directory of the application. Ensure that the application has the read permission to the files in the specified path.|
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci## Attributes
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ciThe attributes inherit from [BaseSpan](ts-basic-components-span.md#basespan). Among the universal attributes, [size](ts-universal-attributes-size.md#size), [background](ts-universal-attributes-background.md#background), and [border](ts-universal-attributes-border.md#border) are supported.
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci### alt<sup>12+</sup>
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_cialt(value: PixelMap)
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ciSets the placeholder image displayed during loading.
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci**Parameters**
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci| Name| Type                                                    | Mandatory| Description                                                        |
47e41f4b71Sopenharmony_ci| ------ | -------------------------------------------------------- | ---- | ------------------------------------------------------------ |
48e41f4b71Sopenharmony_ci| value  | [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7) | Yes  | Placeholder image displayed during loading. The [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7) type is supported.<br>Default value: **null**|
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci### verticalAlign
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_civerticalAlign(value: ImageSpanAlignment)
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ciSets the alignment mode of the image relative to the line height.
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci**Parameters**
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci| Name| Type                                     | Mandatory| Description                                                        |
63e41f4b71Sopenharmony_ci| ------ | ----------------------------------------- | ---- | ------------------------------------------------------------ |
64e41f4b71Sopenharmony_ci| value  | [ImageSpanAlignment](ts-appendix-enums.md#imagespanalignment10) | Yes  | Alignment mode of the image relative to the line height.<br>Default value: **ImageSpanAlignment.BOTTOM**|
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci### objectFit
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ciobjectFit(value: ImageFit)
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ciSets the image scale type.
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci**Parameters**
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci| Name| Type                                     | Mandatory| Description                                       |
79e41f4b71Sopenharmony_ci| ------ | ----------------------------------------- | ---- | ------------------------------------------- |
80e41f4b71Sopenharmony_ci| value  | [ImageFit](ts-appendix-enums.md#imagefit) | Yes  | Image scale type.<br>Default value: **ImageFit.Cover**|
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci### colorFilter<sup>13+</sup>
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_cicolorFilter(value: ColorFilter | DrawingColorFilter)
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ciSets the color filter for the image.
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 13.
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci**Parameters**
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci| Name| Type                                   | Mandatory| Description                                                        |
95e41f4b71Sopenharmony_ci| ------ | --------------------------------------- | ---- | ------------------------------------------------------------ |
96e41f4b71Sopenharmony_ci| value  | [ColorFilter](ts-types.md#colorfilter9) \| [DrawingColorFilter](../../apis-arkgraphics2d/js-apis-graphics-drawing.md#colorfilter) | 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.<br>**NOTE**<br>The DrawingColorfilter type can be used in atomic services. The SVG image to set as the source must have the **stroke** attribute.|
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci## Events
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ciAmong all the universal events, only the [click event](ts-universal-attributes-click.md) is supported. The following events are also supported.
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci### onComplete<sup>12+</sup>
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_cionComplete(callback: ImageCompleteCallback)
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ciTriggered when the image is successfully loaded or decoded. The size of the loaded image is returned.
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci**Parameters**
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci| Name  | Type                                      | Mandatory| Description                      |
115e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ | ---- | -------------------------- |
116e41f4b71Sopenharmony_ci| callback | [ImageCompleteCallback](#imagecompletecallback12) | Yes  | Callback triggered when the image is successfully loaded or decoded.|
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci### onError<sup>12+</sup>
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_cionError(callback: ImageErrorCallback)
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ciTriggered when an error occurs during image loading.
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci**Parameters**
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci| Name  | Type                                      | Mandatory| Description                      |
131e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ | ---- | -------------------------- |
132e41f4b71Sopenharmony_ci| callback | [ImageErrorCallback](ts-basic-components-image.md#imageerrorcallback9) | Yes  | Callback triggered when an error occurs during image loading.|
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci## ImageCompleteCallback<sup>12+</sup>
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_citype ImageCompleteCallback = (result: ImageLoadResult) => void
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ciTriggered when the image is successfully loaded.
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci| Name| Type                      | Mandatory| Description                              |
145e41f4b71Sopenharmony_ci| ------ | -------------------------- | ---- | ---------------------------------- |
146e41f4b71Sopenharmony_ci| result  | [ImageLoadResult](#imageloadresult12) | Yes  | Object returned after the callback is triggered when an image is successfully loaded or decoded.|
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci## ImageLoadResult<sup>12+</sup>
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_ciObject returned after the callback is triggered when an image is successfully loaded or decoded.
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci| Name                      | Type  | Mandatory| Description                                                        |
157e41f4b71Sopenharmony_ci| ---------------------------- | ------ | ---- | ------------------------------------------------------------ |
158e41f4b71Sopenharmony_ci| width                        | number | Yes  | Width of the image.<br>Unit: pixel                                   |
159e41f4b71Sopenharmony_ci| height                       | number | Yes  | Height of the image.<br>Unit: pixel                                   |
160e41f4b71Sopenharmony_ci| componentWidth               | number | Yes  | Width of the component.<br>Unit: pixel                                   |
161e41f4b71Sopenharmony_ci| componentHeight              | number | Yes  | Height of the component.<br>Unit: pixel                                   |
162e41f4b71Sopenharmony_ci| 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.|
163e41f4b71Sopenharmony_ci| contentWidth   | 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**.|
164e41f4b71Sopenharmony_ci| contentHeight  | 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**.|
165e41f4b71Sopenharmony_ci| contentOffsetX | 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**.|
166e41f4b71Sopenharmony_ci| contentOffsetY | 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**.|
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci## Example
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci### Example 1
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ciThis example sets the basic attributes of the image span as well as the alignment mode of the image with the text.
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ci```ts
177e41f4b71Sopenharmony_ci// xxx.ets
178e41f4b71Sopenharmony_ci@Entry
179e41f4b71Sopenharmony_ci@Component
180e41f4b71Sopenharmony_cistruct SpanExample {
181e41f4b71Sopenharmony_ci  build() {
182e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
183e41f4b71Sopenharmony_ci      Text() {
184e41f4b71Sopenharmony_ci        Span('This is the Span and ImageSpan component').fontSize(25).textCase(TextCase.Normal)
185e41f4b71Sopenharmony_ci          .decoration({ type: TextDecorationType.None, color: Color.Pink })
186e41f4b71Sopenharmony_ci      }.width('100%').textAlign(TextAlign.Center)
187e41f4b71Sopenharmony_ci
188e41f4b71Sopenharmony_ci      Text() {
189e41f4b71Sopenharmony_ci        ImageSpan($r('app.media.icon'))
190e41f4b71Sopenharmony_ci          .width('200px')
191e41f4b71Sopenharmony_ci          .height('200px')
192e41f4b71Sopenharmony_ci          .objectFit(ImageFit.Fill)
193e41f4b71Sopenharmony_ci          .verticalAlign(ImageSpanAlignment.CENTER)
194e41f4b71Sopenharmony_ci        Span('I am LineThrough-span')
195e41f4b71Sopenharmony_ci          .decoration({ type: TextDecorationType.LineThrough, color: Color.Red }).fontSize(25)
196e41f4b71Sopenharmony_ci        ImageSpan($r('app.media.icon'))
197e41f4b71Sopenharmony_ci          .width('50px')
198e41f4b71Sopenharmony_ci          .height('50px')
199e41f4b71Sopenharmony_ci          .verticalAlign(ImageSpanAlignment.TOP)
200e41f4b71Sopenharmony_ci        Span('I am Underline-span')
201e41f4b71Sopenharmony_ci          .decoration({ type: TextDecorationType.Underline, color: Color.Red }).fontSize(25)
202e41f4b71Sopenharmony_ci        ImageSpan($r('app.media.icon'))
203e41f4b71Sopenharmony_ci          .size({ width: '100px', height: '100px' })
204e41f4b71Sopenharmony_ci          .verticalAlign(ImageSpanAlignment.BASELINE)
205e41f4b71Sopenharmony_ci        Span('I am Underline-span')
206e41f4b71Sopenharmony_ci          .decoration({ type: TextDecorationType.Underline, color: Color.Red }).fontSize(25)
207e41f4b71Sopenharmony_ci        ImageSpan($r('app.media.icon'))
208e41f4b71Sopenharmony_ci          .width('70px')
209e41f4b71Sopenharmony_ci          .height('70px')
210e41f4b71Sopenharmony_ci          .verticalAlign(ImageSpanAlignment.BOTTOM)
211e41f4b71Sopenharmony_ci        Span('I am Underline-span')
212e41f4b71Sopenharmony_ci          .decoration({ type: TextDecorationType.Underline, color: Color.Red }).fontSize(50)
213e41f4b71Sopenharmony_ci      }
214e41f4b71Sopenharmony_ci      .width('100%')
215e41f4b71Sopenharmony_ci      .textIndent(50)
216e41f4b71Sopenharmony_ci    }.width('100%').height('100%').padding({ left: 0, right: 0, top: 0 })
217e41f4b71Sopenharmony_ci  }
218e41f4b71Sopenharmony_ci}
219e41f4b71Sopenharmony_ci```
220e41f4b71Sopenharmony_ci
221e41f4b71Sopenharmony_ci![imagespan](figures/imagespan.png)
222e41f4b71Sopenharmony_ci
223e41f4b71Sopenharmony_ci### Example 2
224e41f4b71Sopenharmony_ci
225e41f4b71Sopenharmony_ciThis example shows how to set the background style of an image span.
226e41f4b71Sopenharmony_ci
227e41f4b71Sopenharmony_ci```ts
228e41f4b71Sopenharmony_ci// xxx.ets
229e41f4b71Sopenharmony_ci@Component
230e41f4b71Sopenharmony_ci@Entry
231e41f4b71Sopenharmony_cistruct Index {
232e41f4b71Sopenharmony_ci  build() {
233e41f4b71Sopenharmony_ci    Column() {
234e41f4b71Sopenharmony_ci      Text() {
235e41f4b71Sopenharmony_ci        ImageSpan($r('app.media.app_icon'))
236e41f4b71Sopenharmony_ci          .width('60vp')
237e41f4b71Sopenharmony_ci          .height('60vp')
238e41f4b71Sopenharmony_ci          .verticalAlign(ImageSpanAlignment.CENTER)
239e41f4b71Sopenharmony_ci          .textBackgroundStyle({color: Color.Green, radius: "5vp"})
240e41f4b71Sopenharmony_ci      }
241e41f4b71Sopenharmony_ci    }.width('100%').alignItems(HorizontalAlign.Center)
242e41f4b71Sopenharmony_ci  }
243e41f4b71Sopenharmony_ci}
244e41f4b71Sopenharmony_ci```
245e41f4b71Sopenharmony_ci![imagespan](figures/image_span_textbackgroundstyle.png)
246e41f4b71Sopenharmony_ci
247e41f4b71Sopenharmony_ci### Example 3
248e41f4b71Sopenharmony_ciThis example implements a callback triggered when the image is successfully loaded or decoded and a callback triggered when an error occurs during image loading.
249e41f4b71Sopenharmony_ci```ts
250e41f4b71Sopenharmony_ci// xxx.ets
251e41f4b71Sopenharmony_ci@Entry
252e41f4b71Sopenharmony_ci@Component
253e41f4b71Sopenharmony_cistruct Index {
254e41f4b71Sopenharmony_ci  @State src: ResourceStr = $r('app.media.icon');
255e41f4b71Sopenharmony_ci  build(){
256e41f4b71Sopenharmony_ci    Column(){
257e41f4b71Sopenharmony_ci      Text(){
258e41f4b71Sopenharmony_ci        ImageSpan(this.src)
259e41f4b71Sopenharmony_ci          .width(100).height(100)
260e41f4b71Sopenharmony_ci          .onError((err)=>{
261e41f4b71Sopenharmony_ci            console.log("onError:" + err.message)
262e41f4b71Sopenharmony_ci          })
263e41f4b71Sopenharmony_ci          .onComplete((event)=>{
264e41f4b71Sopenharmony_ci            console.log("onComplete: " + event.loadingStatus)
265e41f4b71Sopenharmony_ci          })
266e41f4b71Sopenharmony_ci      }
267e41f4b71Sopenharmony_ci    }.width('100%').height('100%')
268e41f4b71Sopenharmony_ci  }
269e41f4b71Sopenharmony_ci}
270e41f4b71Sopenharmony_ci```
271e41f4b71Sopenharmony_ci### Example 4
272e41f4b71Sopenharmony_ci
273e41f4b71Sopenharmony_ciThis example sets the color filter of the image span.
274e41f4b71Sopenharmony_ci
275e41f4b71Sopenharmony_ci```ts
276e41f4b71Sopenharmony_ci// xxx.ets
277e41f4b71Sopenharmony_ciimport { drawing, common2D } from '@kit.ArkGraphics2D';
278e41f4b71Sopenharmony_ci
279e41f4b71Sopenharmony_ci@Entry
280e41f4b71Sopenharmony_ci@Component
281e41f4b71Sopenharmony_cistruct SpanExample {
282e41f4b71Sopenharmony_ci  private ColorFilterMatrix: number[] = [0.239, 0, 0, 0, 0, 0, 0.616, 0, 0, 0, 0, 0, 0.706, 0, 0, 0, 0, 0, 1, 0];
283e41f4b71Sopenharmony_ci  @State DrawingColorFilterFirst: ColorFilter | undefined = new ColorFilter(this.ColorFilterMatrix)
284e41f4b71Sopenharmony_ci
285e41f4b71Sopenharmony_ci  build() {
286e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
287e41f4b71Sopenharmony_ci      Text() {
288e41f4b71Sopenharmony_ci        ImageSpan($r('app.media.icon'))
289e41f4b71Sopenharmony_ci          .width('50px')
290e41f4b71Sopenharmony_ci          .height('50px')
291e41f4b71Sopenharmony_ci          .colorFilter(this.DrawingColorFilterFirst)
292e41f4b71Sopenharmony_ci      }
293e41f4b71Sopenharmony_ci      .width('50%')
294e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
295e41f4b71Sopenharmony_ci        Text() {
296e41f4b71Sopenharmony_ci          ImageSpan($r('app.media.icon'))
297e41f4b71Sopenharmony_ci            .width('50px')
298e41f4b71Sopenharmony_ci            .height('50px')
299e41f4b71Sopenharmony_ci            .colorFilter(drawing.ColorFilter.createBlendModeColorFilter({ alpha: 255, red: 112, green: 112, blue: 112 }, drawing.BlendMode.SRC))
300e41f4b71Sopenharmony_ci        }
301e41f4b71Sopenharmony_ci        .width('50%')
302e41f4b71Sopenharmony_ci      }.width('100%').height('10%')
303e41f4b71Sopenharmony_ci    }.width('200%').height('100%')
304e41f4b71Sopenharmony_ci  }
305e41f4b71Sopenharmony_ci}
306e41f4b71Sopenharmony_ci```
307e41f4b71Sopenharmony_ci![imagespan](figures/image_span_colorfilter.gif)
308e41f4b71Sopenharmony_ci
309e41f4b71Sopenharmony_ci### Example 5
310e41f4b71Sopenharmony_ci
311e41f4b71Sopenharmony_ciThis example shows how a placeholder image is used in **ImageSpan** during the process of loading an image from the Internet.
312e41f4b71Sopenharmony_ci
313e41f4b71Sopenharmony_ci```ts
314e41f4b71Sopenharmony_ci// xxx.ets
315e41f4b71Sopenharmony_ciimport { http } from '@kit.NetworkKit'
316e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit'
317e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'
318e41f4b71Sopenharmony_ci
319e41f4b71Sopenharmony_ci@Entry
320e41f4b71Sopenharmony_ci@Component
321e41f4b71Sopenharmony_cistruct SpanExample {
322e41f4b71Sopenharmony_ci  @State imageAlt: PixelMap | undefined = undefined
323e41f4b71Sopenharmony_ci
324e41f4b71Sopenharmony_ci  httpRequest() {
325e41f4b71Sopenharmony_ci    // Enter an image URL.
326e41f4b71Sopenharmony_ci    http.createHttp().request("https://www.example.com/xxx.png", (error: BusinessError, data: http.HttpResponse) => {
327e41f4b71Sopenharmony_ci      if (error) {
328e41f4b71Sopenharmony_ci        console.error(`http request failed with. Code: ${error.code}, message: ${error.message}`)
329e41f4b71Sopenharmony_ci      } else {
330e41f4b71Sopenharmony_ci        console.log(`http request success.`)
331e41f4b71Sopenharmony_ci        let imageData: ArrayBuffer = data.result as ArrayBuffer
332e41f4b71Sopenharmony_ci        let imageSource: image.ImageSource = image.createImageSource(imageData)
333e41f4b71Sopenharmony_ci
334e41f4b71Sopenharmony_ci        class tmp {
335e41f4b71Sopenharmony_ci          height: number = 100
336e41f4b71Sopenharmony_ci          width: number = 100
337e41f4b71Sopenharmony_ci        }
338e41f4b71Sopenharmony_ci
339e41f4b71Sopenharmony_ci        let option: Record<string, number | boolean | tmp> = {
340e41f4b71Sopenharmony_ci          'alphaType': 0, // Alpha type.
341e41f4b71Sopenharmony_ci          'editable': false, // Whether the image is editable.
342e41f4b71Sopenharmony_ci          'pixelFormat': 3, // Pixel format.
343e41f4b71Sopenharmony_ci          'scaleMode': 1, // Scale mode.
344e41f4b71Sopenharmony_ci          'size': { height: 100, width: 100 }
345e41f4b71Sopenharmony_ci        }
346e41f4b71Sopenharmony_ci        // Image size.
347e41f4b71Sopenharmony_ci        imageSource.createPixelMap(option).then((pixelMap: PixelMap) => {
348e41f4b71Sopenharmony_ci          this.imageAlt = pixelMap
349e41f4b71Sopenharmony_ci        })
350e41f4b71Sopenharmony_ci      }
351e41f4b71Sopenharmony_ci    })
352e41f4b71Sopenharmony_ci  }
353e41f4b71Sopenharmony_ci
354e41f4b71Sopenharmony_ci  build() {
355e41f4b71Sopenharmony_ci    Column() {
356e41f4b71Sopenharmony_ci      Button("Get Online Image")
357e41f4b71Sopenharmony_ci        .onClick(() => {
358e41f4b71Sopenharmony_ci          this.httpRequest()
359e41f4b71Sopenharmony_ci        })
360e41f4b71Sopenharmony_ci
361e41f4b71Sopenharmony_ci      Text() {
362e41f4b71Sopenharmony_ci        // Enter an image URL.
363e41f4b71Sopenharmony_ci        ImageSpan('https://www.example.com/xxx.png')
364e41f4b71Sopenharmony_ci          .alt(this.imageAlt)
365e41f4b71Sopenharmony_ci          .width(300)
366e41f4b71Sopenharmony_ci          .height(300)
367e41f4b71Sopenharmony_ci      }
368e41f4b71Sopenharmony_ci
369e41f4b71Sopenharmony_ci    }.width('100%').height(250).padding({ left: 35, right: 35, top: 35 })
370e41f4b71Sopenharmony_ci  }
371e41f4b71Sopenharmony_ci}
372e41f4b71Sopenharmony_ci```
373e41f4b71Sopenharmony_ci
374e41f4b71Sopenharmony_ci![imagespan](figures/image_span_alt.gif)
375