使用新版canvas绘制模拟器保存的图片正常,在真机上尺寸变大,怎么解决?
wx.createSelectorQuery().select('#code').fields({ node: true, size: true }).exec((res) => { // Canvas 对象 var canvas = res[0].node // Canvas 画布的实际绘制宽高 var renderWidth = res[0].width var renderHeight = res[0].height // Canvas 绘制上下文 var ctx = canvas.getContext('2d') // 初始化画布大小 var dpr = wx.getWindowInfo().pixelRatio canvas.width = renderWidth * dpr canvas.height = renderHeight * dpr ctx.scale(dpr, dpr) // 清空画布 ctx.clearRect(0, 0, canvas.width, canvas.height)