1. <legend id='ZH2qq'><style id='ZH2qq'><dir id='ZH2qq'><q id='ZH2qq'></q></dir></style></legend>

  2. <i id='ZH2qq'><tr id='ZH2qq'><dt id='ZH2qq'><q id='ZH2qq'><span id='ZH2qq'><b id='ZH2qq'><form id='ZH2qq'><ins id='ZH2qq'></ins><ul id='ZH2qq'></ul><sub id='ZH2qq'></sub></form><legend id='ZH2qq'></legend><bdo id='ZH2qq'><pre id='ZH2qq'><center id='ZH2qq'></center></pre></bdo></b><th id='ZH2qq'></th></span></q></dt></tr></i><div id='ZH2qq'><tfoot id='ZH2qq'></tfoot><dl id='ZH2qq'><fieldset id='ZH2qq'></fieldset></dl></div>
    1. <tfoot id='ZH2qq'></tfoot>
        <bdo id='ZH2qq'></bdo><ul id='ZH2qq'></ul>

      <small id='ZH2qq'></small><noframes id='ZH2qq'>

      生成 div 的图像并另存为

      Generate an image of a div and Save as(生成 div 的图像并另存为)
      <tfoot id='2VGGW'></tfoot>
    2. <legend id='2VGGW'><style id='2VGGW'><dir id='2VGGW'><q id='2VGGW'></q></dir></style></legend>

        <tbody id='2VGGW'></tbody>
      <i id='2VGGW'><tr id='2VGGW'><dt id='2VGGW'><q id='2VGGW'><span id='2VGGW'><b id='2VGGW'><form id='2VGGW'><ins id='2VGGW'></ins><ul id='2VGGW'></ul><sub id='2VGGW'></sub></form><legend id='2VGGW'></legend><bdo id='2VGGW'><pre id='2VGGW'><center id='2VGGW'></center></pre></bdo></b><th id='2VGGW'></th></span></q></dt></tr></i><div id='2VGGW'><tfoot id='2VGGW'></tfoot><dl id='2VGGW'><fieldset id='2VGGW'></fieldset></dl></div>

    3. <small id='2VGGW'></small><noframes id='2VGGW'>

                <bdo id='2VGGW'></bdo><ul id='2VGGW'></ul>
                本文介绍了生成 div 的图像并另存为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想创建一个输入按钮保存图像":

                I'd like to create an input button "Save image" that :

                1. 截取 div 的屏幕截图
                2. 要求在用户的计算机上另存为"

                我发现了如何使用 html2canvas 创建潜水屏幕并在新标签中打开它,它可以完美运行:

                I've found how to create a screen of a dive using html2canvas and to open it in a new tab, it works perfectly :

                function printDiv2(div)
                {
                    html2canvas((div), {
                        onrendered: function(canvas) {
                            var img = canvas.toDataURL();
                            window.open(img);
                      }
                    });
                }
                

                但对你来说,另存为一部分,是一个艰难的部分......我发现了一些有趣的话题,因为我是 JS(和对象)编码的新手,我有点困惑......我想我必须使用 FileSaver.js 并创建一个新的 blobhttp://eligrey.com/blog/post/saving-generated-files-在客户端/

                But for thee Save as part, is a kind of the tough part... I've found interesting topics, as I'm new in JS (and object) coding, I'm a little bit confused... I think I'll have to use the FileSaver.js and to create a new blob http://eligrey.com/blog/post/saving-generated-files-on-the-client-side/

                但我不知道如何在我的 html2canvas 中实现 saveAs,如何正确转换新的 blob...

                But I don't get how to implement the saveAs in my html2canvas, how to cast properly a new blob...

                function printDiv2(div)
                {
                    html2canvas((div), {
                        onrendered: function(canvas) {
                            var img = canvas.toDataURL();
                            window.open(img);
                
                            var blob = new Blob(img, {type: "image/jpeg"});
                            var filesaver = saveAs(blob, "my image.png");
                      }
                    });
                }
                

                我还尝试通过提取 base64 生成的 URL 来解决这个问题,但它对我来说太复杂了,无法理解:http://bl.ocks.org/nolanlawson/0eac306e4dac2114c752

                Also I tried to do something with this, by extracting the base64 generated URL, but it's too complicated for me to understand everyting : http://bl.ocks.org/nolanlawson/0eac306e4dac2114c752

                但是有人给我一些提示并帮助我吗?

                But someone give me a few tips and help me please ?

                推荐答案

                这里是最终代码,如果它可以帮助你:

                Here is the final code, if it can helps you :

                function PrintDiv(div)
                {
                    html2canvas((div), {
                        onrendered: function(canvas) {
                            var myImage = canvas.toDataURL();
                            downloadURI(myImage, "MaSimulation.png");
                      }
                    });
                }
                
                function downloadURI(uri, name) {
                    var link = document.createElement("a");
                
                    link.download = name;
                    link.href = uri;
                    document.body.appendChild(link);
                    link.click();   
                    //after creating link you should delete dynamic link
                    //clearDynamicLink(link); 
                }
                

                这篇关于生成 div 的图像并另存为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Fetch multiple links inside foreach loop(在 foreach 循环中获取多个链接)
                Backbone Fetch Request is OPTIONS method(Backbone Fetch Request 是 OPTIONS 方法)
                Fetch API leaks memory in Chrome(Fetch API 在 Chrome 中泄漏内存)
                How can I download and save a file using the Fetch API? (Node.js)(如何使用 Fetch API 下载和保存文件?(Node.js))
                Send blob data to node using fetch, multer, express(使用 fetch、multer、express 将 blob 数据发送到节点)
                Sending a custom User-Agent string along with my headers (fetch)(发送自定义用户代理字符串以及我的标头(获取))
                <legend id='EF0fv'><style id='EF0fv'><dir id='EF0fv'><q id='EF0fv'></q></dir></style></legend>

                      <tbody id='EF0fv'></tbody>

                      <i id='EF0fv'><tr id='EF0fv'><dt id='EF0fv'><q id='EF0fv'><span id='EF0fv'><b id='EF0fv'><form id='EF0fv'><ins id='EF0fv'></ins><ul id='EF0fv'></ul><sub id='EF0fv'></sub></form><legend id='EF0fv'></legend><bdo id='EF0fv'><pre id='EF0fv'><center id='EF0fv'></center></pre></bdo></b><th id='EF0fv'></th></span></q></dt></tr></i><div id='EF0fv'><tfoot id='EF0fv'></tfoot><dl id='EF0fv'><fieldset id='EF0fv'></fieldset></dl></div>

                        <small id='EF0fv'></small><noframes id='EF0fv'>

                      1. <tfoot id='EF0fv'></tfoot>
                          <bdo id='EF0fv'></bdo><ul id='EF0fv'></ul>