html2canvas(document.querySelector(“#capture”))。then(canvas => { document.querySelector( “画布布局。”)的appendChild(画布)。});我需要调整此画布的大小(2304x1440像素到230.4x144,…
从html2canvas方法获取canvas对象后,使用其上下文以所需的分辨率再次绘制画布。
比如这样,
function resizeCanvas(canvas, newHeight, newWidth) { var context = canvas.getContext('2d'); var imageData = context.getImageData(0, 0, canvas.width, canvas.width); var newCanvas = document.createElement("canvas"); newCanvas.height = canvas.height; newCanvas.width = canvas.width; newCanvas.putImageData(imageData, 0, 0, 0, 0, newWidth, newHeight); return newCanvas; }