GDI+ standard library 1.45 by tic

Post your working scripts, libraries and tools
Surreall
Posts: 8
Joined: 02 Apr 2015, 09:08

Re: GDI+ standard library 1.45 by tic

02 Apr 2015, 13:54

Absolutely brilliant, ty.

And yes that was the issue all along lol, i needed the Gdip_All.ahk :)

Thanks again, and sorry i have been a pain.

Regards

Surreall
Surreall
Posts: 8
Joined: 02 Apr 2015, 09:08

Re: GDI+ standard library 1.45 by tic

02 Apr 2015, 14:17

Sorry to be a pain, last question i promise.

How do i imagesearch with the pCroppedBitmap?

When i message it, it is a load of numbers. So i presume i need to do a reverse of getbitmap from file. And make file from bitmap?

Regards

Surreall

EDIT: i did read through gdip_all, and didnt see an option for this
tic
Posts: 92
Joined: 03 Nov 2014, 03:10

Re: GDI+ standard library 1.45 by tic

02 Apr 2015, 14:45

You should not use the ahk ImageSearch as this will slow down your script substantially (Especially as you'd have to write to disk which is unnecessary).

Use Masterfocus' Gdip_ImageSearch:

https://github.com/MasterFocus/AutoHotk ... mageSearch

I have not tested it yet however.

If you do want to save a bitmap to disk to use with something else:

Gdip_SaveBitmapToFile
guest3456
Posts: 3150
Joined: 09 Oct 2013, 10:31

Re: GDI+ standard library 1.45 by tic

02 Apr 2015, 15:05

tic you may want to start using the inline code tags instead of the full codeboxes for your one liners

User avatar
jNizM
Posts: 2665
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: GDI+ standard library 1.45 by tic

03 Apr 2015, 05:56

[AHK] 1.1.32.00 x64 Unicode | [WIN] 10 Pro (Version 2004) x64 | [GitHub] Profile
Donations are appreciated if I could help you
Guest

Re: GDI+ standard library 1.45 by tic

22 Apr 2015, 00:26

tic wrote:You should not use the ahk ImageSearch as this will slow down your script substantially (Especially as you'd have to write to disk which is unnecessary).

Use Masterfocus' Gdip_ImageSearch:

https://github.com/MasterFocus/AutoHotk ... mageSearch

I have not tested it yet however.

If you do want to save a bitmap to disk to use with something else:

Gdip_SaveBitmapToFile
Any chance of ImageSearch making its way into Gdip2?
tic
Posts: 92
Joined: 03 Nov 2014, 03:10

Re: GDI+ standard library 1.45 by tic

22 Apr 2015, 10:06

Guest wrote:Any chance of ImageSearch making its way into Gdip2?
Definitely. With simple syntax of

Code: Select all

gdip := new Gdip()
bitmap1 := gdip.BitmapFromFile("c:\myFile.png")
bitmap2 := gdip.BitmapFromScreen()
isObj := bitmap2.ImageSearch(bitmap1)
Edit:

Updated above code. GeekDude pointed out an error
Coco-guest

Re: GDI+ standard library 1.45 by tic

22 Apr 2015, 10:25

Code: Select all

gdip := new Gdip()
I'm not sure if intended, but this overrides/changes the object reference(the Class object) stored in the super-global variable Gdip.
GeekDude
Posts: 887
Joined: 02 Oct 2013, 22:13

Re: GDI+ standard library 1.45 by tic

22 Apr 2015, 10:27

tic wrote:

Code: Select all

gdip := new Gdip()
bitmap1 := new gdip.BitmapFromFile("c:\myFile.png")
bitmap2 := new gdip.BitmapFromScreen()
isObj := bitmap2.ImageSearch(bitmap1)
I suppose that means that BitmapFromFile and BitmapFromScreen are subclasses, not methods?
Guest

Re: GDI+ standard library 1.45 by tic

22 Apr 2015, 10:28

tic wrote:
Guest wrote:Any chance of ImageSearch making its way into Gdip2?
Definitely. With simple syntax of

Code: Select all

gdip := new Gdip()
bitmap1 := gdip.BitmapFromFile("c:\myFile.png")
bitmap2 := gdip.BitmapFromScreen()
isObj := bitmap2.ImageSearch(bitmap1)
Thanks for the quick reply, would this be AHK's imagesearch or MasterFocus' faster imagesearch? or are they the same nowadays? :)
tic
Posts: 92
Joined: 03 Nov 2014, 03:10

Re: GDI+ standard library 1.45 by tic

22 Apr 2015, 10:36

Coco-guest wrote:

Code: Select all

gdip := new Gdip()
I'm not sure if intended, but this overrides/changes the object reference(the Class object) stored in the super-global variable Gdip.
I'm not sure it does unless I'm not understanding. Just testing now, if I do:

Code: Select all

gdip := new Gdip()
gdip1 := new Gdip()
and use gdip1 from then on, it still works, so new Gdip() wouldn't still work if the class definition had been overridden
GeekDude wrote:I suppose that means that BitmapFromFile and BitmapFromScreen are subclasses, not methods?
Bitmap Is a sub-class and there are a few top-level methods that will return sub-classes. This is to improve readability. Examples are

Code: Select all

BitmapFromScreen(params*)
BitmapFromZip(zipObj, file)
BitmapFromFile(file)
They all return a Bitmap object
Guest wrote:Thanks for the quick reply, would this be AHK's imagesearch or MasterFocus' faster imagesearch? or are they the same nowadays? :)
As MasterFocus' ImageSearch seems to be used now completely, I would like to take a look at incorporating as-is, or with some modifications after I check the code and with his permission.

Edit:

Ah, sorry GeekDude. My bad. Typo. Fixed in my post
GeekDude
Posts: 887
Joined: 02 Oct 2013, 22:13

Re: GDI+ standard library 1.45 by tic

22 Apr 2015, 10:48

tic wrote:

Code: Select all

gdip := new Gdip()
gdip1 := new Gdip()
and use gdip1 from then on, it still works, so new Gdip() wouldn't still work if the class definition had been overridden
It'd be similar to doing

Code: Select all

a := new Gdip()
b := new a()
It'll "work", but it's not really the same. Any overrides that a does will be inherited by b. You can thank the wonderful world of prototype OOP for this
tic
Posts: 92
Joined: 03 Nov 2014, 03:10

Re: GDI+ standard library 1.45 by tic

22 Apr 2015, 10:55

GeekDude wrote: It'll "work", but it's not really the same. Any overrides that a does will be inherited by b. You can thank the wonderful world of prototype OOP for this
Ah, interesting. Technically, 2 objects shouldn't be instantiated of Gdip, but still, it would be bad practice to advise to override the class. Will have to change the variable name in examples. Thanks for the heads up guys.
Coco-guest

Re: GDI+ standard library 1.45 by tic

22 Apr 2015, 11:33

Code: Select all

gdip := new Gdip() ; gdip.base is Class object
gdip1 := new Gdip() ; gdip1.base is gdip(which is an instance)
From here on new Gdip() would still work(as long as Gdip contains a reference to an object, any object), however, newer instance(s) will use the first instance as their base object.

By the way, it seems that the purpose for instantiating the Gdip object is to load the library and to free it on __Delete. An issue might be encountered if there are more than one active instance of the class(Gdip) at a time and if any of those instances is released, the __Delete method calls GdiplusShutdown and frees the DLL. The remaining active instance(s) might not be able to use/call the Gdiplus functions since the DLL has already been unloaded. Having said that, IMO, for this specific lib, instances should only be allowed to exist one at a time since only one is really needed at a time. So while an instance is active, __New should be temporarily unavailable. Here's a demo of restricting single instance:

Code: Select all

instance := new SingleInstance()
instance2 := new SingleInstance()
MsgBox % IsObject(instance2) ;false, not an object
instance := "" ; release instance, allow creation of new instance again

new_instance := new SingleInstance()
MsgBox % IsObject(new_instance) ; true
new_instance := ""

class SingleInstance
{
	__New()
	{
		; init code
		
		this._New := SingleInstance.__New ; backup Func reference to __New
		SingleInstance.__New := SingleInstance._DummyNew ; temporarily replace the value of '__New' key and have it point to a dummy '__New' method
	}

	_DummyNew()
	{
		return false ; disable creation of new instances
	}

	__Delete()
	{
		; clean up code

		; instance is released, restore original '__New'
		SingleInstance.__New := this._New
	}
}
tic
Posts: 92
Joined: 03 Nov 2014, 03:10

Re: GDI+ standard library 1.45 by tic

22 Apr 2015, 16:22

Very good idea Coco. Thank you. I will implement that now.
guest3456
Posts: 3150
Joined: 09 Oct 2013, 10:31

Re: GDI+ standard library 1.45 by tic

22 Apr 2015, 16:34

GeekDude wrote:It'll "work", but it's not really the same. Any overrides that a does will be inherited by b. You can thank the wonderful world of prototype OOP for this
actually, you can thank AHK syntax choices for confusing you about this. or rather, the choice to cave to the popular request for 'classes'

in AHK, defining a class Gdip {..} is in reality creating a new object with name "Gdip". you should think of it as essentially doing a Gdip := {k:v, k:v, ..} (but without some of the special class stuff such as __New). in AHK, using the keyword class is in actuality instantianting an object of that name. ie, you can already use the "Gdip" object without calling new

GeekDude
Posts: 887
Joined: 02 Oct 2013, 22:13

Re: GDI+ standard library 1.45 by tic

22 Apr 2015, 16:39

Instead of referring to SingleInstance by name inside the class, you should be able to reference it by this.base. I question the usefulness of being able to start/stop gdip manually multiple times. I wonder if it'd be best to just have gdip auto-initiate, and discourage manual creation of new gdip objects.

Code: Select all

class MyClass
{
    static _ := MyClass := new MyClass()
    __New()
    {
        MsgBox, Automatically initiated!
    }
}
ie, you can already use the "Gdip" object without calling new
Sure, but that skips the class initiation metafunctions and some other voodoo that goes on when you initialize a class.
guest3456
Posts: 3150
Joined: 09 Oct 2013, 10:31

Re: GDI+ standard library 1.45 by tic

22 Apr 2015, 17:17

GeekDude wrote:Instead of referring to SingleInstance by name inside the class, you should be able to reference it by this.base. I question the usefulness of being able to start/stop gdip manually multiple times. I wonder if it'd be best to just have gdip auto-initiate, and discourage manual creation of new gdip objects.

Code: Select all

class MyClass
{
    static _ := MyClass := new MyClass()
    __New()
    {
        MsgBox, Automatically initiated!
    }
}
but if a user somehow does MyClass := "" will this class be released and no mechanism to start it back up?

but i agree its not really useful to start/stop gdip multiple times
GeekDude wrote:
ie, you can already use the "Gdip" object without calling new
Sure, but that skips the class initiation metafunctions and some other voodoo that goes on when you initialize a class.
right, but thats not the fault of prototype-based OOP when the language is doing some special voodoo in specific instances of object creation and not other instances, merely for convenience and familiarity of using "classes"

GeekDude
Posts: 887
Joined: 02 Oct 2013, 22:13

Re: GDI+ standard library 1.45 by tic

22 Apr 2015, 17:34

guest3456 wrote:but if a user somehow does MyClass := "" will this class be released and no mechanism to start it back up?
Wouldn't that be an issue with any class? If the user wants to throw away their reference it's on them
guest3456 wrote:right, but thats not the fault of prototype-based OOP when the language is doing some special voodoo in specific instances of object creation and not other instances, merely for convenience and familiarity of using "classes"
Do you want me to revise my original post to read something like "prototype AutoHotkey's implementation of prototype OOP"?

Return to “Scripts and Functions”

Who is online

Users browsing this forum: jetrotal, thegooddoctor and 24 guests