VintaSoft Imaging .NET SDK 14.0: Документация для .NET разработчика
В этом разделе
    Рендеринг изображений
    В этом разделе
    ImageRendererэто класс, который позволяет:
    Рендеринг изображений может работать только со следующими кодеками:
    Вот C#/VB.NET код, который демонстрирует, как отрендерить/получить нужную область изображения:
    /// <summary>
    /// Returns the scaled image region.
    /// </summary>
    /// <param name="image">The source image.</param>
    /// <param name="rect">The image region on source image, which should be rendered.</param>
    /// <param name="scale">The scale factor, which should be applied to the image region.</param>
    /// <returns>The scaled image region.</returns>
    public static Vintasoft.Imaging.VintasoftImage RenderScaledImageRegion(
        Vintasoft.Imaging.VintasoftImage image,
        System.Drawing.Rectangle rect,
        float scale)
    {
        // create the image renderer
        using (Vintasoft.Imaging.ImageRendering.ImageRenderer renderer = 
            new Vintasoft.Imaging.ImageRendering.ImageRenderer(image))
        {
            // create the rendering task
            Vintasoft.Imaging.ImageRendering.ImageRenderingTask task = 
                Vintasoft.Imaging.ImageRendering.ImageRenderingTask.CreateImageRegion(rect, scale);
            // execute the rendering
            return renderer.ExecuteRendering(task);
        }
    }
    
    ''' <summary>
    ''' Returns the scaled image region.
    ''' </summary>
    ''' <param name="image">The source image.</param>
    ''' <param name="rect">The image region on source image, which should be rendered.</param>
    ''' <param name="scale">The scale factor, which should be applied to the image region.</param>
    ''' <returns>The scaled image region.</returns>
    Public Shared Function RenderScaledImageRegion(image As Vintasoft.Imaging.VintasoftImage, rect As System.Drawing.Rectangle, scale As Single) As Vintasoft.Imaging.VintasoftImage
        ' create the image renderer
        Using renderer As New Vintasoft.Imaging.ImageRendering.ImageRenderer(image)
            ' create the rendering task
            Dim task As Vintasoft.Imaging.ImageRendering.ImageRenderingTask = Vintasoft.Imaging.ImageRendering.ImageRenderingTask.CreateImageRegion(rect, scale)
            ' execute the rendering
            Return renderer.ExecuteRendering(task)
        End Using
    End Function
    

    Вот C#/VB.NET код, который демонстрирует, как загрузить JPEG2000 изображение прогрессивно:
    /// <summary>
    /// Renders JPEG2000 image progressively.
    /// </summary>
    /// <param name="jp2Filename">A filename of JPEG image.</param>
    /// <returns>The Vintasoft.Imaging.VintasoftImage object, which stores a bitmap,
    /// which represents the rendeded JPEG2000 image.</returns>
    public static Vintasoft.Imaging.VintasoftImage RenderJpeg2000ImageProgressively(string jp2Filename)
    {
        // create the Vintasoft.Imaging.VintasoftImage object, which contains information about JPEG2000 image
        using (Vintasoft.Imaging.VintasoftImage image = new Vintasoft.Imaging.VintasoftImage(jp2Filename))
        {
            // create the image renderer
            using (Vintasoft.Imaging.ImageRendering.ImageRenderer renderer = 
                new Vintasoft.Imaging.ImageRendering.ImageRenderer(image))
            {
                // create the rendering task
                Vintasoft.Imaging.ImageRendering.ImageRenderingTask task = 
                    Vintasoft.Imaging.ImageRendering.ImageRenderingTask.CreateScaledImage(1);
    
                // set settings of rendering task
                task.DestImagePixelFormat = Vintasoft.Imaging.PixelFormat.Bgra32;
                task.RenderingQuality = Vintasoft.Imaging.ImageRenderingQuality.High;
                task.NeedGenerateIntermediateImage = true;
                task.IsProgressiveDecodingEnabled = true;
                task.ProgressiveDecodingMode = Vintasoft.Imaging.ImageRendering.ProgressiveDecodingMode.Replacement;
                task.ProgressiveDecodingRenderingQuality = Vintasoft.Imaging.ImageRenderingQuality.High;
                task.ProgressiveDecodingDepth = 2;
                task.ProgressiveDecodingScaleFactor = 6;
                task.MaxThreads = 2;
                task.DecodingSteps = task.MaxThreads * 8;
    
                // use IntermediateImageReady event: image part or progressive layer is loaded
                task.IntermediateImageReady +=
                    new System.EventHandler<Vintasoft.Imaging.ImageRendering.IntermediateImageReadyEventArgs>(task_IntermediateImageReady);
    
                // execute the rendering and
                // return the Vintasoft.Imaging.VintasoftImage object, which stores a bitmap,
                // which represents the rendeded JPEG2000 image
                return renderer.ExecuteRendering(task);
            }
        }
    }
    
    /// <summary>
    /// Image part or progressive layer is loaded:
    /// show the e.ChangedRect rectangle of the e.Image on your viewer.
    /// </summary>
    private static void task_IntermediateImageReady(
        object sender,
        Vintasoft.Imaging.ImageRendering.IntermediateImageReadyEventArgs e)
    {
        // intermediate image is ready and can be accessed using the e.Image property
    }
    
    ''' <summary>
    ''' Renders JPEG2000 image progressively.
    ''' </summary>
    ''' <param name="jp2Filename">A filename of JPEG image.</param>
    ''' <returns>The Vintasoft.Imaging.VintasoftImage object, which stores a bitmap,
    ''' which represents the rendeded JPEG2000 image.</returns>
    Public Shared Function RenderJpeg2000ImageProgressively(jp2Filename As String) As Vintasoft.Imaging.VintasoftImage
        ' create the Vintasoft.Imaging.VintasoftImage object, which contains information about JPEG2000 image
        Using image As New Vintasoft.Imaging.VintasoftImage(jp2Filename)
            ' create the image renderer
            Using renderer As New Vintasoft.Imaging.ImageRendering.ImageRenderer(image)
                ' create the rendering task
                Dim task As Vintasoft.Imaging.ImageRendering.ImageRenderingTask = Vintasoft.Imaging.ImageRendering.ImageRenderingTask.CreateScaledImage(1)
    
                ' set settings of rendering task
                task.DestImagePixelFormat = Vintasoft.Imaging.PixelFormat.Bgra32
                task.RenderingQuality = Vintasoft.Imaging.ImageRenderingQuality.High
                task.NeedGenerateIntermediateImage = True
                task.IsProgressiveDecodingEnabled = True
                task.ProgressiveDecodingMode = Vintasoft.Imaging.ImageRendering.ProgressiveDecodingMode.Replacement
                task.ProgressiveDecodingRenderingQuality = Vintasoft.Imaging.ImageRenderingQuality.High
                task.ProgressiveDecodingDepth = 2
                task.ProgressiveDecodingScaleFactor = 6
                task.MaxThreads = 2
                task.DecodingSteps = task.MaxThreads * 8
    
                ' use IntermediateImageReady event: image part or progressive layer is loaded
                AddHandler task.IntermediateImageReady, New System.EventHandler(Of Vintasoft.Imaging.ImageRendering.IntermediateImageReadyEventArgs)(AddressOf task_IntermediateImageReady)
    
                ' execute the rendering and
                ' return the Vintasoft.Imaging.VintasoftImage object, which stores a bitmap,
                ' which represents the rendeded JPEG2000 image
                Return renderer.ExecuteRendering(task)
            End Using
        End Using
    End Function
    
    ''' <summary>
    ''' Image part or progressive layer is loaded:
    ''' show the e.ChangedRect rectangle of the e.Image on your viewer.
    ''' </summary>
    Private Shared Sub task_IntermediateImageReady(sender As Object, e As Vintasoft.Imaging.ImageRendering.IntermediateImageReadyEventArgs)
        ' intermediate image is ready and can be accessed using the e.Image property
    End Sub