I currently writing a program that creates and fills Controls in a WPF application from a XML file. One of the features are that the User can choose a image he wants to display in the program. This image is displayed in a Image Control. After choosing the image, the program saves all data back to the XML file.
The image is converted and saved as follows:
byte[] bytes = new byte[1];
MemoryStream ms = new MemoryStream();
System.Drawing.Image image = new Bitmap(sPathOfImage);
image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
bytes = ms.ToArray();
XElement Image = new XElement("Image", Convert.ToBase64String(bytes));
xDocument.Add(Image);
xDocument.Save("xDocument.xml");
And this works perfectly, all's fine. However, main problem is the length of the value of the XElement Image. Even for 40kb images the lenght is 60,000 signs. And for a 9mb image it needs huge 13,200,000 signs. And now I'm looking for a way better solution to store images in the XML file.
Through specifications it has to be in one XML file.
So, is there a good way to make the string smaller, a more suitable stream, anything I'm missing out? Any hint is appreciated.