用心计较般般错 安心自守事事宽

cgl 坚持、努力终有所获
  新随笔  :: 管理

我们可以对实现IPersistStream接口的类的对象进行保存和读取,如Element,Map等等

以下为应用IPersistStream接口保存当前视图(Map)至文件读取文件并在当前视图展示的代码

 

 

            //保存当前视图至文件

 

            IMemoryBlobStream pMemoryBlobStream = new MemoryBlobStreamClass();

       IObjectStream pObjectStream = new ObjectStreamClass();

            pObjectStream.Stream = pMemoryBlobStream;

             IPersistStream pPersistStream = (IPersistStream)m_map;

             pPersistStream.Save((IStream)pObjectStream, 0);

             pMemoryBlobStream.SaveToFile(@"e:\myfile.blb");

 

            //读取文件并在当前视图展现

             IMemoryBlobStream pMemoryBlobStream = new MemoryBlobStreamClass();

             pMemoryBlobStream.LoadFromFile(@"e:\myfile.blb");

             IObjectStream pObjectStream = new ObjectStreamClass();

             pObjectStream.Stream=pMemoryBlobStream;

             IPersistStream pPersistStream = (IPersistStream)m_map;

             pPersistStream.Load((IStream)pObjectStream);

             m_activeView.Refresh();

 

  要素写入Oracle的Blob字段

 

            if (LayerIndex == -1)
            {
                Guid guid;
                object obj2;
                IPersistStream stream = (IPersistStream)Layer;
                IMemoryBlobStream stream2 = new MemoryBlobStreamClass();
                stream.GetClassID(out guid);
                stream.Save(stream2, 1);
                ((IMemoryBlobStreamVariant)stream2).ExportToVariant(out obj2);
                byte[] buffer = (byte[])obj2;
                sql = String.Format("{0}={1} and {2}={3}", TableHelper.FDLNodeId, NodeId, TableHelper.FDPrjId, nProjectId);
                DBHelper.DataAccess.SaveBLOB(TableHelper.TBLayerNode, TableHelper.FDLNodeRender, sql, buffer);
            }