Store an image in the Xml file as a binary value.

Source: Internet
Author: User
The Blog selected from xinyuxin912 saves an image to the xml file in binary format and selects the Blog from xinyuxin912.

Store an image in the xml file as a binary value.

Try {int readByte = 0; // int bytesToRead = 100; // data buffer size string fileName = ".. /.. /WriteXml. xml "; // the file to be opened // this. textBox1.Text = string. empty; // open the 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 the binary value BinaryReader br = new BinaryReader (fs); XmlTextWriter xmlTxtWt = new XmlTextWriter (fileName, Encoding. UTF8); // The Output setting code indent xmlTxtWt. formatting = Formatting. indented; // xmlTxtWt. indentation = 4; // write the statement xmlTxtWt. writeStartDocument (); xmlTxtWt. writeStartElement ("picture", "ContactDetails "," http://www.deltabis.com/Contact "); // Defines the namespace xmlTxtWt. writeStartElement ("image"); // defines the node xmlTxtWt. writeAttributeString ("imageName", "002.jpg"); // add the image attribute byte [] base64buffer = new byte [bytesToRead]; // open the buffer do {readByte = br. read (base64buffer, 0, bytesToRead); // Read data into the byte array xmlTxtWt. writeBase64 (base64buffer, 0, readByte); // Encode the binary value in the array to Base64 and write it to the XML file} while (bytesToRead <= readByte); xmlTxtWt. writeEndElement (); xmlTxtWt. writeEndElement (); XmlTxtWt. WriteEndDocument (); // xmlTxtWt. Flush (); xmlTxtWt. Close (); MessageBox. Show ("read and write ends! "); // This. textBox1.Text = ReadXml (fileName);} catch (Exception ex) {MessageBox. Show (ex. ToString ());}

The preceding figure stores an image in the Xml file as a binary value. For more information, see PHP Chinese website (www.php1.cn )!

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.