HarmonyOS 现在是否支持图片的快速旋转绘制?

如题:HarmonyOS 现在是否支持图片的快速旋转绘制?

阅读 369
1 个回答

参考下这个demo:

import { image } from '@kit.ImageKit';
import { resourceManager } from '@kit.LocalizationKit';

@Entry
@Component
struct Index {
  @State angle: number = 0
  @State pixelMap?: image.PixelMap = undefined
  async aboutToAppear(): Promise<void> {
    let decodingOptions: image.DecodingOptions = {
      editable: true,
      desiredPixelFormat: 3,
    }
    const rawFileDescriptor: resourceManager.RawFileDescriptor = await getContext(this).resourceManager.getRawFd('startIcon.png');
    const imageSource: image.ImageSource = image.createImageSource(rawFileDescriptor);
    this.pixelMap = await imageSource.createPixelMap(decodingOptions)
  }

  build() {
    Column() {
      Image(this.pixelMap)
        .width(200)
        .height(200)
        .rotate({
          angle: this.angle,
        })
      Button("旋转+").onClick(async ()=>{
        this.angle += 10
      })
      Button("旋转-").onClick(async ()=>{
        this.angle -= 10
      })
    }
  }
}
logo
HarmonyOS
子站问答
访问
宣传栏