Home All Groups Group Topic Archive Search About
Author
13 Nov 2006 4:19 PM
Romain TAILLANDIER
Hi group

I need to XmlSerialize Images. The class to be serialized have a
property MyImage of type Image. When i serailize it, i got an
exception.
I found a workarround which works good by serializing a byte[] (instead
of the Image), i turn the image into a byte[] using a memoryStream (see
the code below in the PS).
But the Xml is not beautifull and look like that :

<MyClass>
<MyImage>eb1BvKJDlv/mlALUWmWDdJDjygsNr0QWGj6/RVtP/.............6Aktil31of+Y</MyImage>
<MyClass>

In one only line of 15000 cols (depending of the size of the image).
When i look to a resx file, images serialized in xml are formatted with
many lines of 80 cols (+ Xml Indentation).

How can i format my XMl file, or my byte[] to be as beautifful as an
resx file ?
is there any atribute to get a good xml for images ?
Is my byte[] prop is necessary or is there more elegant solutions ?

thank you for your help !
ROM
PS : the code is following.

public class MyClass
{
private Image _Image = null;

        /// <summary>
        /// do not use. used only for XmlSerialisation.
        /// </summary>
        public byte[] _InternalImage
        {
            get
            {
                if(this._Image == null)
                    return null;
                MemoryStream memStream = new MemoryStream();
                _Image.Save(memStream, System.Drawing.Imaging.ImageFormat.Gif);
                return memStream.ToArray();

            }

            set
            {
                if(value == null)
                {
                    _Image = null;
                    return;
                }
                _Image = new Bitmap(new MemoryStream(value));
            }
        }

        [XmlIgnore]
        public Image Image
        {
            get { return _Image; }
            set { _Image = value; }
        }
}

AddThis Social Bookmark Button