onShareAppMessage使用canvas画图显示不出来
发布于 5 年前 作者 eqiao 14837 次浏览 来自 问答

大神们好,想canvas画图作为onShareAppMessage的imageUrl,但是为啥我的显示不出来呢?帮看看啥问题吧,非常感谢


//调用cropImg这个函数由imgSrc图片生成一个新的图片保存在headShare 全局变量中

cropImg: function(imgSrc) {

    wx.getImageInfo({

        src: imgSrc,

        success: function(ret) {

            var orWidth = ret.width

            var orHeight = ret.height

            ctx.drawImage(imgSrc, 0, orHeight * 1 / 10, orWidth, orHeight * 8 / 1000500400);

            ctx.draw(falsefunction() {

            wx.canvasToTempFilePath({

                canvasId: 'attendCanvasId',

                fileType: 'jpg',

                success: function(resl) {

                    wx.saveFile({//把文件保存到本地

                        tempFilePath: resl.tempFilePath,

                        success: function(res) {

                                headShare = res.savedFilePath

                                console.log(headShare)

                            }

                        })

                    }

                }) //wx.canvasToTempFilePath end

            }) //ctx.draw end

        }

    })

},


//调用onShareAppMessage之前已经生成图片文件并保存到headShare变量中

onShareAppMessage: function(res) {

    console.log(headShare)//可以打印出图片本地路径

    return {

        title: xitieInfo.title,

        path: '/pages/showxitie/showxitie',

        imageUrl: headShare,

        success: function(res) {

            console.log('成功', res)

        },

        fail: function(res) {

               // 转发失败

             console.log('失败', res)

        }

    }

},

5 回复

要先wx.downFile之后的才能绘制,而且draw()之后需要一定时间才能去生成临时路径

wx.canvasToTempFilePath({})  这个保存的图片不就是在本地吗,你还要在保存一次?

真机上能出来吗

cropImg 在哪里调用的呢

回到顶部