LEADTOOLS Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.22
Controlling Progressive Loads and Saves

The LEAD and JPEG (JFIF) file formats can be extended to support progressive loading and saving of images. Progressive loading is useful for transmitting images, because the first part of the file contains the full dimensions of the image. Therefore, in a paint-while-load routine, you can display the whole image, then progressively clarify it as the rest of the file loads.

Since the progressive formats are newer, some existing applications do not support them. Therefore, especially when saving a file that may be read by another application, you must pay attention to the Passes property.

To avoid saving a progressive file (to save an ordinary LEAD or JPEG file) use the CodecsJpegSaveOptions to set the number of Passes to 0 before calling the method that saves the file.

Technically, only files with more than three passes are progressive files. They include full color in the low-resolution first pass; subsequent passes improve the resolution. Files that contain two or three passes are multiscan files. They include grayscale information in the first pass, and color information in the subsequent pass or passes.

If you want to save a progressive file or take advantage of this feature when loading a progressive file, you can control the number of passes that are required to complete the image. For more information, refer to the Passes property.

JBIG also supports progressive loading of an image. For more information on this, refer to Implementing JBIG Features.

The following example shows how to save a progressive LEAD then implement a progressive paint-while-load:

Visual Basic

             Private Sub PaintWhileLoadTest(ByVal fileName As String, ByVal codecs As RasterCodecs, ByVal viewer As RasterImageViewer)
                codecs.Options.Load.Passes = 10
                AddHandler codecs.LoadImage, AddressOf codecs_LoadImage
                codecs.Load(fileName)
                RemoveHandler codecs.LoadImage, AddressOf codecs_LoadImage
             End Sub
            
             Private Sub codecs_LoadImage(ByVal sender As Object, ByVal e As CodecsLoadImageEventArgs)
                If ((e.Flags And CodecsLoadImageFlags.FirstRow) = CodecsLoadImageFlags.FirstRow) Then
                   If (e.ImagePage = 1) Then
                      RasterImageViewer1.Image = e.Image
                      RasterImageViewer1.Image.DisableEvents()
                   End If
                End If
            
                If (e.ImagePage = 1) Then
                   Application.DoEvents()
                   Dim rc As New Rectangle(0, e.Row, RasterImageViewer1.Image.Width, e.Lines)
                   rc = RasterImageViewer1.Image.RectangleFromImage(RasterViewPerspective.TopLeft, rc)
                   Dim transformer As Transformer = New Transformer(RasterImageViewer1.Transform)
                   rc = Rectangle.Round(transformer.RectangleToPhysical(rc))
                   RasterImageViewer1.Invalidate(rc)
                End If
            
                If ((e.Flags And CodecsLoadImageFlags.LastRow) = CodecsLoadImageFlags.LastRow AndAlso e.Page = e.PageCount) Then
                   RasterImageViewer1.Image.EnableEvents()
                End If
             End Sub
             

C#

             private void PaintWhileLoadTest(string fileName, RasterCodecs codecs, RasterImageViewer viewer)
             {
                codecs.Options.Load.Passes = 10;
                EventHandler<CodecsLoadImageEventArgs> handler = new EventHandler<CodecsLoadImageEventArgs>(codecs_LoadImage);
                codecs.LoadImage += handler;
                RasterImage image = codecs.Load(fileName);
                codecs.LoadImage -= handler;
             }
             
             private void codecs_LoadImage(object sender, CodecsLoadImageEventArgs e)
             {
                if((e.Flags & CodecsLoadImageFlags.FirstRow) == CodecsLoadImageFlags.FirstRow)
                {
                   if(e.ImagePage == 1)
                   {
                      rasterImageViewer1.Image = e.Image;
                      rasterImageViewer1.Image.DisableEvents();
                   }
                }
             
                if(e.ImagePage == 1)
                {
                   Application.DoEvents();
                   Rectangle rc = new Rectangle(0, e.Row, rasterImageViewer1.Image.Width, e.Lines);
                   rc = rasterImageViewer1.Image.RectangleFromImage(RasterViewPerspective.TopLeft, rc);
                   Transformer transformer = new Transformer(rasterImageViewer1.Transform);
                   rc = Rectangle.Round(transformer.RectangleToPhysical(rc));
                   rasterImageViewer1.Invalidate(rc);
                }
             
                if((e.Flags & CodecsLoadImageFlags.LastRow) == CodecsLoadImageFlags.LastRow && e.Page == e.PageCount)
                {
                   rasterImageViewer1.Image.EnableEvents();
                }
             }