Used to display images

Attributes

auto-size

Android
iOS
Clay
Harmony

2.6

// @defaultValue: false
'auto-size'?: boolean;

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

// @defaultValue: true
autoplay?: boolean;

Specifies whether the animated image should start playing automatically once it is loaded.

blur-radius

Android
iOS
Clay
Harmony

0.2

'blur-radius'?: string;

Image blur radius

cap-insets

Android
iOS
Clay
Harmony

1.4

'cap-insets'?: string;

Stretchable area for 9patch images, in percentage or decimal, four values for top, right, bottom, left

cap-insets-scale

Android
iOS
Clay
Harmony

1.4

// @defaultValue: 1
'cap-insets-scale'?: number;

Adjust the scale of stretchable area for 9patch images

defer-src-invalidation

Android
iOS
Clay
Harmony

2.7

// @defaultValue: false
'defer-src-invalidation'?: boolean;

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
// @defaultValue: "ARGB_8888"
'image-config'?: 'ARGB_8888' | 'RGB_565';

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

loop-count

Android
iOS
Clay
Harmony

1.4

// @defaultValue: 0
'loop-count'?: number;

Number of times an animated image plays, 0 stands for infinite

mode

Android
iOS
Clay
Harmony

0.2

// @defaultValue: 'scaleToFill'
mode?: 'scaleToFill' | 'aspectFit' | 'aspectFill' | 'center';

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?: string;

Placeholder image, used same as src

prefetch-height

Android
iOS
1.4
// @defaultValue: "0px"
'prefetch-height'?: string;

Image won't load if its size is 0, but will load if prefetch-height is set

prefetch-width

Android
iOS
1.4
// @defaultValue: "0px"
'prefetch-width'?: string;

Image won't load if its size is 0, but will load if prefetch-width is set

src

Android
iOS
Clay
Harmony

0.2

// @defaultValue: undefined
src?: string;

Supports http/https/base64

tint-color

Android
iOS
Harmony
2.12
'tint-color'?: string;

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.

binderror

Android
iOS
Clay
Harmony

0.2

binderror = (e: ErrorEvent) => {};

Image load error event

bindload

Android
iOS
Clay
Harmony

0.2

bindload = (e: LoadEvent) => {};

Image load success event

Methods

Frontend can invoke component methods via the SelectorQuery API.

pauseAnimation

Android
iOS
Clay
Harmony

2.11


lynx.createSelectorQuery()
.select('#id')
.invoke({
method: 'pauseAnimation',
success: function (res) {},
fail: function (res) {},
})
.exec();

Pauses the animation, without resetting the loop-count.

resumeAnimation

Android
iOS
Clay
Harmony
2.11

lynx.createSelectorQuery()
     .select('#id')
     .invoke({
      method: 'resumeAnimation',
      success: function (res) {},
      fail: function (res) {},
    })
    .exec();

Resumes the animation, without resetting the loop-count.

startAnimate

Android
iOS
Clay
Harmony
Deprecated

lynx.createSelectorQuery()
.select('#id')
.invoke({
method: 'startAnimate',
success: function (res) {},
fail: function (res) {},
})
.exec();

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

lynx.createSelectorQuery()
     .select('#id')
     .invoke({
      method: 'stopAnimation',
      success: function (res) {},
      fail: function (res) {},
    })
    .exec();

Stops the animation, and it will reset the loop-count.

Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.