Occurs during the file save process to provide functionality for manually handling the output image data or monitoring a progress status.
public event EventHandler<CodecsSaveImageEventArgs> SaveImage Public Event SaveImage As EventHandler(Of CodecsSaveImageEventArgs) public event EventHandler<CodecsSaveImageEventArgs> SaveImage synchronized public void addSaveImageListener(CodecsSaveImageListener listener)synchronized public void removeSaveImageListener(CodecsSaveImageListener listener)
add_SaveImage(function(sender, e))remove_SaveImage(function(sender, e))
public:event EventHandler<CodecsSaveImageEventArgs^>^ SaveImage
The event handler receives an argument of type CodecsSaveImageEventArgs containing data related to this event. The following CodecsSaveImageEventArgs properties provide information specific to this event.
| Property | Description |
|---|---|
| Buffer | Gets the memory buffer containing one or more lines of output image data that the you must provide. |
| Cancel | Gets or sets a value which allows the user to abort the save process. |
| FileName | Gets the name of the file currently being saved. |
| FirstPage | Gets the index of the first page being saved. |
| Image | Gets the RasterImage object being saved. |
| ImagePage | Gets the index of the RasterImage.Page currently being saved. |
| LastPage | Gets the index of the last page being saved. |
| Lines | Gets the number of lines to copy from Buffer. |
| Offset | Gets the offset to the start of the image data. |
| OffsetValid | Gets a value that determines whether the Offset property is valid. |
| Page | Gets the page number currently being saved. |
| PagePercent | Gets the save completion percentage of the current page. |
| Row | Gets the current image row number of the first line in Buffer. |
| Stream | Gets the stream object currently being saved. |
| Stream | Gets the stream object currently being saved. |
| TotalPercent | Gets the overall completion percentage for the save operation. |
This event will fire during saving images with the Save methods. If you use this event, you must copy the image data to the provided event buffer.
You can also use this event to get information about the image being saved, provide a progress status, and/or abort the save operation. For information on how to use this event as a progress status monitor, refer to CodecsSaveOptions.RetrieveDataFromImage and CodecsSaveImageEventArgs.
This example will double the density of an image as it is being saved.
using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Color;using Leadtools.Svg;using LeadtoolsExamples.Common;public void SaveImageExample(){RasterCodecs codecs = new RasterCodecs();string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_SaveImage.cmp");// Load the source file (make sure to load as 24 bits/pixel)RasterImage image = codecs.Load(srcFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1);// Instruct RasterCodecs to generate the saved scanlines data for us to manipulatecodecs.Options.Save.RetrieveDataFromImage = true;// Add a handler to the SaveImage eventcodecs.SaveImage += new EventHandler<CodecsSaveImageEventArgs>(codecs_SaveImage);// Save the imagecodecs.Save(image, destFileName, RasterImageFormat.Cmp, 24);codecs.SaveImage -= new EventHandler<CodecsSaveImageEventArgs>(codecs_SaveImage);image.Dispose();// Clean upcodecs.Dispose();}private void codecs_SaveImage(object sender, CodecsSaveImageEventArgs e){// This example works with images saved as 24-bit per pixel onlyDebug.Assert(e.Image.BitsPerPixel == 24);if (e.Row == 0){// Show information about the image being savedConsole.WriteLine("Saving an image with {0} bpp to {1}", e.Image.BitsPerPixel, e.FileName);Console.WriteLine("Offset: {0}, OffsetValid: {1}", e.Offset, e.OffsetValid);Console.WriteLine("Page: {0} of {1}", e.Page, e.LastPage - e.FirstPage + 1);Console.WriteLine("Page percent: {0}%, Total percent: {1}%", e.PagePercent, e.TotalPercent);}Console.WriteLine("Row: {0}, Lines {1}", e.Row, e.Lines);// Get the scanlines from the imageint scanlineLength = e.Image.BytesPerLine;byte[] scanline = new byte[scanlineLength];// Loop through all the scanlines in the datafor (int y = 0; y < e.Lines; y++){// Get this rowe.Buffer.GetData(y * scanlineLength, scanline, 0, scanlineLength);// We got the data, now double the intensity// Remember, this is 24-bits/pixelfor (int x = 0; x < scanlineLength; x++){scanline[x] *= 2;}// Copy it back to the event buffere.Buffer.SetData(y * scanlineLength, scanline, 0, scanlineLength);}}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.ColorImports Leadtools.DrawingImports Leadtools.SvgPublic Sub SaveImageExample()Dim codecs As New RasterCodecs()Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_SaveImage.cmp")' Load the source file (make sure to load as 24 bits/pixel)Dim image As RasterImage = codecs.Load(srcFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1)' Instruct RasterCodecs to generate the saved scanlines data for us to manipulatecodecs.Options.Save.RetrieveDataFromImage = True' Add a handler to the SaveImage eventAddHandler codecs.SaveImage, AddressOf codecs_SaveImage' Save the imagecodecs.Save(image, destFileName, RasterImageFormat.Cmp, 24)RemoveHandler codecs.SaveImage, AddressOf codecs_SaveImageimage.Dispose()' Clean upcodecs.Dispose()End SubPrivate Sub codecs_SaveImage(ByVal sender As Object, ByVal e As CodecsSaveImageEventArgs)' This example works with images saved as 24-bit per pixel onlyDebug.Assert(e.Image.BitsPerPixel = 24)If e.Row = 0 Then' Show information about the image being savedConsole.WriteLine("Saving an image with {0} bpp to {1}", e.Image.BitsPerPixel, e.FileName)Console.WriteLine("Offset: {0}, OffsetValid: {1}", e.Offset, e.OffsetValid)Console.WriteLine("Page: {0} of {1}", e.Page, e.LastPage - e.FirstPage + 1)Console.WriteLine("Page percent: {0}%, Total percent: {1}%", e.PagePercent, e.TotalPercent)End IfConsole.WriteLine("Row: {0}, Lines {1}", e.Row, e.Lines)' Get the scanlines from the imageDim scanlineLength As Integer = e.Image.BytesPerLineDim scanline(scanlineLength - 1) As Byte' Loop through all the scanlines in the dataFor y As Integer = 0 To e.Lines - 1' Get this rowe.Buffer.GetData(y * scanlineLength, scanline, 0, scanlineLength)' We got the data, now double the intensity' Remember, this is 24-bits/pixelFor x As Integer = 0 To scanlineLengthscanline(x) = CType(scanline(x) * 2, Byte)Next' Copy it back to the event buffere.Buffer.SetData(y * scanlineLength, scanline, 0, scanlineLength)NextEnd SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
using Leadtools;using Leadtools.Codecs;using Leadtools.Examples;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Color;using Leadtools.Windows.Media;public void SaveImageExample(Stream inStreamCmp, Stream outStreamCmp){RasterCodecs codecs = new RasterCodecs();// Load the source file (make sure to load as 24 bits/pixel)RasterImage image = codecs.Load(inStreamCmp, 24, CodecsLoadByteOrder.Bgr, 1, 1);// Add a handler to the SaveImage eventcodecs.SaveImage += new EventHandler<CodecsSaveImageEventArgs>(codecs_SaveImage);// Save the imagecodecs.Save(image, outStreamCmp, RasterImageFormat.Cmp, 24);codecs.SaveImage -= new EventHandler<CodecsSaveImageEventArgs>(codecs_SaveImage);image.Dispose();}byte[] _saveImageScanLine;void codecs_SaveImage(object sender, CodecsSaveImageEventArgs e){if (e.Row == 0){// Show information about the image being savedConsole.WriteLine("Saving an image with {0} bpp to {1}", e.Image.BitsPerPixel, e.FileName);//Console.WriteLine("Offset: {0}, OffsetValid: {1}", e.Offset, e.OffsetValid);Console.WriteLine("Page: {0} of {1}", e.Page, e.PageCount);}Console.WriteLine("Row: {0}, Lines {1}", e.Row, e.Lines);// Get the scanlines from the imageint lastRow = e.Row + e.Lines;int bytesPerLine = e.Image.BytesPerLine;RasterNativeBuffer buffer = e.Buffer;// See if we need to re-allocate the managed bufferif (_saveImageScanLine == null || _saveImageScanLine.Length < bytesPerLine)_saveImageScanLine = new byte[bytesPerLine];long offset = 0;for (int y = e.Row; y < lastRow; y++){// Get the row into the managed buffere.Image.Access();e.Image.GetRow(y, _saveImageScanLine, 0, bytesPerLine);e.Image.Release();// We got the data, now double the intensity// Remember, this is 24-bits/pixelfor (int x = 0; x < bytesPerLine; x++)_saveImageScanLine[x] *= 2;// Copy the data into the bufferbuffer.SetData(offset, _saveImageScanLine, 0, bytesPerLine);// Move the pointer to the position in the buffer for the next rowoffset += bytesPerLine;}}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.ColorImports Leadtools.Windows.MediaPublic Sub SaveImageExample(ByVal inStreamCmp As Stream, ByVal outStreamCmp As Stream)Dim codecs As RasterCodecs = New RasterCodecs()' Load the source file (make sure to load as 24 bits/pixel)Dim image As RasterImage = codecs.Load(inStreamCmp, 24, CodecsLoadByteOrder.Bgr, 1, 1)' Add a handler to the SaveImage eventAddHandler codecs.SaveImage, AddressOf codecs_SaveImage' Save the imagecodecs.Save(image, outStreamCmp, RasterImageFormat.Cmp, 24)RemoveHandler codecs.SaveImage, AddressOf codecs_SaveImageimage.Dispose()End SubPrivate _saveImageScanLine As Byte()Private Sub codecs_SaveImage(ByVal sender As Object, ByVal e As CodecsSaveImageEventArgs)If e.Row = 0 Then' Show information about the image being savedConsole.WriteLine("Saving an image with {0} bpp to {1}", e.Image.BitsPerPixel, e.FileName)'Console.WriteLine("Offset: {0}, OffsetValid: {1}", e.Offset, e.OffsetValid);Console.WriteLine("Page: {0} of {1}", e.Page, e.PageCount)End IfConsole.WriteLine("Row: {0}, Lines {1}", e.Row, e.Lines)' Get the scanlines from the imageDim lastRow As Integer = e.Row + e.LinesDim bytesPerLine As Integer = e.Image.BytesPerLineDim buffer As RasterNativeBuffer = e.Buffer' See if we need to re-allocate the managed bufferIf _saveImageScanLine Is Nothing OrElse _saveImageScanLine.Length < bytesPerLine Then_saveImageScanLine = New Byte(bytesPerLine - 1) {}End IfDim offset As Long = 0Dim y As Integer = e.RowDo While y < lastRow' Get the row into the managed buffere.Image.Access()e.Image.GetRow(y, _saveImageScanLine, 0, bytesPerLine)e.Image.Release()' We got the data, now double the intensity' Remember, this is 24-bits/pixelDim x As Integer = 0Do While x < bytesPerLine_saveImageScanLine(x) *= 2x += 1Loop' Copy the data into the bufferbuffer.SetData(offset, _saveImageScanLine, 0, bytesPerLine)' Move the pointer to the position in the buffer for the next rowoffset += bytesPerLiney += 1LoopEnd Sub
|
Products |
Support |
Feedback: SaveImage Event - Leadtools.Codecs |
Introduction |
Help Version 19.0.2017.6.16
|

Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.