Skip to content Skip to sidebar Skip to footer

Convert Canvas Or Control Points To Svg

I am developing a drawing app, and now I want to add a function which creates SVG from my canvas or control points. (I save the mouse coordinates for each drawing step). canvasElem

Solution 1:

I solved the problem by generating SVG file. I translated all my canvas drawing functions into SVG drawing tags.

Something like that:

function exportSVG() {
    var svg = '<?xml version="1.0" standalone="yes"?>';
svg += '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">';
svg += '<svg width="1065px" height="529px" xmlns="http://www.w3.org/2000/svg" version="1.1">';

for(var i=0; i<myPoints.length; i++) {
   svg += "M"+myPoints.x[i]+","+myPoints.y[i]+" ";
   svg += "L"+myPoints.x[i+1]+","+myPoints.y[i+1];
   svg += '" fill="none" stroke="rgb('+color+')" stroke-opacity="'+opacity+'" stroke-width="'+size+'px" stroke-linecap="round" stroke-linejoin="round" />';
}
svg += "</svg>";
}

So, in svg variable there will be SVG file generated from Canvas. Thanks everybody!


Post a Comment for "Convert Canvas Or Control Points To Svg"