【发布时间】:2011-02-22 22:30:17
【问题描述】:
我有以下 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)),但没有帮助。
是什么导致我的绘图拉伸,我该如何防止?
谢谢,
汤姆
【问题讨论】:
-
将您的评论提升为真正的答案,以造福下一个前来寻找的人,我会给您一个 cookie(或点赞,无论我有什么)。