从Hyper Link(来自Internet)设置WPF图像源 [英] Set WPF Image Source from a Hyper Link (from Internet)

查看:93
本文介绍了从Hyper Link(来自Internet)设置WPF图像源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从Internet链接设置WPF图像源。我怎样才能做到这一点?
我尝试了这个,但不起作用:

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


推荐答案

预先link到URL肯定是不正确的。只需确保在文本框中键入图像的完整路径。

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

这篇关于从Hyper Link(来自Internet)设置WPF图像源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆