从超链接(从Internet)设置WPF图像源

Ion*_*zău 4 c# wpf image hyperlink

我尝试从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();
Run Code Online (Sandbox Code Playgroud)

Dou*_*las 7

前置"link"URL肯定是不正确的.只需确保在文本框中键入图像的完整路径即可.

// 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);
Run Code Online (Sandbox Code Playgroud)