// url img地址,图片地址如果是网络图片,网络地址需要处理跨域
// fn 函数,返回一个blob对象
imageToBlob (url, fn) {
if (!url || !fn) return false;
var xhr = new XMLHttpRequest();
xhr.open('get', url, true);
xhr.responseType = 'blob';
xhr.onload = function () {
// 注意这里的this.response 是一个blob对象 就是文件对象
fn(this.status == 200 ? this.response : false);
}
xhr.send();
return true;
}
img to Blob object
Guess you like
Origin blog.csdn.net/qq_42660374/article/details/129589173
Ranking