HarmonyOS 通过传入的uri创建图片源实例

返回的网络图片链接,怎么创建图片实例

HarmonyOS
2024-12-27 16:03:03
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu
import { http } from '@kit.NetworkKit'
import ResponseCode from '@ohos.net.http';
import image from '@ohos.multimedia.image';


loadImageWithUrl() {
  // 使用request下载图片
  http.createHttp().request("http:www.tupian.com",
    {
      method:http.RequestMethod.GET,
      connectTimeout:60000,
      readTimeout:60000
    },
    async (error: BusinessError, data: http.HttpResponse) => {
      if (error) {
        console.error(`http reqeust failed with. Code: ${error.code}, message: ${error.message}`);
      } else {
        if (ResponseCode.ResponseCode.OK === data.responseCode) {
          let imageBuffer: ArrayBuffer = data.result as ArrayBuffer;
          //创建图片源实例
          const imageSourceApi: image.ImageSource = image.createImageSource(imageBuffer);
          console.log("图片下载成功")

        } else {
          console.error("error occurred when image downloaded!")
        }
      }
    })
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
分享
微博
QQ
微信
回复
2024-12-27 18:39:57


相关问题
javaUI 中webview通过布局创建实例失败
6432浏览 • 1回复 待解决
HarmonyOS 创建RN实例问题
1125浏览 • 1回复 待解决
HarmonyOS worker创建时会自动创建实例
494浏览 • 1回复 待解决
DataAbilityHelper.creator()创建实例失败
4790浏览 • 1回复 待解决
创建PolarDB实例如何选择网络类型?
3656浏览 • 1回复 待解决
视频播放实例最多创建多少个
3433浏览 • 1回复 待解决