function imageToBlob(src) {
return new Promise((resolve,reject)=>{
let img = new Image();
img.setAttribute('crossOrigin', 'anonymous');
img.src = src;
img.onload = () => {
let canvas = document.createElement("canvas");
let ctx = canvas.getContext("2d");
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0, img.width, img.height);
let ext = img.src.substring(img.src.lastIndexOf(".") + 1).toLowerCase();
let base64 = canvas.toDataURL("image/" + ext);
let arr = base64.split(','),
mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]),
n = bstr.length,
u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
resolve(u8arr);
}
})
}
imageToBlob('http://localhost/static/images/tabbar/icon_tab_main_sel.png').then(res=>{
console.log(res)
})