图片文件转化成XML文件格式问题
在C#当中,如何把一个图片文件(如:.JPG文件)转化成XML文件的格式?
各位大虾能否提供详细的代码和说明?
谢谢!!!
------解决方案--------------------使用XmlSerializer 类型实现将文件或类或其他东东保存到xml文件
例子如:
关于XML序列化的简单例子:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//选择保存路径
private void button1_Click(object sender, EventArgs e)
{
saveFileDialog1.Filter = "XML文件|*.xml ";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
textBox1.Text=saveFileDialog1.FileName;
}
//将类序列化到XML文件
private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text == " ")
return;
mydata newdata = new mydata();
newdata.myname = "小明 ";
newdata.mybirthday = "09-31 ";
newdata.age = 23;
newdata.imageByte = Encoding.Default.GetBytes( "999adfklasdjfl ".ToCharArray());
XmlSerializer es=new XmlSerializer(typeof(mydata));
TextWriter writer = new StreamWriter(textBox1.Text);
es.Serialize(writer, newdata);
writer.Close();
}
//反序列化XML文件为类
private void button3_Click(object sender, EventArgs e)
{
XmlSerializer sd = new XmlSerializer(typeof(mydata));
TextReader drr = new StreamReader(textBox1.Text);
mydata mm;
mm = (mydata)sd.Deserialize(drr);
MessageBox.Show( "mm.Name= "+mm.myname+ "\r\n "+
"mm.bothday= " + mm.mybirthday + "\r\n " +
"mm.age= "+mm.age+ "\r\n "+
"mm.imageByte= "+Encoding.Default.GetString(mm.imageByte));
}
}
//the class to serializer
public class mydata
{
public string myname;
public string mybirthday;
public int age;
public byte[] imageByte;
}
------解决方案--------------------http://www.souzz.net/html/edu/net/net5/2978.html
可能对你有用