Jump to content

Recommended Posts

Posted

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.

Posted

Look in help file for

_GDIPlus_ImageLoadFromFile

_GDIPlus_ImageGetGraphicsContext

_GDIPlus_GraphicsDrawLine

_GDIPlus_GraphicsDrawEllipse

_GDIPlus_GraphicsDrawRect

_GDIPlus_ImageSaveToFile

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

Posted (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 by UEZ

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

  • 6 months later...
Posted (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 by qwert

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...