4
我嘗試從Internet鏈接設置WPF圖像源。我怎樣才能做到這一點? 我嘗試這樣做,但不工作:設置來自Hyper Link(來自Internet)的WPF圖像源
Image image1 = new Image();
BitmapImage bi3 = new BitmapImage();
bi3.BeginInit();
bi3.UriSource = new Uri("link" + textBox2.Text + ".png", UriKind.Relative);
bi3.CacheOption = BitmapCacheOption.OnLoad;
bi3.EndInit();
很高興幫助過!不要忘記用'「http://」'預先添加圖片;它有助於.NET知道您的URL的方案。 – Douglas
如何知道鏈接是否存在?例如,如果我輸入「http://ahsdjaksdjahk.png」,它不會給我一個錯誤。 –
我不確定...一種方法是嘗試使用WebClient下載鏈接並檢查響應代碼,但我認爲有更好的方法。 – Douglas