public event EventHandler<CodecsPageEventArgs> SavePage synchronized public void addSavePageListener(CodecsSavePageListener listener)synchronized public void removeSavePageListener(CodecsSavePageListener listener)
public:event EventHandler<CodecsPageEventArgs^>^ SavePage
def SavePage(sender,e): # sender: RasterCodecs e: CodecsPageEventArgs 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.
| Property | Description |
|---|---|
| Command | A value indicating how the load or save process should continue. |
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.
This example will use the SavePage event to skip a certain page when saving a multipage file
using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Color;using Leadtools.Svg;public void SavePageExample(){RasterCodecs codecs = new RasterCodecs();codecs.Options.Load.AllPages = true;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 fileRasterImage image = codecs.Load(srcFileName);Debug.WriteLine("Original image has {0} pages", image.PageCount);// Add a handler to the SavePage eventcodecs.SavePage += new EventHandler<CodecsPageEventArgs>(codecs_SavePage);// Save all the pages of this filecodecs.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 1CodecsImageInfo info = codecs.GetInformation(destFileName, true);Debug.WriteLine("Info reports {0} pages saved to the file", info.TotalPages);Debug.Assert(info.TotalPages == (image.PageCount - 1));image.Dispose();// Clean upcodecs.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 informationDebug.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 itif (e.Page == 2 && e.State == CodecsPageEventState.Before){e.Command = CodecsPageEventCommand.Skip;Debug.WriteLine("--- Skipping this page, there should be no 'After' for this one");}}static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";}
import java.io.*;import java.net.*;import java.nio.file.Paths;import java.util.*;import java.time.Instant;import java.time.Duration;import org.junit.*;import org.junit.runner.JUnitCore;import org.junit.runner.Result;import org.junit.runner.notification.Failure;import static org.junit.Assert.*;import leadtools.*;import leadtools.codecs.*;import leadtools.codecs.RasterCodecs.FeedCallbackThunk;import leadtools.drawing.internal.*;import leadtools.imageprocessing.*;import leadtools.imageprocessing.color.ChangeIntensityCommand;import leadtools.svg.*;public void savePageExample() {final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images";RasterCodecs codecs = new RasterCodecs();codecs.getOptions().getLoad().setAllPages(true);String srcFileName = combine(LEAD_VARS_IMAGES_DIR, "Eye.gif");String destFileName = combine(LEAD_VARS_IMAGES_DIR, "Eye_SavePage.gif");// Load all the pages in the fileRasterImage image = codecs.load(srcFileName);System.out.println("Original image has " + image.getPageCount() + " pages");// Add a handler to the SavePage eventcodecs.addSavePageListener(codecsSavePage2);// Save all the pages of this filecodecs.save(image, destFileName, RasterImageFormat.GIF, 0, 1, image.getPageCount(), 1,CodecsSavePageMode.OVERWRITE);codecs.removeSavePageListener(codecsSavePage2);// Check if we saved all pages but 1CodecsImageInfo info = codecs.getInformation(destFileName, true);assertTrue(info.getTotalPages() == (image.getPageCount() - 1));System.out.println("Info reports " + info.getTotalPages() + " pages saved to the file");// Clean upcodecs.dispose();image.dispose();}CodecsSavePageListener codecsSavePage2 = new CodecsSavePageListener() {@Overridepublic void onSavePage(CodecsPageEvent e) {if (e.getState() == CodecsPageEventState.BEFORE && e.getPage() == 1) {// Before saving the first page, show the save operation informationSystem.out.println("Saving " + (e.getPageCount() - 1) + " pages. Image size is " + e.getImage().getWidth()+ " by " + e.getImage().getHeight());}System.out.println(e.getState() == CodecsPageEventState.AFTER ? "After": "Before" + " saving page " + e.getPage() + ":" + e.getPageCount());// If this is the 2nd page, ignore itif (e.getPage() == 2 && e.getState() == CodecsPageEventState.BEFORE) {e.setCommand(CodecsPageEventCommand.SKIP);System.out.println("--- Skipping this page, there should be no 'After' for this one");}}};
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
