简体   繁体   English

通过升级保存HTML5画布

[英]Save HTML5 Canvas with upscaling

I am developing a image editor that has text on it using HTML5 canvas. 我正在开发使用HTML5画布在其上具有文本的图像编辑器。 The canvas I am using has the width and the height of 500 pixels because of the less room to place it on the web page. 我正在使用的画布的宽度和高度为500像素,因为将其放置在网页上的空间较小。 However I need to save the canvas data as an image in a bigger scale like 1000 x 1000 pixels. 但是,我需要将画布数据另存为更大的图像,例如1000 x 1000像素。 How can I achieve this? 我该如何实现? I search for similar issue on the web but could not find an answer. 我在网络上搜索类似的问题,但找不到答案。

To accomplish this you will need to set the width and height attributes on the canvas to 1000 and 1000 . 为此,您需要将画布上的widthheight属性设置为10001000 This represents the native size of the canvas. 这代表画布的原始大小。 Then you can scale down the canvas using CSS to get it to fit on your page. 然后,您可以使用CSS缩小画布,使其适合页面。

Example HTML: HTML示例:

<canvas id="theCanvas" width="1000" height="1000"></canvas>

Example CSS: CSS示例:

theCanvas {
    width: 500px;
    height: 500px;
}

For more information about native vs scaled canvas sizing, see this answer . 有关本地画布大小与缩放画布大小的更多信息,请参见此答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM