views:

183

answers:

0

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)

alt text

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.:

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