用cocos creator做微信小游戏截屏

参考文档:https://developers.weixin.qq.com/minigame/dev/document/render/canvas/Canvas.toTempFilePathSync.html


核心代码:

    var canvas = cc.game.canvas;
    var width  = cc.winSize.width;
    var height  = cc.winSize.height;
    canvas.toTempFilePath({
        x: 0,
        y: 0,
        width: width,
        height: height,
        destWidth: width,
        destHeight: height,
        success (res) {
            //.可以保存该截屏图片
            console.log(res)
            wx.shareAppMessage({
                imageUrl: res.tempFilePath
            })
        }
    })


    // let tempFilePath = canvas.toTempFilePathSync({
    //     x: 0,
    //     y: 0,
    //     width: width,
    //     height: height,
    //     destWidth: width,
    //     destHeight: height
    // })
    // wx.shareAppMessage({
    //     imageUrl: tempFilePath
    // })

你可能感兴趣的:(小程序,小游戏)