473,842 Members | 1,601 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,t rue);

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 20129
PJ
I had this problem when first learning how to create thumbnails from images.
Unfortunately, I don't remember the specific problem....howe ver, 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********@yah oo.com> wrote in message
news:fd******** *************** **@posting.goog le.com...
I get an out of memory exception when attempting to excecute the
following code:

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

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....howe ver, 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********@yah oo.com> wrote in message
news:fd******** *************** **@posting.goog le.com...
I get an out of memory exception when attempting to excecute the
following code:

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

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(ByV al 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.GetPathRoo t(fullPath)

Dim imagename As String = Path.GetFileNam e(fullPath)

Dim extension As String = Path.GetExtensi on(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.GetThumb nailImage(futur ewidth, FinalSize, Nothing, New
IntPtr())

If File.Exists(ima gefolder & imagename) Then File.Delete(ima gefolder &
imagename)

newimage.Save(N ewFullPath, System.Drawing. Imaging.ImageFo rmat.Jpeg)

Catch exp As Exception

result = "failed"

newimage.Dispos e()

Throw exp

End Try

ElseIf width > height Then

BiggerSide = "width"

myratio = FinalSize / width

futureheight = myratio * height

Try

newimage = Normal.GetThumb nailImage(Final Size, futureheight, Nothing, New
IntPtr())

If File.Exists(New FullPath) Then File.Delete(ima gefolder & imagename)

newimage.Save(N ewFullPath, System.Drawing. Imaging.ImageFo rmat.Jpeg)

Catch exp As Exception

result = "failed"

newimage.Dispos e()

Throw exp

End Try

Else

BiggerSide = "Same"

myratio = 1

Try

newimage = Normal.GetThumb nailImage(Final Size, FinalSize, Nothing, New
IntPtr())

If File.Exists(New FullPath) Then File.Delete(ima gefolder & imagename)

newimage.Save(N ewFullPath, System.Drawing. Imaging.ImageFo rmat.Jpeg)

Catch exp As Exception

newimage.Dispos e()

result = "failed"

Throw exp

End Try

End If

Normal.Dispose( )

newimage.Dispos e()

If DeleteOriginal = True Then File.Delete(ful lPath)

Return result

End Function

End Class
"PJ" <pj*********@ho tmail.com> wrote in message
news:u3******** ******@TK2MSFTN GP12.phx.gbl...
I had this problem when first learning how to create thumbnails from images. Unfortunately, I don't remember the specific problem....howe ver, 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********@yah oo.com> wrote in message
news:fd******** *************** **@posting.goog le.com...
I get an out of memory exception when attempting to excecute the
following code:

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

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
4877
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 change. Occasionally, it blows up with an Application Exception. It seems to only die at the customer site
4
5025
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, this problem requires some understanding of threading concepts. Basically, the class contained both a PictureBox object as well as a corresponding Image object (they both had a copy of the same picture). The following was used to access the...
0
1390
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 done so far... 1. Learned from this post that there are problems with the FromFile method when using a UNC share as the source directory: http://tinyurl.com/8exos. 2. Adapted the code in the post to: '\\\
3
2832
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 seem to figure out the correct way to "unload" the file. I have a simple form with a picture box and a button. I am using dir() to get all the the .tif files and display them in the pciture box. Each time the button it pressed it displays the...
1
4765
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 directory. The original file is then backed up and deleted from the image directory. The code is as follows Friend Shared Sub ResizeImage(ByVal path As String, ByVal filename As String)
5
3379
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, when I did this I got the following error: 'System.Drawing.Image.Image()' is inaccessible due to its protection level Looking at other online examples, I found that the proper way to use it is like this:
6
6664
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 can I overcome this problem?
2
2729
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 button DETAILS , CONTINUE , QUITE when details button click then i am getting folowinf message. See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.
9
2311
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 useEmbeddedColorManagement) at Procédo.MainApp.QualityCheckClass.EvaluateTiffImage(ThreadM essageClass& displayObject, String fileName, String startingPageNum, String fileExt) in D:\src\Procédo\MainForm\QualityCheck.vb:line 3957"
0
9872
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10945
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10612
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10672
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10314
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7858
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7038
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4499
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.