Skip to main content
Version: v3

IMG

Start from API_LEVEL 2.0 . Please refer to API_LEVEL.

img_sample

The image widget is used to display images and supports image rotation.

tip
  1. Recommend using 24-bit or 32-bit png format images with RGB or RGBA color scheme.

Create UI widget

import { createWidget, widget } from '@zos/ui'

const img = createWidget(widget.IMG, Param)

Type

Param: object

PropertiesDescriptionRequiredType
srcThe path of the image. Reference folder-structure structureYESstring
wThe width of the widget.If not passed then set the width of the image itselfNOnumber
hThe height of the widget.If not passed then set the height of the image itselfNOnumber
xThe x-axis coordinate of the widget.YESnumber
yThe y-axis coordinate of the widget.YESnumber
pos_xHorizontal offset of the image relative to the widget coordinates.NOnumber
pos_yVertical offset of the image relative to the widget coordinates.NOnumber
angleThe rotation angle of the picture (the 12-point direction is 0 degrees).NOnumber
center_xThe rotation center of the picture.NOnumber
center_yThe rotation center of the picture.NOnumber
alphaTransparency, 0 - 255, default value is 255 for opaque, 0 for full transparencyNOnumber
auto_scaleWhether the image scales with the widget width and height, the default image area size is the size of the resource file itselfNOboolean
auto_scale_obj_fitThis field takes effect only when auto_scale is true, indicating whether the image fills the entire widget area (without maintaining the image aspect ratio)NOboolean

Image example

caution

w and h are the width and height of the image widget, and the IMG area is the display boundary of the image resource

axis

rotate

Code example

import { createWidget, widget, prop } from '@zos/ui'

Page({
build() {
const img = createWidget(widget.IMG, {
x: 125,
y: 125,
src: 'zeppos.png'
})
img.addEventListener(event.CLICK_DOWN, (info) => {
img.setProperty(prop.MORE, {
y: 200
})
})
}
})
import { createWidget, widget, prop } from '@zos/ui'

Page({
build() {
const img_hour = createWidget(widget.IMG)
img_hour.setProperty(prop.MORE, {
x: 0,
y: 0,
w: 454,
h: 454,
pos_x: 454 / 2 - 27,
pos_y: 50 + 50,
center_x: 454 / 2,
center_y: 454 / 2,
src: 'hour.png',
angle: 30
})
}
})