VintaSoft Imaging .NET SDK 12.5: Документация для .NET разработчика
В этом разделе
    TIFF: Как разделить TIFF файл?
    В этом разделе
    TIFF файл можно разделить на два TIFF файла:


    Вот C#/VB.NET код, который демонстрирует, как разделить TIFF файл на два TIFF файла без пережатия данных изображений:
    public void SplitTiffFilesWithoutRecompression(
        System.IO.Stream sourceStream, System.IO.Stream oddStream, System.IO.Stream evenStream)
    {
        // open TIFF files
        Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFile sourceTiff = 
            new Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFile(sourceStream);
        Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFile oddTiff = 
            new Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFile(oddStream);
        Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFile evenTiff = 
            new Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFile(evenStream);
    
        // for each page of the source TIFF file
        Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFile tiff;
        for (int i = 0; i < sourceTiff.Pages.Count; i++)
        {
            // select necessary TIFF file
            if ((i % 2) == 0)
                tiff = evenTiff;
            else
                tiff = oddTiff;
    
            // add page to TIFF file
            tiff.Pages.Add(sourceTiff.Pages[i]);
    
            // save changes to TIFF file
            tiff.SaveChanges();
        }
    
        // release resources used by TIFF files
        evenTiff.Dispose();
        oddTiff.Dispose();
        sourceTiff.Dispose();
    }
    
    Public Sub SplitTiffFilesWithoutRecompression(sourceStream As System.IO.Stream, oddStream As System.IO.Stream, evenStream As System.IO.Stream)
        ' open TIFF files
        Dim sourceTiff As New Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFile(sourceStream)
        Dim oddTiff As New Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFile(oddStream)
        Dim evenTiff As New Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFile(evenStream)
    
        ' for each page of the source TIFF file
        Dim tiff As Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFile
        For i As Integer = 0 To sourceTiff.Pages.Count - 1
            ' select necessary TIFF file
            If (i Mod 2) = 0 Then
                tiff = evenTiff
            Else
                tiff = oddTiff
            End If
    
            ' add page to TIFF file
            tiff.Pages.Add(sourceTiff.Pages(i))
    
            ' save changes to TIFF file
            tiff.SaveChanges()
        Next
    
        ' release resources used by TIFF files
        evenTiff.Dispose()
        oddTiff.Dispose()
        sourceTiff.Dispose()
    End Sub
    


    Вот C#/VB.NET код, который демонстрирует, как разделить TIFF файл на два TIFF файла с пережатием данных изображений:
    public void SplitTiffFilesWithRecompression(System.IO.Stream sourceStream, System.IO.Stream oddStream, System.IO.Stream evenStream)
    {
        // open TIFF files
        Vintasoft.Imaging.ImageCollection sourceImages = new Vintasoft.Imaging.ImageCollection();
        sourceImages.Add(sourceStream);
        Vintasoft.Imaging.Codecs.Encoders.TiffEncoder oddTiffEncoder = 
            new Vintasoft.Imaging.Codecs.Encoders.TiffEncoder(true);
        Vintasoft.Imaging.Codecs.Encoders.TiffEncoder evenTiffEncoder = 
            new Vintasoft.Imaging.Codecs.Encoders.TiffEncoder(true);
    
        // for each page of the source TIFF file
        for (int i = 0; i < sourceImages.Count; i++)
        {
            // save image in necessary TIFF file
            if ((i % 2) == 0)
                evenTiffEncoder.SaveImage(sourceImages[i], evenStream);
            else
                oddTiffEncoder.SaveImage(sourceImages[i], oddStream);
        }
    
        // release resources used by TIFF files
        evenTiffEncoder.Dispose();
        oddTiffEncoder.Dispose();
        sourceImages.Dispose();
    }
    
    Public Sub SplitTiffFilesWithRecompression(sourceStream As System.IO.Stream, oddStream As System.IO.Stream, evenStream As System.IO.Stream)
        ' open TIFF files
        Dim sourceImages As New Vintasoft.Imaging.ImageCollection()
        sourceImages.Add(sourceStream)
        Dim oddTiffEncoder As New Vintasoft.Imaging.Codecs.Encoders.TiffEncoder(True)
        Dim evenTiffEncoder As New Vintasoft.Imaging.Codecs.Encoders.TiffEncoder(True)
    
        ' for each page of the source TIFF file
        For i As Integer = 0 To sourceImages.Count - 1
            ' save image in necessary TIFF file
            If (i Mod 2) = 0 Then
                evenTiffEncoder.SaveImage(sourceImages(i), evenStream)
            Else
                oddTiffEncoder.SaveImage(sourceImages(i), oddStream)
            End If
        Next
    
        ' release resources used by TIFF files
        evenTiffEncoder.Dispose()
        oddTiffEncoder.Dispose()
        sourceImages.Dispose()
    End Sub