码迷,mamicode.com
首页 > 其他好文 > 详细

Base64转Blob的方式

时间:2020-06-29 22:53:33      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:blob   win   image   object   return   UNC   ase   obj   lob   


/**
 * @description 将图片的base64 转变成Blob形式
 * */
function dataURLtoBlob(dataurl) {
    let arr = dataurl.split(‘,‘)
    let mime = arr[0].match(/:(.*?);/)[1]

    let bstr = atob(arr[1])
    let n = bstr.length
    let u8arr = new Uint8Array(n)
    while (n--) {
        u8arr[n] = bstr.charCodeAt(n)
    }
    return new Blob([u8arr], { type: mime })
}

/**
 * @description 使用canvas绘制缩略图
 * */
export const getImageByCanvas = function(url, callback) {
    getThumb(url, dataURL => {
        callback(window.URL.createObjectURL(dataURLtoBlob(dataURL)))
    })
}


Base64转Blob的方式

标签:blob   win   image   object   return   UNC   ase   obj   lob   

原文地址:https://www.cnblogs.com/ezhar/p/13210610.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!