HarmonyOS PixelMap加载图片?

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

阅读 581
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)}`);
}
}
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进