It seems this method doesn't support ico file. I tried with .bmp files, its working fine.

Are you sure this method doesn't support ico files? I haven't seen that claim anywhere until now. Sure would be helpful to know for sure.

Icon class is there.

System.Drawing.Icon c = new Icon(@"c:\app\mapp\p1.ico");
pictureBox1.Image = c.ToBitmap();
Comments
thats it! :)

Are you sure this method doesn't support ico files? I haven't seen that claim anywhere until now. Sure would be helpful to know for sure.

Even i have not seen such claim, but i tried and was talking about result.

Icon class is there.

System.Drawing.Icon c = new Icon(@"c:\app\mapp\p1.ico");
pictureBox1.Image = c.ToBitmap();

I tried that--it did work. What I can't figure out is how to convert my Stream containing the icon (bitmap). I saved that icon to a file from the stream in order to narrow down the problem.

I don't understand why the Bitmap object initialization works from the file OK in this case, but not from my stream:

MemoryStream ms = new MemoryStream(webClient.DownloadData(uriIcon));
            Bitmap bmp = new Bitmap(ms); // throws exception

But, if I save the memorystream above to a file, then read it with the code you gave, it works (no exception thrown).

This failure (ParameterInvalid exception) only occurs with certain icons I test, which is why I provided the sample. How can I convert this icon directly from my stream to a bitmap without having to save it to a file first?

Thanks,
David

This article has been dead for over six months. Start a new discussion instead.