Seite 1 von 1

GDI+ / gDrawing - Pfade auslesen

Verfasst: 19.11.2012 14:19
von Lambda
Ich möchte die internen Wegpunkte in eine Liste kopieren. Da Objekte auch verzerrt/rotiert werden können müsste ich das ganze zusätzlich selbst berechnen damit einzelne Punkte editiert werden können. Auch bei Änderungen der Geometrie (zusammenfassen/ausschneiden).

gDrawing ist momentan für GDI+ eine klasse Bibliothek, allerdings weis ich nicht welche Funktionen ich noch portieren müsste um alle Wegpunkte einer Geometrie in eine Liste zu füllen. gGetPath() ermittelt leider nur die ID und ist kein Pointer zu einer Liste. :D

lG

Re: GDI+ / gDrawing - Pfade auslesen

Verfasst: 25.11.2012 09:07
von Danilo
Du brauchst nur 2 Funktionen:

Code: Alles auswählen

GdipGetPointCount(GpPath* path, INT* count);
GdipGetPathPoints(GpPath*, GpPointF* points, INT count);
Kleines Beispiel:

Code: Alles auswählen

EnableExplicit

XIncludeFile "gDrawing.pbi"

CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    ;Import #PB_Compiler_FilePath + "gdiplus_x64.lib"
    Import "gdiplus_x64.lib"
CompilerElse
    ;Import #PB_Compiler_FilePath + "gdiplus_x86.lib"
    Import "gdiplus_x86.lib"
CompilerEndIf

    GdipGetPointCount(*Path, *count.Long)
    GdipGetPathPoints(*Path, *points.PointF, count.l)

EndImport

Procedure Draw(image)
    Protected i, path, numPoints
    Protected Dim points.POINTF(0)

    If gStartDrawing( ImageOutput(image) )
        gClear(RGBA($80,$80,$80,$FF))
        gSetPenSize(3)

        ;
        ; draw path
        ;
        gDrawingMode(#PB_2DDrawing_Path)
            gSetFont("Arial",150)
            gDrawText(10,10,"PureBasic")
        gDrawingMode(#PB_2DDrawing_Default)
            gDrawPath(#PB_Default,RGBA($FF,$FF,$00,$FF))   ; draw current path with yellow color
        gDrawingMode(#PB_2DDrawing_Outlined)
            gDrawPath(#PB_Default,RGBA($00,$00,$00,$FF))   ; draw current path outlined with black color

        gDrawingMode(#PB_2DDrawing_Default)
        gSetPenSize(3)

        path   = gGetPath()                                 ; get path
        GdipGetPointCount(path, @numPoints)                 ; get number of points in path
        Dim points(numPoints)
        GdipGetPathPoints(path,@points(),numPoints)         ; get the points
        If numPoints > 1
            numPoints - 1
            For i = 0 To numPoints
                gPlot( points(i)\x, points(i)\y, RGBA($FF,$FF,$FF,$FF)) ; draw white point for all path points
            Next i
        EndIf

        gStopDrawing()
    EndIf
EndProcedure

Define img

If gInit()

    img = CreateImage(#PB_Any,800,600)
    Draw(img)

    OpenWindow(#PB_Any,0,0,800,600,"gDrawing: get path points",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
    ImageGadget(#PB_Any,0,0,800,600,ImageID( img ))
    Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

    gEnd()
EndIf

Re: GDI+ / gDrawing - Pfade auslesen

Verfasst: 25.11.2012 15:37
von Lambda
Danke dir! Die beiden wollte ich schon einbinden, nur endete das mit POLINK Fehlern. ^^