标题:c#序列化 图片 求助
只看楼主
lujunliang86
Rank: 1
等 级:新手上路
帖 子:4
专家分:5
注 册:2010-12-9
结帖率:0
已结贴  问题点数:20 回复次数:2 
c#序列化 图片 求助
public void Serializable()
        {
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
               
                saveFileDialog1.Filter = "xml文件(*.xml)|*.xml";
                string name = saveFileDialog1.FileName;
                byte[] value = File.ReadAllBytes(openFileDialog1.FileName);
                Serializable s = new Serializable(name,value)//序列化
                {
                    Name = saveFileDialog1.FileName,
                    Value = File.ReadAllBytes(saveFileDialog1.FileName)

                };
                XmlSerializer ser = new XmlSerializer(typeof(Serializable));
                FileStream fs =new FileStream(saveFileDialog1.FileName,FileMode.Create);
                ser.Serialize(fs, s);
                fs.Close();
            }
        }
        public void DeSerializable()
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                XmlSerializer ser = new XmlSerializer(typeof(Serializable));
                Serializable s = (Serializable)ser.Deserialize(new FileStream(openFileDialog1.FileName, FileMode.Open));
                //FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open);

                this.pictureBox1.Image = Image.FromStream(new MemoryStream(s.Value));


            }
        }
序列化可以把值写进去,反序列怎么不能打开 求大侠帮帮。。。或者有新的方法也可以说下 谢谢
搜索更多相关主题的帖子: 序列 
2010-12-09 17:20
zhoufeng1988
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:北京
等 级:贵宾
威 望:27
帖 子:1432
专家分:6329
注 册:2009-5-31
得分:10 
你这是用的XML序列化方式。
尝试一下二进制序列化方式~
2010-12-10 21:09
c1_wangyf
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:7
帖 子:665
专家分:2832
注 册:2010-5-24
得分:10 
尝试一下楼上意见!
2010-12-10 21:55



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-328523-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.297347 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved