How to append mutipage TIFF Images to a file that is saved using C#? - Image.SaveAdd Method

I am writing a C# console application using VS2010 to generate multipage TIFF images and save these images to a file.

 The variable "img" contains the front image of a check.

 The variable "img2" contains the back image of a check.

 Function A is performed for each pair of front and back images of each check processed from an input file:

 Funtion A

    Byte[] img =  bytes.Skip(irecpositionrevised + irectypelength).Take(intpos1revised).ToArray();

    Byte[] img1 = bytes.Skip(irecpositionrevised + irectypelength + intpos1revised).Take(intpos2revised).ToArray();

    newImage[CheckOrderNum - 1] = MergeTwoImages(ConvertFromByteArray(img), ConvertFromByteArray(img1));

 After all checks have been read & processed via Function A, the following foreach loop is performed to write out
 ALL multipage TIFF images:

 foreach (Image image in newImage)
     image.Save("L:\\F\\Source\\test1.tiff", System.Drawing.Imaging.ImageFormat.Tiff);   <-- this Save only Saves the current TIFF Image            

My goal is to write out ALL mulitpage TIFF Images to a file titled test1.tiff, so that I can see the front image & back image of ALL checks my application reads from an input file.

Currenlty my program OVERWRITES the existing TIFF multipage Image with the most recent TIFF mulitpage read in.

Could you convert the VB6 code in the following link to work with my statements above so that I can append the current record to the existing records? - Image.SaveAdd Method
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I answered this on your previous question concerning the same process:  http:/Q_28711383.html#a40962834

Here is the solution posted again:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;

namespace EE_Q28711383
	class Program
		static void Main(string[] args)
			List<Image> images = new List<Image>();
			images.Add(Image.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "image1.jpg")));
			images.Add(Image.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "image2.jpg")));
			images.MergeImages(new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "image3.tiff")));

	static class Extensions
		public static void MergeImages(this IEnumerable<Image> images, string fileName)
			images.MergeImages(new FileInfo(fileName));

		public static void MergeImages(this IEnumerable<Image> images, FileInfo file)
			if (images == null)
				throw new ArgumentNullException("images", "Images cannot be null");

			if (file == null)
				throw new ArgumentNullException("file", "File cannot be null");

			ImageCodecInfo codec = null;
			Image tiff = null;
			MemoryStream stream = null;
			EncoderParameters parameters = null;
				codec = (from _codec in ImageCodecInfo.GetImageEncoders() where _codec.MimeType.Equals("image/tiff", StringComparison.OrdinalIgnoreCase) select _codec).FirstOrDefault();
				if (codec != default(ImageCodecInfo))
					bool first = true;
					parameters = new EncoderParameters(2);
					parameters.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
					parameters.Param[1] = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.MultiFrame);

					foreach (Image image in images)
						stream = new MemoryStream();
						image.Save(stream, ImageFormat.Tiff);

						if (first)
							tiff = Image.FromStream(stream);
							tiff.Save(file.FullName, codec, parameters);
							first = false;
							parameters.Param[1] = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.FrameDimensionPage);
							tiff.SaveAdd(Image.FromStream(stream), parameters);

					parameters.Param[1] = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.Flush);
			catch (Exception ex)
				Console.WriteLine("Exception reported: {0}", ex);

Open in new window

If you have any questions, please do not hesitate to ask.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.