SVG和HTML5 Canvas有什么区别?

前端之家收集整理的这篇文章主要介绍了SVG和HTML5 Canvas有什么区别?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
SVG和HTML5 Canvas有什么区别?他们似乎也对我做同样的事。基本上,他们都使用坐标点绘制矢量图稿。

我缺少什么? SVG和HTML5 Canvas之间的主要区别是什么?为什么我应该选择一个呢?

解决方法

见维基百科: http://en.wikipedia.org/wiki/Canvas_element

SVG is an earlier standard for drawing
shapes in browsers. However,SVG is at
a fundamentally higher level because
each drawn shape is remembered as an
object in a scene graph or DOM,which
is subsequently rendered to a bit map.
This means that if attributes of an
SVG object are changed,the browser
can automatically re-render the scene.

In the example above,once the
rectangle is drawn,the fact that it
was drawn is forgotten by the system.
If its position were to be changed,
the entire scene would need to be
redrawn,including any objects that
might have been covered by the
rectangle. But in the equivalent SVG
case,one could simply change the
position attributes of the rectangle
and the browser would determine how to
repaint it. It is also possible to
paint a canvas in layers and then
recreate specific layers.

SVG images are represented in XML,and
complex scenes can be created and
maintained with XML editing tools.

The SVG scene graph enables event
handlers to be associated with
objects,so a rectangle may respond to
an onClick event. To get the same
functionality with canvas,one must
manually match the coordinates of the
mouse click with the coordinates of
the drawn rectangle to determine
whether it was clicked.

Conceptually,canvas is a lower level
protocol upon which SVG might be
built.[citation needed] However,this
is not (normally) the case—they are
independent standards. The situation
is complicated because there are scene
graph libraries for Canvas,and SVG
has some bit map manipulation
functionality.

更新:我使用SVG,因为它的标记语言能力 – 它可以由XSLT处理,并可以在其节点中保存其他标记。同样,我可以在我的标记(化学)中保存SVG。这允许我通过标记的组合来操纵SVG属性(例如,渲染)。这可能是在Canvas,但我怀疑,这是很难。

猜你在找的HTML5相关文章