159
rated 0 times
[
161]
[
2]
/ answers: 1 / hits: 6327
/ 9 Years ago, wed, march 18, 2015, 12:00:00
Hello i have problem i try to drawing image on the canvas with drawImage
function 50px x 50px on the 50px x 50px canvas, but i get smaller than i need.
var canvas = document.getElementById(canvas);
var ctx = canvas.getContext(2d);
var img = new Image();
img.onload = function() {
$(canvas).css(width, 50);
$(canvas).css(height, 50);
ctx.drawImage(img, 0, 0, 50, 50); //bad here why not drawing 50x50px image on the canvas?
}
img.src = 'http://www.w3schools.com/tags/planets.gif';
<script src=https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js></script>
<img src=http://www.w3schools.com/tags/planets.gif width=100 height=100 style=position: absolute; top: 0px; left: 0px>
<canvas id=canvas style=position: absolute; top: 0px; left: 120px; border: 1px solid #000></canvas>
More From » html