AutoHotkey Community

It is currently May 27th, 2012, 1:12 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 1000 posts ]  Go to page 1, 2, 3, 4, 5 ... 67  Next
Author Message
PostPosted: May 28th, 2008, 3:27 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Download: Gdip.ahk

Full featured gdi+ library with examples by me tic (Tariq Porter) :)
Supports AHK and AHK_L

This library can be distributed for commercial and non-commercial use and I actively encourage both. I would appreciate it if people give acknowledgement for my work and would be nice to have pasted once at the top of your script something similar to:

Code:
Thanks to tic (Tariq Porter) for his GDI+ Library
http://www.autohotkey.com/forum/viewtopic.php?t=32238


or anything more elaborate if you feel like it!

I would also really appreciate it if people could support my girlfriend Alisa Boniello by watching her youtube video Lovestruck. Thanks!

A big thank you to Lexikos and Sean for their help and contributions

You Can download the official help file maintained by Lucid_Method here

If your OS is not >= XP then you will need gdiplus.dll

You will need to place it in the same directory as the script
Minimum OS is Windows 2000

As well as the below examples you can also see GDI+ voodoo

Examples

Example 1: Gdip.Tutorial.1-Draw.Shapes.ahk - Create a simple gui and draw an ellipse and a rectangle

Example 2: Gdip.Tutorial.2-Draw.Outlined.Shapes.ahk - Create a simple gui and draw the outlines of an ellipse and a rectangle

Example 3: Gdip.Tutorial.3-Create.Gui.From.Image.ahk - Create a gui from an existing image on disk

Example 4: Gdip.Tutorial.4-Draw.Circles.ahk - Create a fullscreen gui and fill it with random ellipses

Example 5: Gdip.Tutorial.5-Create.Bitmap.ahk - Put a few shapes into a bitmap and save to a ".png" filetype

Example 6: Gdip.Tutorial.6-Image.Editing.ahk - Take files from disk, load them onto a background and save to a ".png" filetype

Example 7: Gdip.Tutorial.7-Draw.draggable.rounded.rectangle.ahk - Draw a rounded rectangle for a gui and allow it to be dragged with the left click of the mouse

Example 8: Gdip.Tutorial.8-Write.text.onto.a.gui.ahk - Take the rounded rectangle gui and add text to it, showing all the text options possible

Example 9: Gdip.Tutorial.9-Create.a.progress.bar.on.standard.gui.ahk - Create a nice looking progress bar using the library in a standard gui

Example 10: Gdip.Tutorial.10-Rotate.Flip.or.Mirror.an.image.ahk - Rotate, flip or mirror an image on a layered window

Please note BRA functions will be released soon!

The BRA Library so far: BRA.ahk

Example 11: Gdip.Tutorial.11-Using.BRAs.to.perform.animations.ahk - Using BRA files to transport many images with your script and show animation
Please also download the BRA here: Gdip.tutorial.file-fish.bra

Example 12: Gdip.Tutorial.12-Pixelate.a.bitmap.using.machine.code - Use LockBits and machine code to pixelate an image and update it quickly


Last edited by tic on November 28th, 2011, 7:14 pm, edited 73 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 28th, 2008, 3:36 am 
Offline

Joined: July 15th, 2007, 1:43 am
Posts: 1320
Examples? :lol:

Or please get in the IRC.

_________________
Religion is false. >_>


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 28th, 2008, 3:42 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Well the 1st example I have just posted is how to set a pixel to any colour in an image and save it as any filetype:

Code:
#SingleInstance, Force
SetBatchLines, -1
SetWorkingDir %A_ScriptDir%

#Include Gdip.ahk

pToken := Gdip_Startup()
pBitmap := Gdip_CreateBitmapFromFile("in.png")
Gdip_SetPixel(pBitmap, 100, 100, 0xffff0000)
Gdip_SaveBitmap(pBitmap, "out.png")
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
ExitApp
Return


Very simple example, but more will come. If you see one you like the look of then ask and I'm sure I'll already have an existing example lying around


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 31st, 2008, 1:37 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Example 1 released: This will create a "screensaver" like effect by drawing random circles on the screen, that are randomly filled with different hatched brushes.

Gdip updated to 1.01


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 31st, 2008, 2:12 pm 
I just d/l and ran it, and... - nothing happens.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 31st, 2008, 10:42 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Which OS are you on? If you are Win2000 then you will also need to download gdiplus.dll from the 1st post. Please redownload the example and library


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 1st, 2008, 9:56 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Please download version 1.02 of the library! There are more than just cosmetic changes.

Also example 2 has been added. Could people please repond with how they useful/hard they are finding them or else I don't know if there's any point continuing! :P

Example 2 will show you how to create a bitmap, fill it with shapes and save to any supported filetype


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 2nd, 2008, 3:13 am 
Offline

Joined: July 21st, 2006, 12:26 am
Posts: 223
fast & furious gdi+ manipulation!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 2nd, 2008, 5:08 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
Cool :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 12th, 2008, 5:07 pm 
Offline

Joined: March 11th, 2008, 11:36 pm
Posts: 291
thanks for sharing this well organized library and kind tutorials
gdi is always been an inviolable area for beginners (non-programmers)
seems it will take me to the sweet gdi world
i like the tutorials :)
Thanks tic!!

_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 13th, 2008, 12:06 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Thank you for your kind words. As there is at least some enthusiasm (:P) I have decided to rejiggle the examples. I have made a new 1st example and moved the other ones onwards. The new example is much easier to understand. The same method is used for any gui using gdi+

Please comment if you want some more examples at this level! I guarantee anyone else can be a master of gdi+ in a matter of hours!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 13th, 2008, 1:39 am 
Offline

Joined: March 11th, 2008, 11:36 pm
Posts: 291
people like me who never learn gdi before, must try 1st tutorial on top post.
after following 1st tutorial with 0% knowledge of gdi.
i could draw a frame, filled rectangle in only 20 mins
how easy tic made it for us. this is awesome :)
thank you so much tic

_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 13th, 2008, 6:03 am 
Offline

Joined: April 17th, 2007, 1:37 pm
Posts: 761
Location: Florida
Tic, I'm gonna go through your examples tomorrow - Here's the video I mentioned of the press+hold for right click in vista - The quality is crap but you can see what I'm talking about at least: http://www.youtube.com/watch?v=uvJE7vgw3ts

That's what I'd like to try to emulate once I get better. Difficulty on a scale of 1-10?

_________________
[Join IRC!]
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 13th, 2008, 10:52 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
I've watched the video. If you need a custom texture on the circle as in that example then its a 7/10 but if you just want to draw a circle and fill it with a brush (can be a pre-textured brush) then 3/10. I'll get onto giving an example soon...

Edit:

I have updated the library again. Make sure you always have the latest one!
There is another simple example now using pens rather than brushes!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 24th, 2008, 3:55 am 
Offline

Joined: April 17th, 2007, 1:37 pm
Posts: 761
Location: Florida
What I've gotten so far... Hold Shift down to draw a circle around your mouse - It will stay as long as you hold shift.

Forgive the code, still testing (even if I'm just hacking up tic's example)!

Code:
#SingleInstance, Force
#NoEnv
SetBatchLines, -1

; Uncomment if Gdip.ahk is not in your standard library
#Include, Gdip.ahk
Return
~Shift::
; Start gdi+
If !pToken := Gdip_Startup()
{
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
   ExitApp
}
OnExit, Exit

; Set the width and height we want as our drawing area, to draw everything in. This will be the dimensions of our bitmap
Width := 56, Height := 56
;Width := A_ScreenWidth, Height := A_ScreenHeight

; Create a layered window (+E0x80000 : must be used for UpdateLayeredWindow to work!) that is always on top (+AlwaysOnTop), has no taskbar entry or caption
Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs

; Show the window
Gui, 1: Show, NA

; Get a handle to this window we have created in order to update it later
hwnd1 := WinExist()

; Create a gdi bitmap with width and height of what we are going to draw into it. This is the entire drawing area for everything
hbm := CreateDIBSection(Width, Height)

; Get a device context compatible with the screen
hdc := CreateCompatibleDC()

; Select the bitmap into the device context
obm := SelectObject(hdc, hbm)

; Get a pointer to the graphics of the bitmap, for use with drawing functions
G := Gdip_GraphicsFromHDC(hdc)

; Set the smoothing mode to antialias = 4 to make shapes appear smother (only used for vector drawing and filling)
Gdip_SetSmoothingMode(G, 4)

; Create a fully opaque red brush (ARGB = Transparency, red, green, blue) to draw a circle
hBrush := Gdip_BrushCreateSolid(0xffff0000)


; Fill the graphics of the bitmap with an ellipse using the brush created
; Filling from coordinates (100,50) an ellipse of 200x300
;Gdip_FillEllipse(G, hBrush, 100, 50, 600, 600)

; Delete the brush as it is no longer needed and wastes memory
Gdip_DeleteBrush(hBrush)

; Create a slightly transparent (66) blue brush (ARGB = Transparency, red, green, blue) to draw a rectangle
hBrush := Gdip_BrushCreateSolid(0x660000ff)
hBrush:=Gdip_BrushCreateHatch(0x660000ff, 0xff0000ff, 47)

; Fill the graphics of the bitmap with a rectangle using the brush created
; Filling from coordinates (250,80) a rectangle of 300x200
;Gdip_FillRectangle(G, hBrush, 250, 80, 300, 200)

; Delete the brush as it is no longer needed and wastes memory
Gdip_DeleteBrush(hBrush)


hBrush:=Gdip_BrushCreateSolid(0xEEff0000)
hPen:=Gdip_CreatePen(0xEEFFFFee0, 2)
fatPen:=Gdip_CreatePen(0xEE0000FF, 5)
CoordMode, Mouse, Screen

Loop,60
{
GetKeyState,State,Shift,P
If State = U
   Break
MouseGetPos,MX,MY
;Gdip_DrawArc(pGraphics, hPen, x, y, w, h, StartAngle, SweepAngle)
Gdip_SetCompositingMode(G, 1)
Gdip_Drawarc(G, FatPen, 2, 2, 50, 50, 270, A_Index*6)
Gdip_SetCompositingMode(G, 0)
Gdip_Drawarc(G, hPen, 2, 2, 50, 50, 270, A_Index*6)
UpdateLayeredWindow(hwnd1, hdc, MX-25, MY-25, Width, Height)
Sleep,10
}
Gdip_SetCompositingMode(G, 0)
Loop,
{
   GetKeyState,State,Shift,P
   If State = U
      Break
   MouseGetPos,MX,MY
   UpdateLayeredWindow(hwnd1, hdc, MX-25, MY-25, Width, Height)
   Sleep,10
}
; Update the specified window we have created (hwnd1) with a handle to our bitmap (hdc), specifying the x,y,w,h we want it positioned on our screen
; So this will position our gui at (0,0) with the Width and Height specified earlier
;UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)
Gui,Destroy

; Select the object back into the hdc
SelectObject(hdc, obm)

; Now the bitmap may be deleted
DeleteObject(hbm)

; Also the device context related to the bitmap may be deleted
DeleteDC(hdc)

; The graphics may now be deleted
Gdip_DeleteGraphics(G)
Return

;#######################################################################
Esc::
Exit:
; gdi+ may now be shutdown on exiting the program
Gdip_Shutdown(pToken)
ExitApp
Return

_________________
[Join IRC!]
Image


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1000 posts ]  Go to page 1, 2, 3, 4, 5 ... 67  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon and 16 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group