Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
989 views
in Technique[技术] by (71.8m points)

canvas 把图片转换为文件流file格式 ,缺少name值?

  1. 使用canvas把图片转换为file格式的图片,但是打印缺少name

image.png

let that = this
      var canvas = document.createElement('CANVAS')
      var ctx = canvas.getContext('2d')
      var img = new Image;

      img.crossOrigin = 'Anonymous';
      img.onload = function () {

        canvas.height = img.height;
        canvas.width = img.width;
        let quality = 0.5
        ctx.drawImage(img, 0, 0, 400, 400);
        var dataURL = canvas.toDataURL(outputFormat || 'image/png', quality);
        let resultFile = that.dataURLtoFile(dataURL)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

dataURLtoFile 这个方法实现代码写一下。

new File 的时候可以搞个名字,

formdata.append 的时候也可以搞个名字


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...