all groups > dotnet drawing api > march 2005 >
You're in the

dotnet drawing api

group:

Bug in GDI whit Zoom and Antialias


Bug in GDI whit Zoom and Antialias Davide Rocchelli [ITA]
3/29/2005 12:07:01 AM
dotnet drawing api:
I have found a probable bug when you draw with GDI.
Look this simple code

'***************************
Private WithEvents tmr As Timer

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

Const Zoom As Single = 0.001
Dim p As Pen

'alternate default and antialias
If ((Now.Second Mod 2) = 0) Then
'default
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.Default
Else
'antialias
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
End If

'clear
e.Graphics.Clear(Color.Black)
'zoom
e.Graphics.ScaleTransform(Zoom, Zoom)
'create a pen
p = New Pen(Color.Red, 1)
p.DashPattern = New Single() {5, 5}
'draw line (adjusted to zoom)
e.Graphics.DrawLine(p, (Me.ClientRectangle.Left / Zoom),
(Me.ClientRectangle.Top / Zoom), (Me.ClientRectangle.Right / Zoom),
(Me.ClientRectangle.Bottom / Zoom))
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'start timer
tmr = New Timer
tmr.Interval = 1000
tmr.Start()
End Sub

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

'stop timer
tmr.Stop()
End Sub

Private Sub tmr_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tmr.Tick

'force refresh
Refresh()
End Sub
'***************************

If you set SmoothingMode to AntiAlias or HighQuality the line is ok: the
dash pattern is what you want. But if you set SmoothingMode to another value,
the pattern is obscene, idem if you set p.DashStyle = DashStyle.Dash (or
other value except Solid) without use DashPattern. If yout don't use the zoom
(ScaleTransform) you have no problem.

With personal Pattern you must do this to have the desired pattern

p.DashPattern = New Single() {5 / Zoom, 5 / Zoom}

but if you use this line with e.Graphics.SmoothingMode =
Drawing2D.SmoothingMode.AntiAlias (or HightQuality) the line's style is
obscene.

Suggestion ?

Thanks
Davide [ITA]

RE: Bug in GDI whit Zoom and Antialias Davide Rocchelli [ITA]
3/29/2005 12:23:03 AM
if I set
p = New Pen(Color.Red, 1 / Zoom)
is better, but also with this change if I set
p.DashStyle = Drawing2D.DashStyle.Dot
I have the same terrible graphic result.

[quoted text, click to view]
AddThis Social Bookmark Button