onLoad: function () {
this.label.string = this.text;
this.scheduleOnce(() => {
if (cc.sys.platform == cc.sys.WECHAT_GAME) {
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 / 2,
destHeight: height / 2,
success: (res) => {
//.可以保存该截屏图片
console.log(res)
// wx.shareAppMessage({
// imageUrl: res.tempFilePath
// })
let tf = res.tempFilePath;
console.log(tf);
wx.getFileSystemManager().saveFile({
tempFilePath: tf,
success: (res) => {
console.log(res.savedFilePath) // res.savedFilePath 为一个本地缓存文件路径
let node = new cc.Node();
let sprite = node.addComponent(cc.Sprite);
cc.find('Canvas').addChild(node, 100);
cc.loader.load(res.savedFilePath, (err, res) => {
if (err) return console.error(err);
console.log(res);
sprite.spriteFrame = new cc.SpriteFrame(res);
});
},
fail: res => {
console.log('err:', res);
}
})
}
})
}
}, 3);
},
