I wrote a simple example to show this.
Canvas Size 500px * 400px. The size of the original of my image is 200px * 160px with a resolution of dpi 480. I want to display this image on canvas with the size of the beginning so that it does not change, which will blur the image.
Here is the code:
<html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#canvas").width(500); $("#canvas").height(400); var canvas = $("#canvas").get(0); var ctx = canvas.getContext('2d'); var image = new Image(); image.src = "fish01.png"; </script> </head> <body style="background-color: #ccc; margin: 0px;"> <canvas id="canvas" style="background-color: #66c"></canvas> </body> </html>
Original Image:

Result: 
I think this is strange, since the canvas size is 500 pixels * 400 pixels and the image size is 200 pixels * 160 pixels, how would the image be out of the canvas range? And it seems that the image has been resized.
I want to know how to display an image with the size of the original. Please give some advice. Thanks!
Ovilia
source share