LEADTOOLS Image File Support (Leadtools.Codecs assembly)

SavePage Event

Show in webframe
Example 







Occurs once for each page saved to an image file.
Syntax
public event EventHandler<CodecsPageEventArgs> SavePage
'Declaration
 
Public Event SavePage As EventHandler(Of CodecsPageEventArgs)
'Usage
 
Dim instance As RasterCodecs
Dim handler As EventHandler(Of CodecsPageEventArgs)
 
AddHandler instance.SavePage, handler
public event EventHandler<CodecsPageEventArgs> SavePage

            
synchronized public void addSavePageListener(CodecsSavePageListener listener)
synchronized public void removeSavePageListener(CodecsSavePageListener listener)
            
add_SavePage(function(sender, e))
remove_SavePage(function(sender, e))

public:
event EventHandler<CodecsPageEventArgs^>^ SavePage
Event Data

The event handler receives an argument of type CodecsPageEventArgs containing data related to this event. The following CodecsPageEventArgs properties provide information specific to this event.

PropertyDescription
Command Gets or sets a value indicating how the load or save process should continue.
FileName Gets the name of the file being loaded or saved.
Image Gets the object being loaded from the image file page or the image that is being saved.
Page Gets the page number of the image being loaded or saved.
PageCount Gets the number of pages being loaded or saved.
State Gets the state of the load or save process.
Stream Gets the stream used by the load process.
Remarks
This event will fire once for each page save with any of the Save(RasterImage,String,RasterImageFormat,Int32) methods. You can use this event to get information about the image pages being saved or to skip saving certain pages.
Example
Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.Drawing

Public Sub SavePageExample()
   Dim codecs As RasterCodecs = New RasterCodecs()

   Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Eye.gif")
   Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "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()
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

Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;

public void SavePageExample()
{
   RasterCodecs codecs = new RasterCodecs();

   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Eye.gif");
   string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "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();
}

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");
   }
}

static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
RasterCodecsExamples.prototype.SavePageExample = function ( )
{
   Tools.SetLicense ( ) ;
   with (Leadtools) {
      with (Leadtools.Codecs) {
         var codecs = new RasterCodecs();
         var image;
         var srcFileName = "Assets\\Eye.gif";
         var destFileName = "Eye_SavePage.gif";
         var saveFile;

         Leadtools.RasterSupport.initialize();
         codecs.eventsDispatchMode = Leadtools.LeadEventsDispatchMode.useCoreDispatcher;

         // Load all the pages in the file
         return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
            return codecs.loadAsync(LeadStreamFactory.create(loadFile))
         })
         .then(function (img) {
            image = img;
            console.info("Original image has ", image.pageCount, " pages");

            // Add a handler to the SavePage event
            codecs.addEventListener("savepage", codecs_SavePage);

            // Save all the pages of this file
            return Tools.AppLocalFolder().createFileAsync(destFileName)
         })
         .then(function (saveFileX) {
            saveFile = saveFileX;
            return codecs.saveAsync(image, LeadStreamFactory.create(saveFile), RasterImageFormat.gif, 0, 1, image.pageCount, 1, CodecsSavePageMode.overwrite)
         })
         .then(function () {

            codecs.removeEventListener("savepage", codecs_SavePage);

            // Check if we saved all pages but 1
            return codecs.getInformationAsync(LeadStreamFactory.create(saveFile), true, 1)
         })
         .then(function (info) {
            console.info("Info reports ", info.totalPages, "pages saved to the file");
            console.assert(info.totalPages == (image.pageCount - 1), "info.totalPages == (image.pageCount - 1)");

            image.close();

            // Clean up
            codecs.close();
         });
      }
   }
}
 

function codecs_SavePage(e)
{
   if (e.state == Leadtools.Codecs.CodecsPageEventState.before && e.page == 1) {
      // Before saving the first page, show the save operation information
      console.info(
         "Saving ",
         e.pageCount - 1,
         "pages.  Image size is ",
         e.image.width, " by ", e.image.height);
   }

   console.info(e.state == Leadtools.Codecs.CodecsPageEventState.after ? "After" : "Before", " saving page ",
   e.page, ":", e.pageCount);

   // If this is the 2nd page, ignore it
   if (e.page == 2 && e.state == Leadtools.Codecs.CodecsPageEventState.before) {
      e.command = Leadtools.Codecs.CodecsPageEventCommand.skip;
      console.info("--- Skipping this page, there should be no 'After' for this one");
   }
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;

      
public async Task SavePageExample()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = @"Assets\Eye.gif";
   string destFileName = @"Eye_SavePage.gif";

   // Load all the pages in the file
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));
   Debug.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
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), 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 = await codecs.GetInformationAsync(LeadStreamFactory.Create(saveFile), true, 1);
   Debug.WriteLine("Info reports {0} pages saved to the file", info.TotalPages);
   Assert.IsTrue(info.TotalPages == (image.PageCount - 1));

   image.Dispose();

   // Clean up
   codecs.Dispose();
}

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
      Debug.WriteLine(
         "Saving {0} pages.  Image size is {1} by {2}",
         e.PageCount - 1, e.Image.Width, e.Image.Height);
   }

   Debug.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;
      Debug.WriteLine("--- Skipping this page, there should be no 'After' for this one");
   }
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Examples;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;
using Leadtools.Windows.Media;

public void SavePageExample(Stream inStreamGif, Stream outStreamGif)
{
   RasterCodecs codecs = new RasterCodecs();
   // Load all the pages in the file
   RasterImage image = codecs.Load(inStreamGif);
   Debug.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, outStreamGif, 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(outStreamGif, true);
   Debug.WriteLine("Info reports {0} pages saved to the file", info.TotalPages);
   Debug.Assert(info.TotalPages == (image.PageCount - 1));

   image.Dispose();
}

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
      Debug.WriteLine(
         "Saving {0} pages to {1}.  Image size is {2} by {3}",
         e.PageCount - 1, e.FileName, e.Image.Width, e.Image.Height);
   }

   Debug.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;
      Debug.WriteLine("--- Skipping this page, there should be no 'After' for this one");
   }
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.Windows.Media

Public Sub SavePageExample(ByVal inStreamGif As Stream, ByVal outStreamGif As Stream)
   Dim codecs As RasterCodecs = New RasterCodecs()
   ' Load all the pages in the file
   Dim image As RasterImage = codecs.Load(inStreamGif)
   Debug.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, outStreamGif, 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(outStreamGif, True)
   Debug.WriteLine("Info reports {0} pages saved to the file", info.TotalPages)
   Debug.Assert(info.TotalPages = (image.PageCount - 1))

   image.Dispose()
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
      Debug.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
      Debug.WriteLine("{0} saving page {1}:{2}","After", e.Page, e.PageCount)
   Else
      Debug.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
      Debug.WriteLine("--- Skipping this page, there should be no 'After' for this one")
   End If
End Sub
Requirements

Target Platforms

See Also

Reference

RasterCodecs Class
RasterCodecs Members

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.