zoukankan      html  css  js  c++  java
  • 根据图片路径生成二进制流,下载图片

    let url = this.codes[0].qrImgUrl
    this.getBase64(url).then(function(base64){
      let save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
      save_link.href = base64;
      if(that.pageType=='mediaIds'){
        save_link.download = that.data[0].mediaNo+'.jpg';
      }else{
        save_link.download = that.data[0].salesmanName+that.data[0].accNo+'.jpg';
      }
      let event = document.createEvent('MouseEvents');
      event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
      save_link.dispatchEvent(event);
    },function(err){
    });

    getBase64(img){
      let that = this
      let image = new Image();
      image.crossOrigin = '';
      image.src = img;
      let deferred=$.Deferred();
      if(img){
        image.onload =function (){
        deferred.resolve(that.getBase64Image(image));//将base64传给done上传处理
      }
      return deferred.promise();//问题要让onload完成后再return sessionStorage['imgTest']
      }
    },

    getBase64Image(img,width,height) {//width、height调用时传入具体像素值,控制大小 ,不传则默认图像大小
    let canvas = document.createElement("canvas");
    canvas.width = width ? width : img.width;
    canvas.height = height ? height : img.height;

    let ctx = canvas.getContext("2d");
    ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
    let dataURL = canvas.toDataURL();
    return dataURL;
    },

  • 相关阅读:
    第01组 Beta冲刺(2/4)
    第01组 Beta冲刺(1/4)
    第01组 Alpha事后诸葛亮
    第01组 Alpha冲刺(4/4)
    第01组 Alpha冲刺(3/4)
    第01组 Alpha冲刺(2/4)
    第01组 Alpha冲刺(1/4)
    提高回顾与个人总结
    软件工程结对作业博客
    软件工程第一次阅读作业
  • 原文地址:https://www.cnblogs.com/zhaoxiaobei/p/9278027.html
Copyright © 2011-2022 走看看