我有这样的画布:
<canvas width="640" height="640" id="canvas"></canvas>
我想获取此画布的内容,然后将其缩小5倍至128x128(然后以某种方式发送到我的服务器)
我尝试执行以下操作,但是最终只能得到一张空白画布:
var image = new Image();
image.src = document.getElementById("canvas").toDataURL(); //getting contents of original canvas
var canvas = document.createElement('canvas'); //new canvas to resize original into
var ctx = canvas.getContext('2d');
canvas.width=128
canvas.height=128
ctx.drawImage(image, 0, 0, 128, 128);
document.body.appendChild(canvas); //always blank
编辑: “重复”问题链接已断开