472,347 Members | 2,350 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,347 software developers and data experts.

Out of Memory Exception: System.Drawing.Image.FromFile

I get an out of memory exception when attempting to excecute the
following code:

original = System.Drawing.Image.FromFile(file.FileName,true);

I ONLY get this exception when the file is in the "My Documents"
folder or subfolders. If the file lives anywhere else on the hard
drive, I have no problems.

What could be going on here?

Thanks in advance,
Stacey
Nov 17 '05 #1
3 19564
PJ
I had this problem when first learning how to create thumbnails from images.
Unfortunately, I don't remember the specific problem....however, I think
you'd do much better off by creating an Image object from a byte array.
Grab the file from a FileStream object first and then create the image
object from a BinaryReader off the FileStream instance....

If this isn't helping you...post back and I will give you code I use to
manipulate images from files/streams....just don't have it now...it at work
;-).

"anastasia" <an********@yahoo.com> wrote in message
news:fd*************************@posting.google.co m...
I get an out of memory exception when attempting to excecute the
following code:

original = System.Drawing.Image.FromFile(file.FileName,true);

I ONLY get this exception when the file is in the "My Documents"
folder or subfolders. If the file lives anywhere else on the hard
drive, I have no problems.

What could be going on here?

Thanks in advance,
Stacey

Nov 17 '05 #2
PJ
I had this problem when first learning how to create thumbnails from images.
Unfortunately, I don't remember the specific problem....however, I think
you'd do much better off by creating an Image object from a byte array.
Grab the file from a FileStream object first and then create the image
object from a BinaryReader off the FileStream instance....

If this isn't helping you...post back and I will give you code I use to
manipulate images from files/streams....just don't have it now...it at work
;-).

"anastasia" <an********@yahoo.com> wrote in message
news:fd*************************@posting.google.co m...
I get an out of memory exception when attempting to excecute the
following code:

original = System.Drawing.Image.FromFile(file.FileName,true);

I ONLY get this exception when the file is in the "My Documents"
folder or subfolders. If the file lives anywhere else on the hard
drive, I have no problems.

What could be going on here?

Thanks in advance,
Stacey

Nov 17 '05 #3
Public Function resiseImage(ByVal fullPath As String, _

ByVal FinalSize As Integer, ByVal NewFullPath As String, _

Optional ByVal DeleteOriginal As Boolean = False) As String

Dim result As String = "Success"

Dim imagefolder As String = Path.GetPathRoot(fullPath)

Dim imagename As String = Path.GetFileName(fullPath)

Dim extension As String = Path.GetExtension(imagename)

Dim height As Integer

Dim width As Integer

Dim BiggerSide As String

Dim myratio As Decimal

Dim futureheight As Integer

Dim futurewidth As Integer

Dim Normal As System.Drawing.Image

Dim newimage As System.Drawing.Image

Normal = Normal.FromFile(fullPath)

height = Normal.Height

width = Normal.Width

If height > width Then

BiggerSide = "height"

myratio = FinalSize / width

futurewidth = myratio * width

Try

newimage = Normal.GetThumbnailImage(futurewidth, FinalSize, Nothing, New
IntPtr())

If File.Exists(imagefolder & imagename) Then File.Delete(imagefolder &
imagename)

newimage.Save(NewFullPath, System.Drawing.Imaging.ImageFormat.Jpeg)

Catch exp As Exception

result = "failed"

newimage.Dispose()

Throw exp

End Try

ElseIf width > height Then

BiggerSide = "width"

myratio = FinalSize / width

futureheight = myratio * height

Try

newimage = Normal.GetThumbnailImage(FinalSize, futureheight, Nothing, New
IntPtr())

If File.Exists(NewFullPath) Then File.Delete(imagefolder & imagename)

newimage.Save(NewFullPath, System.Drawing.Imaging.ImageFormat.Jpeg)

Catch exp As Exception

result = "failed"

newimage.Dispose()

Throw exp

End Try

Else

BiggerSide = "Same"

myratio = 1

Try

newimage = Normal.GetThumbnailImage(FinalSize, FinalSize, Nothing, New
IntPtr())

If File.Exists(NewFullPath) Then File.Delete(imagefolder & imagename)

newimage.Save(NewFullPath, System.Drawing.Imaging.ImageFormat.Jpeg)

Catch exp As Exception

newimage.Dispose()

result = "failed"

Throw exp

End Try

End If

Normal.Dispose()

newimage.Dispose()

If DeleteOriginal = True Then File.Delete(fullPath)

Return result

End Function

End Class
"PJ" <pj*********@hotmail.com> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl...
I had this problem when first learning how to create thumbnails from images. Unfortunately, I don't remember the specific problem....however, I think
you'd do much better off by creating an Image object from a byte array.
Grab the file from a FileStream object first and then create the image
object from a BinaryReader off the FileStream instance....

If this isn't helping you...post back and I will give you code I use to
manipulate images from files/streams....just don't have it now...it at work ;-).

"anastasia" <an********@yahoo.com> wrote in message
news:fd*************************@posting.google.co m...
I get an out of memory exception when attempting to excecute the
following code:

original = System.Drawing.Image.FromFile(file.FileName,true);

I ONLY get this exception when the file is in the "My Documents"
folder or subfolders. If the file lives anywhere else on the hard
drive, I have no problems.

What could be going on here?

Thanks in advance,
Stacey


Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: gregory_may | last post by:
I have an application I created called "JpegViewer.exe". It simply loads a Jpeg file and displays in on the screen. It works great, in my lab. ...
4
by: 6tc1 | last post by:
Hi all, I have just finished debugging a windows application and have solved the problem - however, I want to be sure that I understand the problem...
0
by: Eric | last post by:
I have this same problem, and I've *half-way* resolved it. It turns out that this is not exactly an IO problem; it's actually a security issue and...
3
by: Scott | last post by:
Hello, I am running into a problem with my code and can't seem to figure out the solution. I know it has to do with the pciture box control and...
1
by: Rocky | last post by:
I have created a windows service using vb.net which uses a filesystemwatcher to monitoe files in a specifc directory, if images are added to the...
5
by: Jerry J | last post by:
I want to use the System.Drawing.Image class. According to the help file, this is an abstract base class. Because it is supposedly abstract, I...
6
by: sternr | last post by:
Hey, When I try to run the following code: System.Drawing.Image tiffImage = System.Drawing.Image.FromFile(@"C: \Image.tiff"); I get an "Out...
2
by: abhijeet28 | last post by:
Hi friends i have some problem . I am doing project with vb,net 3.0 . I am getting a run time exception , I am getting a messge window mentioning...
9
by: Victory | last post by:
Hi, After calling this function 190 times, i get an exception at the point of exception. The stack trace says: StackTrace " at...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.