Jump to content
Sign in to follow this  

Create png and draw path from an array of coords

Recommended Posts

Hello all,

I've been using autoit for a while now but this is my first post in the forums.

I've made a script that basically captures an object's coords at different time points (and some other stuff like time elapsed from start and current speed of the object tracked) into an array using this function:

Func RecordInfo()
    Local $hDLL = DllOpen("user32.dll")
    $Coords[UBound($Coords) - 1][0] = GUICtrlRead($InputX)
    $Coords[UBound($Coords) - 1][1] = GUICtrlRead($InputY)
    $Coords[UBound($Coords) - 1][2] = GUICtrlRead($InputElapsedTime)
    $Coords[UBound($Coords) - 1][3] = GUICtrlRead($InputCurrentSpeed)
    ReDim $Coords[UBound($Coords) + 1][4]

1) My main question is how to create an image file at the end of the script (after all the coords are captured), and have a line drawn from each point to the next (to make a sort of trajectory or path of the tracked object).

From what I've seen so far, I will probably need to create an empty png of the desired size i.e. length/width (perhaps with _WinAPI_CreateFile() ?), then create a pen (_WinAPI_CreatePen() ?) and then draw the line with _WinAPI_DrawLine() (I have an idea how to draw it). My issue is how to create the file and draw the line inside that.

2) A secondary - sort of related - question is how to additionally create a text file in the end and write some data in it (e.g. the array of coords, the total time elapsed, the relative speed or other info from the script).

Thank you in advance for any replies :)



Share this post

Link to post
Share on other sites

Hi mavygr

>this could interset you.

also, to write/read data to/from files look FileOpen, FileWrite, FileRead, FileClose and other File* commands in the help,

if you want write the whole array have also a look to _FileWriteFromArray, _FileReadToArray

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post

Link to post
Share on other sites

Thanks a lot for the help! I adjusted the code from the example in filewrite() page and I got my text file working. I made a separate function for creating the array file with _FileWriteFromArray().

For the png, _GDIPlus_BitmapCreateFromScan0 is probably the best choice, but when I try to do it, I get a pitch black image :D

Here is the code (line drawing part is not included yet, I'm trying to figure out the basics first...)

Func CreateTrajectoryFile($PenWidth = 2, $PenColour = 0x000000, $BackgroundColour = 0xFFFFFF) ; these are for the lines that will be drawn eventually
    Local Const $iW = 1635, $iH = 1035
    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) ;create an empty bitmap
    Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;get the graphics context of the bitmap
    _GDIPlus_GraphicsSetSmoothingMode($hBmpCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
    _GDIPlus_GraphicsClear($hBmpCtxt, $BackgroundColour) ;clear bitmap with color white
    _GDIPlus_GraphicsDrawString($hBmpCtxt, "Hello", 0, 0, "Arial", 10, 0) ;draw some text to the bitmap
    Local $sFile = @ScriptDir & "\Output files\trajectory.jpg"
    _GDIPlus_ImageSaveToFile($hBitmap, $sFile) ;save bitmap to disk
    ;cleanup GDI+ resources
    ShellExecute($sFile) ;open bitmap with default app
Edited by mavygr

Share this post

Link to post
Share on other sites

Duh, I sorted it out. The color hex is in ARGB so it should be 0xFFFFFFFF instead of 0xFFFFFF >_<

For making the line this worked fine:

For $i = 0 To UBound($Coords) - 3
    _GDIPlus_GraphicsDrawLine($TrajBmpCtxt, $Coords[$i][0], $Coords[$i][1], $Coords[$i + 1][0], $Coords[$i + 1][1], $TrajPen)

Thanks again for your help.

Edited by mavygr

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...