static bool PieceTogether(string src, string dest, ImageFormat format)
{
// Open the directory
DirectoryInfo dir = null;
try
{
dir = new DirectoryInfo(src);
}
catch (Exception ex)
{
Console.Error.WriteLine("There was a problem opening the directory '"+src+"': "+ex.Message);
return false;
}
// Go through each file
System.Collections.Generic.List<string> files = new System.Collections.Generic.List<string>();
foreach (FileInfo fi in dir.GetFiles("*"+GetExt(format)))
{
if (GetBitmap(fi.FullName, true) != null)
{
files.Add(fi.FullName);
}
}
if (files.Count == 0)
{
Console.Error.WriteLine("There were no acceptable files found in '"+src+"'");
return false;
}
if (files.Count != FRAMES)
{
Console.Error.WriteLine("Warning: Expected "+FRAMES+" frames but found "+files.Count+" frames in '"+src+"'");
}
files.Sort();
int size = ANIM_WIDTH * files.Count*ANIM_HEIGHT * 3; // bitmap data size
Bitmap b = new Bitmap(ANIM_WIDTH, files.Count*ANIM_HEIGHT, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(b);
for (int i = 0; i < files.Count; i++)
{
g.DrawImageUnscaled(GetBitmap(files[i], false), 0, i*ANIM_HEIGHT);
}
try
{
b.Save(dest, ImageFormat.Bmp);
}
catch (Exception ex)
{
Console.Error.WriteLine("There was a problem saving to '"+dest+"': "+ex.Message);
return false;
}
try
{
FileStream s = File.Open(dest, FileMode.Open, FileAccess.ReadWrite);
byte[] x = new byte[HEADER_SIZE];
s.Seek(0, SeekOrigin.Begin);
s.Read(x, 0, HEADER_SIZE);
//Adjust file size to be +1 of real (this is how the real activity.bmp is)
SetInt(size+HEADER_SIZE+1, x, 0x02);
//Add the BMP data size
SetInt(size, x, 0x22);
//Set the horiz and vert resolution to 0
SetInt(0, x, 0x26);
SetInt(0, x, 0x2A);
s.Seek(0, SeekOrigin.Begin);
s.Write(x, 0, HEADER_SIZE);
s.Close();
File.SetCreationTimeUtc(dest, DateTime.FromFileTime(creation_time));
File.SetLastWriteTimeUtc(dest, DateTime.FromFileTime(modification_time));
File.SetLastAccessTimeUtc(dest, DateTime.FromFileTime(accessed_time));
}
catch (Exception ex)
{
Console.Error.WriteLine("There was a problem adjusting the saved document '"+dest+"': "+ex.Message);
return false;
}
return true;
}