Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. PictureBox and mem usage

PictureBox and mem usage

Scheduled Pinned Locked Moved Windows Forms
questionperformancehelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 2 Offline
    2 Offline
    2hdass
    wrote on last edited by
    #1

    I am currently working on a project that involves previewing large amount of photoes at the same time, my program will have a view at which it will show the preview of all the image files in a particular directory. As of this moment, all the pictures are shown by using creating a PictureBox control for each picture and then shoving them into a panel. I realize that the mem usage is huge after loading about 120 pictures of ~900kb in size. I am suspecting it is because each PictureBox has loaded the FULL image into the memory, but not the thumbnail. I do realize that in the Image class, there is something called the getthumbnail() mehtod, how do i make use of this? Image is an abstract class, i cant use it directly, do i use some kind of file reader to open a stream and read it as an Image and then use the getthumbnail() method to get a thumbnail and then use it as the image for the pictureBoxes? thank you for your help :D

    L 1 Reply Last reply
    0
    • 2 2hdass

      I am currently working on a project that involves previewing large amount of photoes at the same time, my program will have a view at which it will show the preview of all the image files in a particular directory. As of this moment, all the pictures are shown by using creating a PictureBox control for each picture and then shoving them into a panel. I realize that the mem usage is huge after loading about 120 pictures of ~900kb in size. I am suspecting it is because each PictureBox has loaded the FULL image into the memory, but not the thumbnail. I do realize that in the Image class, there is something called the getthumbnail() mehtod, how do i make use of this? Image is an abstract class, i cant use it directly, do i use some kind of file reader to open a stream and read it as an Image and then use the getthumbnail() method to get a thumbnail and then use it as the image for the pictureBoxes? thank you for your help :D

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, you can load an image in memory, make a thumbnail of the required size, and dispose of the original image in memory:

      public Bitmap GetThumb(string path, int wid, int hei) {
      Image img=Image.FromFile(path); // locks file and loads entire image
      Bitmap bm=new Bitmap(img, wid, hei);
      img.Dispose(); // gets rid of big image in memory, and also the file lock
      return bm;
      }

      Remark: if wid and/or hei are much larger than 120 and the file does contain a thumbnail, then the above provides better quality than a simple Image.GetThumbnailImage(). :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups