createImage: function(){
let imageWidth = this.data.imageWidth,
imageHeight = this.data.imageHeight;
wx.canvasToTempFilePath({ //将canvas生成图片
canvasId: 'gameCanvas',
x: 0,
y: 0,
width: imageWidth,
height: imageHeight,
destWidth: imageWidth, //截取canvas的宽度
destHeight: imageHeight, //截取canvas的高度
success: function (res) {
wx.saveImageToPhotosAlbum({ //保存图片到相册
filePath: res.tempFilePath,
success: function () {
wx.showToast({
title: "生成图片成功!",
duration: 2000
})
}
})
}
})
}
微信小程序canvas生成图片并保存本地
于 2021-10-30 10:06:53 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)