需要帮助让favicon在浏览器C#WPF中工作吗

需要帮助让favicon在浏览器C#WPF中工作吗,c#,wpf,favicon,C#,Wpf,Favicon,我一直在尝试让favicon在我正在创建的Web浏览器上工作。我假设我必须使用图像并对其应用代码。我找到了这段代码,但是FromStream和FromFile给了我一个错误System.Windows.Controls.Image没有包含FromStream的定义,因为我对编程相当陌生,我不知道需要做什么来解决这个问题 任何帮助都将不胜感激 代码如下: public static Image favicon(String u, string file) { Uri url = new Ur

我一直在尝试让favicon在我正在创建的Web浏览器上工作。我假设我必须使用图像并对其应用代码。我找到了这段代码,但是
FromStream
FromFile
给了我一个错误
System.Windows.Controls.Image
没有包含
FromStream
的定义,因为我对编程相当陌生,我不知道需要做什么来解决这个问题

任何帮助都将不胜感激

代码如下:

public static Image favicon(String u, string file)
{
   Uri url = new Uri(u);
   String iconurl = "http://" + url.Host + "/favicon.ico";

   WebRequest request = WebRequest.Create(iconurl);
   try
   {
       WebResponse response = request.GetResponse();

       Stream s = response.GetResponseStream();
       return Image.FromStream(s);
   }
   catch (Exception ex)
   {
       //return a default icon in case 
       //the web site doesn`t have a favicon
       return Image.FromFile(file);
   }
}

我检查了你的密码

您需要通过引用
System.Drawing.dll
使用
System.Drawing
命名空间中的
Image

System.Drawing.Image.FromStream(s)
System.Windows.Controls.Image
没有
FromFile
FromStream
方法


希望这会有所帮助。

只需更改为
System.Drawing.Image.FromStream
我想这可能会有所帮助,我现在遇到错误“类型或命名空间名称'Image'在命名空间'System.Drawing'中不存在”(是否缺少程序集引用?)是否需要以某种方式将Image设置为某个值?我无法对此答案的内容进行评论,但要使用
System.Drawing.Image
类,您需要添加对
System.Drawing
dll的引用。