harmony 鸿蒙ImageBitmap对象

  • 2022-08-09
  • 浏览 (487)

ImageBitmap对象

ImageBitmap对象可以存储canvas渲染的像素数据。

说明:

从 API Version 8 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。

接口

ImageBitmap(src: string)

从API version 9开始,该接口支持在ArkTS卡片中使用。

参数:

参数名 参数类型 必填 默认值 参数描述
src string - 图片的数据源支持本地图片。
1、string格式用于加载本地图片,例如ImageBitmap(“common/images/example.jpg”),图片加载路径的起点为ets文件夹。
2、支持本地图片类型:bmp、jpg、png、svg和webp类型。
说明:
- ArkTS卡片上不支持http://等网络相关路径前缀、datashare://路径前缀以及file://data/storage路径前缀的字符串。

属性

属性 类型 描述
width number ImageBitmap的像素宽度,当前值为0。
从API version 9开始,该接口支持在ArkTS卡片中使用。
height number ImageBitmap的像素高度,当前值为0。
从API version 9开始,该接口支持在ArkTS卡片中使用。

示例:

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

zh-cn_image_0000001194352442

方法

close

close()

释放ImageBitmap对象相关联的所有图形资源,并讲ImageBitmap对象的宽高置为0。

从API version 9开始,该接口支持在ArkTS卡片中使用。

你可能感兴趣的鸿蒙文章

harmony 鸿蒙基于ArkTS的声明式开发范式

harmony 鸿蒙@ohos.arkui.advanced.Counter(计数器组件)

harmony 鸿蒙@ohos.arkui.advanced.SegmentButton(分段按钮)

harmony 鸿蒙@ohos.multimedia.avCastPicker (投播组件)

harmony 鸿蒙属性动画

harmony 鸿蒙枚举说明

harmony 鸿蒙Blank

harmony 鸿蒙Button

harmony 鸿蒙CalendarPicker

harmony 鸿蒙Checkbox

0  赞