为什么我的下载图像不显示

时间:2016-12-14 12:59:57

标签: javascript canvas html2canvas

我有一个问题,我一直想弄清楚,我似乎无法找到正确的答案。当我下载图像时,我只得到一个没有任何内容的黑色图像,为什么有人可以帮助我。我不知道该怎么做。谢谢。  这应该适用于div而不仅仅是普通的图像



  $(function() { 
    $("#save_image_locally").click(function() { 
        html2canvas($("#scream"), {
            onrendered: function(canvas) {
                theCanvas = canvas;


                canvas.toBlob(function(blob) {
                    saveAs(blob, "Dashboard.png"); 
                });
            }
        });
    });
});

<p>Image to use:</p>
<img id="scream" width="220" height="277" src="http://c8.alamy.com/comp/D8MF25/red-rose-flower-detailed-imge-D8MF25.jpg" alt="The Scream">


<button id="save_image_locally">download img</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.1/knockout-min.js"></script>
<script  
 src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script><script src="//cdnjs.cloudflare.com/ajax/libs/knockout/2.3.0/knockout-min.js"></script>
 <link rel="stylesheet"
href="https://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
  <script src="https://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
  <link rel="stylesheet"
 href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
 <script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.3/FileSaver.min.js"></script>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<link href='https://fonts.googleapis.com/css?family=Philosopher' rel='stylesheet' type='text/css'>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="https://rawgit.com/niklasvh/html2canvas/master/dist/html2canvas.js"></script></script>
<script src="https://files.codepedia.info/uploads/iScripts/html2canvas.js"></script>
&#13;
&#13;
&#13;

0 个答案:

没有答案