Leadtools.Codecs Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.12.17
SavePage Event
See Also  Example
Leadtools.Codecs Namespace > RasterCodecs Class : SavePage Event




Occurs once for each page saved to an image file.

Syntax

Visual Basic (Declaration) 
Public Event SavePage() As EventHandler(Of CodecsPageEventArgs)
Visual Basic (Usage)Copy Code
Dim instance As RasterCodecs
Dim handler As EventHandler(Of CodecsPageEventArgs)
 
AddHandler instance.SavePage, handler
C# 
public event EventHandler<CodecsPageEventArgs> SavePage()
Managed Extensions for C++ 
public: __event EventHandler<CodecsPageEventArgs>* SavePage();
C++/CLI 
public:
event EventHandler<CodecsPageEventArgs>^ SavePage();

Example

Visual BasicCopy Code
RasterCodecs.SavePage
      Public Sub SavePageExample()
         RasterCodecs.Startup()
         Dim codecs As RasterCodecs = New RasterCodecs()

         Dim srcFileName As String = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Eye.gif"
         Dim destFileName As String = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Eye_SavePage.gif"

         ' Load all the pages in the file
         Dim image As RasterImage = codecs.Load(srcFileName)
         Console.WriteLine("Original image has {0} pages", image.PageCount)

         ' Add a handler to the SavePage event
         AddHandler codecs.SavePage, AddressOf codecs_SavePage

         ' Save all the pages of this file
         codecs.Save(image, destFileName, RasterImageFormat.Gif, 0, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite)

         RemoveHandler codecs.SavePage, AddressOf codecs_SavePage

         ' Check if we saved all pages but 1
         Dim info As CodecsImageInfo = codecs.GetInformation(destFileName, True)
         Console.WriteLine("Info reports {0} pages saved to the file", info.TotalPages)
         Debug.Assert(info.TotalPages = (image.PageCount - 1))

         image.Dispose()

         ' Clean up
         codecs.Dispose()
         RasterCodecs.Shutdown()
      End Sub

      Private Sub codecs_SavePage(ByVal sender As Object, ByVal e As CodecsPageEventArgs)
         If e.State = CodecsPageEventState.Before AndAlso e.Page = 1 Then
            ' Before saving the first page, show the save operation information
            Console.WriteLine("Saving {0} pages to {1}. Image size is {2} by {3}", e.PageCount - 1, e.FileName, e.Image.Width, e.Image.Height)
         End If

         If e.State = CodecsPageEventState.After Then
            Console.WriteLine("{0} saving page {1}:{2}", "After", e.Page, e.PageCount)
         Else
            Console.WriteLine("{0} saving page {1}:{2}", "Before", e.Page, e.PageCount)
         End If

         ' If this is the 2nd page, ignore it
         If e.Page = 2 AndAlso e.State = CodecsPageEventState.Before Then
            e.Command = CodecsPageEventCommand.Skip
            Console.WriteLine("--- Skipping this page, there should be no 'After' for this one")
         End If
      End Sub
C#Copy Code
RasterCodecs.SavePage 
      public void SavePageExample() 
      { 
         RasterCodecs.Startup(); 
         RasterCodecs codecs = new RasterCodecs(); 
 
         string srcFileName = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Eye.gif"; 
         string destFileName = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Eye_SavePage.gif"; 
 
         // Load all the pages in the file 
         RasterImage image = codecs.Load(srcFileName); 
         Console.WriteLine("Original image has {0} pages", image.PageCount); 
 
         // Add a handler to the SavePage event 
         codecs.SavePage += new EventHandler<CodecsPageEventArgs>(codecs_SavePage); 
 
         // Save all the pages of this file 
         codecs.Save(image, destFileName, RasterImageFormat.Gif, 0, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite); 
 
         codecs.SavePage -= new EventHandler<CodecsPageEventArgs>(codecs_SavePage); 
 
         // Check if we saved all pages but 1 
         CodecsImageInfo info = codecs.GetInformation(destFileName, true); 
         Console.WriteLine("Info reports {0} pages saved to the file", info.TotalPages); 
         Debug.Assert(info.TotalPages == (image.PageCount - 1)); 
 
         image.Dispose(); 
 
         // Clean up 
         codecs.Dispose(); 
         RasterCodecs.Shutdown(); 
      } 
 
      void codecs_SavePage(object sender, CodecsPageEventArgs e) 
      { 
         if(e.State == CodecsPageEventState.Before && e.Page == 1) 
         { 
            // Before saving the first page, show the save operation information 
            Console.WriteLine( 
               "Saving {0} pages to {1}.  Image size is {2} by {3}", 
               e.PageCount - 1, e.FileName, e.Image.Width, e.Image.Height); 
         } 
 
         Console.WriteLine("{0} saving page {1}:{2}", 
            e.State == CodecsPageEventState.After ? "After" : "Before", 
            e.Page, e.PageCount); 
 
         // If this is the 2nd page, ignore it 
         if(e.Page == 2 && e.State == CodecsPageEventState.Before) 
         { 
            e.Command = CodecsPageEventCommand.Skip; 
            Console.WriteLine("--- Skipping this page, there should be no 'After' for this one"); 
         } 
      }

Remarks

This event will fire once for each page save with any of the Save methods. You can use this event to get information about the image pages being saved or to skip saving certain pages.

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also