Question

System.Drawing.Image original = System.Drawing.Image.FromFile(photo);

That's the code where i have the problem "Out of memory."

"photo" is a path of an image which the size is 6400x6400.

Have anyone idea about that?

Was it helpful?

Solution

Is this C#? I think the answer may be here.

out of memory Image.FromFile

Top Answer from user: https://stackoverflow.com/users/31158/jordao

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.

Another top answer and thread to consider then:

Out Of Memory exception on System.Drawing.Image.FromFile()

From user: https://stackoverflow.com/users/22656/jon-skeet

It's worth knowing that OutOfMemoryException doesn't always really mean it's out of memory - particularly not when dealing with files. I believe it can also happen if you run out of handles for some reason.

Are you disposing of all your bitmaps after you're done with them? Does this happen repeatably for a single image?

Also, I would add- have you saved this file out using your code and tried to view it in another image viewer? It may be corrupt if it is being created incorrectly.

OTHER TIPS

Since I assume this is in C#, is your code is in a loop or in the Paint event? This could explain why it is not working. If you load several images or a single image multiple times, you will of course encounter a "Out of memory" Exception.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top