Arcgis style/serverstyle符号库管理器 (转载)

转自:http://xxy12300.blog.163.com/blog/static/26343458201282052953144/

Arcgis style/serverstyle符号库管理器  

 

 
Arcgis style/serverstyle符号库管理器 - 听雨 - 宁静致远
 
搞了一个星期终于把符号管理器写好了。用    IStyleGallery ,IStyleGalleryStorage 接口更新符号时总是提示com错误,即使释放资源也不行,后来才发现原来是用arcgis的symbocontrol控件会一直点用样式文件,导致更新时出错,没办法,只能不用arcgis的控件了,只能把style生成图片显示在listview中。
 
以下是由symbol生成图片的方法,也是从网上查的,在此分享。
 
      /// <summary>
         ///  由symbol创建图片
         /// </summary>
         /// <param name="pSymbol"></param>
         /// <param name="iwidth"></param>
         /// <param name="iheight"></param>
         /// <param name="styleclass">styleclass类型集名称</param>
         /// <returns></returns>
         public System.Drawing.Bitmap SymbolToBitmp(ESRI.ArcGIS.Display.ISymbol pSymbol, int iwidth, int iheight, string styleclass)
         {
             //根据高宽创建图象
             Bitmap bmp = new Bitmap(iwidth, iheight);
             Graphics gImage = Graphics.FromImage(bmp);
             gImage.Clear(Color.White);
             double dpi = gImage.DpiX;
             IEnvelope pEnvelope = new EnvelopeClass();
             pEnvelope.PutCoords(0, 0, (double)bmp.Width, (double)bmp.Height);
 
             tagRECT deviceRect;
             deviceRect.left = 0;
             deviceRect.right = bmp.Width;
             deviceRect.top = 0;
             deviceRect.bottom = bmp.Height;
 
             IDisplayTransformation pDisplayTransformation = new DisplayTransformationClass();
             pDisplayTransformation.VisibleBounds = pEnvelope;
             pDisplayTransformation.Bounds = pEnvelope;
             pDisplayTransformation.set_DeviceFrame(ref deviceRect);
             pDisplayTransformation.Resolution = dpi;
 
             IGeometry pGeo = CreateSymShape(pSymbol, pEnvelope, styleclass);
 
             System.IntPtr hdc = new IntPtr();
             hdc = gImage.GetHdc();
 
 
             ISimpleTextSymbol symbol1 = pSymbol as ISimpleTextSymbol;
             if (symbol1 != null)
             {
                 string text1 = symbol1.Text;
                 bool flag1 = symbol1.Clip;
                 symbol1.Text = "AaBbYyZz";
             }
          
 
 
             //将符号的形状绘制到图象中
             pSymbol.SetupDC((int)hdc, pDisplayTransformation);
             pSymbol.Draw(pGeo);
             pSymbol.ResetDC();
             gImage.ReleaseHdc(hdc);
             gImage.Dispose();  
 
             return bmp;
 
         }
         /// <summary>
         /// 
         /// </summary>
         /// <param name="pSymbol"></param>
         /// <param name="pEnvelope"></param>
         /// <param name="styleclass"></param>
         /// <returns></returns>
         private ESRI.ArcGIS.Geometry.IGeometry CreateSymShape(ISymbol pSymbol, IEnvelope pEnvelope, string styleclass)
         {           
             switch (styleclass)
             {
                 case "Marker Symbols":
                     IArea pArea;
                     pArea = pEnvelope as IArea;
                     return pArea.Centroid as IGeometry;
                 case "Line Symbols":
                 case "Text Symbols":
                     //判断是否为“线”符号  
                     ESRI.ArcGIS.Geometry.IPolyline IpLine;
                     IpLine = new PolylineClass();
 
                     IPoint fpt = new PointClass();
                     IPoint tpt = new PointClass();
 
                     fpt.PutCoords(pEnvelope.LowerLeft.X, (pEnvelope.LowerLeft.Y + pEnvelope.UpperRight.Y) / 2);
                     tpt.PutCoords(pEnvelope.UpperRight.X, (pEnvelope.LowerLeft.Y + pEnvelope.UpperRight.Y) / 2);
 
                     IpLine.FromPoint = fpt;
                     IpLine.ToPoint = tpt;
 
                     return IpLine as IGeometry;
 
                 case "Fill Symbols":
                     //直接返回一个IEnvelope矩形区域
                     return pEnvelope as IGeometry;             
                 default:
                     return pEnvelope as IGeometry;
             }
         }        
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值