Set WPF Image Source from a Hyper Link (from Internet)

好久不见. 提交于 2019-12-23 14:41:16

问题


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:


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


来源:https://stackoverflow.com/questions/10869966/set-wpf-image-source-from-a-hyper-link-from-internet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!