zoukankan      html  css  js  c++  java
  • Scene场景的保存!

    原创文章,转载请注明出处!

    这里学习了一下IStream和IPersistStream接口。

    FileStream、ObjectStream和XmlStream类都继承了IStream接口。IPersist-->IPersistStream和IStream都是COM的接口,微软的接口。

    FileStream、ObjectStream和XmlStream类则是Esri的类对象,new 对象的时候,类名包含class这几个字符FileStreamClass、ObjectStreamClass和XmlStreamClass,明显是RCW封装后的类。

    串行化(serialization)是指将一个对象的当前状态转换成字节流(a stream of bytes)的过程,而反串行化(deserialization)则指串行化过程的逆过程,将字节流转换成一个对象。.Net目前通过Iserializeable接口实现序列化。这也就是我用C#开发的时候想序列化包含COM成员的类是产生的问题。难道必须转换?

    情况描述为:1. 自己定义的一个类,类的成员有.net的值类型和对象,还包括COM对象,这时候应该如何保持我的这个类?

    2.在保存COM对象的时候,比如下面对Scene的序列化,怎样同时保存同一窗体中其他的成员变量(.net变量或对象)?

    View Code
     1 private void 保存场景ToolStripMenuItem_Click(object sender, EventArgs e)
    2 {
    3 SaveFileDialog pSaveDlg = new SaveFileDialog();
    4 pSaveDlg.Filter = "3D场景(*.sce)|*.sce";
    5
    6 pSaveDlg.Title = "生成3D场景";
    7 if (pSaveDlg.ShowDialog() == DialogResult.OK)
    8 {
    9 string exportname = pSaveDlg.FileName;
    10 IMemoryBlobStream pMemoryBlobStream = new MemoryBlobStreamClass();
    11 IObjectStream pObjectStream = new ObjectStreamClass();
    12 pObjectStream.Stream = pMemoryBlobStream;
    13 IPersistStream pPersistStream = (IPersistStream)m_scene;
    14 pPersistStream.Save((IStream)pObjectStream, 0);
    15 pMemoryBlobStream.SaveToFile(exportname);
    16 MessageBox.Show("场景保存成功!");
    17 }
    18 }
    19
    20 private void 打开场景ToolStripMenuItem_Click(object sender, EventArgs e)
    21 {
    22 OpenFileDialog pDlg = new OpenFileDialog();
    23 pDlg.Filter = "3D场景(*.sce)|*.sce";
    24 pDlg.Multiselect = false;
    25 pDlg.Title = "3D场景";
    26 if (pDlg.ShowDialog() == DialogResult.OK)
    27 {
    28 string fileName = pDlg.FileName;
    29 string path = System.IO.Path.GetDirectoryName(fileName);
    30 string name = System.IO.Path.GetFileNameWithoutExtension(fileName);
    31 IMemoryBlobStream pMemoryBlobStream = new MemoryBlobStreamClass();
    32 pMemoryBlobStream.LoadFromFile(fileName);
    33 IObjectStream pObjectStream = new ObjectStreamClass();
    34 pObjectStream.Stream = pMemoryBlobStream;
    35 IPersistStream pPersistStream = (IPersistStream)m_scene;
    36 pPersistStream.Load((IStream)pObjectStream);
    37 axSceneControl1.SceneGraph.Scene = m_scene;
    38 axSceneControl1.SceneGraph.RefreshViewers();
    39 }
    40 }

    参考文献:

    http://www.cnblogs.com/myparamita/archive/2009/01/21/1379325.html

    http://blog.csdn.net/puttytree/article/details/5376423

    文章未经说明均属原创,学习笔记可能有大段的引用,一般会注明参考文献。 欢迎大家留言交流,转载请注明出处。
  • 相关阅读:
    微信小程序用setData修改数组或对象中的一个属性值,超好用,最简单的实现方法,不容错过!大神们 都 在 看 的方法!!!
    pythonchallenge1
    pythonchallenge4
    pythonchallenge7
    pythonchallenge9
    pythonchallenge8
    pythonchallenge2
    pythonchallenge0
    递归排序
    pythonchallenge3
  • 原文地址:https://www.cnblogs.com/yhlx125/p/2306497.html
Copyright © 2011-2022 走看看