VintaSoft Imaging .NET SDK 15.1: Документация для .NET разработчика
В этом разделе
Расширенный функционал для кодирования изображений
В этом разделе
SDK позволяет редактировать изображение, разбитое на тайлы, без перекодирования всего изображения. Это позволяет редактировать очень большие изображения неограниченного размера, которые состоят из тайлов и физически не могут быть полностью загружены в память. Редактирование реализуется путем последовательного изменения тайлов изображения с помощью объекта, реализующего интерфейс IRasterGridEditor.

Объекты, реализующие интерфейс IRasterGridEditor, поддерживают следующие методы:
Интерфейс IRasterGridEditor реализован для TIFF (TiffFile) и JPEG2000 (Jpeg2000File) файлов.

Класс DecoderBase позволяет получить экземпляр, реализующий интерфейс IRasterGridEditor, с помощью метода DecoderBase.GetRasterGridEditor.


Вот C#/VB.NET код, который демонстрирует, как получить тайл изображения, изменить его и сохранить обратно в файл:
/// <summary>
/// Gets an image of first tile of TIFF page,
/// rotates the tile image 180 degrees,
/// sets changed tile image as new image of first tile,
/// saves changes to the source TIFF file.
/// </summary>
public static void ChangeTileOfTiffPage(string tiffFilename, int pageIndex)
{
    using (System.IO.Stream stream = new System.IO.FileStream(
        tiffFilename, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite))
    {
        using (Vintasoft.Imaging.Codecs.Decoders.TiffDecoder decoder =
            new Vintasoft.Imaging.Codecs.Decoders.TiffDecoder(stream))
        {
            // get raster grid editor
            Vintasoft.Imaging.Codecs.ImageFiles.IRasterGridEditor rasterGridEditor = decoder.GetRasterGridEditor();
            // get grid of raster regions
            System.Drawing.Rectangle[] grid = rasterGridEditor.GetRasterEditorGrid(pageIndex);
            if (grid == null || grid.Length == 0)
                throw new System.Exception("Image tiles cannot be changed.");

            // index of the region to change
            int rectIndex = 0;
            // get region to change
            System.Drawing.Rectangle region = grid[rectIndex];
            // image of changing region
            Vintasoft.Imaging.VintasoftImage regionImage;
            // create image renderer
            using (Vintasoft.Imaging.ImageRendering.ImageRenderer renderer =
                new Vintasoft.Imaging.ImageRendering.ImageRenderer(decoder, pageIndex))
            {
                // create region rendering task
                Vintasoft.Imaging.ImageRendering.ImageRenderingTask renderingTask =
                    Vintasoft.Imaging.ImageRendering.ImageRenderingTask.CreateImageRegion(region);
                // set to convert to the source format
                renderingTask.ConvertDestImageToSourceFormat = true;
                // get an image of first tile
                regionImage = renderer.ExecuteRendering(renderingTask);
            }

            // rotate the tile image 180 degrees
            regionImage.Flip(Vintasoft.Imaging.ImageProcessing.Transforms.ImageRotateFlipType.Rotate180FlipNone);

            // set the tile image as new image of first tile
            rasterGridEditor.SetImageRect(pageIndex, rectIndex, regionImage, null);
            regionImage.Dispose();

            // save changes to the source TIFF file
            rasterGridEditor.SaveChanges(null);
        }
    }
''' <summary>
''' Gets an image of first tile of TIFF page,
''' rotates the tile image 180 degrees,
''' sets changed tile image as new image of first tile,
''' saves changes to the source TIFF file.
''' </summary>
Public Shared Sub ChangeTileOfTiffPage(tiffFilename As String, pageIndex As Integer)
    Using stream As System.IO.Stream = New System.IO.FileStream(tiffFilename, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite)
        Using decoder As New Vintasoft.Imaging.Codecs.Decoders.TiffDecoder(stream)
            ' get raster grid editor
            Dim rasterGridEditor As Vintasoft.Imaging.Codecs.ImageFiles.IRasterGridEditor = decoder.GetRasterGridEditor()
            ' get grid of raster regions
            Dim grid As System.Drawing.Rectangle() = rasterGridEditor.GetRasterEditorGrid(pageIndex)
            If grid Is Nothing OrElse grid.Length = 0 Then
                Throw New System.Exception("Image tiles cannot be changed.")
            End If

            ' index of the region to change
            Dim rectIndex As Integer = 0
            ' get region to change
            Dim region As System.Drawing.Rectangle = grid(rectIndex)
            ' image of changing region
            Dim regionImage As Vintasoft.Imaging.VintasoftImage
            ' create image renderer
            Using renderer As New Vintasoft.Imaging.ImageRendering.ImageRenderer(decoder, pageIndex)
                ' create region rendering task
                Dim renderingTask As Vintasoft.Imaging.ImageRendering.ImageRenderingTask = Vintasoft.Imaging.ImageRendering.ImageRenderingTask.CreateImageRegion(region)
                ' set to convert to the source format
                renderingTask.ConvertDestImageToSourceFormat = True
                ' get an image of first tile
                regionImage = renderer.ExecuteRendering(renderingTask)
            End Using

            ' rotate the tile image 180 degrees
            regionImage.Flip(Vintasoft.Imaging.ImageProcessing.Transforms.ImageRotateFlipType.Rotate180FlipNone)

            ' set the tile image as new image of first tile
            rasterGridEditor.SetImageRect(pageIndex, rectIndex, regionImage, Nothing)
            regionImage.Dispose()

            ' save changes to the source TIFF file
            rasterGridEditor.SaveChanges(Nothing)
        End Using
    End Using