NPashaP / Viz

BSD 3-Clause "New" or "Revised" License
106 stars 39 forks source link

How to export as an image?? #8

Closed kayran closed 7 years ago

kayran commented 8 years ago

I tried to export as an png image drawing the svg base64 image in a canvas but the drawImage function throw a "Uncaught InvalidStateError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The HTMLImageElement provided is in the 'broken' state.(anonymous function)"

I made a img and serialize the svg to svg+xml string, and then convert it to base64. this img i pass to canvas.getContext("2d").drawImage function.

this canvas i will export with canvas.toDataUrl.

the same data:image/svg+xml;base64 open nicely in a new tab, like in http://desafio.kayran.com.br/desafio page, but the same data doesnt open im img tag and no open in canvas.

how to solve this issue?

NPashaP commented 8 years ago

I am not sure what is causing the drawimage error.

Does this stackoverflow solution work?