【问题标题】:Capturing Div contents to image using HTML2Canvas not returing anything使用 HTML2Canvas 将 Div 内容捕获到图像不返回任何内容
【发布时间】:2013-06-10 18:18:17
【问题描述】:

我正在使用此代码通过 html2canvas 捕获显示在 Div 中的图像:

$(document).ready(function () {
            $('#<%= btnCapture.ClientID %>').click(function () {
                html2canvas($('#chart_div'), {
                    onrendered: function (canvas) {
                        var img = canvas.toDataURL();
                        window.open(img);
                    }
                });
            });
        });

代码工作并打开一个新的浏览器窗口,其 URL 为 base64,但图像不可见。

为什么图片不可见?

【问题讨论】:

  • div#chart_div 中的数据似乎有问题。向我们展示更多代码,或准备一个工作演示(例如使用jsFiddle.net)。
  • 我正在使用 Google 图表,这些图表在 ID 为“chart_div”的 Div 中呈现。没有更多的 HTML 代码了。
  • Google 图表会在您的 div 中呈现一些内容,这可能有助于我们识别问题。同时添加background: "red", onrendered:... 并重试。 (我怀疑图像可能确实在渲染,但里面什么都没有。)
  • 请在此处查看具有相同 Div 的 Google 图表代码:developers.google.com/chart/interactive/docs/gallery/orgchart
  • 这对我来说似乎工作正常。看看这里:jsfiddle.net/ExpertSystem/n97Rm。我真的需要查看一些你的代码来发现问题。

标签: javascript jquery asp.net html2canvas


【解决方案1】:

使用:“html2canvasproxy.ashx”

            html2canvas($('#chart_div'), {
            "logging": true,
            "proxy": "html2canvasproxy.ashx",                    
            onrendered: function (canvas) {

【讨论】:

    猜你喜欢
    • 2013-01-13
    • 1970-01-01
    • 1970-01-01
    • 2015-12-16
    • 2014-04-03
    • 2018-05-09
    • 2014-04-09
    • 1970-01-01
    相关资源
    最近更新 更多