Bug in GDI whit zoom

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Davide Rocchelli [ITA] ([ITA)
Date: 06/16/04


Date: Wed, 16 Jun 2004 06:27:01 -0700

I have found a probable bug when you draw with GDI.
Look this simple code

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

    'line incriminate
    e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias

    '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

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 oscene, 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 obsene.

The right action is with Drawing2D.SmoothingMode.AntiAlias: if I set thath i want a line, I want a line, not a trash 'cause i make a zoom ...

Suggestion ? I must calculate then pattern depending the quality, and this not good ...

Davide.



Relevant Pages

  • BUG in GDI whit zoom ?
    ... Private Sub Form1_Paint(ByVal sender As Object, ... e.Graphics.ScaleTransform(Zoom, Zoom) ... If you set SmoothingMode to AntiAlias or HighQuality the ... the dash pattern is what you want. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: lines dont stay on form...
    ... Personally for such jobs I would draw ... On way to achieve what you're after and still use your existing "picture ... Private xCentre As Single, yCentre As Single ... Private Sub Label1_DblClick ...
    (microsoft.public.vb.general.discussion)
  • Re: tent dress altering questions (bust)
    ... My plan was to take the pattern and draw an angled line down from the sleeve hole to make it more billowy but how do I accommodate her bosom without making the upper body section to large? ... the point of the dart. ... quadrant of the pattern with the center front on the center front line ...
    (alt.sewing)
  • Re: tent dress altering questions (bust)
    ... I'd copy the pattern, since enlarging a bust whacks the pattern up ... the point of the dart. ... Draw vertical and horizontal lines through the ... quadrant of the pattern with the center front on the center front line ...
    (alt.sewing)
  • Convert Mouse position to picture position?
    ... I making a Picture program where I want users to draw a rectangual to select ... The rectangular box is written in the mouse down/up events ... Private Sub PictureBox1_MouseDown(ByVal sender As Object, ... ' If we "have the mouse", then we draw our lines. ...
    (microsoft.public.dotnet.framework.drawing)