在HarmonyOS NEXT开发中将byte[] 字节流格式的图片数据,展示到Image组件中?

在HarmonyOS NEXT开发中将byte[] 字节流格式的图片数据,展示到Image组件中?

阅读 545
1 个回答

可以通过将buffer转为PixelMap,然后再加载,示例:

let imageSource = image.createImageSource(buffer) 
let options = {alphaType: 0,                    // 透明度 
  editable: false,                 // 是否可编辑 
  pixelFormat: 3,                  // 像素格式 
  scaleMode: 1,                    // 缩略值 
  size: {height: 100, width: 100}} // 创建图片大小 
imageSource.createPixelMap(options).then((pixelMap) => { 
  this.image = pixelMap 
})