参考此文档 https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-image-V5\#writebuffertopixels7或者另一种 demofn1() { let ctx = getContext(this) as common.UIAbilityContext; const resourceMgr: resourceManager.ResourceManager = ctx.resourceManager; // 'ic_poster_style_personal_info2.png' resourceMgr.getRawFileContent('ic_poster_style_personal_info2.png').then((fileData: Uint8Array) => { console.log("Succeeded in getting RawFileContent") // 获取图片的ArrayBuffer const buffer = fileData.buffer.slice(0); const imageSource = image.createImageSource(buffer); this.pixelMap= await imageSource.createPixelMap(decodingOptions) } }).catch((error: BusinessError) => { console.error('Failed to pack the image. And the error is: ' + error); }) }) } Image(this.pixelMap) .border({ width: 1, color: Color.Blue }) .width(200).height(200) .objectFit(ImageFit.None) .backgroundColor(Color.White)
参考此文档 https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-image-V5\#writebuffertopixels7
或者另一种 demo