最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to change dimensions of html5 canvas without it scaling content - Stack Overflow

programmeradmin1浏览0评论

I init my canvas like this:

<canvas id="canvasDiv" width="20" height="20"></canvas>

and somewhere in the code I want to resize it to it's final size:

var canvas = document.getElementById("canvasDiv");
canvas.style.width = 200;
canvas.style.height = 100;

However, any pixel I plot on my canvas is scaled (so it's not 1 pixel anymore).

How does one change the dimensions of a canvas without this scaling effect? (So programmatically)

I init my canvas like this:

<canvas id="canvasDiv" width="20" height="20"></canvas>

and somewhere in the code I want to resize it to it's final size:

var canvas = document.getElementById("canvasDiv");
canvas.style.width = 200;
canvas.style.height = 100;

However, any pixel I plot on my canvas is scaled (so it's not 1 pixel anymore).

How does one change the dimensions of a canvas without this scaling effect? (So programmatically)

Share Improve this question asked Jul 20, 2010 at 19:41 ToadToad 15.9k16 gold badges85 silver badges129 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 16

I think you just need to also set its width & height properties:

canvas.width = 200;
canvas.height = 100;
发布评论

评论列表(0)

  1. 暂无评论