943,545 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 3985
  • C# RSS
Aug 11th, 2009
0

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

Expand Post »
This file looks OK to me. I have permissions. See attached icon file (894 bytes long).
Attached Files
File Type: zip iconfile.zip (351 Bytes, 87 views)
Similar Threads
Reputation Points: 341
Solved Threads: 233
Posting Shark
DdoubleD is offline Offline
984 posts
since Jul 2009
Aug 12th, 2009
0

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

It seems this method doesn't support ico file. I tried with .bmp files, its working fine.
Reputation Points: 165
Solved Threads: 59
Posting Pro in Training
DangerDev is offline Offline
485 posts
since Jan 2008
Aug 12th, 2009
0

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

Click to Expand / Collapse  Quote originally posted by DangerDev ...
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.
Reputation Points: 341
Solved Threads: 233
Posting Shark
DdoubleD is offline Offline
984 posts
since Jul 2009
Aug 12th, 2009
1

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

Icon class is there.
c# Syntax (Toggle Plain Text)
  1. System.Drawing.Icon c = new Icon(@"c:\app\mapp\p1.ico");
  2. pictureBox1.Image = c.ToBitmap();
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Aug 12th, 2009
0

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

Quote ...
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.
Reputation Points: 165
Solved Threads: 59
Posting Pro in Training
DangerDev is offline Offline
485 posts
since Jan 2008
Aug 12th, 2009
0

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

Click to Expand / Collapse  Quote originally posted by adatapost ...
Icon class is there.
c# Syntax (Toggle Plain Text)
  1. System.Drawing.Icon c = new Icon(@"c:\app\mapp\p1.ico");
  2. 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:
C# Syntax (Toggle Plain Text)
  1. MemoryStream ms = new MemoryStream(webClient.DownloadData(uriIcon));
  2. 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
Reputation Points: 341
Solved Threads: 233
Posting Shark
DdoubleD is offline Offline
984 posts
since Jul 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Parameter is Invalid exception retrieving favicon.ico
Next Thread in C# Forum Timeline: C# parsing with XML





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC