Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I would like to add an image into a xml file with
XmlWriter
using C#.
How can I do it?

What I have tried:

Bitmap bmp = new Bitmap(imagePath);
TypeConverter converter = TypeDescriptor.GetConverter(typeof(Bitmap));
XElement img = new XElement("image",
    Convert.ToBase64String(
        (byte[])converter.ConvertTo(bmp, typeof(byte[]))));

xmlWriter.WriteStartElement("img");
xmlWriter.WriteString(img.ToString());
xmlWriter.WriteEndElement();
Posted
Updated 16-Oct-18 3:54am
Comments
Member 14952884 23-Jan-21 2:57am    
How to read it back?

1 solution

 
Share this answer
 
Comments
merh 16-Oct-18 11:44am    
Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900