Reputation: 25
I have been trying to get favicon working on the Web browser that I am creating. I assume that I have to use an image and apply code to it. I found this code but FromStream
and FromFile
are giving me the error System.Windows.Controls.Image
does not contain a definition for FromStream
for both, as I am fairly new to programming I do not know what I need to do to solve the problem.
Any help would be greatly appreciated.
This is the code:
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);
}
}
Upvotes: 1
Views: 574
Reputation: 99
I went through your code.
You need to use Image
from System.Drawing
namespace by referencing System.Drawing.dll
.
System.Drawing.Image.FromStream(s)
System.Windows.Controls.Image
does not have FromFile
and FromStream
methods.
Hope this helps.
Upvotes: 1