test2
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Tiff;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Formats.Tiff.Constants;
using Image = SixLabors.ImageSharp.Image;
using SixLabors.ImageSharp.Processing;
public class TiffMerger
{
//https://github.com/SixLabors/ImageSharp/tree/main/src/ImageSharp
//https://docs.sixlabors.com/articles/imagesharp/index.html?tabs=tabid-1
public void MergeTiffImages1()
{
var inputImages = new List<string>()
{
@"C:\temp\tifs\file_example_TIFF_1MB.tiff",
@"C:\temp\tifs\file_example_TIFF_5MB.tiff"
};
string outputImage = @"C:\temp\tifs\output\result1.tif";
var outputFrames = new List<Image<Rgba32>>();
using (Image<Rgba32> output = new Image<Rgba32>(Configuration.Default, 500, 500, new Rgba32(0, 0, 0, 0)))
{
foreach (string inputImage in inputImages)
{
using (Image<Rgba32> input = Image.Load<Rgba32>(inputImage))
{
// Clone the input image to ensure we're not modifying the original
var clone = input.Clone();
clone.Mutate(x => x.Resize(output.Width, output.Height));
//clone..Mutate(x => x.Resize(500, 500, KnownResamplers.Lanczos3));
output.Frames.AddFrame(clone.Frames[0]);
}
}
// Save all frames to a single TIFF
output.SaveAsTiff(outputImage, new TiffEncoder { Compression = TiffCompression.None });
}
// Dispose all frames
foreach (var frame in outputFrames)
{
frame.Dispose();
}
}
}