【发布时间】:2022-01-05 20:01:35
【问题描述】:
我正在创建一个像素艺术应用程序,当我想从画布中保存图像时,图像太小了,所以当我想调整它的大小时它似乎像素化了。
我想将其调整为更大的尺寸,但我不知道如何。
这是代码示例:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(0, 0, 50, 50);
ctx.fillStyle = 'red';
ctx.fill();
document.write('<img style="width:300px;" src="'+c.toDataURL("image/png")+'"/>');
// This is an image with dimensions 108x108px and it seems very bad when i resize it to 300x300px
// I want to download the canvas image with more resolution
<canvas id="myCanvas" width="108" height="108" style="width: 300px; height:300px;">
</canvas>
【问题讨论】:
-
在
c元素上设置width和height属性。
标签: javascript html css canvas