听说framework 2.0 支持图片url,但是找不到。有没有办法在 C# 中直接从 Url 显示图像?(桌面应用)
通常我遵循的方式是在返回图像后下载图像。这是我的代码..但我不想遵循那种方式。所以我正在寻找一种不使用 Httpwebrequest 或类似的方法..
public Image DownloadImage(string _URL)
{
Image _tmpImage = null;
try
{
// Open a connection
System.Net.HttpWebRequest _HttpWebRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(_URL);
_HttpWebRequest.AllowWriteStreamBuffering = true;
// You can also specify additional header values like the user agent or the referer: (Optional)
_HttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)";
_HttpWebRequest.Referer = "http://www.google.com/";
// set timeout for 20 seconds (Optional)
_HttpWebRequest.Timeout = 20000;
// Request response:
System.Net.WebResponse _WebResponse = _HttpWebRequest.GetResponse();
// Open data stream:
System.IO.Stream _WebStream = _WebResponse.GetResponseStream();
// convert webstream to image
_tmpImage = Image.FromStream(_WebStream);
// Cleanup
_WebResponse.Close();
_WebResponse.Close();
}
catch (Exception _Exception)
{
// Error
Console.WriteLine("Exception caught in process: {0}", _Exception.ToString());
return null;
}
return _tmpImage;
}
我正在寻找另一种方法。我不知道可以是什么..?我想学习如何处理它..