Getting Out of Memory Exception when loading in images
I get a system out of memory error after calling
Image.FromFile
in GetTarget()
. How should I fix this?
40 Replies
How big is the image?
11KB it looks like
And it's height and width?
612 x 369
Hmmm, that shouldn't cause any memory problems
How much memory is the application using in diagnostic tools? (assuming you're using visual studio)
Not really sure what any of this means so just ss'ed lol
Actually, it seems like Image.FromFile throws Out Of Memory for if the file's format is invalid
Ohh
Why would it be invalid?
Its a jpg
Then it's most likely a problem with the pixel format, can you try saving the image again with paint for example?
It looks like that worked .. ?
Agh I have like 20 photos i wanted to load in... I have to do this for all of them now?
Probably 😅
😠is there any better way to do this lol
If you have ImageMagick installed, sure you can write a script to do it automatically
nah thats fine, i just meant would there be a way to use the existing images still
like a diff method or smth
Oh, maybe you could try loading the image using ImageSharp
Gothca
thanks for the help
Load the images using ImageSharp then use Image.FromStream to load the images from ImageSharp's streams
But woudl i be able to get it into a bitmap datatype
like I do for this one
Yeah
Ohh
Is it sixlabors.imagesharp?
Yeah
And loading an image just as simple as
Image.Load
, which will return an Image
instancedo you happen to know the method for imagesharp
to load the images
using var image = Image.Load("IMAGE_PATH_GOES_HERE");
this isnt right but its what i have so far
what am i missing?
You need to save the ImageSharp's
Image
to a temporary stream
So something like
is jpgfromat a package? its not recogfnzied
Should be provided by ImageSharp
hmm doesnt seem to work when i add that to it
ah its jpeg lol
lmao my bad
:kekYep:
woohoo that all seemed to work!
:HYPERS:
tyyy
Please make sure you have
using
before var image
Just to make sure the image instance is disposedhow does using worked in that context?
It would look something like this
using var image = SixLabors.ImageSharp.Image.Load(....);
using
essentially is just syntactic sugar that ensures Dispose
is called on the image instance, that way you won't leak resourcesahh ok awesome
tysm !