AdeHall Posted October 3, 2003 Posted October 3, 2003 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 Quote
*Gurus* divil Posted October 3, 2003 *Gurus* Posted October 3, 2003 You're probably running out of memory and having to swap to disk. Are you disposing of each image and any intermediate bitmaps and graphics objects before loading the next? Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
AdeHall Posted October 3, 2003 Author Posted October 3, 2003 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) ) ; } } Quote
*Gurus* divil Posted October 6, 2003 *Gurus* Posted October 6, 2003 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. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
AdeHall Posted October 6, 2003 Author Posted October 6, 2003 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? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.