Doublebuffered Panel sauberes zeichnen

  • VB.NET

Es gibt 1 Antwort in diesem Thema. Der letzte Beitrag () ist von RodFromGermany.

    Doublebuffered Panel sauberes zeichnen

    Hallo,

    ich habe ein Doublebuffered Panel erstellt, auf dem ich mit der Maus per mousepath zeichnen kann.
    Dies funktioniert auch.
    Nun sind die gezeichneten Linien nicht sehr sauber, sondern haben kleinere Pixel Fehler.
    In OneNote z.B. werden diese Pixelfehler nicht angezeigt, bzw. dort wird sauber gezeichnet.

    Wie bekomme ich dies ebenso hin?

    Ich habe 2 Anhänge angehangen, in der man den Unterschied erkennt.
    Hier mein Code:

    Spoiler anzeigen

    VB.NET-Quellcode

    1. Private Sub pbSignature_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles pbSignature.MouseDown
    2. If e.Button = MouseButtons.Left Then ' draw a filled circle if left mouse is down
    3. mousePathMieter.StartFigure() ' The L mouse is down so we need to start a new line in mousePath
    4. End If
    5. End Sub
    6. Private Sub pbSignature_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles pbSignature.MouseMove
    7. If e.Button = MouseButtons.Left Then ' draw a filled circle if left mouse is down
    8. Try
    9. mousePathMieter.AddLine(e.X, e.Y, e.X, e.Y) 'Add mouse coordiantes to mousePath
    10. Catch
    11. MsgBox("No way, Hose!")
    12. End Try
    13. End If
    14. pbSignature.Invalidate() 'Repaint the PictureBox using the PictureBox1 Paint event
    15. End Sub
    16. Private Sub pbSignature_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles pbSignature.Paint
    17. Try
    18. If clearSign Then
    19. clearSign = False
    20. e.Graphics.Clear(Color.White)
    21. mousePathMieter.Reset()
    22. Else
    23. myUserColor = (System.Drawing.Color.Black) 'You can remove this line and add a user selected color to
    24. 'change the value of myUserColor
    25. e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
    26. e.Graphics.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
    27. e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
    28. myAlpha = 255 ' This will give the color a Alpha effect, you can set this to 255 if you want a full color
    29. '*********************** NOTE ***********************************************
    30. 'The line below set the pen up with the ability to add user selected Alpha, Color and Penwidth
    31. ' A simpler, but less flexible solution would be to replace the line with the following code:
    32. 'Dim CurrentPen = New Pen(System.Drawing.Color.Black, myPenWidth)
    33. '************ End Note ***************************
    34. Dim CurrentPen = New Pen(Color.FromArgb(myAlpha, myUserColor), myPenWidth) 'Set up the pen
    35. e.Graphics.DrawPath(CurrentPen, mousePathMieter) 'draw the path! :)
    36. End If
    37. Catch
    38. ' MsgBox("Not happening!")
    39. End Try
    40. End Sub
    Bilder
    • onenoteZeichnung.png

      7,44 kB, 262×190, 469 mal angesehen
    • selbstzeichnung.png

      9,43 kB, 902×243, 123 mal angesehen

    vivil schrieb:

    Unterschied

    Mit genau Deinem Code, PictureBox ohne DoubleBuffered:
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!