Hello,
Below is my code to merge the tiff files.
using (Merger merger = new Merger(firstFile))
{
ImageJoinOptions joinOptions = new ImageJoinOptions(FileType.TIFF, ImageJoinMode.Horizontal);
foreach (var file in files)
{
var thisFileExtension = Path.GetExtension(file);
if (thisFileExtension == extension)
{
merger.Join(file, joinOptions);
}
else
{
failedFiles.Add(Path.GetFileName(file));
}
}
merger.Save(request.FolderPath + @"\Hmerged.tiff");
}
using (Merger merger = new Merger(firstFile))
{
ImageJoinOptions joinOptions = new ImageJoinOptions(FileType.TIFF, ImageJoinMode.Vertical);
foreach (var file in files)
{
var thisFileExtension = Path.GetExtension(file);
if (thisFileExtension == extension)
{
merger.Join(file, joinOptions);
}
else
{
failedFiles.Add(Path.GetFileName(file));
}
}
merger.Save(request.FolderPath + @"\Vmerged.tiff");
}
OUTPUT:
BitMiracle merged.zip (3.6 MB)
GD Vmerged.zip (3.8 MB)
Expected OUTPUT:
BitMiracle mergedCombined.zip (194.9 KB)
I achieve the same with BitMiracle Can I achieve the same with GroupDocs
@Niteen_Jadhav
Could you please share the source files as well? Moreover, please take a look at this
screenshot.jpg (163.1 KB). We opened/compared âBitMiracle mergedâ and âBitMiracle mergedComnbinedâ, they both look same (cannot find out the difference). GroupDocs output on the other hand shows collection of various images.
Mistakenly added wrong tiff,
here is the correct tiff along with sample.
BitMiracle mergedCombined.zip (194.9 KB)
GD hmerged.zip (233.1 KB)
GD Vmerged.zip (153.0 KB)
Original Files.zip (234.7 KB)
1 Like
@Niteen_Jadhav
Please use this code - Merge to paged TIFF.
The key difference is the use of simple JoinOptions
instead of ImageJoinOptions
. This applies only to multi-page images like TIF and TIFF files.
Below is your updated code,
//C# code to merge TIFF
// Create a new Merger instance using the first file in the list
using (Merger merger = new Merger(firstFile))
{
// Define the JoinOptions for TIFF file type
JoinOptions joinOptions = new JoinOptions(FileType.TIFF);
// Iterate through each file in the provided files list
foreach (var file in files)
{
// Get the file extension of the current file
var thisFileExtension = Path.GetExtension(file);
// Check if the file's extension matches the expected extension
if (thisFileExtension == extension)
{
// Join the current file to the merger using the specified JoinOptions
merger.Join(file, joinOptions);
}
else
{
// If the extension does not match, add the file name to the failedFiles list
failedFiles.Add(Path.GetFileName(file));
}
}
// Save the merged output to the specified folder with the name 'merged.tiff'
merger.Save(request.FolderPath + @"\merged.tiff");
}