Solved

Followup to previous recursive folder loop - showing thumbnails

Posted on 2006-10-23
7
250 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 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

728 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