private void StitchIntoOneBmp(string TmpFolder, string outFilename)
{
var imgsFiles = Directory.GetFiles(TmpFolder)
.Where(fff => fff.Contains("out") && fff.Contains(".jpg"))
.ToArray();
if (imgsFiles.Length == 0) {
ErrorMessage2 = "No thumbnails found in tmp directory";
return;
}
var nCol = (int)Math.Ceiling(Math.Sqrt(imgsFiles.Length));
var nRow = (int)Math.Ceiling((double)imgsFiles.Length / nCol);
#if ONE_LINE_TEST
// tmp 1 line test
nCol = imgsFiles.Length;
nRow = 1;
#endif
Bitmap allThumbs = new Bitmap(nCol*ThumbW, nRow*ThumbH);
Graphics ggg = Graphics.FromImage(allThumbs);
int i = 1;
for (int r = 0; r < nRow; r++) {
for (int c = 0; c < nCol; c++) {
Bitmap bmp = (Bitmap)Image.FromFile(String.Format("{0}/out{1}.jpg", TmpFolder, i));
ggg.DrawImage(bmp, ThumbW * c, ThumbH * r);
bmp.Dispose();
i++;
if (i > imgsFiles.Length)
break;
}
if (i > imgsFiles.Length)
break;
}
ggg.Flush();
// save all to one jpg file
if (File.Exists(outFilename)) {
if (PleaseUnlockThisFile != null)
PleaseUnlockThisFile(outFilename);
File.Delete(outFilename);
}
allThumbs.Save(outFilename, ImageFormat.Jpeg);
allThumbs.Dispose();
// delete all tmp images
foreach (var fff in imgsFiles)
File.Delete(fff);
}