免费视频|新人指南|投诉删帖|广告合作|地信网APP下载

查看: 5081|回复: 3
收起左侧

ArcGIS Engine编写的ColorRamp下拉框

[复制链接]

2072

主题

100000万

铜板

363

好友

地信专家组

每一次的分离都是为了下一次的相聚

Rank: 14Rank: 14Rank: 14Rank: 14

积分
17622

精华勋章宣传勋章爱心勋章组织勋章地信元老灌水勋章荣誉会员勋章活跃勋章贡献勋章

发表于 2009-12-3 21:26 | 显示全部楼层 |阅读模式
编写一个colorramp下拉框,无非就做两件事,首先将colorramp绘制成一个bitmap图片,其次就是将该图片绘制到combobox的item上。
那么现看看后面一个问题怎么绘制到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_FillSymbol和m_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
复制代码
过程基本就完成了,应该说没什么难度
20090923113147203.jpg

0

主题

613

铜板

2

好友

助理工程师

Rank: 5Rank: 5

积分
192
发表于 2013-10-8 10:05 | 显示全部楼层
支持下,楼主真好

评分

参与人数 1铜板 +1 收起 理由
admin + 1 亲,你好快哦~~~

查看全部评分

回复 支持 反对

使用道具 举报

0

主题

613

铜板

2

好友

助理工程师

Rank: 5Rank: 5

积分
192
发表于 2013-10-9 19:07 | 显示全部楼层
支持下,谢谢楼主
回复 支持 反对

使用道具 举报

37

主题

2万

铜板

111

好友

钻石会员

Rank: 26Rank: 26Rank: 26Rank: 26Rank: 26Rank: 26Rank: 26

积分
5763
发表于 2022-2-26 13:12 | 显示全部楼层
支持支持,难度比较大
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

在线客服
快速回复 返回顶部 返回列表