What is the difference between canvas and SVG
What is the difference between SVG and HTML5 canvas?
See Wikipedia: 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 in that every shape drawn is saved as an object in a scene diagram or DOM, which is then rendered into a bitmap. This means that the browser can automatically re-render the scene when attributes of an SVG object are changed.
In the example above, the fact that the rectangle has been drawn is forgotten by the system once it has been drawn. If the position is to be changed, the entire scene must be redrawn, including any objects that may have been covered by the rectangle. In the corresponding SVG case, however, one could simply change the position attributes of the rectangle and the browser would determine how it should be redrawn. It is also possible to paint a canvas in layers and then recreate certain layers.
SVG images are represented in XML, and complex scenes can be created and managed using XML editing tools.
The SVG scene diagram allows event handlers to be associated with objects so that a rectangle may respond to an onClick event. To get the same functionality with Canvas, the coordinates of the mouse click must be manually matched with the coordinates of the drawn rectangle to see if it was clicked.
Conceptually, Canvas is a lower level protocol that SVG could be built on. [Citation required] However, this is (usually) not the case - these are independent standards. The situation is complicated because there are scene diagram libraries for canvas and SVG has some bitmap manipulation capabilities.
UPDATE: I use SVG because of its markup language capabilities - it can be handled by XSLT and have other markup in its nodes. Likewise, I can keep SVG in my markup (chemistry). This allows me to edit SVG attributes (e.g. rendering) using markup combinations. This may be possible in Canvas, but I suspect it is a lot more difficult.
SVG is like a "draw" program. The drawing is given as a drawing instruction for each shape, and any part of any shape can be changed. Drawings are shape-oriented.
Canvas is like a "painting" program. Once the pixels appear on the screen, this is your drawing. You can only change shapes by overwriting them with different pixels. Paintings are pixel-oriented.
For some programs it is very important to be able to change drawings. eg drawing apps, diagram tools etc. SVG has an advantage here.
For some artistic programs it is important to be able to control individual pixels.
It is easier with Canvas than SVG to get great animation performance for user manipulation over mouse hoists.
A single pixel on the computer screen often consumes 4 bytes of information, and a computer screen today takes up several megabytes. As a result, Canvas may be inconvenient if you want the user to edit an image and then upload it again.
In contrast, drawing a handful of shapes that cover the entire screen with SVG takes a few bytes, downloads quickly, and is easy to upload again, with the same benefits going one way as going the other Direction is going. So SVG can be faster than canvas.
Google implemented Google Maps with SVG. This gives the web app its brisk performance and smooth scrolling.
High level summary of Canvas vs. SVG
- Pixel based (Dynamic .png)
- Single HTML element. (Check item in developer tool. You can only see canvas tags.)
- Changed just through the script
- The interaction between the event model and the user is detailed (x, y).
- The performance is better with a smaller surface area, a larger number of objects (> 10,000) or both
- Shape based
- Several graphical elements that become part of the DOM
- Changed by script and CSS
- Event model / user interaction is abstracted (rect, path)
- Performance is better with a smaller number of objects (<10 KB), a larger surface area, or both
You can find detailed information on the differences at http://msdn.microsoft.com/en-us/library/ie/gg193983(v=vs.85).aspx
There is a difference in what they are and what they do for you.
- SVG is a document format for scalable vector graphics.
To go into more detail about the format and API:
Svg allows you to view, save, and edit the file in many different tools. With canvas, you just draw and nothing remains of what you've just done other than the resulting image left on the screen. You can animate both of them. SVG does the redrawing for you by just looking at the specified elements and attributes. With Canvas, you have to redraw each frame yourself using the API. You can scale both of them, but SVG will do it for you. If you use the artboard again, you must reissue the drawing commands for the specified size.
Two things that struck me the most about SVG and Canvas were:
Ability to use Canvas without a DOM, with SVG being heavily dependent on the DOM and slowing down performance as complexity increases. Like in game design.
The advantage of using SVG is that the resolution remains the same on all platforms that lack Canvas.
You will find a lot more details on this page. http://dev.opera.com/articles/view/svg-or-canvas-choosing-between-the-two/
It absolutely depends on your need.
If you only want to display an image / diagram on one screen, it is recommended as a canvas. (Example is PNG, GIF, BMP, etc.)
If you want to expand the functionality of your graphics, e.g. For example, if you move the mouse over the diagram and want to zoom in on a certain area without affecting the display quality, select SVG. (Good examples are AutoCAD, Visio, and GIS files).
If you want to create a dynamic flowchart creation tool with shape connector, it is better to choose SVG instead of CANVAS.
As the screen gets bigger, the canvas starts to deteriorate as more pixels need to be drawn.
As the number of objects on the screen increases, SVG begins to grow
deteriorate as we continuously add them to the DOM.
See also: http://msdn.microsoft.com/en-us/library/gg193983(v=vs.85).aspx
On the other hand, the CANVAS code is much easier to read. You don't have to worry about XML namespaces. And you can call the graphics functions directly because you don't have to create a DOM.
The lesson is clear: if you want to quickly draw some graphics, use the CANVAS. If you want to share the graphics, format them with CSS, or use DOM event handlers in your graphics, create an SVG.
Adding to the above:
SVG is easy to transmit over the web when compared to JPEG, GIF, etc., and also scales extremely when resized without losing quality.
It is based on an object model.
Is suitable for the use of large rendering areas.
SVG has all support for event handlers.
Changes are permitted via script and CSS.
SVG has better scalability
SVG is vector based (made up of shapes).
SVG is not suitable for game graphics. SVG does not depend on the resolution.
SVG is suitable for API animation.
SVG is good for printing with high quality and any resolution.
Is suitable for small renderings
Canvas does not provide any recourse for event handlers.
Changes are only allowed through the script.
Canvas has poor scalability.
Canvas is based on a grid (consists of one pixel).
Canvas is suitable for game graphics.
Canvas is completely dependent on the resolution.
Canvas doesn't have an API for animation.
Canvas is not suitable for high quality, high resolution printing.
- What is the new Apple file system
- Which is the easiest job
- Is Michael Crichton considered the upstream writer
- How can I learn Dutch in India
- What was Joseph Stalin's greatest strength?
- How likely do we remember our dreams?
- The lack of acceleration reduces the strength
- Computer science will always be in demand
- What is gucci belt wrap
- What are the best alternatives to Pandora
- Summer school classes are usually cheaper
- When was Happiesta com founded
- How should I write an online marketing plan
- Climate skeptics are smart people
- What is another word for victory?
- Make Steakhaeuser sous vide your steak
- What is the prison of addiction
- Flooding is common in Round Rock Texas
- Who was the best student of Dronacharya
- Why are Cuban cigars popular
- Is Tejas a world class air fighter
- How much do mutual fund wholesalers earn
- What does a house party consist of
- Can I use Thrombophob Gel for scars?