←Select platform

SaveImage Event

Summary
Occurs during the file save process to provide functionality for manually handling the output image data or monitoring a progress status.
Syntax
C#
VB
C++
Java
public event EventHandler<CodecsSaveImageEventArgs> SaveImage 
Public Event SaveImage As EventHandler(Of CodecsSaveImageEventArgs) 
synchronized public void addSaveImageListener(CodecsSaveImageListener listener) 
synchronized public void removeSaveImageListener(CodecsSaveImageListener listener) 
public: 
event EventHandler<CodecsSaveImageEventArgs^>^ SaveImage 
Event Data

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.

PropertyDescription
Buffer Gets the memory buffer containing one or more lines of output image data that the you must provide.
Remarks

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.

Example

This example will double the density of an image as it is being saved.

C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
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 manipulate 
	codecs.Options.Save.RetrieveDataFromImage = true; 
 
	// Add a handler to the SaveImage event 
	codecs.SaveImage += new EventHandler<CodecsSaveImageEventArgs>(codecs_SaveImage); 
 
	// Save the image 
	codecs.Save(image, destFileName, RasterImageFormat.Cmp, 24); 
 
	codecs.SaveImage -= new EventHandler<CodecsSaveImageEventArgs>(codecs_SaveImage); 
 
	image.Dispose(); 
 
	// Clean up 
	codecs.Dispose(); 
} 
 
private void codecs_SaveImage(object sender, CodecsSaveImageEventArgs e) 
{ 
	// This example works with images saved as 24-bit per pixel only 
	Debug.Assert(e.Image.BitsPerPixel == 24); 
 
	if (e.Row == 0) 
	{ 
		// Show information about the image being saved 
		Console.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 image 
	int scanlineLength = e.Image.BytesPerLine; 
	byte[] scanline = new byte[scanlineLength]; 
 
	// Loop through all the scanlines in the data 
	for (int y = 0; y < e.Lines; y++) 
	{ 
		// Get this row 
		e.Buffer.GetData(y * scanlineLength, scanline, 0, scanlineLength); 
 
		// We got the data, now double the intensity 
		// Remember, this is 24-bits/pixel 
		for (int x = 0; x < scanlineLength; x++) 
		{ 
			scanline[x] *= 2; 
		} 
 
		// Copy it back to the event buffer 
		e.Buffer.SetData(y * scanlineLength, scanline, 0, scanlineLength); 
	} 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS21\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 21.0.2021.7.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Codecs Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.