【问题标题】:SVG to Shape (EaselJS)SVG 到形状 (EaselJS)
【发布时间】:2013-03-26 21:10:50
【问题描述】:

在 EaselJS 中,只有形状可以变成蒙版,所以我想知道是否可以以某种方式将 Inkscape 制作的 SVG 转换为 EaselJS,我发现了这个很棒的工具 - http://www.professorcloud.com/svg-to-canvas/,它允许我将 SVG 转换为上下文,但是有没有轻松将 SVG 转换为 EaselJS 形状的方法/工具(这与 Flash/AS3 中的形状几乎相同)?我只需要这样的基本形状:

<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   version="1.1"
   width="776.4032"
   height="405.87927"
   id="svg1383">
  <defs
     id="defs1385" />
  <metadata
     id="metadata1388">
    <rdf:RDF>
      <cc:Work
         rdf:about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
        <dc:title></dc:title>
      </cc:Work>
    </rdf:RDF>
  </metadata>
  <g
     transform="translate(15.455332,-13.016229)"
     id="layer1">
    <path
       d="m 1193.5963,82.437378 a 369.81683,206.47517 0 1 1 -739.63371,0 A 369.81683,206.47517 0 1 1 1193.5963,82.437378 Z"
       transform="matrix(1.0497132,0,0,0.98287671,-491.98585,134.93009)"
       id="mask"
       style="fill:#008000;fill-opacity:1;stroke:none;display:inline" />
  </g>
  <g
     transform="translate(15.455332,-13.016229)"
     id="layer2" />
</svg>

【问题讨论】:

标签: javascript canvas shape easeljs


【解决方案1】:

在您提供的网页上生成 js 代码后,您可以覆盖名为 draw 的函数。只需将生成的代码粘贴到您的函数中,您应该就能看到您的图像。

示例代码:

  var s = new createjs.Shape();
  // this is important because if we dont change graphics our overriden
  // function wont be called.
  s.graphics.beginFill("#FF0000").rect(0, 0, 75, 100);

  //save old draw function
  var oldDraw = s.draw;
  // here we switch draw funciton to the one generated from svg file
  s.draw = this.draw;
  // draw our model on cache
  s.cache(0, 0, 66, 113, 2);
  // and now we can back to old drawing function
  s.draw = oldDraw;

【讨论】:

  • 我试过这个:SVG 显示在画布上,但不幸的是,对原始矩形进行了剪辑。省略 s.graphics.beginFill() 等没有帮助。任何帮助将不胜感激......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-27
  • 1970-01-01
  • 2013-12-18
  • 2017-04-08
  • 1970-01-01
相关资源
最近更新 更多