Solved

Followup to previous recursive folder loop - showing thumbnails

Posted on 2006-10-23
7
244 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
  • 4
  • 2
7 Comments
 
LVL 62

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 62

Accepted Solution

by:
Fernando Soto earned 500 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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 62

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 62

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now