Click here to Skip to main content
13,046,087 members (74,506 online)
Rate this:
Please Sign up or sign in to vote.
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.

The images can be in 2 folders and I search on just the product number, product number-1.jpg and in the second folder.

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;
        newheight = height;
        result = (double)bmp.Width / bmp.Height * width;
        newwidth = (int)result;
    artikel.Afbeelding = bmp.GetThumbnailImage(newwidth, newheight, null, new IntPtr());

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.

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
Posted 10-Sep-12 23:34pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Virtualize[^] your datagridview.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Beyond virtualizing the gridview, you could also use a "proxy" object for the image. A default picture would be shown first, and the actual image loaded in a different thread and shown when available. That's similar to Microsoft's method in Windows Explorer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 11 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100