Serialize a Bitmap in C#/.NET to XML

后端 未结 4 1444
悲&欢浪女
悲&欢浪女 2020-11-27 06:12

I want to XML-Serialize a complex type (class), that has a property of type System.Drawing.Bitmap among others.

    /// <         


        
4条回答
  •  甜味超标
    2020-11-27 06:27

    Implement IXmlSerializable and then handle all the serialization details yourself.

    Since you say it's a large type and you only have a problem with the bitmap consider doing something like this:

    public class BitmapContainer : IXmlSerializable
    {
        public BitmapContainer() { }
    
        public Bitmap Data { get; set; }
    
        public XmlSchema GetSchema()
        {
            throw new NotImplementedException();
        }
    
        public void ReadXml(XmlReader reader)
        {
            throw new NotImplementedException();
        }
    
        public void WriteXml(XmlWriter writer)
        {
            throw new NotImplementedException();
        }
    }
    
    public class TypeWithBitmap
    {
        public BitmapContainer MyImage { get; set; }
    
        public string Name { get; set; }
    }
    

提交回复
热议问题