【问题标题】:html2canvas does not produce toDataUrl() to convert to base64html2canvas 不生成 toDataUrl() 来转换为 base64
【发布时间】:2019-08-06 02:28:29
【问题描述】:

我正在使用下面的库将我的 html div 转换为画布。

https://html2canvas.hertzen.com/

一切正常。 现在我想要的基本上是,而不是下载(可以通过 saveAsPNG() 方法获得),我想将数据发送到服务器。 现在知道我们需要使用 toDataUrl() 进行转换才能实现这一点,它会转换为 base64。

使用toDataUrl()这个方法,说的不是函数。

下面是sn-p

html2canvas(document.querySelector("#canvasTxt")).then(canvas => {
    console.log(canvas);   //---1
    console.log(canvas.toDataUrl('image/png')); //---2
    console.log(canvas[0].toDataUrl('image/png')); //----3
}); 

1) 以画布形式给出输出

2) canvas.toDataUrl 不是函数

3) canvas[0] 未定义——所以我假设没有节点列表

那么有没有办法使用库进行转换? 因为我想将转换后的图像发送到服务器而不允许下载。

任何帮助将不胜感激!

【问题讨论】:

    标签: javascript html canvas html2canvas


    【解决方案1】:

    错字:toDataURLURL全部大写。

    html2canvas(document.body).then(canvas => {
        console.log(canvas.toDataURL('image/png'));
    }); 
    

    【讨论】:

    • @Kalido ...谢谢伙计!我虽然没有威士忌来做那个愚蠢的
    猜你喜欢
    • 1970-01-01
    • 2020-10-03
    • 2014-06-06
    • 2017-03-22
    • 1970-01-01
    • 2015-04-22
    • 2016-06-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多