HarmonyOS PixelMap加载图片?

我把网络地址转成PixelMap之后,gif不是动态的了,要怎么处理?

阅读 583
1 个回答

方式一:直接使用本地uri展示 – 可以展示gif动态效果

this.imageUrl = fileUri.getUriFromPath(tempPath);

方式二:本地文件转为pixelMap展示

let file = fileIo.openSync(tempPath, fileIo.OpenMode.READ_ONLY);
let imageSource: image.ImageSource = image.createImageSource(file.fd);
let opts: image.InitializationOptions = {
  editable: false,
  pixelFormat: image.PixelMapFormat.RGBA_8888,
  alphaType: 0,
  size: { height: 100, width: 100 }
}
this.imageUrl1 = await imageSource.createPixelMap(opts);
}).catch((err: BusinessError) => {
  console.error(`Invoke downloadTask failed, code is ${err.code}, message is ${err.message}`);
});
} catch (error) {
  console.error(`Invoke downloadFile failed, error is ${JSON.stringify(error)}`);
}
}
}