function base64ToBlob(base64) { var arr = base64.split(','); var mime = arr[0].match(/:(.*?);/)[1] || 'image/png'; // 去掉url的頭,並轉化為byte var bytes = win... ...
function base64ToBlob(base64) { var arr = base64.split(','); var mime = arr[0].match(/:(.*?);/)[1] || 'image/png'; // 去掉url的頭,並轉化為byte var bytes = window.atob(arr[1]); // 處理異常,將ascii碼小於0的轉換為大於0 var ab = new ArrayBuffer(bytes.length); // 生成視圖(直接針對記憶體):8位無符號整數,長度1個位元組 var ia = new Uint8Array(ab); for (var i = 0; i < bytes.length; i++) { ia[i] = bytes.charCodeAt(i); } return new Blob([ab], { type: mime }); }