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

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2009
Posts: 920
Reputation: DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough 
Solved Threads: 147
DdoubleD DdoubleD is offline Offline
Posting Shark

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

 
0
  #1
Aug 11th, 2009
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, 2 views)
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 483
Reputation: DangerDev has a spectacular aura about DangerDev has a spectacular aura about 
Solved Threads: 58
DangerDev's Avatar
DangerDev DangerDev is offline Offline
Posting Pro in Training

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

 
0
  #2
Aug 12th, 2009
It seems this method doesn't support ico file. I tried with .bmp files, its working fine.
Freedom in the Mind, Faith in the words.. Pride in our Souls...
Indian Developer
http://falaque.wordpress.com/
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 920
Reputation: DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough 
Solved Threads: 147
DdoubleD DdoubleD is offline Offline
Posting Shark

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

 
0
  #3
Aug 12th, 2009
Originally Posted by DangerDev View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,639
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 472
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

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

 
1
  #4
Aug 12th, 2009
Icon class is there.
  1. System.Drawing.Icon c = new Icon(@"c:\app\mapp\p1.ico");
  2. pictureBox1.Image = c.ToBitmap();
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 483
Reputation: DangerDev has a spectacular aura about DangerDev has a spectacular aura about 
Solved Threads: 58
DangerDev's Avatar
DangerDev DangerDev is offline Offline
Posting Pro in Training

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

 
0
  #5
Aug 12th, 2009
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.
Freedom in the Mind, Faith in the words.. Pride in our Souls...
Indian Developer
http://falaque.wordpress.com/
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 920
Reputation: DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough 
Solved Threads: 147
DdoubleD DdoubleD is offline Offline
Posting Shark

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

 
0
  #6
Aug 12th, 2009
Originally Posted by adatapost View Post
Icon class is there.
  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:
  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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC