Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
4.00/5 (1 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.

C#
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.

C#
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

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.
 
Share this answer
 
Virtualize[^] your datagridview.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900