GDI+ / gDrawing - Pfade auslesen

Für allgemeine Fragen zur Programmierung mit PureBasic.
Lambda
Beiträge: 526
Registriert: 16.06.2011 14:38

GDI+ / gDrawing - Pfade auslesen

Beitrag 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
Benutzeravatar
Danilo
-= Anfänger =-
Beiträge: 2284
Registriert: 29.08.2004 03:07

Re: GDI+ / gDrawing - Pfade auslesen

Beitrag 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
cya,
...Danilo
"Ein Genie besteht zu 10% aus Inspiration und zu 90% aus Transpiration" - Max Planck
Lambda
Beiträge: 526
Registriert: 16.06.2011 14:38

Re: GDI+ / gDrawing - Pfade auslesen

Beitrag von Lambda »

Danke dir! Die beiden wollte ich schon einbinden, nur endete das mit POLINK Fehlern. ^^
Antworten