Home Backend Development XML/RSS Tutorial Store an image as a binary value in an Xml file

Store an image as a binary value in an Xml file

Mar 01, 2017 pm 05:29 PM

Choose from xinyuxin912's Blog

Save a picture in the form of a binary value into an xml file

try   {    int readByte = 0;        
//    int bytesToRead = 100;       
//数据缓冲区大小    
string fileName = "../../WriteXml.xml";   
//要打开的文件    
//   this.textBox1.Text = string.Empty;           
    // 打开图片文件,利用该图片构造一个文件流    
    FileStream fs = new FileStream("../../001.jpg",FileMode.Open);    
    // 使用文件流构造一个二进制读取器将基元数据读作二进制值    
    BinaryReader br = new BinaryReader(fs);
     XmlTextWriter xmlTxtWt = new XmlTextWriter(fileName,Encoding.UTF8);    
     //输出设置 代码缩进    
     xmlTxtWt.Formatting = Formatting.Indented;    
     //   
     xmlTxtWt.Indentation = 4;
    //书写声明    
    xmlTxtWt.WriteStartDocument();    
    xmlTxtWt.WriteStartElement("picture","ContactDetails","http://www.deltabis.com/Contact");//定义命名空间    
    xmlTxtWt.WriteStartElement("image");            
    //定义节点    
    xmlTxtWt.WriteAttributeString("imageName","002.jpg");        
    //添加图片属性
    byte[] base64buffer = new byte[bytesToRead];          
    //开辟缓冲区    
    do    
    {     
    readByte = br.Read(base64buffer,0,bytesToRead);      
    //将数据读入字节数组      
    xmlTxtWt.WriteBase64(base64buffer,0,readByte);       
    //将数组中二进制值编码为Base64并写出到XML文件
    }while(bytesToRead <= readByte);
     xmlTxtWt.WriteEndElement();    
     xmlTxtWt.WriteEndElement();    
     xmlTxtWt.WriteEndDocument();
 //    
 xmlTxtWt.Flush();    
 xmlTxtWt.Close();
    MessageBox.Show("读写结束!");
    //   
    this.textBox1.Text = ReadXml(fileName);   
    }   
    catch(Exception ex)   
    {    
    MessageBox.Show(ex.ToString());   
    }
Copy after login

The above is how to save a picture in the form of a binary value into an Xml file Content, please pay attention to the PHP Chinese website (www.php.cn) for more related content!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
Securing Your XML/RSS Feeds: A Comprehensive Security Checklist Securing Your XML/RSS Feeds: A Comprehensive Security Checklist Apr 08, 2025 am 12:06 AM

Methods to ensure the security of XML/RSSfeeds include: 1. Data verification, 2. Encrypted transmission, 3. Access control, 4. Logs and monitoring. These measures protect the integrity and confidentiality of data through network security protocols, data encryption algorithms and access control mechanisms.

RSS Document Tools: Building, Validating, and Publishing Feeds RSS Document Tools: Building, Validating, and Publishing Feeds Apr 09, 2025 am 12:10 AM

How to build, validate and publish RSSfeeds? 1. Build: Use Python scripts to generate RSSfeed, including title, link, description and release date. 2. Verification: Use FeedValidator.org or Python script to check whether RSSfeed complies with RSS2.0 standards. 3. Publish: Upload RSS files to the server, or use Flask to generate and publish RSSfeed dynamically. Through these steps, you can effectively manage and share content.

Is There an RSS Alternative Based on JSON? Is There an RSS Alternative Based on JSON? Apr 10, 2025 am 09:31 AM

JSONFeed is a JSON-based RSS alternative that has its advantages simplicity and ease of use. 1) JSONFeed uses JSON format, which is easy to generate and parse. 2) It supports dynamic generation and is suitable for modern web development. 3) Using JSONFeed can improve content management efficiency and user experience.

From XML to Readable Content: Demystifying RSS Feeds From XML to Readable Content: Demystifying RSS Feeds Apr 11, 2025 am 12:03 AM

RSSfeedsareXMLdocumentsusedforcontentaggregationanddistribution.Totransformthemintoreadablecontent:1)ParsetheXMLusinglibrarieslikefeedparserinPython.2)HandledifferentRSSversionsandpotentialparsingerrors.3)Transformthedataintouser-friendlyformatsliket

XML's Advantages in RSS: A Technical Deep Dive XML's Advantages in RSS: A Technical Deep Dive Apr 23, 2025 am 12:02 AM

XML has the advantages of structured data, scalability, cross-platform compatibility and parsing verification in RSS. 1) Structured data ensures consistency and reliability of content; 2) Scalability allows the addition of custom tags to suit content needs; 3) Cross-platform compatibility makes it work seamlessly on different devices; 4) Analytical and verification tools ensure the quality and integrity of the feed.

Building Feeds with XML: A Hands-On Guide to RSS Building Feeds with XML: A Hands-On Guide to RSS Apr 14, 2025 am 12:17 AM

The steps to build an RSSfeed using XML are as follows: 1. Create the root element and set the version; 2. Add the channel element and its basic information; 3. Add the entry element, including the title, link and description; 4. Convert the XML structure to a string and output it. With these steps, you can create a valid RSSfeed from scratch and enhance its functionality by adding additional elements such as release date and author information.

RSS Documents: How They Deliver Your Favorite Content RSS Documents: How They Deliver Your Favorite Content Apr 15, 2025 am 12:01 AM

RSS documents work by publishing content updates through XML files, and users subscribe and receive notifications through RSS readers. 1. Content publisher creates and updates RSS documents. 2. The RSS reader regularly accesses and parses XML files. 3. Users browse and read updated content. Example of usage: Subscribe to TechCrunch's RSS feed, just copy the link to the RSS reader.

XML's Role in RSS: The Foundation of Syndicated Content XML's Role in RSS: The Foundation of Syndicated Content Apr 12, 2025 am 12:17 AM

The core role of XML in RSS is to provide a standardized and flexible data format. 1. The structure and markup language characteristics of XML make it suitable for data exchange and storage. 2. RSS uses XML to create a standardized format to facilitate content sharing. 3. The application of XML in RSS includes elements that define feed content, such as title and release date. 4. Advantages include standardization and scalability, and challenges include document verbose and strict syntax requirements. 5. Best practices include validating XML validity, keeping it simple, using CDATA, and regularly updating.

See all articles