Set WPF Image Source from a Hyper Link (from Inter

2019-06-26 03:11发布

I try to set WPF image source from an Internet link. How can I do this? I tried this, but doesn't work:

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();

1条回答
一纸荒年 Trace。
2楼-- · 2019-06-26 04:06

Prepending "link" to the URL is certainly incorrect. Just make sure that you type the full path of your image into your textbox.

// 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);
查看更多
登录 后发表回答