0
我試圖循環遍歷所有加載的圖像,我能夠處理多達40個圖像,然後我得到Out的內存錯誤,儘管我正在處理變量tempImage。代碼在「Bitmap tempImage = new Bitmap(fileName);」線,PLZ的幫助! 有沒有辦法處理大量的輸入文件?像批處理一樣,將進程分成塊?由於該操作將持續超過一分鐘,程序將在此之前崩潰。在System.Drawing.dll中發生未處理的異常類型'System.OutOfMemoryException'
foreach (string fileName in openFileDialog.FileNames)
{
circleDetection examDetect = new circleDetection();
Bitmap tempImage = new Bitmap(fileName);
directory.Text = fileName;
PictureBox picBox = new PictureBox();
picBox.Width = 200;
picBox.Height = 200;
picBox.Location = new System.Drawing.Point(picBoard.Controls.Count * (picBox.Width + 5) + 5, 5);
picBox.SizeMode = PictureBoxSizeMode.Zoom;
picBox.BorderStyle = BorderStyle.FixedSingle;
examDetect.ProcessImage(tempImage);
picBox.Image = examDetect.getImage();
Console.WriteLine(i++);
student.Add(compare(examDetect));
picBoard.Controls.Add(picBox);
tempImage.Dispose();
}
在'foreach'循環中使用'using'並查看會發生什麼 –
您的位圖有多大?因爲你的考試系列已經有了tempimage的參考資料,所以處置tempimage也無濟於事。 –
爲什麼你將'tempImage'添加到'Exam'(對位圖持有一個引用),然後處理它? –