zoukankan      html  css  js  c++  java
  • ArcEngine BLOB字段读写

    http://www.3sbase.com/old/chxnews.asp?id=664 http://www.cnblogs.com/feedback/archive/2008/05/27/1208275.html http://bbs.esrichina-bj.cn/ESRI/thread-74169-1-1.html -------------------- ①将Ilayer转换为Byte数组 public static byte[] CreateByteFromLayer(ILayer pLayer) {//Engine中的BlobStream对象 IMemoryBlobStream pBlobStream = new MemoryBlobStream(); IPersistStream pPerStreamout = (IPersistStream)pLayer; pPerStreamout.Save(pBlobStream, 0); //存入BlobStream IMemoryBlobStreamVariant pVar = (IMemoryBlobStreamVariant)pBlobStream; //转换为Variant类型 object pobj = new object(); pVar.ExportToVariant(out pobj); //转入Object对象 return pobj as byte[];//强制转换为Byte数组,并返回 } ②将 Byte数组转换为ILayer对象(此函数需根据不同的Layer类型,用不同的Layer对象转换) public static ILayer GetLayerFromByte(byte[] pByte, int iLayerType) {IMemoryBlobStream pBlobStream = new MemoryBlobStreamClass(); //与BlobSream指向的内存 IMemoryBlobStreamVariant pVar = (IMemoryBlobStreamVariant)pBlobStream; object pobj = pByte as object; pVar.ImportFromVariant(pobj); //从Byte数据读取数据 IPersistStream pPerStreamout = null; switch (iLayerType) //根所Layer类型转换为不同的Layer对象 {case 0: pPerStreamout = new FeatureLayerClass(); break; case 1: pPerStreamout = new FDOGraphicsLayerClass(); break; default: return null; } pPerStreamout.Load(pBlobStream); //载入数据,并强制转换为ILayer类型 return pPerStreamout as ILayer; } 曾经做过的,有两个函数~你看下吧,调试通过了,一个为将ILayer转换为byte数组,一个为将byte数组转换为ILayer对象。           在之前,我都尽量避免读写blob字段,原因如下 第一:不方便手工维护。 第二:不方便做数据转换。 第三:其他人不知道里面放了什么,对于交流上有障碍。 最近,由于项目的需要,不得不去实现blob字段的读写。 AE的对象都是存在数据库中里的blob字段的,他自己实现了对象的流化(序列化),那么他一定也提供了接口出来。大不了,用API去读写。这是我最初的想法。 这其中探索的过程就不多说了,下面用代码来说明 void SaveHistoryToFld(IFeature pFea, THistorys pHistorys) { IFormatter formatter = new BinaryFormatter(); Stream Ms = new MemoryStream(); formatter.Serialize(Ms, pHistorys);//对象序列化 int n = (int)Ms.Length; Ms.Position = 0; byte[] pReadByte = new Byte[n]; Ms.Read(pReadByte, 0, n);//读取到内存中 IMemoryBlobStream2 pBlob = new MemoryBlobStreamClass(); pBlob.ImportFromMemory(ref pReadByte[0], (uint)n);//转到AE认可的接口中 SetFldValue(pFea, CC_History, pBlob);//保存 } bool LoadHistoryFromFld(IFeature pFea, out THistorys pHistorys) { pHistorys = null; object pObj = GetFldValue(pFea, CC_History);//读取blob字段 if (pObj == null || pObj == DBNull.Value) return false; IMemoryBlobStream2 pBlob = new MemoryBlobStreamClass(); pBlob = (IMemoryBlobStream2)pObj;//转换到AE认可的内存流中 int n = (int)pBlob.Size; byte[] pReadByte = new Byte[n]; object pObj2 = null; (pBlob as IMemoryBlobStreamVariant).ExportToVariant(out pObj2);//输出到变量 pReadByte = (byte[])pObj2;//强制转换为字节数组 Stream Ms = new MemoryStream(); Ms.Write(pReadByte, 0, n);//强制转换为内存流 Ms.Position = 0; IFormatter formatter = new BinaryFormatter(); pHistorys = (THistorys)formatter.Deserialize(Ms);//反序列化 return true; } 代码如此清楚,我就不多说了。^_^
  • 相关阅读:
    div拖拽缩放jquery插件编写——带8个控制点
    vuejs快速入门
    逗号运算笔记
    怎样用PHP制作验证码呢?
    mac下多个php版本快速切换的方法是怎么样
    HTML5 拖拽复制功能的实现方法
    CentOS下使用Percona XtraBackup对MySQL5.6数据库innodb和myisam的方法
    MySQL数据很大的时候
    Facebook MyRocks at MariaDB
    Mysql数据库知识-Mysql索引总结 mysql mysql数据库 mysql函数
  • 原文地址:https://www.cnblogs.com/adodo1/p/4327949.html
Copyright © 2011-2022 走看看