Jump to content

draw a rectanlge to an image


vkrisz81
 Share

Recommended Posts

hello

so i tried but i cant find out WHY not

i wanted to draw a single rectangle to an existing image file to test gdi.

but nothing happens

maybe i use wrong that gdi i dont know, but i could not find a simple example for it..

$bitmap=_GDIPlus_ImageLoadFromFile(@ScriptDir&"\image1.jpg")
$bitmap_w=_GDIPlus_ImageGetWidth($bitmap)
$hBrush = _GDIPlus_BrushCreateSolid(0x7F00007F)

_GDIPlus_GraphicsFillRect($bitmap,2,2,100,123,$hBrush)
_GDIPlus_ImageSaveToFile($bitmap,@ScriptDir&"\image1_b.jpg")
_GDIPlus_ImageDispose($bitmap)

so maybe miss something? i cant understand really its logic..

Link to comment
Share on other sites

Looks like you're just trying to draw a rectangle and save it, not draw it. You can draw on bitmaps and you can draw on graphics objects, you cannot draw directly on images loaded from file. Of course I'm sure some GDI+ guru knows how to do it, just not me.

_GDIPlus_Startup()
; Load the image from the file
Local $hWnd_image = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\image1.png")
; Create a bitmap based on the width and height of the image
Local $hWnd_bitmap = _GDIPlus_BitmapCreateFromScan0(_GDIPlus_ImageGetWidth($hWnd_image), _GDIPlus_ImageGetHeight($hWnd_image))
; create a graphics object from the bitmap
Local $hWnd_graphics = _GDIPlus_ImageGetGraphicsContext($hWnd_bitmap)

; draw the image onto the graphic
_GDIPlus_GraphicsDrawImage($hWnd_graphics, $hWnd_image, 0, 0)
; draw a filled rectangle
_GDIPlus_GraphicsFillRect($hWnd_graphics, 2, 2, 100, 123)
; save the bitmap that was used to create the graphic
_GDIPlus_ImageSaveToFile($hWnd_bitmap, @ScriptDir & "\image1_b.jpg")

; clean up resources
_GDIPlus_ImageDispose($hWnd_image)
_GDIPlus_ImageDispose($hWnd_bitmap)
_GDIPlus_GraphicsDispose($hWnd_graphics)
_GDIPlus_Shutdown()

 

Link to comment
Share on other sites

yes i wanted to modify directly an image because as if i would like to make watermark, put my logo to photos on my directory, but at first i wish only to be able to draw a rectangle and after it to be able to write some letters to my rectanlge to a given image. i test your script ty

Link to comment
Share on other sites

The _GDIPlus_Graphics* draw/fill functions need a graphic handle not an image handle. You have to create a wrapper handle using _GDIPlus_ImageGetGraphicsContext to be able to draw to the image,

Try this:

#include <GDIPlus.au3>

_GDIPlus_Startup()
$bitmap=_GDIPlus_ImageLoadFromFile(@ScriptDir&"\image1.jpg")
$hGfx=_GDIPlus_ImageGetGraphicsContext($bitmap)
$bitmap_w=_GDIPlus_ImageGetWidth($bitmap)
$hBrush=_GDIPlus_BrushCreateSolid(0x7F00007F)

_GDIPlus_GraphicsFillRect($hGfx,2,2,100,123,$hBrush)
_GDIPlus_ImageSaveToFile($bitmap,@ScriptDir&"\image1_b.jpg")
_GDIPlus_GraphicsDispose($hGfx)
_GDIPlus_ImageDispose($bitmap)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_Shutdown()

 

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

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
 Share

  • Recently Browsing   0 members

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