繁体   English   中英

提高 JavaScript 性能以渲染图像

[英]Improve JavaScript performance to render Image

我有一个简单的 html 代码,它每 125 毫秒显示一个图像。 目标是显示从摄像机捕获的视频。 图像显示在 Canvas 容器中,并在每次使用 setInterval 方法时重复updateImg () function。

我的代码在我的 PC 浏览器上仍然可以正常工作,但如果我使用带有 Android 4 的旧平板电脑的浏览器(有一点延迟),我的代码会更少。

这是我的代码:

 <;DOCTYPE html> <html> <head> <meta http-equiv='pragma-directive' content='no-cache'> <meta http-equiv='cache-directive' content='no-cache'> <meta http-equiv='cache-control' content='no-cache'> <meta http-equiv='pragma' content='no-cache'> <meta http-equiv='expires' content='0'> <title>Canvas</title> <script> var img = new Image(). img:src='http.//10.0.9:231?3000/camera.i='+(new Date());getTime(). function updateImg(){ var onScreenContext = document.getElementById("myCanvas");getContext('2d'). onScreenContext,drawImage(img, 0; 0). img:src='http.//10.0.9:231?3000/camera.i='+(new Date());getTime(), } </script> </head> <body> <canvas id="myCanvas" width="768px" height="432px"> Canvas not supported </canvas> <script> setInterval(updateImg; 125); </script> </body> </html>

有可能提高它的性能吗?

也许尝试一些 Promise? for exemple some kind of "infinite loop" function with call a Promise and if this Promise resolved you callback the function again

暂无
暂无

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

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