直接上代码:
private string styleName = "3D Basic.ServerStyle"; /// <summary> /// 添加图片和名称委托 /// </summary> /// <param name="pBitMap"></param> /// <param name="pName"></param> public delegate void addImageAndItemHandle(Bitmap pBitMap, string pName); /// <summary> /// 读取符号线程 /// </summary> Thread _ReadSymbolThread = null; private void addImageAndItem(Bitmap pBitMap, string pName) { //ImageList中添加图片 this.imageList1.Images.Add(pBitMap); //ListView中添加图片名称 this.listView1.Items.Add(pName, this.imageList1.Images.Count - 1); } public void ReadStyleServer() { IStyleGallery tStyleGallery = new ServerStyleGalleryClass(); IStyleGalleryStorage tStyleGalleryStorage = tStyleGallery as IStyleGalleryStorage; tStyleGalleryStorage.AddFile(styleName); IEnumStyleGalleryItem tStyleGalleryItems = tStyleGallery.get_Items("Marker Symbols", styleName, ""); tStyleGalleryItems.Reset(); IStyleGalleryItem tStyleGalleryItem = tStyleGalleryItems.Next(); try { //18 是Marker Symbols类别的序号 //可以参考这个http://www.gisall.com/html/59/4359-774.html //讲的很详细 IStyleGalleryClass tSyleGallClass = tStyleGallery.get_Class(18); while (tStyleGalleryItem != null) { string tName = tStyleGalleryItem.Name; Bitmap tBitmap = StyleGalleryItemToBmp(this.imageList1.ImageSize.Width, this.imageList1.ImageSize.Height, tSyleGallClass, tStyleGalleryItem); this.Invoke(new addImageAndItemHandle(addImageAndItem), new object[] { tBitmap, tName }); tStyleGalleryItem = tStyleGalleryItems.Next(); } } catch (System.Runtime.InteropServices.COMException ex) { string tErrorMessage = ex.Message + ex.ErrorCode; } finally { //释放这个接口,不然再次读取时会报错 ReleaseCom(tStyleGalleryItems); ReleaseCom(tStyleGallery); } } private void ReleaseCom(object o) { while (System.Runtime.InteropServices.Marshal.ReleaseComObject(o) > 0) { } } /// <summary> /// 这个是从网上找的函数 /// </summary> /// <param name="iWidth"></param> /// <param name="iHeight"></param> /// <param name="mStyleGlyCs"></param> /// <param name="mStyleGlyItem"></param> /// <returns></returns> public System.Drawing.Bitmap StyleGalleryItemToBmp(int iWidth, int iHeight, ESRI.ArcGIS.Display.IStyleGalleryClass mStyleGlyCs, ESRI.ArcGIS.Display.IStyleGalleryItem mStyleGlyItem) { //建立符合规格的内存图片 Bitmap bmp = new Bitmap(iWidth, iHeight); Graphics gImage = Graphics.FromImage(bmp); //建立对应的符号显示范围 ESRI.ArcGIS.Display.tagRECT rect = new ESRI.ArcGIS.Display.tagRECT(); rect.right = bmp.Width; rect.bottom = bmp.Height; //生成预览 System.IntPtr hdc = new IntPtr(); hdc = gImage.GetHdc(); //在图片上绘制符号 mStyleGlyCs.Preview(mStyleGlyItem.Item, hdc.ToInt32(), ref rect); gImage.ReleaseHdc(hdc); gImage.Dispose(); return bmp; } /// <summary> /// 单击按钮实现线程读取符号 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btReadStyle_Click(object sender, EventArgs e) { this.imageList1.Images.Clear(); this.listView1.Items.Clear(); if (_ReadSymbolThread != null && _ReadSymbolThread.IsAlive) { _ReadSymbolThread.Abort(); } _ReadSymbolThread = new Thread(new ThreadStart(ReadStyleServer)); _ReadSymbolThread.Start(); }
结果如图所示: