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 的图像并另存为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                Ordinals in words javascript(javascript中的序数)
                getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)
                <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>