xml圖片的生成

string xmlFileName=strTempXml;
     XmlTextWriter xw=new XmlTextWriter(xmlFileName,Encoding.UTF8);
     xw.WriteStartDocument();
     xw.WriteStartElement("image");
     xw.WriteString(photo);
     xw.WriteEndElement();
     xw.WriteEndDocument();
     xw.Flush();
     xw.Close();
     //寫入xml成功

     //從xml讀入到圖片
     XmlTextReader xr=new XmlTextReader(strTempXml);
     byte[] buffer = new byte[bufferSize];
     int readByte=0;
     //Create a file to write the bmp back.  jpgNewFile表示新圖片
     this.jpgPackFile=this.jpgPackFile.Replace(".jpg",j+".jpg");
     FileStream fileNew = new FileStream(this.jpgPackFile, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
     BinaryWriter bw = new BinaryWriter(fileNew);
     xr.MoveToContent();   
     do
     {
      readByte=xr.ReadBase64(buffer, 0, bufferSize);
      bw.Write(buffer, 0, readByte);
     } while(readByte>=bufferSize);

     bw.Flush();    
     bw.Close();    
     fileNew.Close();
     xr.Close();//關閉 !!!!  

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章