如何在C#Winforms中加速缩略图创建?

发布于 2025-02-09 03:29:33 字数 584 浏览 1 评论 0原文

我的任务是从C#Windows表单控件中的文件夹中创建一系列图像的缩略图。图像的数量未知,因此我使用flowloayoutpanel的实例来排列它们。然后,我创建了许多实例的picturebox,然后将所有图像的缩略图分配给它们,例如在以下代码中(明显的操作省略):

FlowLayoutPanel flp = new FlowLayoutPanel();
foreach (string fileName in fileNames)
{
    PictureBox pb = new PictureBox();
    pb.Image = Image.FromFile(fileName).GetThumbnailImage(pb.Height, pb.Width, null, new IntPtr());
    flp.Controls.Add(pb);
}

此代码功能非常慢:需要很多秒钟即使在释放模式下,显示一百张图像左右。 我还试图自己分配图像,而不是创建缩略图,但仍然非常慢。

是否有可能以不同的方式加速缩略图或实现所需的结果(类似于专辑的缩略图)(例如,在外部C例程中通过Interop添加)?

My task is to create an array of thumbnails of images from a folder in a C# Windows Forms control. The number of images is unknown, so I use an instance of FlowLoayoutPanel to arrange them. Then I create a number of instances of PictureBox and assign the thumbnails of all the images to them, like in the following code (obvious action omitted):

FlowLayoutPanel flp = new FlowLayoutPanel();
foreach (string fileName in fileNames)
{
    PictureBox pb = new PictureBox();
    pb.Image = Image.FromFile(fileName).GetThumbnailImage(pb.Height, pb.Width, null, new IntPtr());
    flp.Controls.Add(pb);
}

This code functions, but very slowly: it takes many seconds to display a hundred images or so, even in Release mode.
I also tried to assign the images themselves, instead of creating thumbnails, but it is still very slow.

Is there any possibility to accelerate the creation of thumbnails or to achieve the desired result (an album-like collection of thumbnails) in a different way (e.g. in an external C routine to add via Interop)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文