Read the image into the Dom and save it as an xml file.
Source: Internet
Author: User
Read the image into the Dom and save it as an xml file.
1. Namespace required
Using System. Text;
Using System. IO;
Using System. Xml;
2's folder contains jpg images
3. Generate a docSave. xml file
//************************************** **************************************** *******************************
Try
{
XmlDocument myXmlDoc = new XmlDocument ();
MyXmlDoc. LoadXml ("<picture> <name> picture </name> </picture> ");
XmlElement elem = myXmlDoc. CreateElement ("image ");
// Open an image file and use the image to construct a File Stream
FileStream fs = new FileStream (".../../001.jpg", FileMode. Open );
// Construct a binary reader using a file stream to read the base metadata as a binary value
BinaryReader br = new BinaryReader (fs );
Byte [] imageBuffer = new byte [br. BaseStream. Length];
Br. Read (imageBuffer, 0, Convert. ToInt32 (br. BaseStream. Length ));
String textString = System. Convert. ToBase64String (imageBuffer );
Fs. Close ();
Br. Close ();
XmlText text = myXmlDoc. CreateTextNode (textString );
MyXmlDoc. DocumentElement. AppendChild (elem );
MyXmlDoc. DocumentElement. LastChild. AppendChild (text );
MyXmlDoc. Save (".../../docSave. xml ");
MessageBox. Show ("read and write ends! ");
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.