using System
using System.Drawing
using System.Collections
using System.ComponentModel
using System.Windows.Forms
using System.Data
using System.Xml
using System.IO
using System.Drawing.Imaging
namespace xmlfile
{
/// <summary>厅哗
/// aboatfile 的摘要说扮悉行明。
/// </summary>
public class xmlfile
{
public xmlfile()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
//找开一幅XML图片(XmlTextReader)
public Image openxmlfile(string xmlfilepath)
{
XmlTextReader readxml=new XmlTextReader(xmlfilepath)
int len=64*1024
byte[] bytebmp=new byte [len]
while (readxml.Read())
{
if (readxml.NodeType==XmlNodeType.Element)
{
if (readxml.LocalName.Equals("image"))
{
readxml.ReadBase64(bytebmp,0,len)
}
}
}
readxml.Close()
readxml=null
FileStream streamfile=File.OpenWrite(@"陆简C:Documents and SettingsAdministratorLocal SettingsTempa.bmp")
streamfile.Write(bytebmp,0,bytebmp.Length)
streamfile.Close()
streamfile=null
Image img
img=System.Drawing.Bitmap.FromFile(@"C:Documents and SettingsAdministratorLocal SettingsTempa.bmp")
return img
}
//保存一幅XML图片(XmlTextWriter)
public void savexmlfile(string xmlname)
{
FileStream fs=new FileStream(@"C:a.bmp",FileMode.Open)
string time=DateTime.Now.ToLongDateString()
int len=4029
int readByte=0
byte[] imgdata = new byte[len]
XmlTextWriter xw=new XmlTextWriter(xmlname,System.Text.Encoding.UTF8)
xw.WriteStartDocument()
xw.WriteComment("XML图片,用base64储存创建于"+time)
xw.WriteStartElement("image")
BinaryReader br = new BinaryReader(fs)
do
{
readByte=br.Read(imgdata, 0, len)
xw.WriteBase64(imgdata, 0, readByte)
}
while (len <= readByte )
xw.WriteEndElement()
xw.WriteEndDocument()
fs.Close()
xw.Flush()
xw.Close()
File.Delete(@"C:a.bmp")
}
}
}
2、然后桥皮在新的界面里绝丛点击选择“另存为”按钮。
3、之后在新的界面里在“保存类型”右侧点击选择“XML 文档”按钮。
4、然并消樱后在新的界面里点击选择“保存”按钮即可将TXT格式的文件转换成XML了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)