private void demo2(string CurrentStyleFile, string CurrentStyleGalleryClass) { IStyleGallery pStyleGallery = new ServerStyleGalleryClass(); IStyleGalleryStorage pStyleGalleryStorage; pStyleGalleryStorage = pStyleGallery as IStyleGalleryStorage; //增加符号文件 pStyleGalleryStorage.AddFile(CurrentStyleFile); //根据当前符号的类别和文件得到符号的枚举循环 //符号类别包括Fill Symbol,Line Symbol等 IEnumStyleGalleryItem mEnumStyleItem; mEnumStyleItem = pStyleGallery.get_Items(CurrentStyleGalleryClass, CurrentStyleFile, ""); //得到符号文件类别的各个条目,增加到一个Combox中 IEnumBSTR pEnumBSTR = pStyleGallery.get_Categories(CurrentStyleGalleryClass); pEnumBSTR.Reset(); string Category = ""; Category = pEnumBSTR.Next(); while (Category != null) { //cbxCategory.Items.Add(Category); Category = pEnumBSTR.Next(); } //得到各个符号并转化为图片 mEnumStyleItem.Reset(); IStyleGalleryItem mStyleItem = mEnumStyleItem.Next(); int ImageIndex = 0; IStyleGalleryClass mStyleClass = new FillSymbolStyleGalleryClassClass(); while (mStyleItem != null) { //调用另一个类的方法将符号转化为图片 Bitmap bmpB = StyleGalleryItemToBmp(32, 32, mStyleClass, mStyleItem); Bitmap bmpS = StyleGalleryItemToBmp(16, 16, mStyleClass, mStyleItem); Largeimage.Images.Add(bmpB); Smallimage.Images.Add(bmpS); ListViewItem lvItem = new ListViewItem(new string[] { mStyleItem.Name, mStyleItem.ID.ToString(), mStyleItem.Category }, ImageIndex); this.lvRendererFields.Items.Add(lvItem); mStyleItem = mEnumStyleItem.Next(); ImageIndex++; } //必须采用此方式进行释放,第二次才能正常读取 System.Runtime.InteropServices.Marshal.ReleaseComObject(mEnumStyleItem); }
/// <summary> /// 读取ServerStyle中的文件并显示 /// </summary> /// <param name="StyleGalleryClass">符号文件的种类</param> /// <param name="CategoryClass">符号的种类</param> /// <param name="cbxCategory">符号文件的种类的容器</param> /// <param name="lvSymbol">符号位图的容器</param> public static void ReadServerStyle(string StyleGalleryClass, string CategoryClass, ComboBox cbxCategory, ListView lvSymbol) { lvSymbol.Items.Clear(); lvSymbol.LargeImageList.Images.Clear(); IStyleGallery pStyleGallery = new ServerStyleGalleryClass(); IStyleGalleryStorage pStyleGalleryStorage = pStyleGallery as IStyleGalleryStorage; // 增加符号文件 //pStyleGalleryStorage.TargetFile = _STYLEFILE; for (int i = pStyleGalleryStorage.FileCount - 1; i >= 0; i--) { pStyleGalleryStorage.RemoveFile(pStyleGalleryStorage.get_File(i)); } pStyleGalleryStorage.AddFile(_STYLEFILE); // 根据当前符号的类别和文件得到符号的枚举循环子,符号类别包括Fill Symbol,Line Symbol等 IEnumStyleGalleryItem pEnumStyleItem = pStyleGallery.get_Items(StyleGalleryClass, _STYLEFILE, ""); // 得到符号文件类别的各个条目,增加到一个Combox中 if (cbxCategory != null) { cbxCategory.Items.Clear(); cbxCategory.Items.Add(_ALLSYMBOLS); IEnumBSTR pEnumBSTR = pStyleGallery.get_Categories(StyleGalleryClass); pEnumBSTR.Reset(); string Category = ""; Category = pEnumBSTR.Next(); while (Category != null) { cbxCategory.Items.Add(Category); Category = pEnumBSTR.Next(); } } pEnumStyleItem.Reset(); IStyleGalleryItem mStyleItem = pEnumStyleItem.Next(); IStyleGalleryClass mStyleClass = null; for (int i = 0; i < pStyleGallery.ClassCount; i++) { mStyleClass = pStyleGallery.get_Class(i); string str = mStyleClass.Name; if (str == StyleGalleryClass) { break; } } // 得到各个符号并转化为图片 int ImageIndex = 0; ImageList Largeimage = lvSymbol.LargeImageList; if (CategoryClass == "" || CategoryClass == _ALLSYMBOLS) { while (mStyleItem != null) { // 调用另一个类的方法将符号转化为图片 Bitmap bmpB = StyleGalleryItemToBmp(32, 32, mStyleClass, mStyleItem); Largeimage.Images.Add(bmpB); ListViewItem lvItem = new ListViewItem(new string[] { mStyleItem.Name, mStyleItem.ID.ToString(), mStyleItem.Category }, ImageIndex); lvSymbol.Items.Add(lvItem); ImageIndex++; mStyleItem = pEnumStyleItem.Next(); } } else { while (mStyleItem != null) { if (CategoryClass == mStyleItem.Category) { // 调用另一个类的方法将符号转化为图片 Bitmap bmpB = StyleGalleryItemToBmp(32, 32, mStyleClass, mStyleItem); Largeimage.Images.Add(bmpB); ListViewItem lvItem = new ListViewItem(new string[] { mStyleItem.Name, mStyleItem.ID.ToString(), mStyleItem.Category }, ImageIndex); lvSymbol.Items.Add(lvItem); ImageIndex++; } mStyleItem = pEnumStyleItem.Next(); } } // 必须采用此方式进行释放,第二次才能正常读取 System.Runtime.InteropServices.Marshal.ReleaseComObject(pEnumStyleItem); }