Je kunt png embedden in een XML middels Base64 encoding, in normale byte order gaat het niet goed omdat XML geen formaat is voor binary data, je zult er speciaal een writer voor moeten schijven want niet veel programma's doen dit zo. Ik vond een voorbeeld in C#:
//Load the picture from a file
Image picture = Image.FromFile(@"c:\temp\test.gif");
//Create an in-memory stream to hold the picture's bytes
System.IO.MemoryStream pictureAsStream = new System.IO.MemoryStream();
picture.Save(pictureAsStream, System.Drawing.Imaging.ImageFormat.Gif);
//Rewind the stream back to the beginning
pictureAsStream.Position = 0;
//Get the stream as an array of bytes
byte[] pictureAsBytes = pictureAsStream.ToArray();
//Create an XmlTextWriter to write the XML somewhere... here, I just chose
//to stream out to the Console output stream
System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Console.Out);
//Write the root element of the XML document and the base64 encoded data
writer.WriteStartElement("w", "binData",
"http://schemas.microsoft.com/office/word/2003/wordml");
writer.WriteBase64(pictureAsBytes, 0, pictureAsBytes.Length);
writer.WriteEndElement();
writer.Flush();
Toegevoegd na 2 minuten:
En dan ziet het er zo uit:
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAAYagMeiWXwAAAG9JREFUeJzt1jEKgDAMRuEnZGhPofc%2FVQSPIcTdxUV4HVLoUCj8H00o2YoBMF57fpz%2FujODHXUFRwPKBqj5DVigB041HiJ9gFyCVOMbsEIPXNwuAHkgiJL%2F4qABNqB7QAeUPBAE2QAZUDZAfwEb8ABSIBqcFg%2B4TAAAAABJRU5ErkJggg%3D%3D
- Bronnen:
-
http://www.codingforums.com/xml/91489-embe...