JasonHo

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

编辑器加载中...

//Image写入XML
using System.IO;
using System.Runtime.Serialization.Formatters.Soap;


string MyFile = @"D:\数据处理\image.xml";
string imageFile = @"G:\zengwei.jpg";
Stream MyStream;
SoapFormatter MyFormatter =new SoapFormatter();


void Mathod1()
{
    try
    {
        MyStream = new FileStream(
            MyFile, 
            FileMode.Create, 
            FileAccess.Write, 
            FileShare.None);
        MyFormatter.Serialize(
            MyStream, pictureBox1.Image);
        MyStream.Close();
        MessageBox.Show("完成!");
    }
    catch (Exception ex)
    {
       
    }
}

//读取XML显示IMAGE
void Mathod2(){
    try
    {
        MyStream = new FileStream(
            MyFile,
            FileMode.Open,
            FileAccess.Read,
            FileShare.None);
        pictureBox1.Image = 
            (Bitmap)MyFormatter.Deserialize(MyStream);
        MyStream.Close();
    }
    catch (Exception ex)
    { }
}
void Mathod3()
{
    pictureBox1.Image = Image.FromFile(imageFile);
}

  

posted on 2012-02-21 14:11  JasonHo  阅读(1259)  评论(0编辑  收藏  举报