ts-components-canvas-imagebitmap.md 1.4 KB
Newer Older
Z
zengyawen 已提交
1
# ImageBitmap
Z
zengyawen 已提交
2

E
esterzhou 已提交
3
An **ImageBitmap** object stores pixel data rendered on a canvas.
Z
zengyawen 已提交
4

E
esterzhou 已提交
5 6 7
> **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.
Z
zengyawen 已提交
8 9 10



Z
zengyawen 已提交
11
## Attributes
Z
zengyawen 已提交
12

E
esterzhou 已提交
13
| Name| Type| Description| 
Z
zengyawen 已提交
14
| -------- | -------- | -------- |
E
esterzhou 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| width | number | Pixel width of the **ImageBitmap** object.| 
| height | number | Pixel height of the **ImageBitmap** object.| 

**Example**

  ```ts
  // 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%')
    }
  }
  ```

  ![en-us_image_0000001194352442](figures/en-us_image_0000001194352442.png)

E
ester.zhou 已提交
47 48 49 50 51 52 53 54 55 56


## Methods


### close

close()

Releases all graphics resources associated with this **ImageBitmap** object. This API is a void API.