
let sysInfo = wx.getSystemInfoSync(),width =sysInfo.windowWidth,height =sysInfo.windowHeight;
canvas.style.width = width + "px";
canvas.style.height = height + "px";
canvas.height = height * window.devicePixelRatio;
canvas.width = width * window.devicePixelRatio;
ctx.scale(window.devicePixelRatio, window.devicePixelRatio);

本文介绍了一种使用微信开发者工具获取设备屏幕尺寸,并据此调整canvas画布大小的方法。通过调用wx.getSystemInfoSync()同步获取窗口宽度和高度,然后设置canvas的宽高样式及实际尺寸,并应用设备像素比进行缩放。
3039





