首页 > 开发 > HTML > 正文

html5 canvas的宽高有大小限制吗?

2017-09-09 13:57:30  来源: 网友分享

我写了一个js将一个包含流程信息的json字符串转换成流程图输出,canvas根据流程图需要大小计算出自己的宽高,再在算好宽高的canvas上画流程图,如下图

现在的问题是如果流程复杂,end活动太多,导致canvas宽度过大,就画不出来任何图形了。

解决方案

我在stackoverflow找到答案了:

canvas的大小有限制,而且浏览器或者设备不同,其限制还不一样。

翻译:
截至2012年7月,Safari上第三代iPad最大6826像素高度的canvas。Internet Explorer 9的最大高度为8192像素。(我认为的最大宽度是相同的,但没有测试这个。) u3000

超过最大宽度使得在Safari iPad上的画布无用,没有什么会被画出来。Internet Explorer 9仍将使用可用的8192像素,但不会超出范围的画。

我没有在其他浏览器测试特定的上限,但最新版本的Safari(Mac)和Safari,Chrome,Firefox(Windows)都允许至少8192像素。

原文:
As of July 2012, Safari on a 3rd generation iPad has a maximum canvas height of 6826 pixels. Internet Explorer 9 has a maximum height of 8192 pixels. (I assume the maximum widths are the same, but have not tested this.)

Exceeding the maximum width in Safari on iPad renders the canvas useless; nothing will draw. Internet Explorer 9 will still use the available 8192 pixels, but will not draw outside that range.

I have not tested for specific upper limits on other browsers, but the latest versions of Safari (Mac) and Safari, Chrome, and Firefox (Windows) all allow at least 8192 pixels.

摘自答案地址