zoukankan      html  css  js  c++  java
  • 图片 base64 file blob 之间相互的转化

    //base64码转化为文件
    // dataURLtoFile(dataurl, filename) {
    // 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 File([u8arr], filename, {type:mime})
    // },
    // getBase64(fileObj) {
    // let file = fileObj;
    // let cvs = document.createElement("canvas");
    // let ctx = cvs.getContext("2d");
    // if(file) {
    // var url = window.URL.createObjectURL(file);//PS:不兼容IE
    // var img = new Image();
    // img.src = url;
    // img.onload = function() {
    // ctx.clearRect(0, 0, cvs.width, cvs.height);
    // cvs.width = img.width;
    // cvs.height = img.height;
    // ctx.drawImage(img, 0, 0, img.width, img.height);
    // var base64 = cvs.toDataURL("image/png");
    // //callback(base64);
    // }
    // }
    // },
    blobToFile(theBlob, fileName) {
    theBlob.lastModifiedDate = new Date();
    theBlob.name = fileName;
    return theBlob;
    },
    dataURLtoBlob(dataurl) {
    var 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 });
    }

  • 相关阅读:
    前端js(一)
    前端CSS
    前端HTML
    视图等
    Navicat使用
    查询语句
    SpringBoot不能直接访问templates下的静态资源
    Mybatis什么时候用${}
    thymeleaf使用restul风格URL
    SpringBoot使用PageHelper
  • 原文地址:https://www.cnblogs.com/lhqdbk/p/12626568.html
Copyright © 2011-2022 走看看