我有以下一段 HTML:
<style type="text/css">
#c{width:200px;height:500px}
</style>
<canvas id="c"></canvas>
<script type="text/javascript">
var i = new Image();
i.onload = function () {
var ctx = document.getElementById('c').getContext('2d');
ctx.drawImage(i, 0, 0);
}
i.width = i.height = 20; // actual size of square.png
i.src = 'square.png';
</script>
问题是绘制的图像会与画布的大小成比例地自动拉伸(调整大小)。我尝试使用所有可用的参数 ( drawImage(i, 0, 0, 20, 20, 0, 0, 20, 20)
),但没有帮助。
是什么导致我的绘图拉伸,我该如何防止这种情况?
谢谢,
汤姆