Having some trouble drawing part of an image properly. The width and height are not matching the original.
Check out my code below:
window.onload = function() {
ImageObjSketch = new Image(); // URL
ImageObjSketch.src = 'https://i.imgur.com/75lATF9.png';
canvasClone = document.getElementById("squareTarget");
ctxClone = canvasClone.getContext("2d");
ctxClone.drawImage(ImageObjSketch,34,119,16,16,0,0,38,38);
}
#squareTarget {
width: 38px; height: 38px;
position: relative;
right: 0px;
display: inline-block;
border: 1px #000000 solid;
}
<canvas id="squareTarget"></canvas>
The square size is not proportional to the image, even though I specified a full size.
Also, why does this code need to be run twice in order to see the image?