[英]resize a canvas with jquery width & height to fit an image dimensions
我有一個可以使用香草javascript而不是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版本時,我得到了拉伸圖像。
為什么?
這是一個已知的錯誤:
就像這樣寫:
c.attr({"height": image.height , "width": image.width});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.