Voglio ridimensionare l'immagine scattata dalla fotocamera iOS sul lato client con HTML5 Canvas ma continuo a correre in questo strano bug in cui l'immagine ha un rapporto errato se maggiore di ~ 1.5mbHTML5 Canvas drawImage ratio bug iOS
Funziona sul desktop ma non nell'ultima versione di iOS con l'API di caricamento multimediale.
È possibile vedere un esempio qui: http://jsbin.com/ekuros/1
Qualsiasi idea di come risolvere questo problema per favore? È un problema di memoria?
$('#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);
});
Ho provato 1.2M foto sul mio codice e problema è lo stesso. Puoi verificarlo su http://orientation.gokercebeci.com –
Ho appena colpito questo. Potete crederci!?! – zaf
Questo problema è stato risolto su iPhone4 con iOS 7, ma è interessante notare che il problema non è stato risolto su iPhone5C con iOS 7 ed è in effetti molto peggiore di prima. –