读取符号库文件

/// <summary>
/// 导入符号
/// </summary>
/// <param name="serverStylePath">符号库文件路径</param>
public static void ImportSymbols(string serverStylePath)
{
if (string.IsNullOrEmpty(serverStylePath) || !File.Exists(serverStylePath))
{
return;
}

int iIndexPoint = serverStylePath.LastIndexOf('\\');
string strName = serverStylePath.Substring(iIndexPoint + 1);
int imageIndex = 1;
try
{
IStyleGallery pStyleGallery = new ServerStyleGalleryClass();
SymbologyControlClass pSymbologyControlClass = new SymbologyControlClass();
IStyleGalleryStorage pStyleGalleryStorage = pStyleGallery as IStyleGalleryStorage;
pStyleGalleryStorage.AddFile(serverStylePath);
pStyleGalleryStorage.TargetFile = serverStylePath;
pStyleGallery.ImportStyle(serverStylePath);
ISymbologyStyleClass pSymbologyStyleClass = null;
for (int j = 0; j < pStyleGallery.ClassCount; j++)
{
IEnumStyleGalleryItem enumItems = null;
try
{
IStyleGalleryClass styleGalleryClass = pStyleGallery.Class[j];
enumItems = pStyleGallery.Items[styleGalleryClass.Name, "", ""];
pSymbologyStyleClass = pSymbologyControlClass.GetStyleClass(SymbolOperate.GetTypeName(styleGalleryClass.Name));
if (enumItems == null) continue;
enumItems.Reset();
IStyleGalleryItem pStyleItem = enumItems.Next();
List<IRow> symbloList = new List<IRow>();
while (pStyleItem != null)
{
IPersistStream pPersistStream = pStyleItem as IPersistStream;
IMemoryBlobStream pBlobStream = new MemoryBlobStreamClass();
pPersistStream.Save(pBlobStream, 0);
IMemoryBlobStreamVariant mbsv = (IMemoryBlobStreamVariant)pBlobStream;
object obj;
mbsv.ExportToVariant(out obj);
stdole.IPictureDisp picture = pSymbologyStyleClass.PreviewItem(pStyleItem, PictureWidth, PictureHeight);

Image pImage = AxHostConverter.GetImageFromDispPicture(picture);
SymbolLibraryRow pRow = new SymbolLibraryRow();
pRow.SetValue(SymbolLibraryRow.FIELD_SYMBOLNAME, strName);
pRow.SetValue(SymbolLibraryRow.FIELD_SYMBOLCLASS, styleGalleryClass.Name);
pRow.SymbolStyle = obj as byte[];
pRow.SymbolID = pStyleItem.ID;
pRow.Image = SymbolOperate.GetByteByImage(pImage);
pRow.SymbolItemName = pStyleItem.Name;
pRow.SymbolItemCategory = pStyleItem.Category;
symbloList.Add(pRow);
pStyleItem = enumItems.Next();
imageIndex++;
if (imageIndex % 20 == 0)
{
GC.Collect();
System.Windows.Forms.Application.DoEvents();
}
}
SymbolLibraryTable.symbolLibraryTable.Save(symbloList);
}
catch
{

}
finally
{
ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(enumItems);
}

}
pStyleGallery.Clear();
}
catch
{

}
}

转载于:https://www.cnblogs.com/lzh5d/p/7001563.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值