// 保存图片至相册
			saveImg() {
				//获取文件管理器对象
				const fs = wx.getFileSystemManager()
				//文件保存路径
				const Imgpath = wx.env.USER_DATA_PATH + '/qrcodeImg' + '.png'
				//base64图片文件
				let imageSrc = this.src.replace(/^data:image\/\w+;base64,/, '')

				//写入本地文件
				fs.writeFile({
					filePath: Imgpath,
					data: imageSrc,
					encoding: 'base64',
					success(res) {
						console.log(res)

						//保存到手机相册
						wx.saveImageToPhotosAlbum({
							filePath: Imgpath,
							success(res) {
								console.log(res)
								wx.showToast({
									title: '保存成功',
									icon: 'success'
								})
							},
							fail: function(err) {
								console.log("失败了")
								console.log(err)
							}
						})
					}
				})
			}
posted on 2022-01-21 22:35  无聊猿  阅读(227)  评论(0编辑  收藏  举报