【发布时间】:2016-01-22 15:14:36
【问题描述】:
我正在尝试使用此功能将图像引导到我的画布中:
function handleImage(e) {
var reader = new FileReader();
reader.onload = function (event) {
var img = new Image();
// img.onprogress = function (e) {
// ProgressPerc = e.loaded / e.total * 100;
// alert(ProgressPerc);
// $('#ProgressBar').css('width', ProgressPerc + '%');
// $("#sp_progressCount").html(ProgressPerc + '%');
// }
img.onload = function () {
// var canvas = ctx.canvas;
var hRatio = canvas.width / img.width;
var vRatio = canvas.height / img.height;
var ratio = Math.min(hRatio, vRatio);
var centerShift_x = (canvas.width - img.width * ratio) / 2;
var centerShift_y = (canvas.height - img.height * ratio) / 2;
ctx.clearRect(0, 0, canvas.width, canvas.height);
resizeContainer(img.width * ratio, img.height * ratio);
ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, img.width * ratio, img.height * ratio);
// d = ctx.getImageData(centerShift_x, centerShift_y, img.width * ratio, img.height * ratio);
}
img.src = event.target.result;
}
reader.readAsDataURL(e.target.files[0]);
}
希望工作顺利,但现在我想添加一个进度条,显示加载数据的百分比,并基于此链接http://blogs.adobe.com/webplatform/2012/01/13/html5-image-progress-events/
我发现我可以使用这段代码:
// img.onprogress = function (e) {
// ProgressPerc = e.loaded / e.total * 100;
// alert(ProgressPerc);
// $('#ProgressBar').css('width', ProgressPerc + '%');
// $("#sp_progressCount").html(ProgressPerc + '%');
// }
但我发现在链接中这些功能只建议稍后添加,浏览器不支持它。 所以我被困在这里....
【问题讨论】:
标签: javascript html canvas