Page 3 of 23
Re: GDI+ standard library 1.45 by tic
Posted: 02 Apr 2015, 13:54
by Surreall
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
Re: GDI+ standard library 1.45 by tic
Posted: 02 Apr 2015, 14:17
by Surreall
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
Re: GDI+ standard library 1.45 by tic
Posted: 02 Apr 2015, 14:45
by tic
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
Re: GDI+ standard library 1.45 by tic
Posted: 02 Apr 2015, 15:05
by guest3456
tic you may want to start using the inline code tags instead of the full codeboxes for your one liners
Re: GDI+ standard library 1.45 by tic
Posted: 03 Apr 2015, 05:56
by jNizM
Re: GDI+ standard library 1.45 by tic
Posted: 22 Apr 2015, 00:26
by Guest
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?
Re: GDI+ standard library 1.45 by tic
Posted: 22 Apr 2015, 10:06
by tic
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
Re: GDI+ standard library 1.45 by tic
Posted: 22 Apr 2015, 10:25
by Coco-guest
I'm not sure if intended, but this overrides/changes the object reference
(the Class object) stored in the super-global variable
Gdip.
Re: GDI+ standard library 1.45 by tic
Posted: 22 Apr 2015, 10:27
by geek
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?
Re: GDI+ standard library 1.45 by tic
Posted: 22 Apr 2015, 10:28
by Guest
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?
Re: GDI+ standard library 1.45 by tic
Posted: 22 Apr 2015, 10:36
by tic
Coco-guest wrote: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
Re: GDI+ standard library 1.45 by tic
Posted: 22 Apr 2015, 10:48
by geek
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
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
Re: GDI+ standard library 1.45 by tic
Posted: 22 Apr 2015, 10:55
by tic
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.
Re: GDI+ standard library 1.45 by tic
Posted: 22 Apr 2015, 11:33
by Coco-guest
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
}
}
Re: GDI+ standard library 1.45 by tic
Posted: 22 Apr 2015, 16:22
by tic
Very good idea Coco. Thank you. I will implement that now.
Re: GDI+ standard library 1.45 by tic
Posted: 22 Apr 2015, 16:34
by guest3456
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
Re: GDI+ standard library 1.45 by tic
Posted: 22 Apr 2015, 16:39
by geek
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.
Re: GDI+ standard library 1.45 by tic
Posted: 22 Apr 2015, 17:17
by guest3456
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"
Re: GDI+ standard library 1.45 by tic
Posted: 22 Apr 2015, 17:34
by geek
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"?
Re: GDI+ standard library 1.45 by tic
Posted: 22 Apr 2015, 17:56
by guest3456