Saving PNG files with FileSaver.js

后端 未结 1 539
时光说笑
时光说笑 2021-01-05 04:12

I\'m trying to use FileSaver.js to download PNG files that are being served from my express app. The files are being sent as base64 encoded strings, but when I try to use Fi

相关标签:
1条回答
  • 2021-01-05 05:07

    I've found that you'll probably want to write it to a Canvas first.

    Click Here

    base_image = new Image();
    base_image.src = Base64String
    

    canvas into a blob

    var canvas = document.getElementById('YourCanvas');
    context = canvas.getContext('2d');
    // Draw image within
    context.drawImage(base_image, 0,0);
    

    then you can use FileSaver.js to save it

    and finally save it

    x_canvas.toBlob(function(blob) {
    saveAs(blob, "screenshot.png");
    }, "image/png");
    

    A nice fiddle was also created for this in that post Click Here For Fiddle

    0 讨论(0)
提交回复
热议问题