我想用HTML5 Canvas调整客户端iOS摄像头的图像大小,但我一直运行在这个奇怪的错误,其中图像的错误比率大于〜1.5mbHTML5 Canvas drawImage ratio bug iOS
它可以在桌面上运行,但不能在带媒体上传API的最新iOS版本中运行。
这里你可以看到一个例子:http://jsbin.com/ekuros/1
任何想法如何解决这个好吗?这是一个记忆问题吗?
$('#file').on('change', function (e) {
var file = e.currentTarget.files[0];
var reader = new FileReader();
reader.onload = function (e) {
var image = $('<img/>');
image.on('load', function() {
var square = 320;
var canvas = document.createElement('canvas');
canvas.width = square;
canvas.height = square;
var context = canvas.getContext('2d');
context.clearRect(0, 0, square, square);
var imageWidth;
var imageHeight;
var offsetX = 0;
var offsetY = 0;
if (this.width > this.height) {
imageWidth = Math.round(square * this.width/this.height);
imageHeight = square;
offsetX = - Math.round((imageWidth - square)/2);
} else {
imageHeight = Math.round(square * this.height/this.width);
imageWidth = square;
offsetY = - Math.round((imageHeight - square)/2);
}
context.drawImage(this, offsetX, offsetY, imageWidth, imageHeight);
var data = canvas.toDataURL('image/jpeg');
var thumb = $('<img/>');
thumb.attr('src', data);
$('body').append(thumb);
});
image.attr('src', e.target.result);
};
reader.readAsDataURL(file);
});
我试过1.2M的照片在我的代码和问题是一样的。你可以查看http://orientation.gokercebeci.com – 2012-09-28 12:13:02
我刚刚打过。你相信吗!?! – zaf 2013-05-20 17:05:22
这是在iPhone4下固定在iOS 7下,但有趣的是,这个问题在iOS 7下并没有固定在iPhone5C上,实际上比之前更糟糕。 – 2013-10-09 14:10:25