Jump to content
Sign in to follow this  

GDI+ Help - Drawing a line on an image

Recommended Posts

How exactly would I load an image from the disk, draw a red cross from end to end and save it as a new image. I know to use _GDIPlus_GraphicsDrawLine but how?

I already got the end to end bit down:

The width and height is 500x350

Draw two lines at (0, 0, 550, 350) and (550, 0, 0, 350) respectively.

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha


Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Share this post

Link to post
Share on other sites








Share this post

Link to post
Share on other sites

Here an example:


#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>

$sFile = FileOpenDialog("Select an image", "", "Images (*.jpg;*.bmp;*.png;*.gif;*.tif)")
If @error Then Exit

Global $hImage = _GDIPlus_ImageLoadFromFile($sFile)
If Not $hImage Then
Global $iW = _GDIPlus_ImageGetWidth($hImage), $iH = _GDIPlus_ImageGetHeight($hImage)
Global $hGUI = GUICreate("GDI+ Test", $iW, $iH) ;no check when image is larger than screen!
Global $hGfx = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;only for display purposes
Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGfx)
Global $hImgContext = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;this is needed to copy the image to the bitmap and draw on it
_GDIPlus_GraphicsDrawImageRect($hImgContext, $hImage, 0, 0, $iW, $iH) ;copy loaded image to bitmap (not display in GUI yet)
Global $hBrush = _GDIPlus_BrushCreateSolid(0xFFFF0000) ;create a brush AARRGGBB
_GDIPlus_GraphicsFillRect($hImgContext, $iW / 2 - 10, 0, 20, $iH, $hBrush) ;draw filled rectangle of the image vertically
_GDIPlus_GraphicsFillRect($hImgContext, 0, $iH / 2 - 10, $iW, 20, $hBrush) ;draw filled rectangle of the image horizontally

_GDIPlus_GraphicsDrawImageRect($hGfx, $hBitmap, 0, 0, $iW, $iH) ;copy modified image to graphic handle -> display it in the GUI

_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\Modified.jpg")

;clean up resources
ShellExecute(@ScriptDir & "\Modified.jpg")


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

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...