Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
991 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 Answer

0 votes
by (71.8m points)

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

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...