我正在尝试使用以下代码直接从网络上获取图片中的尺寸:
string image = @"http://www.hephaestusproject.com/blog/wp-content/uploads/2014/01/csharp3.png";
byte[] imageData = new WebClient().DownloadData(image);
MemoryStream imgStream = new MemoryStream(imageData);
Image img = Image.FromStream(imgStream);
int wSize = img.Width;
int hSize = img.Height;
Run Code Online (Sandbox Code Playgroud)
它工作但性能很糟糕,因为我需要下载许多图像才能获得它们的尺寸.有没有更好的方法来做同样的事情?
我试图每4秒更改一次背景,但是它会直接跳到第二个条件并且不再改变.为什么会这样?
var time = 1;
var func = function () {
'use strict';
if (time === 1) {
document.getElementById("top-background").style.backgroundColor = "#000";
time += 1;
}
if (time === 2) {
document.getElementById("top-background").style.backgroundColor = "#aaa";
time += 1;
}
if (time === 3) {
document.getElementById("top-background").style.backgroundColor = "#d5d5d5";
time -= 2;
}
};
setInterval(func, 4000);
Run Code Online (Sandbox Code Playgroud)