public void StopRedirecting()
public void stopRedirecting()
public:
void StopRedirecting();
def StopRedirecting(self):
LEADTOOLS I/O redirection allows you to replace the default input/output methods for opening, reading, writing, seeking, and closing files.
For example, you can redirect all the library I/O methods to your own I/O methods to load/save images from your own streams.
Call StartRedirecting to enable I/O redirection and StopRedirecting to reset it back to the defaults.
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:\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.*;
// LeadDynamicStream myStream;
// // Redirect Open event example
// CodecsRedirectOpenListener codecsOpen = new CodecsRedirectOpenListener() {
// @Override
// public void onRedirectOpen(CodecsRedirectOpenEvent e) {
// try {
// InputStream inputStream = Files.newInputStream(Paths.get(e.getFileName()));
// myStream = new LeadDynamicStream(inputStream, false);
// } catch (Exception ex) {
// System.err.println(ex.getMessage());
// }
// System.out.println("Mode: " + e.getMode());
// e.setSuccess(true);
// }
// };
// // Redirect Seek event example
// CodecsRedirectSeekListener codecsSeek = new CodecsRedirectSeekListener() {
// @Override
// public void onRedirectSeek(CodecsRedirectSeekEvent e) {
// myStream.seek(e.getOrigin(), e.getOffset());
// e.setOffset(0);
// }
// };
// // Redirect Read event example
// CodecsRedirectReadListener codecsRead = new CodecsRedirectReadListener() {
// @Override
// public void onRedirectRead(CodecsRedirectReadEvent e) {
// byte[] byteBuffer = new byte[e.getCount()];
// myStream.read(byteBuffer, e.getCount());
// e.setRead(e.getCount());
// System.out.println("The number of bytes that read request should copy to the
// buffer is : " + e.getCount());
// System.out.println("The actual number of bytes that this read request has
// copied to Buffer is : " + e.getRead());
// }
// };
// // Redirect Write event example
// CodecsRedirectWriteListener codecsWrite = new CodecsRedirectWriteListener() {
// @Override
// public void onRedirectWrite(CodecsRedirectWriteEvent e) {
// byte[] byteBuffer = new byte[e.getCount()];
// // Marshal.Copy(e.getBuffer(), byteBuffer, 0, e.Count);
// myStream.write(byteBuffer, e.getCount());
// e.setWritten(e.getCount());
// System.out.println("The number of bytes that write request should copy from
// the buffer is : " + e.getCount());
// System.out.println("The actual number of bytes that this write request has
// copied from Buffer is : " + e.getWritten());
// }
// };
// // Redirect Close event example
// CodecsRedirectCloseListener codecsClose = new CodecsRedirectCloseListener(){
// @Override
// public void onRedirectClose(CodecsRedirectCloseEvent arg0) {
// myStream.close();
// }
// };
// // public void startRedirectingExample() throws IOException {
// final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images";
// RasterCodecs codecs = new RasterCodecs();
// codecs.addRedirectOpenListener(codecsOpen);
// codecs.addRedirectSeekListener(codecsSeek);
// codecs.addRedirectReadListener(codecsRead);
// codecs.addRedirectWriteListener(codecsWrite);
// codecs.addRedirectCloseListener(codecsClose);
// String srcFileName = combine(LEAD_VARS_IMAGES_DIR, "test_image1.cmp");
// System.out.println(srcFileName);
// codecs.startRedirecting();
// RasterImage image = codecs.load(srcFileName);
// myStream.close();
// codecs.save(
// image,
// combine(LEAD_VARS_IMAGES_DIR,
// "Image1_redirect.jpg"),
// RasterImageFormat.JPEG,
// image.getBitsPerPixel()
// );
// codecs.stopRedirecting();
// // Clean up
// myStream.dispose();
// image.dispose();
// codecs.dispose();
// }
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