Burgaud Posted July 14, 2015 Share Posted July 14, 2015 I need to draw lines, circles, rectangles on either JPG or PNG.Not to screen, but to file.Unfortunately all the searches gave me screen based drawing.Need help. thanks. Link to comment Share on other sites More sharing options...
Xandy Posted July 14, 2015 Share Posted July 14, 2015 (edited) I would load image file to screen, draw to screen, then save back to file. Is that acceptable? Edited July 14, 2015 by Xandy Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
UEZ Posted July 14, 2015 Share Posted July 14, 2015 Look in help file for_GDIPlus_ImageLoadFromFile_GDIPlus_ImageGetGraphicsContext_GDIPlus_GraphicsDrawLine_GDIPlus_GraphicsDrawEllipse_GDIPlus_GraphicsDrawRect_GDIPlus_ImageSaveToFile Xandy 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Burgaud Posted July 15, 2015 Author Share Posted July 15, 2015 The canvas is 40x60cm.I dont have that screen. Link to comment Share on other sites More sharing options...
UEZ Posted July 15, 2015 Share Posted July 15, 2015 (edited) Try something like this here:#include <GDIPlus.au3> Global Const $sFile = FileOpenDialog("Select an image", "", "Images (*.jpg;*.png;*.bmp;*.gif)", $FD_FILEMUSTEXIST) If @error Then Exit ;exit when dialog has been canceled _GDIPlus_Startup() Global $hImage = _GDIPlus_ImageLoadFromFile($sFile) If Not $hImage Or @error Then Exit + (_GDIPlus_Shutdown()) ;exit when the image is not supported by GDI+ (strange syntax but it works :-) Global $aDim = _GDIPlus_ImageGetDimension($hImage) Global Const $hCanvas = _GDIPlus_ImageGetGraphicsContext($hImage) ;get the canvas _GDIPlus_GraphicsSetSmoothingMode($hCanvas, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;set antialiasing for the canvas to increase quality Global Const $hPen = _GDIPlus_PenCreate(0xFFFF0000) ;create a red pen (ARGB format) _GDIPlus_GraphicsDrawLine($hCanvas, 0, 0, $aDim[0], $aDim[1], $hPen) ;draw a line from 0,0 to w,h _GDIPlus_PenSetColor($hPen, 0xFF00FF00) ;change the pen color to green _GDIPlus_GraphicsDrawEllipse($hCanvas, 0, 0, $aDim[0], $aDim[1], $hPen) ;draw an ellipse _GDIPlus_PenSetColor($hPen, 0xFF0000FF) ;change the pen color to blue _GDIPlus_GraphicsDrawRect($hCanvas, $aDim[0] / 2 - 10, $aDim[1] / 2 - 10, 20, 20, $hPen) ;draw a rectangle in the center Global Const $sFileSave = @ScriptDir & "\Modified.jpg" _GDIPlus_ImageSaveToFile($hImage, $sFileSave) ;save the modified image ;clean up the gdiplus resources _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hCanvas) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() ShellExecute($sFileSave) Edited July 15, 2015 by UEZ Xandy 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
qwert Posted January 24, 2016 Share Posted January 24, 2016 (edited) This is a nice example. Here it is updated for the change to the GDI+ dimension calls: #include <GDIPlus.au3> Global Const $sFile = FileOpenDialog("Select an image", "", "Images (*.jpg;*.png;*.bmp;*.gif)", $FD_FILEMUSTEXIST) If @error Then Exit ;exit when dialog has been canceled _GDIPlus_Startup() Global $hImage = _GDIPlus_ImageLoadFromFile($sFile) If Not $hImage Or @error Then Exit + (_GDIPlus_Shutdown()) ;exit when the image is not supported by GDI+ (strange syntax but it works :-) Global $aDim [2] ; was: = _GDIPlus_ImageGetDimension($hImage) $aDim[0] = _GDIPlus_ImageGetWidth ( $hImage ) $aDim[1] = _GDIPlus_ImageGetHeight ( $hImage ) Global Const $hCanvas = _GDIPlus_ImageGetGraphicsContext($hImage) ;get the canvas _GDIPlus_GraphicsSetSmoothingMode($hCanvas, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;set antialiasing for the canvas to increase quality Global Const $hPen = _GDIPlus_PenCreate(0xFFFF0000) ;create a red pen (ARGB format) _GDIPlus_GraphicsDrawLine($hCanvas, 0, 0, $aDim[0], $aDim[1], $hPen) ;draw a line from 0,0 to w,h _GDIPlus_PenSetColor($hPen, 0xFF00FF00) ;change the pen color to green _GDIPlus_GraphicsDrawEllipse($hCanvas, 0, 0, $aDim[0], $aDim[1], $hPen) ;draw an ellipse _GDIPlus_PenSetColor($hPen, 0xFF0000FF) ;change the pen color to blue _GDIPlus_GraphicsDrawRect($hCanvas, $aDim[0] / 2 - 10, $aDim[1] / 2 - 10, 20, 20, $hPen) ;draw a rectangle in the center Global Const $sFileSave = @ScriptDir & "\Modified.jpg" _GDIPlus_ImageSaveToFile($hImage, $sFileSave) ;save the modified image ;clean up the gdiplus resources _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hCanvas) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() ShellExecute($sFileSave) Edited January 24, 2016 by qwert Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now