public partial class Form1 : Form
    {
        public Form1()
        {
           
            InitializeComponent();
            ShowPictrue();
        }
        Image img = null;        
        
        int index = 0;        string [] path =System.IO.Directory.GetFiles(Application.StartupPath + "\\image\\");
        private void ShowPictrue()
        {
            foreach (string p in path)
            {
                img = Image.FromFile(p);//为什么会说内存不够?要有足够的内存
                imageList1.Images.Add(img);
            }                 
            this.pictureBox1.Image = imageList1.Images[0];
        } 
    }
请大家帮我看看为什么编译器不让遍历path,我想把 应用程序\\image\\路径下的文件名存到PATH中,
然后在把这些文件依次放到imageList1中,并在pictureBox1中显示

解决方案 »

  1.   

     string[] path = System.IO.Directory.GetFiles(Application.StartupPath + "\\NEWFACE\\");
                for (int i = 0; i < path.Length; i++)
                {
                    
                    if(path[i].Substring(path[i].LastIndexOf('.'),path[i].Length-path[i].LastIndexOf('.'))==".jpg")
                    {
                
                        Image image = Image.FromFile(path[i]);
                        list.Images.Add(image);                }
                              }
                pictureBox1.Image = list.Images[0];
    我的好像可以啊
      

  2.   

    你不是把path输出来看一下有没有没有图片的文件啊
    我刚就试了一下,要是不是图片文件就会出现内存不够的错误
      

  3.   

    文件可以是隐藏的,你自己输出来看一下,反正结论就是你的那个Image文件夹里面有一个
    我推测一下应该是Thumbs.db
      

  4.   

    你的多了判断.jpg的代码,我的没判断。我现在上班跟前没电脑只能明天在试了。不过非常感谢你的帮助,我明天把path输出看下就知道了。谢谢你了,呵呵,我才学c#比较菜
      

  5.   

    哈哈,找到问题了。果然如你所说path最后一个是\image\Thumbs.db我手机不知怎么不能给分。我的密码是1982419bai,你可以先用我的号给你分下。要不只有我休假回去结贴了。偶工厂上班上网不方便只能手机。谢谢你了,问题解决了呵呵!