rendering

Pay attention to the point

Canvas needs to get the small program code picture before drawing. At present, the small program code picture can be obtained by downloadFile and fs.writeFile

  • When reading applets via fs.writeFile, pay attention to data: ArrayBuffer format. Therefore, when requesting server, set responseType to ArrayBuffer and read binary data through Base64 encoding to get applets image.
  • Note that the name of the image is designed randomly when you temporarily save the applets, otherwise the new applets may not overwrite the previous error.

The following code requests the service interface

wx.request({
    url: '',
    data: data,
    header: {},
    responseType: 'ArrayBuffer'
})
Copy the code

Gets a small program code picture

const tmpPath = wx.env.USER_DATA_PATH + "/" + Date.now() + "wxcode.png" wx.getFileSystemManager().writeFile({ filePath: tmpPath, data: imgData, encoding: 'base64', success: Const CTX = wx.createcanvasContext ('sCanvas',this) ctx.drawImage(tmpPath,0,0,0)}})Copy the code