【貌似官方修复了这个问题。现在可以了。】
https://developers.weixin.qq.com/miniprogram/dev/api/canvas/CanvasContext.drawImage.html
drawImage( )不支持本地tmp路径的临时文件,谨慎使用,太坑了。
写法1.
```
path = 'tmp/wxf65e9ae5f68283d2.o6zAJs5h4IkyHaGS7_j6gUPGTR9c.arwyj04Eq2ok341457e272957e237fa21d743912f60b.jpg'
ctx.drawImage(path, 0, 0, width, height, 0, 0, canvasWidth, canvasHeight)
```
提示:Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)';at SelectorQuery callback function
写法2.
```
const img = canvas.createImage()
img.src = path
img.onload = () =>{
ctx.drawImage(img, 0, 0, width, height, 0, 0, canvasWidth, canvasHeight)
}
```
提示:tmp/wxf65e9ae5f68283d2.o6zAJs5h4IkyHaGS7_j6gUPGTR9c.arwyj04Eq2ok341457e272957e237fa21d743912f60b.jpg:1 GET http://tmp/wxf65e9ae5f68283d2.o6zAJs5h4IkyHaGS7_j6gUPGTR9c.arwyj04Eq2ok341457e272957e237fa21d743912f60b.jpg net::ERR_PROXY_CONNECTION_FAILED
我也碰到这个问题,模拟器不用代理可以正常画图,真机还是不可以,你们怎么处理的?
这个问题还没解决啊,我也碰到同样的问题
可以存到云服务器,然后
wx.cloud.getTempFileURL
你的写法有问题吧
ctx.fillText(`经办人:${obj.partyAOperator}`,20,1040);
ctx.save();
ctx.beginPath();
let seal = canvas.createImage();
seal.src = '../../resource/image/seal.png';
seal.onload = (res) => {
ctx.drawImage(seal,0, 0, 150, 150);
}
ctx.closePath();
ctx.restore();
ctx.fillText("乙方(电子签名):",20,1080);
我的都没问题受了你方法二的启发
同问,也遇到同样问题
谢邀,可以把图片放到图片服务器再配置合法域名用wx.getImageInfo或wx.downloadFile缓存到本地试试
我也是这个需求,用的写法2,请问怎么解决????