如何从最后一个索引文件的字符串数组将图像加载到 pictureBox?

How can i load image to pictureBox from string array the last index file?

我试过这个:

string[] files = System.IO.Directory.GetFiles(combinedsatelliteimagesdir);
NumericComparer ns = new NumericComparer();
Array.Sort(files, ns);
pictureBox1.Image = Image.FromFile(files[files.Length -1]);

但是我遇到了内存不足的异常:

pictureBox1.Image = Image.FromFile(files[files.Length -1]);

变量文件包含 847 个索引,例如第一个索引如下所示:

C:\Users\user\AppData\Local\mws\My天气Station\satelliteImages\SatImage0.GIF

msdn,你得到 OutOfMemoryException 如果

The file does not have a valid image format.

-or-

GDI+ does not support the pixel format of the file.

您可能正在阅读一些非图像文件。


关于thumbs.db

Thumbs.db is an image cache which makes thumbnail viewing faster. The file is automatically created in Windows Vista, 7 and 8 whenever images are encountered in a folder. It's usually hidden but can appear, disappear and is often impossible to delete

试试这个

pictureBox1.Image = Image.FromFile(@files[files.Length - 1]);

对了,你确定最后一个文件每次都是图片吗?没有隐藏 "desktop.ini" 或其他东西?