harmony 鸿蒙ImageBitmap
ImageBitmap
An ImageBitmap object stores pixel data rendered on a canvas.
NOTE
The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
APIs
ImageBitmap(src: string)
Since API version 9, this API is supported in ArkTS widgets.
Parameters
Name | Type | Mandatory | Default Value | Description |
---|---|---|---|---|
src | string | Yes | - | Image source. Local images are supported. 1. The string format is used to load local images, for example, ImageBitmap(“common/images/example.jpg”). The start point of the image loading path is the ets folder. 2. Supported image formats: bmp, jpg, png, svg, and webp. NOTE ArkTS widgets do not support the strings with the http://, datashare://, or file://data/storage. |
Attributes
Name | Type | Description |
---|---|---|
width | number | Pixel width of the ImageBitmap object. The current value is 0. Since API version 9, this API is supported in ArkTS widgets. |
height | number | Pixel height of the ImageBitmap object. The current value is 0. Since API version 9, this API is supported in ArkTS widgets. |
Example
// xxx.ets
@Entry
@Component
struct ImageExample {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
private img:ImageBitmap = new ImageBitmap("common/images/example.jpg")
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
.width('100%')
.height('100%')
.backgroundColor('#ffff00')
.onReady(() =>{
this.context.drawImage( this.img,0,0,500,500,0,0,400,200)
})
}
.width('100%')
.height('100%')
}
}
Methods
close
close()
Releases all graphics resources associated with this ImageBitmap object and sets its width and height to 0.
Since API version 9, this API is supported in ArkTS widgets.
你可能感兴趣的鸿蒙文章
harmony 鸿蒙ArkTS-based Declarative Development Paradigm
0
赞
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦