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
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...
Original Code:
Spoiler anzeigen
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
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
- ' Declaration required for interop
- <DllImport("gdiplus.dll")> _
- Public Shared Function GdipWindingModeOutline(ByVal path As HandleRef, ByVal matrix As IntPtr, ByVal flatness As Single) As Integer
- End Function
- Private Sub someControl_Paint(ByVal sender As Object, ByVal e As PaintEventArgs)
- ' Create a path and add some rectangles to it
- Dim path As New GraphicsPath()
- path.AddRectangles(rectangles.ToArray())
- ' Create a handle that the unmanaged code requires. nativePath private unfortunately
- Dim handle As New HandleRef(path, DirectCast(path.[GetType]().GetField("nativePath", BindingFlags.NonPublic Or BindingFlags.Instance).GetValue(path), IntPtr))
- ' Change path so it only contains the outline
- GdipWindingModeOutline(handle, IntPtr.Zero, 0.25F)
- Using outlinePen As New Pen(Color.FromArgb(255, Color.Red), 2)
- g.DrawPath(outlinePen, path)
- End Using
- End Sub
Original Code:
Quellcode
- // Declaration required for interop[DllImport(@"gdiplus.dll")]publicstaticexternintGdipWindingModeOutline(HandleRef path,IntPtr matrix,float flatness );void someControl_Paint(object sender,PaintEventArgs e){
- // Create a path and add some rectangles to it
- GraphicsPath path =newGraphicsPath();
- path.AddRectangles(rectangles.ToArray());
- // Create a handle that the unmanaged code requires. nativePath private unfortunately
- HandleRef handle =newHandleRef(path,(IntPtr)path.GetType().GetField("nativePath",BindingFlags.NonPublic|BindingFlags.Instance).GetValue(path));
- // Change path so it only contains the outline
- GdipWindingModeOutline(handle,IntPtr.Zero,0.25F);
- using(Pen outlinePen =newPen(Color.FromArgb(255,Color.Red),2))
- {
- g.DrawPath(outlinePen, path);
- }}
Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von „Lindi666“ () aus folgendem Grund: Lösung selbst gefunden -.-