?
Solved

Followup to previous recursive folder loop - showing thumbnails

Posted on 2006-10-23
7
Medium Priority
?
251 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 63

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 63

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 63

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 63

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

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!

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

771 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