小程序使用canvasToTempFilePath时,报错 not supported?
const query = uni.createSelectorQuery() query.select('#imageCanvas').fields({ node: true, size: true }).exec((res) => { console.log('res',res); // Canvas 对象 const canvas = res[0].node // 渲染上下文 const ctx = canvas.getContext('2d') const width = res[0].width const height = res[0].height // 初始化画布大小 const dpr = uni.getWindowInfo().pixelRatio canvas.width = width * dpr canvas.height = height * dpr // ctx.scale(dpr, dpr) // 图片对象 const image = canvas.createImage() // 图片加载完成回调 image.onload = () => { console.log('ctx', ctx); // 将图片绘制到 canvas 上 // ctx.drawImage(image, 0, 0, appStore.$state.systemInfo.windowWidth * dpr, appStore.$state.systemInfo.windowHeight * dpr) ctx.drawImage(image,200,400, 500, 500, 200, 400,500,500) setTimeout(async function () { console.log('canvas', canvas); // ctx.fillStyle = 'rgba(0, 0, 200, 0.5)'; // ctx.fillRect(30, 30, 50, 50); uni.canvasToTempFilePath({ //裁剪对参数 canvasId: "imageCanvas", canvas:{type:'2d'}, x: image_x, //画布x轴起点 y: image_y, //画布y轴起点 width: image_width, //画布宽度 height: image_height, //画布高度 destWidth: image_width, //输出图片宽度 destHeight: image_height, //输出图片高度 success: function (res) { console.log('图片', res); //清除画布上在该矩形区域内的内容。 // that.canvas.clearRect(0, 0, that.data.width, that.data.height) // that.canvas.drawImage(res.tempFilePath, image_x, image_y, image_width, image_height) // that.canvas.draw() uni.hideLoading() console.log(res.tempFilePath); }, fail: function (e) { console.log('失败了', e); uni.hideLoading() uni.showToast({ title: '出错啦...', icon: 'loading' }) } }); }, 5000); } image.src = src.value }); canvasToTempFilePath提示 {"errMsg": "canvasToTempFilePath:fail :not supported"}