out of memory Image.FromFile

In the Image.FromFile documentation, an OutOfMemoryException can be throw if:

The file does not have a valid image format.

-or-

GDI+ does not support the pixel format of the file.

Check your image format.

Also, if you want to close the stream right after loading the image, you must make a copy of the image. Take a look here. GDI+ must keep the stream open for the lifetime of the image.

Leave a Comment