Large amount of thumbnails in datagridview c#
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Large amount of thumbnails in datagridview c#

  1. #1
    Join Date
    Aug 2012
    Posts
    9

    Large amount of thumbnails in datagridview c#

    I have a article table with over 10000 records
    There are around 1500 articles with a picture.
    And around 500 with around 3 pictures of the article.

    Searched for many houres on the internet. But didn't find any option that was good in my case.

    Now the program self runs for 5 days each week and is then shut down.
    If it would run faster I would integrate it in another program.
    So now its just loaded in the datatable so it is fast once it's loaded.

    Code:
    Boolean bool3 = System.IO.File.Exists(strImagePath1 + artikel.ArtikelId + ".jpg");
    Boolean bool1 = System.IO.File.Exists(strImagePath1 + artikel.ArtikelId + "-1.jpg");
    Boolean bool2 = System.IO.File.Exists(strImagePath2 + artikel.ArtikelId + ".jpg");
    if (bool3 == true || bool1 == true || bool2 == true)
    {
        if (bool3 == true) 
        {
            bmp = new Bitmap(System.Drawing.Bitmap.FromFile(strImagePath1 + artikel.ArtikelId + ".jpg"));
        }
        if (bool1 == true && bool3 == false)
        {
            bmp = new Bitmap(System.Drawing.Bitmap.FromFile(strImagePath1 + artikel.ArtikelId + "-1.jpg"));
        }
    
        if (bool2 == true && bool3 == false && bool1 == false)
        {
            bmp = new Bitmap(System.Drawing.Bitmap.FromFile(strImagePath2 + artikel.ArtikelId + ".jpg"));
        }
        if (bmp.Width > bmp.Height)
        {
            result = (double)bmp.Height / bmp.Width * height;
            newheight = (int)result;
            newwidth = width;
        }
        else
        {
            newheight = height;
            result = (double)bmp.Width / bmp.Height * width;
            newwidth = (int)result;
        }
        artikel.Afbeelding = bmp.GetThumbnailImage(newwidth, newheight, null, new IntPtr());
        bmp.Dispose();
    Now the question is can it load faster. just need low quality thumbnails.
    If the product is called seperatly I will call it from the folder.
    It can't have effect on sorting/filtering.
    The pictures change sometimes to so can't work with reference.

    Maybe one option is just loading a thumbnail in the database and get the rest of the images in the folders.
    But I would like to know what is your suggestion.

    Tried this already but still long loading time.

    Code:
    public static System.Drawing.Image ResizeImage(System.Drawing.Image image, int width, int height)
    {
        //a holder for the result 
        Bitmap result = new Bitmap(width, height);
    
        //use a graphics object to draw the resized image into the bitmap 
        using (Graphics graphics = Graphics.FromImage(result))
        {
            //set the resize quality modes to high quality 
            graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
            graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low;
            graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
            //draw the image into the target bitmap 
            graphics.DrawImage(image, 0, 0, result.Width, result.Height);
        }
        //return the resulting bitmap 
        return result;
    }
    Thanks in advance

  2. #2
    Join Date
    Jul 2012
    Posts
    90

    Re: Large amount of thumbnails in datagridview c#

    My guess would be it is, at least in part, due to the fact that you are generating the thumbnails at runtime. If you create the thumbnail as a separate picture and save it in the DB with the full size picture when the full size picture is saved you could save a lot of time during page load. You could save even more by caching the thumbnails since they are small (just make sure that when a picture is changed, you change it's thumbnail in the cache as well as in the DB). This would also allow you to pre-cache the thumbnails when the application first starts.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center