簡體   English   中英

下載畫布作為圖像無法在firefox和microsoft邊緣工作

[英]Download canvas as image not working in firefox and microsoft edge

我想下載canvas作為圖像,但不是在firefox和microsoft邊緣工作但使用chrome

這是我的代碼:

    DownloadImage = (i) => {
        var _this = this;

        this.modeler.saveSVG(function (err, svg) {
            if (err) console.log(err)
            _this.setState({ datasvg: svg }, function () {
                const canvas = _this.refs.canvasforimage;  
                const options = {
                    log: false,
                    ignoreMouse: true,

                };

                canvg(canvas, this.state.datasvg, options);

                const image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
                const element = document.createElement("a");
                element.setAttribute('download', 'diagram.png');
                element.setAttribute('href', image);
                element.click();

有什么解決方案嗎?

這是我用來將畫布內容保存為PNG圖像文件的代碼:

canvas.toBlob(blob => {
    var a = document.createElement("a"),
        url = URL.createObjectURL(blob);
    a.href = url;
    a.download = "image.png";
    document.body.appendChild(a);
    a.click();
    setTimeout(function() {
        document.body.removeChild(a);
        window.URL.revokeObjectURL(url);
    }, 0);
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM