我在浏览器中使用HTML显示图像(从文件)...我有另一个程序,以保持我的屏幕截图,并把它作为一个图像文件“image.jpeg”。我使用setTimeout定期在浏览器上显示此图像。然而,图像不改变浏览器..如何在不刷新闪烁的情况下在浏览器中显示不断变化的图像文件?
这里是我的代码...我用这样一个新的映像加载每次的JavaScript函数运行一个Image对象,但似乎并不奏效。 ..
<html>
<head>
<script type="text/JavaScript">
var x=0, y=0;
var canvas, context, img;
function timedRefresh(timeoutPeriod)
{
canvas = document.getElementById("x");
context = canvas.getContext("2d");
img = new Image();
img.src = "image.jpeg";
context.drawImage(img, x, y);
x+=20; y+=20;
//img.destroy();
setTimeout("timedRefresh(1000)",timeoutPeriod);
}
</script>
<title>JavaScript Refresh Example</title>
</head>
<body onload="JavaScript:timedRefresh(1000);">
<canvas id="x" width="600" height="600" />
</body>
</html>
...感谢伟大的作品现在:) – Craig 2011-03-27 12:50:27
这是一个绝妙的主意使用伪造的财产,以防止使用缓存图像。 – 2014-08-28 22:02:33