Kontur eines GraphicsPath

  • VB.NET

    Kontur eines GraphicsPath

    Hallo,

    Ich habe einen Drawing2D.GraphicsPath der viele Punkte enthält.
    Nun möchte ich den Path so verändern, dass er nur noch die Punkte seiner Kontur enthält.
    Leider hab ich keine bereits implementierte Funktion dafür gefunden, also muss ich mir eine selbst machen :S

    Ich hab keinen Plan wie ich dabei vorgehen soll. Kann mir jemand Tipps geben?

    Zur Veranschaulichung noch ne kleine Skizze:


    mfg Lindi666

    //EDIT:

    Sorry, ich hätte genauer Suchen sollen :wacko:

    Hab jetzt was gefunden, allerdings auf C#, macht ja nix.
    Ich habs übersetzt, der Original-Code stammt von dieser Seite.

    GDI+ besitzt eine solche Funktion, allerdings ist diese nicht über Managed Code erreichbar. Kp was die sich dabei gedacht haben...

    VB.NET-Quellcode

    1. ' Declaration required for interop
    2. <DllImport("gdiplus.dll")> _
    3. Public Shared Function GdipWindingModeOutline(ByVal path As HandleRef, ByVal matrix As IntPtr, ByVal flatness As Single) As Integer
    4. End Function
    5. Private Sub someControl_Paint(ByVal sender As Object, ByVal e As PaintEventArgs)
    6. ' Create a path and add some rectangles to it
    7. Dim path As New GraphicsPath()
    8. path.AddRectangles(rectangles.ToArray())
    9. ' Create a handle that the unmanaged code requires. nativePath private unfortunately
    10. Dim handle As New HandleRef(path, DirectCast(path.[GetType]().GetField("nativePath", BindingFlags.NonPublic Or BindingFlags.Instance).GetValue(path), IntPtr))
    11. ' Change path so it only contains the outline
    12. GdipWindingModeOutline(handle, IntPtr.Zero, 0.25F)
    13. Using outlinePen As New Pen(Color.FromArgb(255, Color.Red), 2)
    14. g.DrawPath(outlinePen, path)
    15. End Using
    16. End Sub


    Original Code:
    Spoiler anzeigen

    Quellcode

    1. // Declaration required for interop[DllImport(@"gdiplus.dll")]publicstaticexternintGdipWindingModeOutline(HandleRef path,IntPtr matrix,float flatness );void someControl_Paint(object sender,PaintEventArgs e){
    2. // Create a path and add some rectangles to it
    3. GraphicsPath path =newGraphicsPath();
    4. path.AddRectangles(rectangles.ToArray());
    5. // Create a handle that the unmanaged code requires. nativePath private unfortunately
    6. HandleRef handle =newHandleRef(path,(IntPtr)path.GetType().GetField("nativePath",BindingFlags.NonPublic|BindingFlags.Instance).GetValue(path));
    7. // Change path so it only contains the outline
    8. GdipWindingModeOutline(handle,IntPtr.Zero,0.25F);
    9. using(Pen outlinePen =newPen(Color.FromArgb(255,Color.Red),2))
    10. {
    11. g.DrawPath(outlinePen, path);
    12. }}

    Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von „Lindi666“ () aus folgendem Grund: Lösung selbst gefunden -.-