1

我正在开发一个画布上传脚本来为客户上传巨大的图像。除了一个问题,我的一切都按需要工作。巨大的图像不起作用。目标是能够上传大约 20000x20000 的图像。

大约 15000x15000 的图像可以正常工作,但更大的则不行。结果甚至不一致。大多数情况下它们只是变黑,但有时浏览器会停止并给出它停止工作的页面。

var oc = document.createElement('canvas'), octx = oc.getContext('2d');
oc.width = img.width;
oc.height = img.height;

var iStep = .9;

while (oc.width * iStep > width) {
        oc.width *= iStep;
        oc.height *= iStep;
    octx.drawImage(img, 0, 0, img.width, img.height, 0, 0, oc.width, oc.height);
    console.log('Resized to: height: ' + oc.height + '; width: '+oc.width);

}

oc.width = width;
oc.height = oc.width * img.height / img.width;

octx.drawImage(img, 0, 0, oc.width, oc.height);

sDataString = oc.toDataURL("image/jpeg", .8);

// Followed by an ajax upload

上传的图像大多是质量在 20k 左右的艺术品。

你们知道如何解决黑色图像吗?

4

0 回答 0