Here's some code taken from Kirk Evans Blog that demonstrates how to encode an image 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();