Trying to load an icon with GDI+ using GdipLoadImageFromFile:
Image image;
String filename = "C:\Archive\-=Images=-\Microsoft\Vista\shell32\Icon_129.ico";
Status result = GdipLoadImageFromFile(filename, out image);
returns the status OutOfMemory (3).
You can also use the object wrapper form:
Image image = new Image(filename, false)
According to the SDK, the OutOfMemory error is a bit of a lie:
If you construct a GDI+ object and then immediately call the GetLastStatus method of that object, you can determine whether the constructor succeeded or failed. In such cases, GetLastStatus might return OutOfMemory even though there was plenty of memory available to create the object. Several GDI+ constructors set the status to OutOfMemory when they fail regardless of the reason for failure.
So what is the problem, if not "OutOfMemory"?
It seems to only happen with icons that contains a 256x256 PNG compressed (i.e. a "Vista style") icon.
The icons were either ripped out of Windows' resource dll's, or created from scratch in Icon Workshop. The icons work fine in other programs, e.g.:
- Windows Explorer
- Axialis Icon Workshop
- LoadImage()
- Delphi
- Photoshop CSx (with an icon format plugin)
In other words, the icon is fine.
It's not even like it's error code 0, being mis-interpreted as "Out of memory", it really is returning 3 in EAX.
What's up with GDI+?
And it's not like i'm the only person to have problems loading icons using GDI+.
Note: i get the same error if i try to load the same icon from an IStream.
Related questions
- Using 256 x 256 Vista icon in application.
- Icon Extraction in VIsta..
- Can 48x48 or 64x64 icons be obtained from the Vista Shell?
- Windows chooses wrong icon from multi-icon file and self renders to correct size
- How to get big Vista icons for a shortcut created with a VS2008 Setup and Deployment project?
- Winforms .NET 2.0: How to draw a Png icon?
- WinForms .NET 2.0: How to paint the proper sized icon?
- Get full quality 16 x 16 icon using Icon.ExtractAssociatedIcon and ImageList
- can i extract the icon image from vista application? (mainly word and pdf)
- Get File Icon used by Shell
- 256x256 icons trouble again, or how to get TRUE icon size through IImageList