我试图将数据URI转换为图像数据,但我遇到了这个错误:
无法执行' atob' on' Window':要解码的字符串不是 正确编码
功能:
function dataURLtoBlob(dataurl) {
var arr = dataurl.split(',');
var mime = arr[0].match(/:(.*?);/)[1];
var bstr = window.atob(arr[1]);
var n = bstr.length;
var u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new Blob([u8arr], {
type: mime
});
}
dataurl是:
SRC ="数据:图像/ PNG; BASE64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAgAElEQVR4Xmy9edRl6VXe95z5nHvuvd9Uc5W6q9WSWiOSGISEmCQmx2ZKCAtjsryygv9JVsY / SGwSRw54GezYBiHANEkV7WeKQBWriul64VufPLj2vMCbSUTqQU5OAPx2lIl + S0qZWAskN2jLhaZ5ioaZRZBgMbG1AL ...