Starts file I/O redirection.
Syntax
Visual Basic (Declaration) | |
---|
Public Sub StartRedirecting() |
Visual Basic (Usage) | Copy Code |
---|
Dim instance As RasterCodecs
instance.StartRedirecting()
|
C# | |
---|
public void StartRedirecting() |
Managed Extensions for C++ | |
---|
public: void StartRedirecting(); |
C++/CLI | |
---|
public:
void StartRedirecting(); |
Example
Visual Basic | Copy Code |
---|
RasterCodecs.StartRedirecting
Private myStream As FileStream
Private Sub Codecs_Open(ByVal sender As Object, ByVal e As CodecsRedirectOpenEventArgs)
myStream = New FileStream(e.FileName, e.Mode)
e.Success = True
End Sub
Private Sub Codecs_Seek(ByVal sender As Object, ByVal e As CodecsRedirectSeekEventArgs)
myStream.Seek(e.Offset, e.Origin)
End Sub
Private Sub Codecs_Read(ByVal sender As Object, ByVal e As CodecsRedirectReadEventArgs)
Dim byteBuffer As Byte() = New Byte(e.Count - 1) {}
myStream.Read(byteBuffer, 0, e.Count)
Marshal.Copy(byteBuffer, 0, e.Buffer, e.Count)
e.Read = e.Count
Console.WriteLine("The number of bytes that read request should copy to the buffer is : {0}", e.Count)
Console.WriteLine("The actual number of bytes that this read request has copied to Buffer is : {0}", e.Read)
End Sub
Private Sub Codecs_Write(ByVal sender As Object, ByVal e As CodecsRedirectWriteEventArgs)
Dim byteBuffer As Byte() = New Byte(e.Count - 1) {}
Marshal.Copy(e.Buffer, byteBuffer, 0, e.Count)
e.Written = e.Count
myStream.Write(byteBuffer, 0, e.Count)
Console.WriteLine("The number of bytes that write request should copy from the buffer is : {0}", e.Count)
Console.WriteLine("The actual number of bytes that this write request has copied from Buffer is : {0}", e.Written)
End Sub
Private Sub Codecs_Close(ByVal sender As Object, ByVal e As CodecsRedirectCloseEventArgs)
myStream.Close()
End Sub
Public Sub StartRedirectingExample()
RasterCodecs.Startup()
Dim codecs As RasterCodecs = New RasterCodecs()
AddHandler codecs.RedirectOpen, AddressOf Codecs_Open
AddHandler codecs.RedirectSeek, AddressOf Codecs_Seek
AddHandler codecs.RedirectRead, AddressOf Codecs_Read
AddHandler codecs.RedirectWrite, AddressOf Codecs_Write
AddHandler codecs.RedirectClose, AddressOf Codecs_Close
Dim srcFilename As String = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1.cmp"
codecs.StartRedirecting()
Dim image As RasterImage = codecs.Load(srcFilename)
myStream.Close()
codecs.Save(image, "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1_redirect.jpg", RasterImageFormat.Jpeg, image.BitsPerPixel)
codecs.StopRedirecting()
myStream.Dispose()
image.Dispose()
codecs.Dispose()
RasterCodecs.Shutdown()
End Sub |
C# | Copy Code |
---|
RasterCodecs.StartRedirecting // 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); e.Success = true; } // Redirect Seek event example private void Codecs_Seek(object sender, CodecsRedirectSeekEventArgs e) { myStream.Seek(e.Offset, e.Origin); } // 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; Console.WriteLine("The number of bytes that read request should copy to the buffer is : {0}", e.Count); Console.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); e.Written = e.Count; myStream.Write(byteBuffer, 0, e.Count); Console.WriteLine("The number of bytes that write request should copy from the buffer is : {0}", e.Count); Console.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.Startup(); 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 = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1.cmp"; codecs.StartRedirecting(); RasterImage image = codecs.Load(srcFilename); myStream.Close(); codecs.Save(image, @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1_redirect.jpg", RasterImageFormat.Jpeg, image.BitsPerPixel); codecs.StopRedirecting(); // Clean up myStream.Dispose(); image.Dispose(); codecs.Dispose(); RasterCodecs.Shutdown(); } |
Remarks
Requirements
Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
See Also