Jump to content
Burgaud

Drawing Lines,Circles,Rectangles to file

Recommended Posts

Burgaud

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.

Share this post


Link to post
Share on other sites
Xandy

I would load image file to screen, draw to screen, then save back to file.  Is that acceptable?

Edited by Xandy

Share this post


Link to post
Share on other sites
UEZ

Look in help file for

_GDIPlus_ImageLoadFromFile

_GDIPlus_ImageGetGraphicsContext

_GDIPlus_GraphicsDrawLine

_GDIPlus_GraphicsDrawEllipse

_GDIPlus_GraphicsDrawRect

_GDIPlus_ImageSaveToFile

  • Like 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
Burgaud

The canvas is 40x60cm.
I dont have that screen.

Share this post


Link to post
Share on other sites
UEZ

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 by UEZ
  • Like 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
qwert

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 by qwert

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

×