←Select platform

RedirectWrite Event

Summary
Replaces the normal LEADTOOLS method for writing to a file.
Syntax
C#
C++/CLI
Java
Python
public event EventHandler<CodecsRedirectWriteEventArgs> RedirectWrite 
synchronized public void addRedirectWriteListener(CodecsRedirectWriteListener listener) 
synchronized public void removeRedirectWriteListener(CodecsRedirectWriteListener listener) 
public: 
event EventHandler<CodecsRedirectWriteEventArgs^>^ RedirectWrite 
def RedirectWrite(sender,e): # sender: RasterCodecs e: CodecsRedirectWriteEventArgs 
Event Data

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

PropertyDescription
Buffer Gets a pointer to the unmanaged memory buffer from which this write operation should copy the data.
Remarks

You can redirect all the toolkit I/O methods to your own I/O methods to load/save images from your own streams.

To replace the normal method for writing to a file, set your own subscribe to this event then call the StartRedirecting method.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
       
// Redirect Read event example 
FileStream myStream; 
 
// Redirect Open event example 
private void Codecs_Open(object sender, CodecsRedirectOpenEventArgs e) 
{ 
   myStream = new FileStream(e.FileName, e.Mode); 
   Console.WriteLine("Access: {0}, Share: {1}", e.Access, e.Share); 
   e.Success = true; 
} 
 
// Redirect Seek event example 
private void Codecs_Seek(object sender, CodecsRedirectSeekEventArgs e) 
{ 
   myStream.Seek(e.Offset, e.Origin); 
   e.Offset = myStream.Position; 
} 
 
// Redirect Read event example 
private void Codecs_Read(object sender, CodecsRedirectReadEventArgs e) 
{ 
   byte[] byteBuffer = new byte[e.Count]; 
   myStream.Read(byteBuffer, 0, e.Count); 
   Marshal.Copy(byteBuffer, 0, e.Buffer, e.Count); 
   e.Read = e.Count; 
   Debug.WriteLine("The number of bytes that read request should copy to the buffer is : {0}", e.Count); 
   Debug.WriteLine("The actual number of bytes that this read request has copied to Buffer is : {0}", e.Read); 
} 
 
// Redirect Write event example 
private void Codecs_Write(object sender, CodecsRedirectWriteEventArgs e) 
{ 
   byte[] byteBuffer = new byte[e.Count]; 
   Marshal.Copy(e.Buffer, byteBuffer, 0, e.Count); 
   myStream.Write(byteBuffer, 0, e.Count); 
   e.Written = e.Count; 
 
   Debug.WriteLine("The number of bytes that write request should copy from the buffer is : {0}", e.Count); 
   Debug.WriteLine("The actual number of bytes that this write request has copied from Buffer is : {0}", e.Written); 
} 
 
// Redirect Close event example 
private void Codecs_Close(object sender, CodecsRedirectCloseEventArgs e) 
{ 
   myStream.Close(); 
} 
 
 
public void StartRedirectingExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   codecs.RedirectOpen += new EventHandler<CodecsRedirectOpenEventArgs>(Codecs_Open); 
   codecs.RedirectSeek += new EventHandler<CodecsRedirectSeekEventArgs>(Codecs_Seek); 
   codecs.RedirectRead += new EventHandler<CodecsRedirectReadEventArgs>(Codecs_Read); 
   codecs.RedirectWrite += new EventHandler<CodecsRedirectWriteEventArgs>(Codecs_Write); 
   codecs.RedirectClose += new EventHandler<CodecsRedirectCloseEventArgs>(Codecs_Close); 
 
   string srcFilename = Path.Combine(LEAD_VARS.ImagesDir, "test_image1.cmp"); 
 
   codecs.StartRedirecting(); 
   RasterImage image = codecs.Load(srcFilename); 
   myStream.Close(); 
   codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "Image1_redirect.jpg"), RasterImageFormat.Jpeg, image.BitsPerPixel); 
   codecs.StopRedirecting(); 
 
   // Clean up 
   myStream.Dispose(); 
   image.Dispose(); 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

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

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