Splitting Tiff Files...HELP!!!

I surely hope someone here can help me out, because I've looked all over the internet and have found nothing that helps. I've found some code that I thought would solve my problem, but none of it compiles!

My background - business programming with VB, from VB3 through VB.Net under .Net 2005. No graphics programming experience whatsoever.

My problem - write a C# routine (in .Net 2005) using GDI+ to take a tiff file containing multiple fax documents and split the file into multiple tiffs.

This is as far as I've been able to get:

staticString[] SplitFile(String file_name)

{

System.Drawing.Image imageFile;

// File name hard-coded for testing...waiting to have file provided on server
imageFile = System.Drawing.
Image.FromFile("test.tif");

System.Drawing.Imaging.FrameDimension frameDimensions =new System.Drawing.Imaging.FrameDimension(imageFile.FrameDimensionsList[0]);

int NumberOfFrames = imageFile.GetFrameCount(frameDimensions);

int intFrame = 0;

while (intFrame < NumberOfFrames)

{

imageFile.SelectActiveFrame(frameDimensions, intFrame);

intFrame++;

}

imageFile.Dispose();

// Code below added so that module will compile. The assignment indicated the procedure should
//return a string array (I assume of file names for a later procedure to save the info to a db)

string
[] s;

s =newstring[5];

s[0] =" ";

return s;

}

[2520 byte] By [MikeTheTiger] at [2007-12-25]
# 1

You did not mention what error you get on compile time!

Anyhow Try this if it compiles:

return new string[1];

Best Regards,

RizwanSharp at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# General...
# 2

I guess I didn't make myself clear. There's no error, I just can't figure out how to write the code to split the file. I have the code to select the active frame, but don't know how to then save each frame to another file. Where I've gotten compile errors is in some code that I've found on the internet that doesn't compile and I didn't really understand the code well enough to even make an attempt to fix it; none of that code is included in my post. Again, I'm not a graphics programmer and am very much a novice at C#.

Thanks.

MikeTheTiger at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# General...
# 3

Ahh! OK, I wish you get it done within 24 hours, If you dont get a solution then I'll try to check this code with a Tiff file and telll you the results I'm succeffull to accomlish this.

I wish you all the best!

Best Regards,

RizwanSharp at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# General...
# 4
Try this code, it stores the frames in files named 0.tif, 1.tif, etc in the same folder as your executable:

static String[] SplitFile(String file_name) {
System.Drawing.Image imageFile;
imageFile = System.Drawing.Image.FromFile(file_name);
System.Drawing.Imaging.FrameDimension frameDimensions = new System.Drawing.Imaging.FrameDimension(imageFile.FrameDimensionsList[0]);
int NumberOfFrames = imageFile.GetFrameCount(frameDimensions);
string[] paths = new string[NumberOfFrames];
for (int intFrame = 0; intFrame < NumberOfFrames; ++intFrame) {
imageFile.SelectActiveFrame(frameDimensions, intFrame);
Bitmap bmp = new Bitmap(imageFile);
paths[intFrame] = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + @"\" + intFrame.ToString() + ".tif";
bmp.Save(paths[intFrame], System.Drawing.Imaging.ImageFormat.Tiff);
bmp.Dispose();
}
imageFile.Dispose();
return paths;
}

nobugz at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# General...
# 5
Great!! It works! This was driving me crazy. Thanks!!!!
MikeTheTiger at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# General...