473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 19957
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. When I am using it at a customer site, things...
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 before I move on. Before I detail 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 maybe even an ASP.NET bug. Here is what I've...
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 unloading the image inthe picture box but I can't...
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 directory they are resized and saved in a remote...
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 created another class that inherits from it. However,...
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 Of Memory" Exception. Does anybody know how...
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 that "out of memory". this message box have three...
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 System.Drawing.Image.FromFile(String filename, Boolean...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.