I want to XML-Serialize a complex type (class), that has a property of type System.Drawing.Bitmap among others.
/// <
You can also to implement ISerializable and to use SerializationInfo to deal manually with your bitmap content.
EDIT: João is right: Correct way to deal with XML serialization is to implement IXmlSerializable, not ISerializable:
public class MyImage : IXmlSerializable
{
public string Name { get; set; }
public Bitmap Image { get; set; }
public System.Xml.Schema.XmlSchema GetSchema()
{
throw new NotImplementedException();
}
public void ReadXml(System.Xml.XmlReader reader)
{
throw new NotImplementedException();
}
public void WriteXml(System.Xml.XmlWriter writer)
{
writer.WriteStartElement("Name");
writer.WriteString(this.Name);
writer.WriteEndElement();
using(MemoryStream ms = new MemoryStream())
{
this.Image.Save(ms, ImageFormat.Bmp );
byte[] bitmapData = ms.ToArray();
writer.WriteStartElement("Image");
writer.WriteBase64(bitmapData, 0, bitmapData.Length);
writer.WriteEndElement();
}
}
}