简体   繁体   English

使用Fabric Js对画布进行Svg到画布转换会污染画布

[英]Svg to canvas conversion using Fabric Js taints the canvas

I am using fabric.js to convert svg to canvas, the code that i use works fine in chrome but in IE 11 the canvas that is created is getting tainted thus preventing me from reading data from canvas,below is code that i use 我使用fabric.js将svg转换为canvas,我使用的代码在chrome中运行良好但在IE 11中创建的画布变得污染,从而阻止我从画布读取数据,下面是我使用的代码

    var d3canvas = document.createElement('canvas');
    d3canvas.id = canvasId;

    fabric.loadSVGFromString(svg.node().parentNode.innerHTML, function (objects, options) {
        var canvasObj = new fabric.Canvas(canvasId);
        var obj = fabric.util.groupSVGElements(objects, options);
        canvasObj.add(obj).renderAll();

        var canvasdata = d3canvas.toDataURL("image/bmp");//this line causes error as canvas is tainted
}

my question is whether there is a way to create canvas from svg without tainting the canvas in Fabric.js? 我的问题是,是否有办法从svg创建画布而不污染Fabric.js中的画布?

Note:I have already used canvg to convert svg to canvas but as the svg is complex its not getting properly converted to canvas 注意:我已经使用canvg将svg转换为canvas,但由于svg很复杂,它没有正确转换为canvas

First deselect all object of canvas and use below code to convert canvas to SVG. 首先取消选择画布的所有对象,并使用下面的代码将画布转换为SVG。

canvas.deactivateAllWithDispatch();
canvas.renderAll();
var image   = canvas.toSVG();
var svg_image = "data:image/svg+xml,"+encodeURIComponent(image);

You will get SVG image value into svg_image variable. 您将获得SVG图像值到svg_image变量中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM