当前位置 : 主页 > 手机开发 > 其它 >

用cocos creator做微信小游戏截屏

来源:互联网 收集:自由互联 发布时间:2021-06-13
参考文档: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 .toTempFi

参考文档: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
    // })
网友评论