Out of memory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raids51
    New Member
    • Nov 2007
    • 59

    Out of memory

    im making a program that will create a new button for every file in a directory(my pictures) and the background image for the button will be the picture...but when i run it i get an out of memory error...here is the code
    Dim dir As New DirectoryInfo(M y.Computer.File System.SpecialD irectories.MyPi ctures)
    Dim f As FileInfo
    For Each f In dir.GetFiles

    Dim newbutton As New Button
    'below is where the problem is'
    newbutton.Backg roundImage = Image.FromFile( f.FullName)
    newbutton.Text = f.Name

    Me.Controls.Add (newbutton)

    Next f
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by raids51
    im making a program that will create a new button for every file in a directory(my pictures) and the background image for the button will be the picture...but when i run it i get an out of memory error...here is the code
    Dim dir As New DirectoryInfo(M y.Computer.File System.SpecialD irectories.MyPi ctures)
    Dim f As FileInfo
    For Each f In dir.GetFiles

    Dim newbutton As New Button
    'below is where the problem is'
    newbutton.Backg roundImage = Image.FromFile( f.FullName)
    newbutton.Text = f.Name

    Me.Controls.Add (newbutton)

    Next f
    try writing the files name in the command button, instead of adding it as the bgimage.

    newbutton.capti on = f.FullName

    instead of

    newbutton.Backg roundImage = Image.FromFile( f.FullName)

    that way you'll see how many buttons you're generating and how they look without a background image.

    If this works fine, then the problem is that you're using many and heavy images and your computer cannot handle them

    I this doesnt work, may be the problem is with the loop, or with the sub-files you might have.

    HTH

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Yes, without seeing the code it's difficult to give a definite answer. But images can be quite memory-hungry and loading a lot of them at once might use it all up.

      Are these buttons all visible at once, or do you have to scroll, or what? If you really do need to show the images on them, there are a number of things you might try. For example, reducing each image to a thumbnail for display, rather than simply "showing it small". Or perhaps you could get away with only loading them as they scroll onto the display, and throwing them away when they scroll off.

      Comment

      • raids51
        New Member
        • Nov 2007
        • 59

        #4
        Originally posted by kadghar
        try writing the files name in the command button, instead of adding it as the bgimage.

        newbutton.capti on = f.FullName

        instead of

        newbutton.Backg roundImage = Image.FromFile( f.FullName)

        that way you'll see how many buttons you're generating and how they look without a background image.

        If this works fine, then the problem is that you're using many and heavy images and your computer cannot handle them

        I this doesnt work, may be the problem is with the loop, or with the sub-files you might have.

        HTH
        yah. that works i was doing that before... mabey my laptop just cant handle it

        Comment

        • raids51
          New Member
          • Nov 2007
          • 59

          #5
          Originally posted by kadghar
          try writing the files name in the command button, instead of adding it as the bgimage.

          newbutton.capti on = f.FullName

          instead of

          newbutton.Backg roundImage = Image.FromFile( f.FullName)

          that way you'll see how many buttons you're generating and how they look without a background image.

          If this works fine, then the problem is that you're using many and heavy images and your computer cannot handle them

          I this doesnt work, may be the problem is with the loop, or with the sub-files you might have.

          HTH
          but the pictures are only 2kb

          Comment

          • raids51
            New Member
            • Nov 2007
            • 59

            #6
            well... i found out what is wrong:D...the problem wasnt because of the file size...it was because the program was listing EVERY file in the my pictures file...includin g the systems files(thumbs.db and the desktop.ini or w.e)which werent pictures...so apparently you cant load a picture from a file when the file isnt a picture file:P

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Originally posted by raids51
              so apparently you cant load a picture from a file when the file isnt a picture file:P
              Well, that's a bit disappointing, then. :)

              Glad to see you got the problem sorted, though.

              By the way, I wouldn't set too much store by the file size. A 2KB JPEG file, for instance, can decompress to quite a large image. This will take up lots of RAM if held there as a bitmap (which I think they are).

              Comment

              Working...