954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Image.FromFile("myfilename.ico") throws "out of memory" exception...why?

This file looks OK to me. I have permissions. See attached icon file (894 bytes long).

Attachments iconfile.zip (0.34KB)
DdoubleD
Posting Shark
996 posts since Jul 2009
Reputation Points: 341
Solved Threads: 233
 

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

DangerDev
Posting Pro in Training
485 posts since Jan 2008
Reputation Points: 165
Solved Threads: 59
 
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.

DdoubleD
Posting Shark
996 posts since Jul 2009
Reputation Points: 341
Solved Threads: 233
 

Icon class is there.

System.Drawing.Icon c = new Icon(@"c:\app\mapp\p1.ico");
pictureBox1.Image = c.ToBitmap();
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 
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.

DangerDev
Posting Pro in Training
485 posts since Jan 2008
Reputation Points: 165
Solved Threads: 59
 

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

DdoubleD
Posting Shark
996 posts since Jul 2009
Reputation Points: 341
Solved Threads: 233
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You