What is the difference between SVG and HTML5 Canvas?

前端 未结 10 2076
误落风尘
误落风尘 2020-11-30 18:08

What are the differences between SVG and HTML5 Canvas? They both seem to do the same to me. Basically, they both draw vector artwork using coordinate points.

What am

10条回答
  •  离开以前
    2020-11-30 18:59

    There's a difference in what they are, and what they do for you.

    • SVG is a document format for scalable vector graphics.
    • Canvas is a javascript API for drawing vector graphics to a bitmap of a specific size.

    To elaborate a bit, on format versus API:

    With svg you can view, save and edit the file in many different tools. With canvas you just draw, and nothing is retained about what you just did apart from the resulting image on the screen. You can animate both, SVG handles the redrawing for you by just looking at the elements and attributes specified, while with canvas you have to redraw each frame yourself using the API. You can scale both, but SVG does it automatically, while with canvas again, you have to re-issue the drawing commands for the given size.

提交回复
热议问题