Before this tried to transfer the base64 picture to the canvas and then save to the phone, but the real machine debugging does not support this way, I hope you do not go to the soup pit

Here’s how it works: Scene is base64, print the following:



No nonsense, directly on the code :(there is code description at the end)

var aa = wx.getFileSystemManager(); console.log('that.data.scene:', that.data.scene) aa.writeFile({ filePath:wx.env.USER_DATA_PATH+'/test.png', data: that.data.scene.slice(22), encoding:'base64', success: res => { wx.saveImageToPhotosAlbum({ filePath: Wx.env. USER_DATA_PATH + '/test.png', success: function (res) {wx.showtoast ({title: 'save successful ',})}, fail: function (err) { console.log(err) } }) console.log(res) }, fail: err => { console.log(err) } })Copy the code

Code parsing:

Wx.getfilesystemmanager () is to get the file manager object;

Aa. WriteFile is a writeFile. For details, click the official document.

Wx.env. USER_DATA_PATH+ ‘/test.png’ Here is the name of the file to create a temporary file.

That.data.scene. Slice (22) The base64 element is removed. It is important to note that after removing this element, the base64 encoding in the SRC of the image component will not display the image.

Wx saveImageToPhotosAlbum is save images to the photo album

writeFile