简体   繁体   English

来自IE的javascript save canvas(png)

[英]javascript save canvas(png) from IE

I used html2canvas library. 我使用了html2canvas库。 I want to store the image using the html2canvas. 我想使用html2canvas存储图像。 I success to store image from html2canvas!!! 我成功地存储来自html2canvas的图像! WOW!!! 哇!!! but.... IE has failed... I want to store all of browser. 但.... IE已经失败了...我想存储所有的浏览器。

I find navigator.msSaveBlob... I was happy~ but the happiness did not last long... base64 Encording Image is String! 我找到navigator.msSaveBlob ...我很高兴〜但幸福并没有持续多久... base64 Encording Image是String! but I want to store pngfile! 但我想存储pngfile! help me!!! 帮我!!! (PS. I seriously want to slap a strong chest of IE) (PS。我真的想要打一个强大的IE浏览器)

~this is code~ 〜这是代码〜

html2canvas($("body")[0], {
        onrendered: function(canvas) {
      var img = canvas.toDataURL("image/png");
      var img2 = img.split("data:image/png;base64,")[1];



      //var blobObject = new Blob([img2],{type:"image/jpeg"});
        var blobObject = new Blob([img2]);
      window.navigator.msSaveBlob(blobObject, 'test.png'); // The user only has the option of clicking the Save button.
      alert('File save request made using msSaveBlob() - note the single "Save" button below.');
    }
});

The sad answer is... :-(( 可悲的答案是......: - ((

Chrome & Firefox have supported canvas.toBlob for a while, but... Chrome和Firefox已经支持canvas.toBlob一段时间了,但......

IE & Edge don't yet natively support canvas.toBlob IE&Edge尚未原生支持canvas.toBlob

But there are nice polyfills that bring .toBlob to IE/Edge. 但是有很好的.toBlob.toBlob带到了IE / Edge。

I like Eli Grey's FileSaverJS and his canvas-toBlobJS . 我喜欢Eli Gray的FileSaverJS和他的canvas-toBlobJS

BlueImp's JavaScript-Canvas-to-Blob is popular, too. BlueImp的JavaScript-Canvas-to-Blob也很受欢迎。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM