如何在窗口表单中加载多个图像 [英] How to load multiple images in a window forms

查看:71
本文介绍了如何在窗口表单中加载多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在一个窗口中加载多个图像,问题是当我加载了这么多图像时,可以说它抛出了500个或更多图像而导致内存不足,另一个问题是它的height属性.控件仅限于约32,000,当我尝试添加许多pictureBox时,它不适合面板控件,并且某些pictureBox不显示,这是我的代码..

I need to load multiple image in a window, the problem is when I''m loading so many images, lets say about 500 or more images it throws out of memory exception, another problem is the height property of the control is only limited to about 32,000, when I try to add many pictureBox it does not fit in the panel control and some pictureBox are not display, here''s my codes ..

private void Form1_Load(object sender, EventArgs e)
{
    string imageDirectory = @"c:\temp\myImages";

    string[] imageFileList = Directory.GetFiles(imageDirectory);

    int iCtr = 0;
    foreach (string imageFile in imageFileList)
    {
        PictureBox eachPictureBox = new PictureBox();
        eachPictureBox.Size = new Size(850, 1100);
        eachPictureBox.Location = new Point(1, iCtr * 1100 + 1);
        eachPictureBox.Image = Image.FromFile(imageFile);
        iCtr++;

        panel1.Controls.Add(eachPictureBox);

    }

}



我尝试在加载窗口窗体时加载它,任何提示将不胜感激,谢谢..



I try to load it when the window form loads, any tips will be much appreciated, thanks ..

推荐答案

好吧,您有自己的答案.您可能有什么尘世原因加载这么多图像?您无法对面板的最大大小做任何事情,可以尝试使用自然滚动的控件,该控件可能没有限制b.c可能实际上并不能一次全部存在.

您无法采取任何措施来改变以下事实:每个映像都使用特定数量的RAM,或者计算机上的RAM有有限的限制. IMO最好的选择是创建自己的可滚动控件,该控件在滚动时加载可见图像(可能一页一页地显示),并在不再显示旧图像时清理其内存.
Well, you kind of have your answer. What earthly reason could you have for loading so many images ? You can''t do anything about the max size of a panel, you could try using a naturally scrollable control, which may not have a limit b.c it may not actually all exist visually at once.

You can''t do anything to change the fact that each image uses a particular amount of RAM, or that the RAM on your machine has a finite limit. Your best bet IMO would be to create your own scrollable control, which loads the visible images as you scroll ( probably page by page ), and cleans up it''s memory as it stops showing the old images.


您好,三心之力,

您可以使用虚拟化概念来加载Christian提到的图像.他提到的上述两个概念之一将对您有所帮助.
Hi triskellionheart,

You can use the virtualizing concept to load the images as mentioned by Christian. One of the above two concept mentioned by him will help you.


您好,

当您从文件夹文件中读取文件时,它会选择sum和隐藏文件,例如desktop.ini等,因此会出现错误
Hi,

When u are reading from folder files it picks sum hidden file as well like desktop.ini etc hence the error


这篇关于如何在窗口表单中加载多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆