RasterImage Constructor(SerializationInfo,StreamingContext) (original) (raw)
Summary
This constructor is required by ISerializable.
Syntax
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
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";
}
Leadtools Assembly