←Select platform

GetObjectData Method

Summary
Populates a specified SerializationInfo with the data needed to serialize this object.
Syntax
C#
C++/CLI
Python
public virtual void GetObjectData( 
   SerializationInfo info, 
   StreamingContext context 
) 
public: 
virtual void GetObjectData(  
   SerializationInfo^ info, 
   StreamingContext context 
)  
def GetObjectData(self,info,context): 

Parameters

info
The SerializationInfo to populate with data.

context
The contextual information about the source or destination of the serialization.

Remarks

This method implements ISerializable.GetObjectData.

The RasterImage class supports standard .NET serialization. Serialization a RasterImage is the process of converting the state of an RasterImage object into a form that can be persisted or transported. The complement of serialization is deserialization, which converts a stream into an RasterImage object. Together, these processes allow the image data to be easily stored and transferred.

When you serialize an RasterImage object, all the data inside the object are saved. This include the image data of all pages as well as the current page number, region information, low bit/high bit, palette data, metadata (tags, markers and comments), etc. In other words, the RasterImage can be constructed back to its original state from the stream.

For more information and examples regarding serialization of an RasterImage object, refer to RasterImage Serialization.

This method will use the value of RasterDefaults.CompressOnSerialize to determine whether to use compression when serializing the RasterImage object.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
 
 
public void MyRasterImageSerializationTest() 
{ 
   // Load an image 
   RasterCodecs codecs = new RasterCodecs(); 
   RasterImage img = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")); 
 
   // create a new MyRasterImage instance out of this image 
   MyRasterImage myImage = new MyRasterImage(img); 
 
   // Set our custom data 
   myImage.MyIntegerData = 10; 
   myImage.MyStringData = "My string"; 
   string msg = string.Format("Before serialization.  MyIntegerData = {0}, MyStringData = {1}", myImage.MyIntegerData, myImage.MyStringData); 
   Console.WriteLine(msg); 
 
   // img is invalid now and should be disposed 
   img.Dispose(); 
 
   // Serialize myImage 
   BinaryFormatter formatter = new BinaryFormatter(); 
   MemoryStream ms = new MemoryStream(); 
   formatter.Serialize(ms, myImage); 
 
   // dispose myImage 
   myImage.Dispose(); 
   myImage = null; 
 
   // Deserialize back from the stream 
   ms.Position = 0; 
   myImage = formatter.Deserialize(ms) as MyRasterImage; 
 
   msg = string.Format("After serialization.  MyIntegerData = {0}, MyStringData = {1}", myImage.MyIntegerData, myImage.MyStringData); 
   Console.WriteLine(msg); 
 
   // re-save the image 
   codecs.Save(myImage, Path.Combine(LEAD_VARS.ImagesDir, "Image1_MySerialized.bmp"), RasterImageFormat.Bmp, 24); 
 
   // Clean up 
   ms.Close(); 
   ms.Dispose(); 
   myImage.Dispose(); 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

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

Leadtools Assembly

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