I am trying to resize an image on a mobile device. (Use of angular 2 based ionic structure 2).
The maximum file size is 5 MB, and some devices take up more images. Therefore, I am currently trying to resize the image using canvas.toDataURL(), but it is very slow. (The application does not respond for 15-20 seconds).
My current resize function is as follows:
private resize(outputFormat, sourceImgObj, quality) {
let mimeType = "image/jpeg";
let cvs = document.createElement('canvas');
cvs.width = sourceImgObj.naturalWidth;
cvs.height = sourceImgObj.naturalHeight;
let ctx = cvs.getContext("2d").drawImage(sourceImgObj, 0, 0);
let newImageData = cvs.toDataURL(mimeType, quality/100);
return newImageData;
}
Which (in my opinion) was founded at that time, if not like jic .
This feature works. In the browser it is decent, but still slow (Chrome). But when you run this function on the device, for example, when you select an image size of 8 MB, the application will basically crash.
/ ?
, cordova-plugin-camera, . base64 ( , ).