Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Followup to previous recursive folder loop - showing thumbnails

Posted on 2006-10-23
7
Medium Priority
?
254 Views
Last Modified: 2010-04-23
Got some help recently (http://www.experts-exchange.com/Q_22027719.html) on displaying thumbnail images on a flowlayoutpanel.  The app should recursively scan through a folder tree laid out like:
\\servername\share\users\username1
\\servername\share\users\username2
\\servername\share\users\username3
[etc...]

Under each of these subfolders sits a file, JPG.LST.

My goal here is to display the images as they are 'read'.  The previous solution scanned all subfolders first, and with over 150,000 images, took a bit too long before the user was presented with anything (about 40 minutes).

Now, I also want to implement a solution (right now, I'm using a menu item) to pause the process, so that the user can continue the following day.  This option would only be available after a full page has been loaded.  I believe I have this implemented already, just thought it might bear mentioning (I'm writing the 'file' and position into an xml config file).

Here's the code as it stands now:

    Private DisplayCount As Integer = 192
    Private NextImage As Integer = 0
    Private UserImagesNames As New ArrayList

 Private Sub process(ByVal strDir As String)
   Dim di As DirectoryInfo = New DirectoryInfo(strDir)
     For Each fi As FileInfo In di.GetFiles("JPG.LST")
      Using sr As New StreamReader(fi.FullName)
       Dim input As String = sr.ReadToEnd()
       UserImagesNames.AddRange(input.Split(CrLf, StringSplitOptions.RemoveEmptyEntries))
       DisplayImages()
      End Using
     Next

     For Each subdir As DirectoryInfo In di.GetDirectories
       process(subdir.FullName)
     Next
    End Sub

   Private Sub DisplayImages()
        If NextImage >= UserImagesNames.Count Then Return

        ' Control type to be place in the FlowLayoutPanel
        Dim pb As PictureBox

        ' Get and dispplay the images
        For idx As Integer = 0 To DisplayCount - 1
            pb = New PictureBox
            pb.SizeMode = PictureBoxSizeMode.AutoSize
            pb.Margin = New System.Windows.Forms.Padding(1, 1, 1, 1)
            pb.Size = New Size(60, 60)
            pb.SizeMode = PictureBoxSizeMode.StretchImage
            pb.Image = Image.FromFile(UserImagesNames(NextImage).ToString)
            pb.Show()
            FlowLayoutPanel1.Controls.Add(pb)
            NextImage += 1
            If NextImage >= UserImagesNames.Count Then Exit For
            Application.DoEvents()
        Next
    End Sub
0
Comment
Question by:sirbounty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 17796667
Hi sirbounty;

I have read through your post but am not sure what questionyou are asking. ;=(

Fernando
0
 
LVL 67

Author Comment

by:sirbounty
ID: 17797412
Well, I believe I have it setup the way I want it - but it doesn't seem to be working 100%.
I dropped the images in half (192 total now) - so that overcomes the out of memory problem, but it's still shutting down here:

pb.Image = Image.FromFile(UserImagesNames(NextImage).ToString)

I get another "out of memory" - but I'm only on NextImage for value 30 - that shouldn't kill it, should it?
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 17797591
I looked at the documentation for the Image.FromFile method and this is what I found.

The method will throw an exception of OutOfMemoryException for the following reasons.

    1. The file does not have a valid image format.
    2. GDI+ does not support the pixel format of the file.

So the exception is misleading.

This is what you may want to do to get around this.

            Try
                pb.Image = Image.FromFile(UserImagesNames(NextImage).ToString)
            Catch ex As Exception
                ' Write the name of the file out to a log file
                Console.WriteLine("Image file not displayed " & UserImagesNames(NextImage).ToString)
            End Try

The documentation may be found at: http://msdn2.microsoft.com/en-us/library/stf701f5.aspx

Fernando
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 67

Author Comment

by:sirbounty
ID: 17798281
Seems to be working.
I think I'll have a default "Cannot load" image to place in there during the catch (cause it leaves a 'blank' box otherwise).

Have a couple more questions following this...stay tuned! :^)
And thanx again!
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 17798335
No problem. ;=)
0
 

Expert Comment

by:NimoDos
ID: 20543660
Hi Fernando,

Can an image object hold a pdf document?
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 20545921
Hi NimoDos;

No. You will get the error "OutOfMemoryException" which is misleading. The real reason is that one of two reasons, 1. The file does not have a valid image format or 2. GDI+ does not support the pixel format of the file.

Have a Happy New Year.

Fernando
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question