<image>
Used to display different types of images, including web images, static resources, and locally stored images.
This feature depends on the image loading service provided by Lynx Service.
Usage Guide
<image> is an empty element and no longer supports child nodes.
The following examples show how the <image> element is used in different scenarios.
Displaying images with different cropping/scaling modes
Supports controlling the image cropping/scaling mode using mode.

Adding borders, rounded corners, and backgrounds to the image
You can set the image's borders, rounded corners, and background colors using CSS styles.

Adding special drawing effects to the image
Supports special drawing effects like Gaussian blur.

Adapting to the original image aspect ratio
Use auto-size to automatically adjust the <image> size to match the original image aspect ratio.

Listening to image load success/failure
You can bind events to listen for the image load state.
Used to display images
Attributes
auto-size
Android
iOS
Clay
Harmony
2.6
When set to true and the
<image>
element has no width or height,
the size of the
<image>
will be automatically adjusted
to match the image's original dimensions after the image is successfully loaded,
ensuring that the aspect ratio is maintained.
autoplay
Android
iOS
Clay
Harmony
2.11
Specifies whether the animated image should start playing automatically once it is loaded.
blur-radius
Android
iOS
Clay
Harmony
0.2
Image blur radius
cap-insets
Android
iOS
Clay
Harmony
1.4
Stretchable area for 9patch images, in percentage or decimal, four values for top, right, bottom, left
Using cap-insets does not require the original image to be a 9-patch image.
cap-insets-scale
Android
iOS
Clay
Harmony
1.4
Adjust the scale of stretchable area for 9patch images
defer-src-invalidation
Android
iOS
Clay
Harmony
2.7
When set to true, the
<image>
will only clear the previously displayed image resource after a new image has successfully loaded.
The default behavior is to clear the image resource before starting a new load.
This can resolve flickering issues when the image src is switched and reloaded. It is not recommended to enable this in scenarios where there is node reuse in views like lists.
image-config
Android
Clay
1.4
ARGB_8888
: 32-bit memory per pixel, supports semi-transparent images.
RGB_565
: 16-bit memory per pixel, reduces memory usage but loses transparency.
Support PC platform since 3.5
Affects the actual memory usage of the image bitmap.
Taking an image with a resolution of 1024*768 as an example, the actual memory usage is (1024 * 768 * bits per pixel / 8) Bytes.
The default is ARGB_8888. Frontend developers can optimize image memory usage by setting it to RGB_565.
ARGB_8888
: Each pixel occupies 32 bits of memory and includes an alpha channel.
RGB_565
: Each pixel occupies 16 bits of memory, which reduces memory usage but results in the loss of transparency.
Setting RGB_565 may affect the display of
<image>
's border-radius. You can set border-radius on the parent view of the
<image>
and add the clip-radius attribute to the parent view.
It is not recommended to use RGB_565 when mode="aspectFit", as it may cause black borders in the cropped area.
loop-count
Android
iOS
Clay
Harmony
1.4
Number of times an animated image plays, 0 stands for infinite
mode
Android
iOS
Clay
Harmony
0.2
Specifies image cropping/scaling mode
scaleToFill
: Scales the image without preserving the aspect ratio, stretching the image to fill the element.
aspectFit
: Scales the image while preserving aspect ratio so that the long side is fully visible.
aspectFill
: Scales the image while preserving aspect ratio, ensuring the short side fills the element.
center
: Does not scale the image; image is centered.
placeholder
Android
iOS
Clay
Harmony
1.4
Placeholder image, used same as src
prefetch-height
Android
iOS
1.4
Image won't load if its size is 0, but will load if prefetch-height is set
prefetch-width
Android
iOS
1.4
Image won't load if its size is 0, but will load if prefetch-width is set
src
Android
iOS
Clay
Harmony
0.2
Supports http/https/base64
tint-color
Android
iOS
Clay
Harmony
2.12
Changes the color of all non-transparent pixels to the tint-color specified. The value is a
<color>
.
Events
Frontend can bind corresponding event callbacks to listen for runtime behaviors of the element, as shown below.
bindcurrentloopcomplete
Android
iOS
Harmony
3.7
Triggered when one loop of the animated image finishes playing.
binderror
Android
iOS
Clay
Harmony
0.2
Image load error event
bindfinalloopcomplete
Android
iOS
Harmony
3.7
Triggered when the animated image finishes playing all
loop-count
loops. If
loop-count
is not set, this callback will not be triggered.
bindload
Android
iOS
Clay
Harmony
0.2
Image load success event
bindstartplay
Android
iOS
Harmony
3.7
Triggered when the animated image starts playing.
Methods
Frontend can invoke component methods via the SelectorQuery API.
pauseAnimation
Android
iOS
Clay
Harmony
2.11
Pauses the animation, without resetting the loop-count.
resumeAnimation
Android
iOS
Clay
Harmony
2.11
Resumes the animation, without resetting the loop-count.
startAnimate
Android
iOS
Clay
Harmony
Deprecated
Restart the animation playback method controlled by the front end, and the animation playback progress and loop count will be reset.
stopAnimation
Android
iOS
Clay
Harmony
2.11
Stops the animation, and it will reset the loop-count.
Advanced Features
Request URL Redirection Mapping
Feature Description
By implementing a URL redirection mechanism, developers can intercept specific image URLs and map them to specific resource paths. This ability is useful for the following scenarios:
- Improving static resource loading speed
- Supporting custom image protocol access schemes
- Protecting sensitive resource access paths
Implementation Principle
This feature is implemented based on the MediaResourceFetcher interface, with the core process divided into two stages:
-
Resource Type Detection (
isLocalResource)- Determines if the request URL matches the custom protocol
- Returns a boolean indicating whether to handle it locally
-
Path Conversion (
shouldRedirectUrl)- Parses the original URL
- Converts it into a valid resource path
- Returns the final accessible URL address
The following example shows how to map a URL like http://localhost/xxx to an app's built-in resource path:
Read the API reference of MediaResourceFetcher for more details.
Compatibility
LCD tables only load in the browser