When zooming in on a vector drawing in Visual Basic .NET, after a certain point the lines get thicker with each zoom action.
App functionality is basically to draw some lines:
... and when zooming in:
The matrix is set in the PrepareDrawing method:
Private Function PrepareDrawing(ByRef g As Graphics) As Matrix
'Create transformation matrix
Dim myMatrix = New Matrix
'Determine the zoom factor
If zoomfactor > 10000 Then zoomfactor = 10000
If zoomfactor < 0.001 Then zoomfactor = 0.001
scaleFactor = zoomfactor * BORDERFACTOR * Math.Min(pb.Width / viewportModel.Width, pb.Height / viewportModel.Height)
'Determine the offset to keep everything centered
If panningOffset.IsEmpty Then
ZoomToNetwork()
End If
myMatrix.Translate(panningOffset.X, panningOffset.Y)
myMatrix.Scale(scaleFactor, -scaleFactor, MatrixOrder.Append)
'transform current graphics
g.Transform = myMatrix
Return myMatrix
End Function
And the zooming functionality is set in the ZoomInWithMouseWheel method:
Public Sub ZoomInWithMouseWheel(ByVal e As Point, ByVal delta As Single)
Dim orgZoomfactor = zoomfactor
Dim screenX As Double = e.X
Dim screenY As Double = e.Y
If delta > 0 Then
zoomfactor = zoomfactor * 1.1
Else
zoomfactor = zoomfactor / 1.1
End If
scaleFactor = zoomfactor * BORDERFACTOR * Math.Min(pb.Width / viewportModel.Width, pb.Height / viewportModel.Height)
Dim perc = zoomfactor / orgZoomfactor
panningOffset.Offset(-(perc * screenX - screenX) / scaleFactor, (perc * screenY - screenY) / scaleFactor)
End Sub
It turns out that when the first element of the matrix becomes larger than 1, the line width increases with this number.
Any thoughts on what is happening and how I can prevend the line width from increasing?
Okay, found the answer. Line width should be compensated for the matrix element(0), e.g.:
g.DrawLines(New Pen(Color.Blue, lineWidth / g.Transform.Elements(0)), pnts)
where lineWidth is 1 for example