zoukankan      html  css  js  c++  java
  • 将图片保存至一个XML文件[转]

          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();
  • 相关阅读:
    mysql事务
    python zip dict函数
    有关mysql索引
    hash(散列函数)
    Docker使用
    Mac终端命令自动补全
    python序列化与反序列化(json与pickle)
    python txt、excel读写
    python 正则表达式
    python进行数据预处理-pandas
  • 原文地址:https://www.cnblogs.com/chuncn/p/971413.html
Copyright © 2011-2022 走看看