2014-01-05 77 views
2

我有這就是香草工作的JavaScript代碼,而不是使用jQuery調整jquery的寬度和高度的畫布,以適應圖像尺寸

這個工程:

image.src = 'data:image/png;base64,' + <base64>; 
c = document.getElementById('canvas-base'); 
c.height = image.height; 
c.width = image.width;    
      ctx = c.getContext("2d"); 

      image.addEventListener('load', function() { 
       ctx.drawImage(image, 0, 0); 
       ctx.stroke(); 
      }, true); 

,但是這是不工作:

c = $('#canvas-base'); 
c.height(image.height).width(image.width); 
      ctx = c[0].getContext("2d"); 
      image.addEventListener('load', function() { 
       ctx.drawImage(image, 0, 0); 
       ctx.stroke(); 
      }, true); 

與jQuery版本我得到一個拉伸的圖像。

爲什麼?

回答

相關問題