由于需要使用截图功能,所以使用canvas 画图,再安卓和开发工具上都是正常的,但是再部分ios机型上,画出来的宽度只有原来的5分之3
再drawImage方面中增加图片宽度可以继续延申,目前兼容存在问题
已知机型 iphone 6, iphone 8 , iphone 11
代码如下
<canvas type="2d" id="canvas" style="width: 600rpx; height: 735rpx;"></canvas>
wx.createSelectorQuery().select('#canvas')
.fields({ node: true, size: true })
.exec((res) => {
const canvas = res[0].node
const ctx = canvas.getContext('2d')
const infoSync = wx.getSystemInfoSync()
//const dpr = infoSync.pixelRatio
const dpr = 3
ctx.fillStyle = 'rgba(255, 255, 255, 0)';
const width = infoSync.windowWidth / 750 * 600 * dpr
const height = infoSync.windowHeight / 750 * 735 * dpr
canvas.width = width
canvas.height = height
let img = canvas.createImage()
img.src = background.path
img.onload = ()=>{
ctx.drawImage(img , 0 , 0,width ,height)
}
})