WinForm的文档中,将PictureBox的Image属性等非文字内容都转变成文本保存,这是通过序列化(Serialization)实现的,
Eg:
using System.Runtime.Serialization.Formatters.Soap;
Stream stream = new FileStream("D:\\Image.xml",FileMode.Create,FileAccess.Write,FileShare.None);
SoapFormatter f = new SoapFormatter();
Image img = Image.FromFile("D:\\Image.bmp");
f.Serialize(stream,img);
stream.Close();
读取的话﹐先定义一个picturebox,然后做SoapFormatter的Serializer的反序列Deserializer操作﹐将操作后的对象转换成Image并赋给Picturebox的Image就可以看到原来的图片了。代码如下:
Stream stream = new FileStream("D:\\Image.xml",FileMode.Open ,FileAccess.Read ,FileShare.None);
SoapFormatter f = new SoapFormatter();
Image img = (Image)f.Deserialize(stream);
pictureBox1.Image = img;
stream.Close();
Eg:
using System.Runtime.Serialization.Formatters.Soap;
Stream stream = new FileStream("D:\\Image.xml",FileMode.Create,FileAccess.Write,FileShare.None);
SoapFormatter f = new SoapFormatter();
Image img = Image.FromFile("D:\\Image.bmp");
f.Serialize(stream,img);
stream.Close();
读取的话﹐先定义一个picturebox,然后做SoapFormatter的Serializer的反序列Deserializer操作﹐将操作后的对象转换成Image并赋给Picturebox的Image就可以看到原来的图片了。代码如下:
Stream stream = new FileStream("D:\\Image.xml",FileMode.Open ,FileAccess.Read ,FileShare.None);
SoapFormatter f = new SoapFormatter();
Image img = (Image)f.Deserialize(stream);
pictureBox1.Image = img;
stream.Close();