I want to draw a modified SVG image on an HTML canvas.
It works great in Chromium, but not in Firefox. In Firefox, the image is pixelated.
Here is an SVG image:
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="200" height="200" viewbox="0 0 200 200"> <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red"/> </svg>
And here is the code:
<!DOCTYPE html> <html> <head> <title>Resized SVG in Canvas</title> <meta charset="utf-8"/> <script> window.addEventListener('load', function() { var canvas = document.getElementById('canvas'), context = canvas.getContext('2d'), image = new Image(); image.src = 'circle1.svg'; image.height = 400; image.width = 400; image.addEventListener('load', function() { try { context.drawImage(image, 0, 0, 400, 400); } catch(error) { console.log(error); } }, false); }, false); </script> </head> <body> <canvas height="600" id="canvas" width="600"></canvas> </body> </html>
Result:

I would like the SVG image to be resized without pixelation in Firefox, like in Chromium.
Currently, I put <img/> on top of the canvas to get an SVG image without pixelation, but it's pretty slow because there are a lot of images.
source share