工作中发现,在 ios 做 webgl 不能将 canvas 的大小设置超过 4096*4096,如果超出,ios 将不显示这个 canvas。下面是做的小实验。
当大小为 4096*4096
![pc正常]()
![ios正常]()
当大小为 4096*4097
![pc正常]()
![ios不显示]()
贴上实验代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> </head> <body style="background-color: #000"> <script> var canvas = document.createElement("canvas"); canvas.width = 4096; canvas.height = 4097; var context = canvas.getContext("2d"); context.fillStyle = "#fff"; context.fillRect(0, 0, 1024, 1024); context.fillStyle = "#f00"; context.fillRect(0, 0, 512, 512); context.fillStyle = "#fff"; context.font = "30px 黑体"; context.fillText( "当画布大小为:" + canvas.width + "*" + canvas.height, 0, 256 ); document.body.appendChild(canvas); </script> </body> </html>
|