I am try to make an upload picture webpage in mobile phones, but it always run out of memory and the browser quit once the picture is too big. Here are my code:
<input type="file" id="testFile" />
<img src="" style="position:relative;" id="uploadingImg" />
function setImage() {
var fileList = this.files;
var imageType = /image/;
for(var i = 0;i < fileList.length;i++) {
document.getElementById('uploadingImg').file = fileList[i];
var reader = new FileReader();
reader.onload = function(e) {
document.getElementById('uploadingImg').src = e.target.result;
}
reader.readAsDataURL(fileList[i]);
}
}
document.getElementById('testFile').addEventListener('change', setImage, false);
Does anyone knows how to preview one picture by using <img>
or <canvas>
element?
Please don't use "readAsDataURL"
, because when it comes to document.getElementById('uploadingImg').src = e.target.result;
It will run out of memory. Because the base64 Url occupy too much memory and it exist in the memory with many three or four copies.
How can I use "readAsArrayBuffer"
and use "drawImage"
by canvas?
or other method?
All is ok if I can preview one picture in local disk without using "readAsDataUrl"
.
Thanks!