『公告』 预祝您龙年大吉,万事如意, 过节期间, 大家如需数据服务,请拨打400 或直接添加客服微信,再祝大家龙年,心想事成。
关注我们 新浪 腾讯

基于ArcGIS Engine编写的ColorRamp下拉框

基于ArcGIS Engine编写的ColorRamp下拉框
基于ArcGIS Engine编写的ColorRamp下拉框。

       编写一个colorramp下拉框,无非就做两件事,首先将colorramp绘制成一个bitmap图片,其次就是将该图片绘制到comboboxitem上。

       那么现看看后面一个问题怎么绘制到combobox上:vb.net代码实例

 

       首先在form上加载一个imagelist,将要绘制的图片存放到里面(将以自己截个colorramp的图片),再加载combobox,将其Drawmode设置为owenrdrawfixed,然后在其DrawItem事件中编写

 

       Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem

        Dim iRectangle As System.Drawing.Rectangle

        If e.Index = -1 Or sender Is Nothing Then

            Exit Sub

        Else

            '绘制背景

            e.DrawBackground()

            '绘制焦点框

            e.DrawFocusRectangle()

            '绘制图例

            iRectangle = New System.Drawing.Rectangle(e.Bounds.Left + 1, e.Bounds.Top + 1, 117, 14)

            e.Graphics.DrawImage(Me.ImageList1.Images(e.Index), iRectangle)

        End If

    End Sub

       复制代码

       上面一段代码就可以将imagelist中相应序号的图片绘制到相应序号的item上了,视觉部分完毕,很easy吧?

 

 

       有了上面的过程我们就应该思考怎么样得到指定colorramp的图像,如果能得到colorramp的图像,只要替换imagelist中的图片就可以实现我们的目的。

       注意:下面的代码首先新建一个ESRI.ArcGIS.Display.IGradientFillSymbol和一个ColorRamp

 

Private Sub DrawColorRamp()

        '新建 m_FillSymbolm_ColorRamp

 

        m_FillSymbol.ColorRamp = m_ColorRamp

        Me.PictureBox1.Image = SymbolToBitmap(m_FillSymbol, 0, Me.PictureBox1.Width, Me.PictureBox1.Height)

    End Sub

       复制代码

 

Friend Function SymbolToBitmap(ByVal iSymbol As ESRI.ArcGIS.Display.ISymbol, ByVal iStyle As Integer, ByVal iWidth As Integer, ByVal iHeight As Integer) As System.Drawing.Bitmap

        Dim iHDC As New IntPtr

        Dim iBitmap As System.Drawing.Bitmap

        Dim iGraphics As System.Drawing.Graphics

        Dim itagRECT As ESRI.ArcGIS.Display.tagRECT

        Dim iEnvelope As ESRI.ArcGIS.Geometry.IEnvelope

        Dim iDisplayTransformation As ESRI.ArcGIS.Display.IDisplayTransformation

        Dim iPoint As ESRI.ArcGIS.Geometry.IPoint

        Dim iPolyline As ESRI.ArcGIS.Geometry.IGeometryCollection

        Dim iPolygon As ESRI.ArcGIS.Geometry.IGeometryCollection

        Dim iRing As ESRI.ArcGIS.Geometry.IRing

        Dim iSegmentCollection As ESRI.ArcGIS.Geometry.ISegmentCollection

        Dim iGeometry As ESRI.ArcGIS.Geometry.IGeometry

        iBitmap = New System.Drawing.Bitmap(iWidth, iHeight)

        iGraphics = System.Drawing.Graphics.FromImage(iBitmap)

        iEnvelope = New ESRI.ArcGIS.Geometry.Envelope

        iEnvelope.PutCoords(0, 0, iWidth, iHeight)

        With itagRECT

            .left = 0

            .right = iWidth

            .top = 0

            .bottom = iHeight

        End With

        iDisplayTransformation = New ESRI.ArcGIS.Display.DisplayTransformation

        With iDisplayTransformation

            .VisibleBounds = iEnvelope

            .Bounds = iEnvelope

            .DeviceFrame = itagRECT

            .Resolution = iGraphics.DpiX

        End With

        iHDC = iGraphics.GetHdc.ToInt32

        '获取Geometry

        If TypeOf (iSymbol) Is ESRI.ArcGIS.Display.IMarkerSymbol Then

            Select Case iStyle

                Case 0

                    iPoint = New ESRI.ArcGIS.Geometry.Point

                    iPoint.PutCoords(iWidth / 2, iHeight / 2)

                    iGeometry = iPoint

            End Select

        ElseIf TypeOf (iSymbol) Is ESRI.ArcGIS.Display.ILineSymbol Then

            iSegmentCollection = New ESRI.ArcGIS.Geometry.Path

            iPolyline = New ESRI.ArcGIS.Geometry.Polyline

            Select Case iStyle

                Case 0

                    iSegmentCollection.AddSegment(CreateLine(0, iHeight / 2, iWidth, iHeight / 2))

                    iPolyline.AddGeometry(iSegmentCollection)

                    iGeometry = iPolyline

                Case 1

                    iSegmentCollection.AddSegment(CreateLine(0, iHeight / 4, iWidth / 4, 3 * iHeight / 4))

                    iSegmentCollection.AddSegment(CreateLine(iWidth / 4, 3 * iHeight / 4, 3 * iWidth / 4, iHeight / 4))

                    iSegmentCollection.AddSegment(CreateLine(3 * iWidth / 4, iHeight / 4, iWidth, 3 * iHeight / 4))

                    iPolyline.AddGeometry(iSegmentCollection)

                    iGeometry = iPolyline

            End Select

        ElseIf TypeOf (iSymbol) Is ESRI.ArcGIS.Display.IFillSymbol Then

            iSegmentCollection = New ESRI.ArcGIS.Geometry.Ring

            iPolygon = New ESRI.ArcGIS.Geometry.Polygon

            Select Case iStyle

                Case 0

                    iSegmentCollection.AddSegment(CreateLine(5, iHeight - 5, iWidth - 6, iHeight - 5))

                    iSegmentCollection.AddSegment(CreateLine(iWidth - 6, iHeight - 5, iWidth - 6, 6))

                    iSegmentCollection.AddSegment(CreateLine(iWidth - 6, 6, 5, 6))

                    iRing = iSegmentCollection

                    iRing.Close()

                    iPolygon.AddGeometry(iSegmentCollection)

                    iGeometry = iPolygon

            End Select

        ElseIf TypeOf (iSymbol) Is ESRI.ArcGIS.Display.ISimpleTextSymbol Then

            Select Case iStyle

                Case 0

                    iPoint = New ESRI.ArcGIS.Geometry.Point

                    iPoint.PutCoords(iWidth / 2, iHeight / 2)

                    iGeometry = iPoint

            End Select

        End If

        '绘制图形

        iSymbol.SetupDC(iHDC, iDisplayTransformation)

        iSymbol.Draw(iGeometry)

        iSymbol.ResetDC()

        iGraphics.ReleaseHdc(iHDC)

        iGraphics.Dispose()

        SymbolToBitmap = iBitmap

    End Function

       复制代码

       过程基本就完成了,应该说没什么难度


      京ICP备2025132830号-1 京公网安备 号