Created
June 16, 2016 19:50
-
-
Save StoneCypher/b002be929be96303f666af7ace90e0a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html> | |
| <head> | |
| <script type="text/javascript"> | |
| window.onload = function() { | |
| paintSvgToCanvas(document.getElementById('source'), document.getElementById('tgt')); | |
| } | |
| function paintSvgToCanvas(uSvg, uCanvas) { | |
| var ctx = uCanvas.getContext('2d'), | |
| DOMURL = window.URL || window.webkitURL || window; | |
| var img = new Image(); | |
| var svg = new Blob([uSvg.outerHTML], {type: 'image/svg+xml;charset=utf-8'}); | |
| var url = DOMURL.createObjectURL(svg); | |
| img.onload = function () { | |
| ctx.drawImage(img, 0, 0); | |
| DOMURL.revokeObjectURL(url); | |
| } | |
| img.src = url; | |
| uCanvas.getContext('2d').drawImage(img, 0, 0); | |
| } | |
| </script> | |
| </head> | |
| <body> | |
| <svg xmlns="http://www.w3.org/2000/svg" width="467" height="462" id="source"> | |
| <rect x="80" y="60" width="250" height="250" rx="20" style="fill:#ff0000; stroke:#000000;stroke-width:2px;" /> | |
| <rect x="140" y="120" width="250" height="250" rx="40" style="fill:#0000ff; stroke:#000000; stroke-width:2px; fill-opacity:0.7;" /> | |
| </svg> | |
| <canvas height="462px" width="467px" id="tgt"></canvas> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment