- 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
2021-05-01 - 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
2021-06-09 - wx.canvasToTempFilePath报错,提示image格式错误?
基础库版本:2.16.1 报错内容: VM1309 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)' 代码段: // 创建离屏 2D canvas 实例 const canvas = wx.createOffscreenCanvas({type: '2d', width: 300, height: 150}) // 获取 context。注意这里必须要与创建时的 type 一致 const context = canvas.getContext('2d') // 创建一个图片 const image = canvas.createImage() // 等待图片加载 await new Promise(resolve => { image.onload = resolve image.src = 'http://1812.img.pp.sohu.com.cn/images/blog/2009/11/18/18/8/125b6560a6ag214.jpg' // 要加载的图片 url }) // 把图片画到离屏 canvas 上 context.clearRect(0, 0, 300, 150) context.drawImage(image, 0, 0, 300, 150) wx.canvasToTempFilePath({ canvas: canvas, quality: 1, success: (res) => { let filePath = res.tempFilePath; //获取图片地址 console.log("filePath:",filePath) } }, this)
2021-05-23 - canvas type为2d时 怎么通过chooseImage获取图片?
旧代码可以直接将 res.tempFilePaths[0] 显示出来 wx.chooseImage({ count: 1, success: (res) => { canvas.drawImage(res.tempFilePaths[0],0,0,150,100); canvas.draw() }, }) canvas type为2d,img.src=res.tempFilePaths[0]无法显示,只能使用本地地址或者网络地址,这个要怎么解决? let img=canvas.createImage; img.src = '../../images/0.png'; img.onload = () => { ctx.drawImage(img,0,0,res[0].width,res[0].height); }
2021-08-02