Add frame to multi page tiff

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
What Im doing is Im moving 2 tiff files to a folder, one is a multi-page tiff the other is not, all I want to do is append the single frame tiff to the multi-page tiff. This is the code I have at the moment which moves the files and attempts to append them, but currently the file appends as 2 images instead of adding the single frame tiff to the 3 page multi page tiff image: private void firstCombine()
{
try
{

System.Drawing.Imaging.Encoder encoder = System.Drawing.Imaging.Encoder.SaveFlag;
ImageCodecInfo encoderInfo = ImageCodecInfo.GetImageEncoders().First(i => i.MimeType == "image/tiff");
EncoderParameters encoderParameters = new EncoderParameters(1);
encoderParameters.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.MultiFrame);
String Verbals = ConfigurationSettings.AppSettings["Compile"];
string[] fileImages = Directory.GetFiles(Verbals);
String CompleteCompile = ConfigurationSettings.AppSettings["CompleteCompile"];
//List of the bitmap images that will bind

//List<System.Drawing.Bitmap> images = new List<System.Drawing.Bitmap>();

//GENERATE a bitmap which will be the bitmap the images are binded to
System.Drawing.Bitmap firstImage = new System.Drawing.Bitmap(fileImages[0]);
string filenameWithoutPath2 = Path.GetFileName(fileImages[0]);
//SAVES the file with the file path(textbox2.text) and the name of the file(textbox3.text)
firstImage.Save(CompleteCompile + filenameWithoutPath2, encoderInfo, encoderParameters);
int d = 0;
encoderParameters.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.FrameDimensionPage);
foreach (string image in fileImages)
{

d++;
if (d == 1)
{
//MessageBox.Show("1");
string filenameWithoutPath = Path.GetFileName(image);
delete.Add(@Verbals + filenameWithoutPath);
}
else if (d > 1)
{
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(image);
//ADDS THE images to the firstImage as a multiframe tiff image.
int frameCount = bitmap.GetFrameCount(FrameDimension.Page);

firstImage.SaveAdd(bitmap, encoderParameters);
string filenameWithoutPath = Path.GetFileName(image);
delete.Add(@Verbals + filenameWithoutPath);
bitmap.Dispose();
// File.Delete(@Verbals + filenameWithoutPath);

}
}

// CLEAR THE FILE IN MEMORY HOLDING THE BITMAP
encoderParameters.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.Flush);
firstImage.SaveAdd(encoderParameters);
// File.Delete(@Verbals + textBox3.Text.ToString() + d.ToString() + ".tif");
firstImage.Dispose();
foreach (string file in delete)
{
File.Delete(file);
}



// foreach (string file in delete)
//{
// File.Delete(file);
//}
}
catch//(Exception error)
{
//MessageBox.Show(error.Message);
}
}

If anyone can help I will be much appreciated

View the full article
 
Back
Top