GDI+ standard library 1.45 by tic

Post your working scripts, libraries and tools
Pacsa
Posts: 7
Joined: 02 Mar 2015, 11:02

Re: GDI+ standard library 1.45 by tic

04 Mar 2015, 02:02

It's all good now.
Thanks a lot, GeekDude!
tic
Posts: 92
Joined: 03 Nov 2014, 03:10

Re: GDI+ standard library 1.45 by tic

06 Mar 2015, 13:08

I have begun to create Gdip library version 2

https://github.com/tariqporter/Gdip/blo ... /Gdip2.ahk

Original method names will be included for users that need more control. Commented lines demonstrate how to perform the same actions calling the methods explicitly rather than using the new object based library. Dispose methods are still included as disposal cannot always be left to garbage collection, for an example, creating thousands of different coloured brushes in a loop that will only be used once.

This is only compatible with AHK 1.1 - The version that is linked to on this website and not the legacy version of AHK. Suggestions are welcomed.
tic
Posts: 92
Joined: 03 Nov 2014, 03:10

Re: GDI+ standard library 1.45 by tic

06 Mar 2015, 13:24

GeekDude wrote:I suggest calling it AHK v1.1, not AHK_L
Changed in my post. I think it should be named AHK v2 really as it isn't a minor upgrade from the old AHK. Object support as one example is a large overhaul
RHCP
Posts: 196
Joined: 30 Sep 2013, 10:59

Re: GDI+ standard library 1.45 by tic

19 Mar 2015, 09:38

When the width or height parameters are omitted and the screen DPI is greater than 100% the function fails to update the window (though it returns success). I believe this is due to the function calling the wingetPos command which will return DPI scaled width and height values. If these width and height values are greater than those used when calling CreateDIBSection() the window will not be updated.

Try running this code with different screen DPIs.

Code: Select all

#SingleInstance, Force
#NoEnv
OnExit, Exit
pToken := Gdip_Startup()
x := y := 250
w := h := 300
msgbox % A_screenDPI
Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
Gui, 1: Show, NA x%x% y%y% w%w% h%h%
hwnd1 := WinExist()
hbm := CreateDIBSection(w, h)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)

G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetSmoothingMode(G, 4)
pBrush := Gdip_BrushCreateSolid(0xaa000000)
Gdip_FillRoundedRectangle(G, pBrush, 0, 0, w, h, 20)
Gdip_DeleteBrush(pBrush)
WinGetPos,,, GUIWidth, GUIHeight, ahk_id %hwnd1%

;***
UpdateLayeredWindow(hwnd1, hdc) ; works fine when DPI is 100%
; This works with all DPIs --> UpdateLayeredWindow(hwnd1, hdc,,, w, h)

SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)
msgbox  width: %GUIWidth%`nHeight: %GUIHeight%
Return

f1::ExitApp

Exit:
Gdip_Shutdown(pToken)
ExitApp
Return
Edit: I'm a moron. You just have to disable gui scaling (-DPIScale) when creating the GUI.
serg
Posts: 43
Joined: 21 Mar 2015, 05:33

Re: GDI+ standard library 1.45 by tic

21 Mar 2015, 06:36

Hi tic!
Could you please comment on how new GDIP will be different (besides syntax)?
Im not a programmer by any means, just AHK "user", so to speak. So I wonder how this "object-oriented-ness" of new GDIP version will look like, and if I should update my GDIP-based scripts (~3,000 lines) or keep using old GDIP...
Thanks again for your wonderful work! :thumbup:
tic
Posts: 92
Joined: 03 Nov 2014, 03:10

Re: GDI+ standard library 1.45 by tic

23 Mar 2015, 13:10

Hi serg

The new library will have a simpler syntax and with Object support we can now better manage our drawing, making it much simpler to concentrate on our actual program, and not worry so much about Gdip. A very simple example if you take Gdip2 from the github repo

https://github.com/tariqporter/Gdip

A rewritten example 1 to use this beta Gdip2:

Code: Select all

#Persistent
#SingleInstance Force

;Start Gdip
gdip := new Gdip()

;Create Point and Size objects for positioning our window
point1 := new gdip.Point(0, 0)
size1 := new gdip.Size(1400, 1050)

;Create a Gdip Object. This will be for all the drawing we do, and to display on screen
obj1 := new gdip.Object(size1)

;Create a Gdip Window. We need to pass it a Point and Size object (Or can pass our drawing Object, to take its dimensions as below)
win1 := new gdip.Window(point1, obj1)

;Create a brush. Can accept ARGB or separated values as A, R, G, B
brush1 := new gdip.Brush(255, 255, 0, 0)

;Fill Ellipse by passing our brush, and then some spoof Point and Size objects.
;Could use: new gdip.Point(100, 500)
;new gdip.Size(200, 300)
obj1.FillEllipse(brush1, { X: 100, Y: 500 }, { Width: 200, Height: 300 })

brush2 := new gdip.Brush(102, 0, 0, 255)
obj1.FillRectangle(brush2, { X: 250, Y: 80 }, { Width: 300, Height: 200 })

;Update the window on the screen with everything we've just done
;Pass our drawing Object along with a Point
win1.Update(obj1, point1)

;Optionally dispose of our objects. They would automatically be deleted however
brush1.Dispose()
brush2.Dispose()
obj1.Dispose()
gdip.Dispose()
return
  • Things to note are :
  • Now all the objects we will use to draw are encapsulated in a single object.
  • We use Point and Size objects to perform drawings and positioning, and in the instance of "single use" Size/Point objects, we can create dummy objects as shown in FillEllipse and FillRectangle above.
  • We dispose of our objects, but this isn't necessary as they would be automatically disposed of by ahk when out of scope.
This is still beta and a lot is still being figured out. I'm having to battle a little bit with AHK not throwing any errors if I make a mistake, for example you try and access a method on the wrong object, or you spell it wrong, etc

Anyway....Overall this will greatly simplify your existing and new applications, which ensures fewer errors and allows you to concentrate on what's important.
serg
Posts: 43
Joined: 21 Mar 2015, 05:33

Re: GDI+ standard library 1.45 by tic

23 Mar 2015, 14:08

tic,
Thank you for such a detailed answer! Indeed, your new GDIP lib looks easier than the old one and more "elegant", so to speak.
I think it should be included in standard AHK package, with instructions, - any AHK newbie will do huge favor to him/herself by learning how to use this lib. And it fits nicely right into the AHK philosophy - super easy to learn and it gives so much functionality!
Keep on doing great work, tic! This GDIP project of yours is awesome!
tic
Posts: 92
Joined: 03 Nov 2014, 03:10

Re: GDI+ standard library 1.45 by tic

27 Mar 2015, 16:50

I am still working on the v2 Gdip beta library. There are still lots of changes to be made.
Download the repository from github and run

Gdip2.Beta-Test.4-Zoom.Player.ahk

Gdip github

Zip support is still in testing and will be replaced by machine code to improve seeking speed.
IcoMoon icons added

https://icomoon.io/#preview-free

There isn't any commenting yet, as this is still just a preview
Please give comments as they will be valuable going forward
Surreall
Posts: 8
Joined: 02 Apr 2015, 09:08

Re: GDI+ standard library 1.45 by tic

02 Apr 2015, 09:09

Hi there,

I was wondering if you can help me, i find gdip quite confusing as i am not a proficient programmer.

I am trying to crop an image i am searching with, can i use GDIP for that?

I had in mind something like this:

1) i use testimage.png, and would like to search the screen for a percentage of the horizontal of that image.
So if the testimage.png is 10x100, would like to be able to crop the image horizontally, say 60%, so i am only using the first 60 pixels in my imagesearch.

I presume i would need to save the saved testimage.png as a temporary image, example, temporarytestimage.png.
The cut off the last number of horizontal pixels, using gdip? So if i wanted to search only 60% i would cut the image by the last 40 pixals.
Then use the new temporarytestimage.png in the imagesearch
Then delete afterwards.

Is all my ramblings possible with GDIP?

Kindest Regards
Surreall
User avatar
Learning one
Posts: 157
Joined: 04 Oct 2013, 13:59
Location: Croatia
Contact:

Re: GDI+ standard library 1.45 by tic

02 Apr 2015, 10:38

Surreall wrote:... I am trying to crop an image ...
I'm willing to partially help you; see Resize, Rotate, Crop, Clone bitmap
Surreall
Posts: 8
Joined: 02 Apr 2015, 09:08

Re: GDI+ standard library 1.45 by tic

02 Apr 2015, 10:55

Learning one wrote:
Surreall wrote:... I am trying to crop an image ...
I'm willing to partially help you; see Resize, Rotate, Crop, Clone bitmap
That is absolutely awesome, thank you.

I will have a play with those tonight!
Surreall
Posts: 8
Joined: 02 Apr 2015, 09:08

Re: GDI+ standard library 1.45 by tic

02 Apr 2015, 11:08

Learning one wrote:
Surreall wrote:... I am trying to crop an image ...
I'm willing to partially help you; see Resize, Rotate, Crop, Clone bitmap

THis is probably a really stupid question, but how do i load an image into the variable pbitmap?

if the image is in %A_ScriptDir%\images\test.png

I thought

pbitmap := %A_ScriptDir%\images\test.png, which obviously doesnt work.

Also, can i copy the output bitmap onto clipboard, so i can view the new image in paint?

Regards

Surreall
tic
Posts: 92
Joined: 03 Nov 2014, 03:10

Re: GDI+ standard library 1.45 by tic

02 Apr 2015, 11:47

pbitmap := %A_ScriptDir%\images\test.png, which obviously doesnt work.
pBitmap := Gdip_CreateBitmapFromFile("images\test.png")
Also, can i copy the output bitmap onto clipboard, so i can view the new image in paint?
Gdip_SetBitmapToClipboard(pBitmap
Surreall
Posts: 8
Joined: 02 Apr 2015, 09:08

Re: GDI+ standard library 1.45 by tic

02 Apr 2015, 13:29

tic wrote:
pbitmap := %A_ScriptDir%\images\test.png, which obviously doesnt work.
pBitmap := Gdip_CreateBitmapFromFile("images\test.png")
Also, can i copy the output bitmap onto clipboard, so i can view the new image in paint?
Gdip_SetBitmapToClipboard(pBitmap)

Thank you very much.

I am having a little issue, it keeps saying preview not available. For testing i am just using:

Code: Select all

pBitmap := Gdip_CreateBitmapFromFile("images\test.png")
Gdip_SetBitmapToClipboard(pBitmap)
I keep getting preview not available, and when i try to paste into paint i get "the information on the clipboard cannot be inserted into Paint".
I have this in my code,

Code: Select all

SetworkingDir %A_ScriptDir%
And i have the folder Images as well.The image files are there in the correct location. I have tried png and bmp versions as well to no avail.

Am i missing something obvious?

Regards

Surreall
tic
Posts: 92
Joined: 03 Nov 2014, 03:10

Re: GDI+ standard library 1.45 by tic

02 Apr 2015, 13:30

Please read the examples on the first page. You need to initialize Gdip:

pToken := Gdip_Startup()
Surreall
Posts: 8
Joined: 02 Apr 2015, 09:08

Re: GDI+ standard library 1.45 by tic

02 Apr 2015, 13:46

I copied tutorial 10 exactly.

The first gui comes up, where i can browes to my image, then nothing else happens.

Press go and nothing.

Regards

Surreall
tic
Posts: 92
Joined: 03 Nov 2014, 03:10

Re: GDI+ standard library 1.45 by tic

02 Apr 2015, 13:47

Make sure you are using the Gdip_All as that covers different versions of AHK

Return to “Scripts and Functions”

Who is online

Users browsing this forum: hasantr, LunarSummer, Peaceful, PhonexEric24 and 19 guests