- 解决方法 将canvas放到到dpr倍,然后在将canvas放到css下
const dpr = window.devicePixelRatio;
// Set the "actual" size of the canvas
canvas.width = width * dpr;
canvas.height = height * dpr;
ctx.drawImage(img,0,0,canvas.width,canvas.height)
// Scale the context to ensure correct drawing operations
ctx.scale(dpr, dpr);
// Set the "drawn" size of the canvas
canvas.style.width = `${width}px`;
canvas.style.height = `${height}px`;