Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm trying to load multiple jpegs from disk to create thumbnails. I've tried various ways but the Image.FromFile( path ) or Bitmap aBitmap = new Bitmap( path ) methods seem very slow.

 

The jpegs are about 750k each but it is taking approx 30-40 seconds to load 100.

 

Are there any faster ways to load the data?

Thanks

Ade

Posted

This is a little benchmark prog I tried, to make sure that it was the IO that was taking the time before I do anything with the image.

I ended up forcing the garbage collector because as you say I was running out of memory.

 

When you use one of the commercial photo apps out there they seem to be able to read in and convert the same images in a fraction of the time. Surely .NET can't be making that much difference can it?

 


if ( openFileDialog1.FileNames != null )
			{
				DateTime StartTime = DateTime.Now;
				System.Diagnostics.Debug.WriteLine( "Start:" + StartTime.ToLongTimeString());
									int i=0;
				foreach ( string FileName in openFileDialog1.FileNames )
				{
					i++;
					Bitmap _bitmapNew;
					 _bitmapNew = (Bitmap)Image.FromFile( FileName, false );
										_bitmapNew = null;
					GC.Collect();
					GC.WaitForPendingFinalizers();
				}
				DateTime EndTime = DateTime.Now;
				System.Diagnostics.Debug.WriteLine( "End:" + EndTime.ToLongTimeString());
				System.Diagnostics.Debug.WriteLine( "Loading " + i.ToString() + " Photos took " + (EndTime - StartTime) ) ;
			}
}

  • *Gurus*
Posted

There's no need to invoke the garbage collector like that. In my last post I said you need to dispose of objects when you're done with them. In that example you're still not doing this.

 

Bitmap _bitmapNew;
_bitmapNew = (Bitmap)Image.FromFile( FileName, false );
_bitmapNew.Dispose();
_bitmapNew = null;

 

Don't worry too much if you see your memory usage increasing - if it becomes a problem, or after a short delay, the garbage collector will collect.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

Thanks Divil

 

The memory as you say is looking after itself better.

However, it is still taking 45 seconds to load and dispose of 145 jpgs.

 

Do you think 1/3 of a second is a long time to open and load a 700k file from disk?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...