中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
返回的网络图片链接,怎么创建图片实例
微信扫码分享
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!") } } }) }