I am trying to follow the instructions from the following link:
Merging two tiff image using c#.net
However when I get to the SaveAdd method I'm getting "A generic error occurred in GDI+"
The solution in the above link does show how bitmap1, bitmap2 or newFileName are initialized so I'm thinking it has something to do with that, but I'm not sure...
Here is my code:
string filePathA = "C:\\Users\\me\\Documents\\Projects\\TestTifMerge\\Samples\\00000516.tif";
string filePathB = "C:\\Users\\me\\Documents\\Projects\\TestTifMerge\\Samples\\11164_6018188.tif";
string newFileName = "C:\\Users\\me\\Documents\\Projects\\TestTifMerge\\Samples\\combined.tif";
Bitmap bitmap1;
Bitmap bitmap2;
bitmap1 = (Bitmap) Image.FromFile( filePathA );
bitmap2 = (Bitmap) Image.FromFile( filePathB );
ImageCodecInfo tiff = null;
foreach( ImageCodecInfo codec in ImageCodecInfo.GetImageEncoders() ) {
if( codec.MimeType == "image/tiff" ) {
tiff = codec;
break;
}
}
Encoder encoder = Encoder.SaveFlag;
EncoderParameters parameters = new EncoderParameters( 1 );
parameters.Param[ 0 ] = new EncoderParameter( encoder, ( long ) EncoderValue.MultiFrame );
bitmap1.Save( newFileName, tiff, parameters );
//Bitmap bitmapTemp = new Bitmap( bitmap1 );
parameters.Param[ 0 ] = new EncoderParameter( encoder, ( long ) EncoderValue.FrameDimensionPage );
bitmap2.SaveAdd( parameters );
As you can see the code I'm using is pretty much the same as the solution suggested in the link. The code seems to make it past the Save method, but chokes on the SaveAdd method.
Any ideas?