canvasToImage() { // canvas画布转成图片
var that = this;
wx.canvasToTempFilePath({
quality: 1,
fileType: 'jpg',
canvasId: 'mycanvas',
success: function(res) {
wx.hideLoading();
console.log('图片地址' + res.tempFilePath);
that.setData({
img_temp: res.tempFilePath
})
// wx.previewImage({
// current: res.tempFilePath, // 当前显示图片的http链接
// urls: [res.tempFilePath] // 需要预览的图片http链接列表
// })
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success(res) {
console.log(res);
wx.showModal({
title: '',
content: '图片已保存到相册',
showCancel: false,
confirmText: '好的',
confirmColor: '#72B9C3',
success: function(res) {
if (res.confirm) {
console.log('用户点击确定');
}
}
})
},
fail: function(res) {
if (res.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
wx.openSetting({
success(settingdata) {
console.log(settingdata)
if (settingdata.authSetting['scope.writePhotosAlbum']) {
that.saveImg(); //保存失败尝试再次保存
} else {
console.log('获取权限失败,给出不给权限就无法正常使用的提示')
}
}
})
}
}
})
},
fail: function(res) {
console.log(res)
}
}, this)
},