HTML5 canvas image how can be saved in SVG or base 64 format?
can we export ca开发者_运维知识库nvas image as svg or base 64 and then import it back again?
It's not easy, no. There is no direct method to export Canvas graphics to SVG - they are fundamentally different types of representation, Canvas 2D uses a raster display, like television images, and SVG stores the geometric shapes, which can be resized without degradation of quality.
The simple answer is if you need SVG output, don't use canvas, start with SVG (the simpler SVG graphics library http://raphaeljs.com/ might be useful here).
The complex answer is - you could export to SVG if you record all the canvas operations you perform and have some way to recreate them with SVG, but, unless you have a restricted set of operations, that basically means you need to implement all canvas drawing functions and modes!
andrewmu gets a well-deserved point from me for the great answer to the question in its original form.
The amended question ("or base64") is easy to Google: canvas.toDataURL()
.
精彩评论