1
如何使用FileStream讀取目錄中的所有jpeg文件,以便文件不被鎖定?我目前的代碼如下,沒有提及FileStream,因爲我無法使它工作。非常感謝您的幫助。C#如何使用FileStream讀取目錄中的所有jpeg文件,以便文件不被鎖定?
public Form1()
{
InitializeComponent();
images = new List<Image>();
// add images
DirectoryInfo di = new DirectoryInfo(@"\\server\files\");
FileInfo[] finfos = di.GetFiles("*.jpg", SearchOption.TopDirectoryOnly);
foreach (FileInfo fi in finfos)
images.Add(Image.FromFile(fi.FullName));
}
private void buttonNext_Click(object sender, EventArgs e)
{
index++;
if (index < 0 || index >= images.Count)
index = 0;
pictureBox1.Image = images[index];
int count = index + 1;
labelCount.Text = "Showing " + count.ToString() + " of " + images.Count;
}