←Select platform

Offset Property

Summary
Gets or sets the byte offset relative to Origin.
Syntax
C#
C++/CLI
Java
Python
public long Offset { get; set; } 
public long getOffset() 
public void setOffset(long value) 
public: 
property int64 Offset { 
   int64 get(); 
   void set (    int64 ); 
} 
Offset # get and set (CodecsRedirectSeekEventArgs) 

Property Value

The byte offset relative to Origin this seek operation should move. After the seek operation is done. This property should updated with the new offset value. The default value is 0.

Remarks

If Offset is negative, the new position is required to precede the position specified by Origin by the number of bytes specified by Offset. If Offset is zero (0), the new position is required to be the position specified by Origin. If Offset is positive, the new position is required to follow the position specified by Origin by the number of bytes specified by Offset.

Example
C#
Java
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(); 
// } 
Requirements

Target Platforms

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

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