My effort to retrieve favicon.ico sometimes fails even though it is found. It fails when attempting to convert the stream into a BMP or an Image using FromStream(), with the ArgumentException, or Parameter Invalid. I've tried all kinds of things to manipulate this and I guess I don't know what I'm doing.

When I save the stream to a file (SaveStreamAsIconFile) as *.ico, it appears to be a valid icon (explorer displays it, and the IDE even shows it).

Here is a link that won't work, and also the code I am using to download and convert the stream:

www.Juniper.com

public static Image GetFavIcon (Uri uriIcon)
        {
            WebClient webClient = new WebClient();
            
            MemoryStream ms = new MemoryStream(webClient.DownloadData(uriIcon));

            MiscMethods.SaveStreamAsIconFile(ms, uriIcon.Host);
            
            ms.Position = 0;
            
            Bitmap bmp = new Bitmap(ms);

            return bmp;//Image.FromStream(ms);
        }

When I try:

Image img = Image.FromFile(fileName);

I get a SystemException: "Out of Memory".

Admittedly, I don't know much concerning graphics. Can anybody tell me why this icon throws an exception? I have included it for examination.

Do not create duplicate thread for the same question.

Sorry, it won't happen again. I would have deleted this one if I could have. I just thought if I narrowed down the title/topic it might be easier found by someone knowledgeable with the Image class.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.