←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#
Java
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:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.FileInputStream; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.io.ObjectInputStream; 
import java.io.ObjectOutputStream; 
 
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.*; 
 
 
public void MyRasterImageSerializationTest() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   RasterCodecs codecs = new RasterCodecs(); 
   RasterImage img = codecs.load(combine(LEAD_VARS_IMAGES_DIR, "sample5.cmp")); 
 
   // create a new MyRasterImage instance out of this image 
   SerializeRasterImage myImage = new SerializeRasterImage(img); 
 
   // Set our custom data 
   myImage.setMyIntegerData(10); 
   myImage.setMyStringData("My string"); 
   String msg = String.format("Before serialization.  MyIntegerData = %s, MyStringData = %s%n", 
         myImage.getMyIntegerData(), myImage.getMyStringData()); 
   System.out.println(msg); 
 
   // img is invalid now and should be disposed 
   img.dispose();; 
 
   // Serialization 
   try { 
      // Saving of object in a file 
      File serFile = new File(combine(LEAD_VARS_IMAGES_DIR, "Serialized.txt")); 
      FileOutputStream fos = new FileOutputStream(serFile); 
      ObjectOutputStream out = new ObjectOutputStream(fos); 
 
      // Method for serialization of object 
      out.writeObject(myImage); 
 
      out.close(); 
      fos.close(); 
 
      System.out.println("Object has been serialized"); 
 
      // dispose myImage 
      myImage = null; 
 
      // Deserialize back from the stream 
      // Reading the object from a file 
      File deserFile = new File(combine(LEAD_VARS_IMAGES_DIR, "Serialized.txt")); 
      FileInputStream fis = new FileInputStream(deserFile); 
      ObjectInputStream in = new ObjectInputStream(fis); 
 
      // Method for deserialization of object 
      myImage = (SerializeRasterImage) in.readObject(); 
 
      in.close(); 
      fis.close(); 
 
      System.out.println("Object has been deserialized "); 
      System.out.println("a = " + myImage.getMyIntegerData()); 
      System.out.println("b = " + myImage.getMyStringData()); 
 
   } catch (IOException | ClassNotFoundException ex) { 
      System.out.println(ex); 
   } 
 
   msg = String.format("After serialization.  MyIntegerData = %s, MyStringData = %s%n", myImage.getMyIntegerData(), 
         myImage.getMyStringData()); 
   System.out.println(msg); 
 
   // re-save the image 
   codecs.save(myImage, combine(LEAD_VARS_IMAGES_DIR, "Image1_MySerialized.bmp"), RasterImageFormat.BMP, 24); 
 
   assertTrue("Image unsuccessfully saved to " + combine(LEAD_VARS_IMAGES_DIR, "Image1_MySerialized.bmp"), 
         (new File(combine(LEAD_VARS_IMAGES_DIR, "Image1_MySerialized.bmp"))).exists()); 
   System.out.println("Image is saved to " + combine(LEAD_VARS_IMAGES_DIR, "Image1_MySerialized.bmp")); 
 
   // Clean up 
   myImage.dispose(); 
   codecs.dispose(); 
} 
Requirements

Target Platforms

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

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