爲什麼我無法返回從try塊中的url獲取的圖像? 。 對不起,我英語不好:(C#從try-catch塊返回
這是錯誤我得到:
返回語句丟失
public static Image GetExternalImg(string name, string size)
{
try
{
// Get the image from the web.
WebRequest req = WebRequest.Create(String.Format("http://www.picturesite.com/picture.png", name, size));
// Read the image that we get in a stream.
Stream stream = req.GetResponse().GetResponseStream();
// Save the image from the stream that we are rreading.
Image img = Image.FromStream(stream);
// Save the image to local storage.
img.Save(Environment.CurrentDirectory + "\\images\\" + name + ".png");
return img;
}
catch (Exception)
{
}
}
任何幫助,將不勝感激,因爲我被困現在:()
如果發現異常,我想顯示一個來自資源的圖像。我可能嗎? –
當然,嵌入圖像作爲一個ñ嵌入資源,並在這裏看看:http://stackoverflow.com/questions/1192054/load-image-from-resources-in-c-sharp –
謝謝,我要去試試:)。 –