LEADTOOLS (Leadtools assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
RasterImage Constructor(SerializationInfo,StreamingContext)
See Also  Example
Leadtools Namespace > RasterImage Class > RasterImage Constructor : RasterImage Constructor(SerializationInfo,StreamingContext)



info
The data needed to serialize or deserialize an object.
context
The source and destination of a given serialized stream.
This constructor is required by System.Runtime.Serialization.ISerializable.

Syntax

Visual Basic (Declaration) 
Protected Function New( _
   ByVal info As SerializationInfo, _
   ByVal context As StreamingContext _
)
Visual Basic (Usage)Copy Code
Dim info As SerializationInfo
Dim context As StreamingContext
 
Dim instance As New RasterImage(info, context)
C# 
protected RasterImage( 
   SerializationInfo info,
   StreamingContext context
)
C++/CLI 
protected:
RasterImage( 
   SerializationInfo^ info,
   StreamingContext context
)

Parameters

info
The data needed to serialize or deserialize an object.
context
The source and destination of a given serialized stream.

Example

Visual BasicCopy Code
Public Sub MyRasterImageSerializationTest()
      ' Load an image
      Dim codecs As RasterCodecs = New RasterCodecs()

      Dim img As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"))

      ' create a new MyRasterImage instance out of this image
      Dim myImage As MyRasterImage = New MyRasterImage(img)

      ' Set our custom data
      myImage.MyIntegerData = 10
      myImage.MyStringData = "My string"
      Dim msg As String = String.Format("Before serialization.  MyIntegerData = {0}, MyStringData = {1}", myImage.MyIntegerData, myImage.MyStringData)
      MessageBox.Show(msg)

      ' img is invalid now and should be disposed
      img.Dispose()

      ' Serialize myImage
      Dim formatter As BinaryFormatter = New BinaryFormatter()
      Dim ms As MemoryStream = New MemoryStream()
      formatter.Serialize(ms, myImage)

      ' dispose myImage
      myImage.Dispose()
      myImage = Nothing

      ' Deserialize back from the stream
      ms.Position = 0
         myImage = CType(formatter.Deserialize(ms), MyRasterImage)

      msg = String.Format("After serialization.  MyIntegerData = {0}, MyStringData = {1}", myImage.MyIntegerData, myImage.MyStringData)
      MessageBox.Show(msg)

      ' re-save the image
      codecs.Save(myImage, Path.Combine(LEAD_VARS.ImagesDir, "Image1_MySerialized.bmp"), RasterImageFormat.Bmp, 24)

      ' Clean up
      ms.Close()
      myImage.Dispose()
      codecs.Dispose()
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
C#Copy Code
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);
      MessageBox.Show(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);
      MessageBox.Show(msg);

      // re-save the image
      codecs.Save(myImage, Path.Combine(LEAD_VARS.ImagesDir, "Image1_MySerialized.bmp"), RasterImageFormat.Bmp, 24);

      // Clean up
      ms.Close();
      myImage.Dispose();
      codecs.Dispose();
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
SilverlightCSharpCopy Code
SilverlightVBCopy Code

Remarks

The RasterImage class supports standard .NET serialization. Serialization of a RasterImage is the process of converting the state of a 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 includes 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.

Requirements

Target Platforms: Silverlight, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only), Windows Phone 7

See Also