Click here to Skip to main content
14,932,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i im trying to make a .tga image converter in c# and i get this message:
System.OutOfMemoryException: 'Out of memory.'

What I have tried:

System.Drawing.Image image = System.Drawing.Image.FromFile(@"C:thefiles/thing.tga");
image.Save(@"C:\Users\Me\Desktop\imagetest.png",System.Drawing.Imaging.ImageFormat.Png);
Posted
Updated 19-Jul-18 1:14am
Comments
MadMyche 18-Jul-18 14:51pm
   
Which line throws that error?
Member 13915301 18-Jul-18 14:52pm
   
first line

I don't think Targa images are natively supported. You may want to check out .NET Targa Image Reader[^] for the reading part of the problem.
   
Comments
Member 13915301 18-Jul-18 15:37pm
   
its says Paloma doesn't exist in the current content
Eric Lynch 18-Jul-18 16:07pm
   
what step are you doing when "it" says it and what is "it"?
MadMyche 18-Jul-18 17:31pm
   
Did you grab that project, or are you just using commands without it?
Just for completeness.

The exception type / error message is misleading but documented:
Remarks

Managed GDI+ has built-in encoders and decoders that support the following file types:
BMP
GIF
JPEG
PNG
TIFF

The file remains locked until the Image is disposed.

If the file does not have a valid image format or if GDI+ does not support the pixel format of the file, this method throws an OutOfMemoryException exception.
So TGA images are not natively supported and require to be handled by own code or using a library.
   
Comments
Eric Lynch 19-Jul-18 8:58am
   
Wow, someone actually documented that without taking the time to say, "hey, let's change that to an exception that describes what went wrong"...sad :)
Jochen Arndt 19-Jul-18 9:09am
   
That will never happen because creating a new exception might let existing applications terminate when they did not catch generic exceptions (System.Exception and System.SystemException) but only the specific exceptions that might occur.
Eric Lynch 19-Jul-18 9:25am
   
Yep, I understand its stuck now. However, I was hoping maybe somebody wrote documentation before they released it. In which case, they could have fixed it before release. I know, I know...novel concept actually writing documentation for a product BEFORE release...also, never going to happen :)
Jochen Arndt 19-Jul-18 10:03am
   
The culprit is the GDI+ function GdipLoadImageFromFile() which returns the GpStatus code 3 (OutOfMemory) when loading the image fails due to an unsupported image format or a corrupted file.

There is the GpStatus code 13 (UnknownImageFormat). I guess that it was a typo in the source code which was detected too late.
Eric Lynch 20-Jul-18 20:25pm
   
That's funny...the old "missing digit" excuse. That at least puts it in prspective..oops missed an "e"...seriously, thank you for brightening my day!
phil.o 19-Jul-18 10:04am
   
There has been a discussion a few months ago about that very same issue.
Unfortunately, managed gdi+ is quite terrible, imho. Lot of things have been left behind.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900