HarmonyOS 如何将jpeg Uint8Array 转为ui展示image

HarmonyOS
2024-12-25 16:10:00
1015浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

参考此文档 https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-image-V5#writebuffertopixels7

或者另一种 demo

fn1() {
  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)
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
分享
微博
QQ
微信
回复
2024-12-25 18:43:09
相关问题
HarmonyOS 如何将Uint8Array转为ArrayBuffer
653浏览 • 1回复 待解决
如何将字符串转为Uint8Array
1886浏览 • 1回复 待解决
如何将Uint8Array转ArrayBuffer?
1100浏览 • 1回复 待解决
HarmonyOS 如何将Uint8Array转成ArrayBuffer
1132浏览 • 1回复 待解决
如何将Uint8Array转字符串?
1468浏览 • 1回复 待解决
Uint8Array 如何直接转为String or Json
3810浏览 • 1回复 待解决
HarmonyOSUint8Array
861浏览 • 1回复 待解决
Uint8Array如何转成ArrayBuffer
2302浏览 • 1回复 待解决
HarmonyOS ArrayBuffer如何转成Uint8Array
962浏览 • 1回复 待解决
HarmonyOS string转Uint8Array
954浏览 • 2回复 待解决
HarmonyOS 录音发送Uint8Array
630浏览 • 1回复 待解决
ArrayBuffer怎么转Uint8Array
1269浏览 • 1回复 待解决
HarmonyOS Uint8Array转16进制
833浏览 • 2回复 待解决
Uint8Array是@Sendable类吗?
1002浏览 • 1回复 待解决
HarmonyOS Uint8Array怎么正确转ArrayBuffer
2416浏览 • 1回复 待解决
HarmonyOS List<number>怎么转Uint8Array
839浏览 • 1回复 待解决
HarmonyOS string怎么与Uint8Array互转?
1796浏览 • 1回复 待解决
HarmonyOS uint8Array转字符串
1069浏览 • 1回复 待解决
HarmonyOS socket.TLSSocket发送Uint8Array对象
635浏览 • 1回复 待解决