如何正确绘制到gdi +中的地图坐标

时间:2014-03-23 08:46:33

标签: vb.net drawing gdi+

我想要使用大型扫描地图来显示移动目标的位置

我将地图加载到面板内的图片框

  • 面板设置为自动滚动。图片框大小模式设置为 auto_size

为了计算变换,我让用户采样3个点来计算仿射变换矩阵

 [x' y' 1] = [x y 1] * [a b 0
                        c d 0
                        e f 1]

我知道转换成功,因为鼠标悬停事件显示正确的坐标:

Private Sub picMap_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picMap.MouseMove
            If _CalibSuccess Then

                Dim CurPoint(0) As PointF
                CurPoint(0).X = e.X : CurPoint(0).Y = e.Y

                Dim genericGraphics As Drawing.Graphics = CreateGraphics()
                Dim Mat As Drawing2D.Matrix = New Drawing2D.Matrix(mdlGlobal._GeoRefParams(0), mdlGlobal._GeoRefParams(3), _
                                                                   mdlGlobal._GeoRefParams(1), mdlGlobal._GeoRefParams(4), _
                                                                   mdlGlobal._GeoRefParams(2), mdlGlobal._GeoRefParams(5))
                genericGraphics.Transform = Mat
                genericGraphics.TransformPoints(Drawing2D.CoordinateSpace.Device, Drawing2D.CoordinateSpace.World, CurPoint)

                lblX.Text = CurPoint(0).X
                lblY.Text = CurPoint(0).Y
            Else
                lblX.Text = e.X
                lblY.Text = e.Y
            End If

        End Sub

但是当我尝试在屏幕上绘制标记时,我什么都没得到

Private Sub picMap_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles picMap.Paint
        Dim drawGraphics As Graphics = e.Graphics


        If _CalibSuccess And _BroadCasting Then
            Dim Mat As Drawing2D.Matrix = New Drawing2D.Matrix(mdlGlobal._GeoRefParams(0), mdlGlobal._GeoRefParams(3), _
                                                               mdlGlobal._GeoRefParams(1), mdlGlobal._GeoRefParams(4), _
                                                               mdlGlobal._GeoRefParams(2), mdlGlobal._GeoRefParams(5))
            drawGraphics.ResetTransform()
            drawGraphics.Transform = Mat

            drawGraphics.FillRectangle(Brushes.Red, _ShipBase.X - (100.0F / 3600.0F), _ShipBase.Y - (100.0F / 3600.0F), (200.0F / 3600.0F), (200.0F / 3600.0F))

        End If
    End Sub

你能告诉我我做错了什么吗?

1 个答案:

答案 0 :(得分:0)

你的变换矩阵与它需要的相反。您可以判断,因为您的TransformPoints调用是从World到Device坐标,但您的鼠标输入已经在Device坐标中。