How do I create a fast/low memory usage thumbnail control on WinForms?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • theplague
    New Member
    • Feb 2009
    • 1

    How do I create a fast/low memory usage thumbnail control on WinForms?

    Hi guys,
    I've tried to create an user control that contains a picture box and have also created a similar control that paints an image inside a panel control with a border to make it look like a thumbnail, on both approaches it seems to use a lot of ram memory to keep that image displayed on the thumbnail and scrolling through many thumbnails can suck up some cpu time, what is the fastest approach to create several controls, thumbnail like inside a master panel that won't use so much memory and cpu?
    Thanks!
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    ... To make it look like a thumbnail ...
    It sounds like you aren't actually making a thumbnail, but rather loading the full size image and having Windows display it scaled down. The problem with this is exactly what you have seen: The object in memory is the full size image. If you are using a typical 10mp camera you are going to go out of memory really fast.

    There are some built in GetThumbnail routines available to you from the .NET framework. Or you can read in the fullsize image, and scale it yourself into a new bitmap object, then dispose of the fullsize object and place the scaled image in your PictureBox. Personally this is what I do. My scaling methods have a few more arguments so I can choose to preserve the full color-depth or not, add a border or not, scale to max width or max height etc.

    But for starters use the built in functions to see if that solves your issues and is of sufficient quality to save you the work in writting your own scaling.

    TIP. The .NET method for GetImage.FromFi le(string FilePath) has a glitch that keeps the file on hard drive locked up as long as you are using it. So if you use this method load to a TemporaryImage the copy that into a FinalImage then .Dispose() of TemporaryImage so your application is still tied to the harddrive file keeping any other program from having access to it.

    Comment

    • kunal pawar
      Contributor
      • Oct 2007
      • 297

      #3
      U can use Bitmap class to get thumbail of image.

      Bitmap b = new Bitmap(fileName );

      Image img = b.GetThumbailIm age(...);

      b.dispose();

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        Originally posted by kunal pawar
        U can use Bitmap class to get thumbail of image.

        Bitmap b = new Bitmap(fileName );

        Image img = b.GetThumbailIm age(...);

        b.dispose();
        I'm a huge beleiver in learning through doing and experimenting.
        So... Can you? When you try to do this does it work? What does Visual Studio tell you when you try to run this?

        Comment

        Working...