我希望先将文件中的图像转换为jpeg,然后再上传到正在构建的网站中。但是,此转换必须在drawImage之前进行,因为drawImage需要花费很长时间才能上载png文件。
var canvas = $("<canvas></canvas>").appendTo(rowWithAllData.children("td.ui-fileupload-preview")),
canvasCtx = canvas.get(0).getContext("2d", {alpha: false}),
fileURL = window.URL || window.webkitURL,
f = fileURL.createObjectURL(file),
img = new Image();
img.onload = function() {
for (var x = 0; x < 4; x++) {
for (var y = 0; y < 4; y++) {
tempCtx.drawImage(img, Math.ceil(x*img.width/4), Math.ceil(y*img.height/4), Math.ceil(img.width/4), Math.ceil(img.height/4), Math.ceil(x*width/4), Math.ceil(y*height/4), Math.ceil(width/4), Math.ceil(height/4))
}
}
img.src = f;