收藏
回答

wx.canvasToTempFilePath() 回调函数不输出

问题模块 框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
API和组件 小程序 Bug wx.canvasToTempFilePath() 工具 1.02.1911262 2.9.3
watermark() {
        let url = "https://wx.qlogo.cn/mmhead/Q3auHgzwzM5BbJAtWj9oGjSzLsqLaZSs43YWw1pSdPm2Zqrkoug9ibg/0"
        wx.getImageInfo({
            src: url,
            success: (res) => {
                console.log("获取详情成功", res)
                let ctx = wx.createCanvasContext('firstCanvas')
                this.setData({
                    canvasHeight: res.height,
                    canvasWidth: res.width
                })
                //将图片src放到cancas内,宽高为图片大小
                ctx.drawImage(url, 0, 0, res.width, res.height)
                //将声明的时间放入canvas
                ctx.setFontSize(30) //注意:设置文字大小必须放在填充文字之前,否则不生效
                ctx.setFillStyle('grey')
                ctx.fillText("水印", 0, 30)
                ctx.strokeText("水印", 0, 30)
                ctx.draw(false, (e) => {
                    console.log(e)
                    // 该通过函数将canvas绘制导出为图片          
                    wx.canvasToTempFilePath({
                        x: 0,
                        y: 0,
                        quality:1,
                        width: this.data.canvasWidth,
                        height: this.data.canvasHeight,
                        canvasId: "firstCanvas",
                        success: function(res) {
                            console.log(res);
                            console.log(res.tempFilePath);
                        },
                        fail: function(err) {
                            console.log(err)
                        },
                        complete: function(e){
                            console.log(e)
                        }
                    });
                })
            },
            fail: err => {
                console.log(err)
            }
        })
    },

回调里的log都没有输出 页面也不报错


最后一次编辑于  11-27
回答关注问题邀请回答
收藏

1 个回答

问题标签