I am implement a image editor with canvas using google closure, and when I try to use canvas to drawImage from an img element, the canvas cannot display correct size of image, the code is as the following:
// replace image with canvas
var $originImage = goog.dom.getElementByClass('testImageClass', $sectionDom);
var $canvas = goog.dom.getElement('testCanvasId');
if ($originImage && $canvas) {
var ctx = $canvas.getContext("2d");
ctx.drawImage($originImage, 0, 0, $originImage.clientWidth, $originImage.clientHeight);
goog.dom.classlist.add($originImage, 'display-none');
goog.dom.classlist.remove($canvas, 'display-none');
}
And the display is like this: enter image description here
the upper block is the original image and the lower block is the canvas. Do you know the reason? Thanks in advance!