datagridview c#中的大量缩略图 [英] Large amount of thumbnails in datagridview c#
问题描述
我有一个包含超过10000条记录的商品表
大约有1500篇带有图片的文章.
大约有500张,其中约有3张图片.
在互联网上搜索了多个小时.但是没有找到对我而言很好的选择.
现在该程序每周运行5天,然后关闭.
如果可以更快地运行,我可以将其集成到另一个程序中.
因此,现在它刚刚加载到数据表中,因此一旦加载就很快了.
图片可以放在2个文件夹中,我只搜索产品编号,产品编号-1.jpg和第二个文件夹中的内容.
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;
}
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.
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
推荐答案
虚拟化 [ ^ ]您的datagridview.
Virtualize[^] your datagridview.
除了虚拟化gridview之外,您还可以为图像使用代理"对象.将首先显示默认图片,然后将实际图片加载到其他线程中,并在可用时显示.类似于Windows资源管理器中Microsoft的方法.
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.
这篇关于datagridview c#中的大量缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!