4

我尝试从 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();
4

1 回答 1

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);
于 2012-06-03T11:44:27.253 回答