ImgSource 為一個url string 如 "http://lh3.ggpht.com/_aUxwb_torSg/SZ5FjN1UkzI/AAAAAAAAAds/0FM7vPHF0Ho/showBorder.png"
Code 如下
public BitmapImage GetImagefromWeb(string ImgSource)
{
/// Declare BitmapImage Bi
BitmapImage Bi = new BitmapImage();
/// Create the requests.
WebRequest requestPic = WebRequest.Create(ImgSource);
/// Se proxy
/// if web request by proxy
IWebProxy iProxy = WebRequest.DefaultWebProxy;
/// Get potentially, setup credentials on the proxy here
iProxy.Credentials = CredentialCache.DefaultCredentials;
/// Set proxy
requestPic.Proxy = iProxy;
/// Get response
WebResponse responsePic = requestPic.GetResponse();
Bi.BeginInit();
/// Set Bi source from Stream
Bi.StreamSource = responsePic.GetResponseStream();
Bi.EndInit();
return Bi;
}
沒有留言:
張貼留言