+ 5
How to scale an image in canvas?
I want to scale this image making it the same size as the canvas, but without affecting its proportions. https://code.sololearn.com/WLJGi89dLrcO/?ref=app
3 Respuestas
+ 5
Is this what you want?
var scale = Math.min(C.width / img.width, C.height / img.height);
ctx.drawImage(img, 0, 0, img.width * scale, img.height * scale);
But obviously, if the Canvas does not have the same aspect ratio as the image, the scaled image would never fit the Canvas perfectly.
More on drawImage: https://www.w3schools.com/tags/canvas_drawimage.asp
+ 3
Thanks you! Yes, is that :D
+ 1
You're welcome! 😊