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)
},