W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
ImageData對象可以存儲canvas渲染的像素數(shù)據(jù)。
從 API Version 8 開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標單獨標記該內(nèi)容的起始版本。
屬性 | 類型 | 描述 |
---|---|---|
width | number | 矩形區(qū)域?qū)嶋H像素寬度,單位為px。 從API version 9開始,該接口支持在ArkTS卡片中使用。 |
height | number | 矩形區(qū)域?qū)嶋H像素高度,單位為px。 從API version 9開始,該接口支持在ArkTS卡片中使用。 |
data | Uint8ClampedArray | 一維數(shù)組,保存了相應的顏色數(shù)據(jù),數(shù)據(jù)值范圍為0到255。 從API version 9開始,該接口支持在ArkTS卡片中使用。 |
可使用px2vp接口進行單位轉(zhuǎn)換。
示例:
- // xxx.ets
- @Entry
- @Component
- struct Translate {
- private settings: RenderingContextSettings = new RenderingContextSettings(true)
- private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
- private img:ImageBitmap = new ImageBitmap("/common/images/1234.png")
- 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,130,130)
- var imagedata = this.context.getImageData(50,50,130,130)
- this.context.putImageData(imagedata,150,150)
- })
- }
- .width('100%')
- .height('100%')
- }
- }
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: