使用canvas.createImage在ios真机调试时加载不出图片?
开发者工具没问题,ios真机调试一直报undefined! ios版本:17.4.1 微信版本:8.0.47 基础库版本:3.4.3 代码片段:https://developers.weixin.qq.com/s/C58NUbmx7yR3 const query = wx.createSelectorQuery()
query.select('#myCanvas')
.fields({ node: true, size: true,style :true})
.exec((res)=>{
const canvas = res[0].node
const ctx = canvas.getContext('2d')
// 1.设置画布大小
canvas.width = res[0].width
canvas.height = res[0].height
// 2.复制图片到画布
const imgObj = canvas.createImage()
imgObj.src = 'https://img0.baidu.com/it/u=1956177774,56494919&fm=253&fmt=auto&app=138&f=JPEG?w=190&h=190'
imgObj.onerror = ((res)=>{
console.log(res);
})
imgObj.onload = (res)=>{
console.log(res); // 这里报undefined
const i_wid = canvas.width
const i_hei = i_wid * res.path[0].height / res.path[0].width
// drawImage(imageResource, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight)
ctx.drawImage(imgObj , 0 ,0 ,res.path[0].width , res.path[0].height , 0, canvas.height - i_hei ,canvas.width,i_hei)
}