static bool BreakUp(String src, String dest, ImageFormat format)
{
Bitmap b = null;
try {
b = new Bitmap(src);
}
catch (Exception ex)
{
Console.Error.WriteLine("There was a problem opening the source image '"+src+"': "+ex.Message);
return false;
}
if (b.Width != ANIM_WIDTH || b.Height % ANIM_HEIGHT != 0)
{
Console.Error.WriteLine("The source image must be "+ANIM_WIDTH+"px wide and a multiple of "+ANIM_HEIGHT+"px tall");
return false;
}
if (!Directory.Exists(dest))
{
try {
Directory.CreateDirectory(dest);
} catch (Exception ex) {
Console.Error.WriteLine("There was a problem creating the directory '"+dest+"': "+ex.Message);
return false;
}
}
string name = Path.GetFileNameWithoutExtension(src);
int frames = b.Height / ANIM_HEIGHT;
Rectangle r = new Rectangle(0, 0, ANIM_WIDTH, ANIM_HEIGHT);
for (int i = 0; i < frames; i++)
{
r.Y = i*ANIM_HEIGHT;
string path = Path.Combine(dest, name+i.ToString("000")+GetExt(format));
Bitmap x = b.Clone(r, PixelFormat.Format24bppRgb);
try
{
x.Save(path, format);
}
catch (Exception ex)
{
Console.Error.WriteLine("Unable to save '"+path+"': "+ex.Message);
}
}
return true;
}