用Visual Studio建立Console應用程序,記得引用程序集System.Drawing;
代碼如下:
using System;
using System.Drawing;
using System.IO;
using System.Net;
namespace Keleyi.Com
{
class KeleyiImage
{
static void Main(string[] args)
{
WebRequest request = WebRequest.Create(@"http://keleyi.com/image/a/tvh00n12.jpg");
request.Credentials = CredentialCache.DefaultCredentials;
Stream s = request.GetResponse().GetResponseStream();
byte[] b = new byte[74373];
MemoryStream mes_keleyi_com = new MemoryStream(b);
s.Read(b, 0, 74373);
s.Close();
Image image = Image.FromStream(mes_keleyi_com);
Console.WriteLine("高{0},寬{1}", image.Height, image.Width);
Console.WriteLine("更多信息請訪問keleyi.com,按任意健退出 - 柯樂義");
Console.ReadKey();
}
}
}
原文:http://keleyi.com/a/bjac/f37p93cv.htm