个人案例
微商店助手
一机在手,生意到手。
微商店助手扫码体验
切换一下基础库就行了。我真是服了,排查了一天,最后发现是基础库问题。 开始用的是 2.18.1,不管用什么样的姿势,都是报这个错。 后面换成 2.20.3,好了。 再切回 2.18.1,又报错。 可以断定是基础库的问题了。
TypeError: Failed to execute 'drawImage' 报错?下面是我的代码,想通过wx.getImageInfo获取网络图片后,然后用drawImage在canvas上将图片显示出来,但是一直报错。 代码如下: onShow: function () { var that = this const query = wx.createSelectorQuery() query.select('#shareCanvas') .fields({ node: true, size: true }) .exec((res) => { const canvas = res[0].node const ctx = canvas.getContext('2d') const dpr = wx.getSystemInfoSync().pixelRatio canvas.width = res[0].width * dpr canvas.height = res[0].height * dpr ctx.scale(dpr, dpr) wx.getImageInfo({ src: that.data.photoUrl, success(res) { console.log("头像路径:"+res.path) ctx.drawImage(res.path, 0, 0) ctx.draw() } }) }) }, 报错信息如下: thirdScriptError 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 api getImageInfo success callback function TypeError: 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 CanvasRenderingContext2D.e.drawImage (http://127.0.0.1:51536/appservice/__dev__/WAService.js:2:647372) at success (http://127.0.0.1:51536/appservice/pages/card/img.js:47:15) at Function.o.<computed> (http://127.0.0.1:51536/appservice/__dev__/WAService.js:2:1366445) at Object.success (http://127.0.0.1:51536/appservice/__dev__/WAService.js:2:124200) at y (http://127.0.0.1:51536/appservice/__dev__/WAService.js:2:526317) at v (http://127.0.0.1:51536/appservice/__dev__/WAService.js:2:526555) at http://127.0.0.1:51536/appservice/__dev__/WAService.js:2:528109 at n.<anonymous> (http://127.0.0.1:51536/appservice/__dev__/asdebug.js:1:12078) at http://127.0.0.1:51536/appservice/__dev__/WAService.js:2:124200 at http://127.0.0.1:51536/appservice/__dev__/WAService.js:2:107123
2022-05-18切换一下基础库就行了。我真是服了,排查了一天,最后发现是基础库问题。 开始用的是 2.18.1,不管用什么样的姿势,都是报这个错。 后面换成 2.20.3,好了。 再切回 2.18.1,又报错。 可以断定是基础库的问题了。
2d的canvas,wx.canvasToTempFilePath报错drawImage同一段代码,在三种情况下的报错 模拟器调试:代码中没使用drawImage,但是调用wx.canvasToTempFilePath就报错, 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)' 预览:canvasToTempFilePath:fail invalid viewId 真机调试:Unhandled promise rejection TypeError: r.Canvas is not a constructor wxml: canvas type="2d" id="testCanvas">/canvas> js: onReady: function () { console.log("here") const query=wx.createSelectorQuery() query.select("#testCanvas").fields({node:true, size:true}, function(res){ console.log("here2", res) var canvas=res.node var ctx=canvas.getContext('2d') const dpr = wx.getSystemInfoSync().pixelRatio canvas.width = res.width * dpr canvas.height = res.height * dpr ctx.scale(dpr, dpr) ctx.fillRect(0, 0, 100, 100) wx.canvasToTempFilePath({ canvas: "textCanvas", success:function(cttfp){ console.log("here3", cttfp) }, fail:function(cttfp){ console.error("饼图绘制失败", cttfp) } }) }).exec() },
2022-05-18切换一下基础库就行了。我真是服了,排查了一天,最后发现是基础库问题。 开始用的是 2.18.1,不管用什么样的姿势,都是报这个错。 后面换成 2.20.3,好了。 再切回 2.18.1,又报错。 可以断定是基础库的问题了。
wx.canvasToTempFilePath报错,怎么解决?let that = this let imageInfo = await App.wxp.getImageInfo({ src: "https://xxx.com/files/sharePoster.jpg" }); console.log("图片信息", imageInfo); if (imageInfo.path) { // 创建离屏画布 let canvas = wx.createOffscreenCanvas({ type: '2d', width: imageInfo.width, height: imageInfo.height }); console.log("canvas", canvas); let context = canvas.getContext('2d') // 创建海报图片 const sharePoster = canvas.createImage() sharePoster.src = imageInfo.path sharePoster.onload = e => { // 把图片画到离屏 canvas 上 context.clearRect(0,0, canvas.width, canvas.height); context.drawImage(sharePoster, 0, 0, imageInfo.width, imageInfo.height, 0, 0, imageInfo.width, imageInfo.height); let base64 = context.canvas.toDataURL('image/png'); console.log(base64); // base64可以正常显示图片 that.setData({ src: base64, invite: true }) setTimeout(() => { // 报错: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)' wx.canvasToTempFilePath({ canvas: canvas, // canvas type="2d" 时使用该属性 complete(res) { console.log("tempFilePath", res); } }, that) // 有无this都会报错 }, 1000); } } 小程序调用wx.canvasToTempFilePath报错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) 开发者工具版本:稳定版1.05.2204180(windows)调试基础库版本:2.24.0
2022-05-18切换一下基础库就行了。我真是服了,排查了一天,最后发现是基础库问题。 开始用的是 2.18.1,不管用什么样的姿势,都是报这个错。 后面换成 2.20.3,好了。 再切回 2.18.1,又报错。 可以断定是基础库的问题了。
createOffscreenCanvas 无法保存到本地?基础库 2.17.0,最新版开发工具 createOffscreenCanvas 生成的 canvas ,调用 wx.canvasToTempFilePath,提示 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),请问怎么办? https://developers.weixin.qq.com/s/wKmn7Vmn7GqI
2022-05-18切换一下基础库就行了。我真是服了,排查了一天,最后发现是基础库问题。 开始用的是 2.18.1,不管用什么样的姿势,都是报这个错。 后面换成 2.20.3,好了。 再切回 2.18.1,又报错。 可以断定是基础库的问题了。
createOffscreenCanvas 如何使用?canvasToTempFilePath报错1、使用离屏 定义如下 const canvas = wx.createOffscreenCanvas({ type: '2d', width: canvasWidth, height: canvasHeight }) const canvasCtx = canvas.getContext('2d') 2、顺利生成 let res = canvasCtx.createImageData(canvasWidth,canvasHeight) (一点也不顺利的 结果 ) res 的 值{data: Uint8ClampedArray(1216500), width: 375, height: 811, dataUnion: Uint8ClampedArray(1216500)} 3、问题1 我要怎么用这个数据呢? 4、也无法存下图片,这一步报错 wx.canvasToTempFilePath({ x: 0, y: 0, width: canvasWidth, height: canvasHeight, destWidth: canvasWidth, destHeight: canvasHeight, canvas: canvas, success(res) { console.log(res.tempFilePath) } }) wx.canvasToTempFilePath 这一步的报错信息如下 VM282 WAService.js:2 TypeError: 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)'
2022-05-18切换一下基础库就行了。我真是服了,排查了一天,最后发现是基础库问题。 开始用的是 2.18.1,不管用什么样的姿势,都是报这个错。 后面换成 2.20.3,好了。 再切回 2.18.1,又报错。 可以断定是基础库的问题了。
createOffscreenCanvas 生成的canvas实例无法保存至本地?const canvas = wx.createOffscreenCanvas({type: '2d', width: 750, height: 1334}) wx.canvasToTempFilePath({ canvas: canvas, success: (resss) => { }, fail: function(err) { console.log(err) } }) 报错: TypeError: 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)' 开发工具, 调试基础库 2.17.0
2022-05-18切换一下基础库就行了。我真是服了,排查了一天,最后发现是基础库问题。 开始用的是 2.18.1,不管用什么样的姿势,都是报这个错。 后面换成 2.20.3,好了。 再切回 2.18.1,又报错。 可以断定是基础库的问题了。
使用新版的canvas合成海报的问题?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)' TypeError: 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)' 这个错误啥意思啊,不懂?在线等大佬
2022-05-18切换一下基础库就行了。我真是服了,排查了一天,最后发现是基础库问题。 开始用的是 2.18.1,不管用什么样的姿势,都是报这个错。 后面换成 2.20.3,好了。 再切回 2.18.1,又报错。 可以断定是基础库的问题了。
如何在上传图片前对图片进行裁剪?hi,如题,我想在上传图片前对图片进行裁剪,但是我用 ctx.drawImage(tempFilePaths[0], 0, 0, 90, 80); 类似这种方法报如下错误: 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 TypeError: 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)' 请教大佬有没有简单一点的方法?
2022-05-18切换一下基础库就行了。我真是服了,排查了一天,最后发现是基础库问题。 开始用的是 2.18.1,不管用什么样的姿势,都是报这个错。 后面换成 2.20.3,好了。 再切回 2.18.1,又报错。 可以断定是基础库的问题了。
Failed to execute 'drawImage' on 'CanvasRenderin ?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 TypeError: 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)'
2022-05-18切换一下基础库就行了。我真是服了,排查了一天,最后发现是基础库问题。 开始用的是 2.18.1,不管用什么样的姿势,都是报这个错。 后面换成 2.20.3,好了。 再切回 2.18.1,又报错。 可以断定是基础库的问题了。
新的canvas的drawImage不支持本地tmp路径的临时文件吗?【貌似官方修复了这个问题。现在可以了。】 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
2022-05-18