参考下这个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 }) } } }
参考下这个demo: