我尝试从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();
答案 0 :(得分:7)
将"link"
预先添加到网址肯定是不正确的。只需确保在文本框中键入图像的完整路径。
// For example, type the following address into your text box:
textBox2.Text = "http://www.gravatar.com/avatar/ccac9a107581b343e832a2b040278b98?s=128&d=identicon&r=PG";
bi3.UriSource = new Uri(textBox2.Text, UriKind.RelativeOrAbsolute);