Use GDI+ to do image search?
Re: Use GDI+ to do image search?
another update question, Why is it that when I pass my code to my friends, the needle image is not recognized? but if they take a screenshot of their own needle, it works fine. Is there any solution to this? I already set the variation to 100-250 (i've been experimenting with this. Thanks so much again for the reply
Re: Use GDI+ to do image search?
It could by any of a number of reasons. It could be the result of anti-aliased text being rendered differently in different instances (most likely, I think). It may be that their graphics card renders it differently. It could be the application renders it differently in different situations such as scaling for screen resolution. Increasing the allowable variation won’t be good enough if the pixels are fundamentally different, which can and does happen in situations like these.
If they send you their needle images and you zoom in on theirs and yours in MS Paint (or some other picture viewer that doesn’t distort the image like the standard picture viewer does), then you will see the differences between the images if you look closely.
If they send you their needle images and you zoom in on theirs and yours in MS Paint (or some other picture viewer that doesn’t distort the image like the standard picture viewer does), then you will see the differences between the images if you look closely.
Re: Use GDI+ to do image search?
That makes alot of sense, thank you so much for replying
-
- Posts: 16
- Joined: 15 Jul 2021, 21:08
Re: Use GDI+ to do image search?
Could you share your final script, please? I was learning GDI+ too, I want to know how the successful script running with GDI, I will be appreciate if u want to share the simple tutorial too thanks
Re: Use GDI+ to do image search?
my "Gdip_BitmapFromHWND" is returning 0boiler wrote: ↑16 Mar 2021, 08:31Try replacing Gdip_BitmapFromHWND() with this version which allows for more graphics rendering approaches to be captured:Code: Select all
Gdip_BitmapFromHWND(hwnd) { WinGetPos,,, Width, Height, ahk_id %hwnd% hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm) RegExMatch(A_OsVersion, "\d+", Version) PrintWindow(hwnd, hdc, Version >= 8 ? 2 : 0) pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm) SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc) return pBitmap }
I've already tried to modify the library as you said, but it still keeps returning 0
when I go to use Gdip_ImageSearch it returns "-1001", claiming there is a problem with Haystack
can you help me? my code is:
Code: Select all
#NoEnv
#SingleInstance Force
SetBatchLines, -1
Process, Priority,, High
#Include GDIP.ahk
#Include Gdip_ImageSearch.ahk ; (this is masterfocus' gdip_imagesearch.ahk)
3::
ptok := Gdip_startup()
win := Gdip_BitmapFromHWND( WinExist("ahk_class MSPaintApp") ) ;Haystack is paint open with png Needle (testimg.png)
pic := Gdip_createBitmapFromFile("testimg.png")
err := Gdip_imageSearch( win, pic, xy, 0,0,0,0, 15, ,1,0 )
Gdip_disposeImage( win )
Gdip_disposeImage( pic )
Gdip_shutdown(ptok)
return
Re: Use GDI+ to do image search?
What do you get if you have that window open and run the following?
Are you sure it’s not the one that is getting the image from a file (as opposed to the one from the MSPaint window) that is returning a 0? Use the full path to the file, not just the file name.
Code: Select all
MsgBox, % WinExist("ahk_class MSPaintApp")
Are you sure it’s not the one that is getting the image from a file (as opposed to the one from the MSPaint window) that is returning a 0? Use the full path to the file, not just the file name.
Re: Use GDI+ to do image search?
it looks like the GDIP I was using only works on 32Bits systems (not sure)boiler wrote: ↑18 Oct 2021, 03:17What do you get if you have that window open and run the following?Code: Select all
MsgBox, % WinExist("ahk_class MSPaintApp")
Are you sure it’s not the one that is getting the image from a file (as opposed to the one from the MSPaint window) that is returning a 0? Use the full path to the file, not just the file name.
I used another GDIP library and it worked. can you analyze it for me and see what the difference between the two is? I'm not so good at it
GDIP LIBRARY ERROR (OLD):
https://raw.githubusercontent.com/tariqporter/Gdip/master/Gdip.ahk
GIP LIBRARY WORKING (NEW):
https://raw.githubusercontent.com/berban/Gdip/master/Gdip.ahk
Re: Use GDI+ to do image search?
another question too, could you explain to me what the command is for: "Gdip_startup()" and "Gdip_disposeImage()" and "Gdip_shutdown()"boiler wrote: ↑18 Oct 2021, 03:17What do you get if you have that window open and run the following?Code: Select all
MsgBox, % WinExist("ahk_class MSPaintApp")
Are you sure it’s not the one that is getting the image from a file (as opposed to the one from the MSPaint window) that is returning a 0? Use the full path to the file, not just the file name.
THXX
Re: Use GDI+ to do image search?
Are you asking me to analyze the changes that were made from one to the other to make it 64-bit compatible? What would you do with that information? I like to help where I can, but I’m not going to take the time to do that as I don’t see the value in it. Maybe someone else wouldn’t mind doing that for you.
Re: Use GDI+ to do image search?
It’s the way the Microsoft’s GDI+ functions work. You must initialize GDI+ before you can call any of its functions, then you have to delete the GDI+ objects before shutting down or else they’ll stay in memory for no reason, causing you to have less available RAM for other applications. Then you have to shut it down to have GDI+ clean up the other resources it put in place from memory.
Re: Use GDI+ to do image search?
No no, I wanted to know if this was really the problemboiler wrote: ↑19 Oct 2021, 06:23Are you asking me to analyze the changes that were made from one to the other to make it 64-bit compatible? What would you do with that information? I like to help where I can, but I’m not going to take the time to do that as I don’t see the value in it. Maybe someone else wouldn’t mind doing that for you.
Re: Use GDI+ to do image search?
I used the command:boiler wrote: ↑19 Oct 2021, 06:32It’s the way the Microsoft’s GDI+ functions work. You must initialize GDI+ before you can call any of its functions, then you have to delete the GDI+ objects before shutting down or else they’ll stay in memory for no reason, causing you to have less available RAM for other applications. Then you have to shut it down to have GDI+ clean up the other resources it put in place from memory.
Gdip_disposeImage(imagebitmap)
however, when I called
msgbox, %imagebitmap%
the image bitmap was still allocated in memory
Re: Use GDI+ to do image search?
And what has told you that the variable you used to pass the image pointer to the function would change by calling the function? (Hint: Nothing)
The way you would know if it was successfully released is when the return value of the function call is 0:
Code: Select all
MsgBox, % Gdip_disposeImage(imagebitmap)
Re: Use GDI+ to do image search?
was using a different version of Gdip_BitmapFromHWND()boiler wrote: ↑16 Mar 2021, 08:31Try replacing Gdip_BitmapFromHWND() with this version which allows for more graphics rendering approaches to be captured:Code: Select all
Gdip_BitmapFromHWND(hwnd) { WinGetPos,,, Width, Height, ahk_id %hwnd% hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm) RegExMatch(A_OsVersion, "\d+", Version) PrintWindow(hwnd, hdc, Version >= 8 ? 2 : 0) pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm) SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc) return pBitmap }
could you explain to a noob like me what is the difference between the one you sent and the one in the script Gdip_All?
what is the need for this line of code?
Code: Select all
RegExMatch(A_OsVersion, "\d+", Version)
I'll start using the one you sent, thanks
please, help me:
viewtopic.php?f=76&t=96073&hilit=Gdip+image+search
-
- Posts: 343
- Joined: 08 Jun 2019, 17:36
Re: Use GDI+ to do image search?
Code: Select all
RegExMatch(A_OsVersion, "\d+", Version)
PrintWindow(hwnd, hdc, Version >= 8 ? 2 : 0)
I believe this helps get pixel data from hardware accelerated windows. This flag will cause printwindow to fail on Win7 and below so you have to set it to 0 for those OS. I posted in your other thread but saving the bitmap to file can help identify whether this flag is needed for your application windows. If the bitmap shows up as all black you may need this flag.
Re: Use GDI+ to do image search?
how can i set to 0 on win7 operating systems?doubledave22 wrote: ↑28 Oct 2021, 17:27This says if Windows version is Win 8 or higher then use the 0x2 flag which is an undocumented flag called PW_RENDERFULLCONTENT. https://stackoverflow.com/a/40042587Code: Select all
RegExMatch(A_OsVersion, "\d+", Version) PrintWindow(hwnd, hdc, Version >= 8 ? 2 : 0)
I believe this helps get pixel data from hardware accelerated windows. This flag will cause printwindow to fail on Win7 and below so you have to set it to 0 for those OS. I posted in your other thread but saving the bitmap to file can help identify whether this flag is needed for your application windows. If the bitmap shows up as all black you may need this flag.
Re: Use GDI+ to do image search?
You don’t set it. That statement sets it. He was describing what it does because you asked, not something more that you have to do.
Re: Use GDI+ to do image search?
Code: Select all
PrintWindow(hwnd, hdc, Version >= 8 ? 2 : 0)
Also PrintWindow is slower and needed only for windows that use hardware acceleration and that are not visible (lies under others).
Re: Use GDI+ to do image search?
I'm confused so better not use?malcev wrote: ↑28 Oct 2021, 21:11It is not right, because on win8 PW_RENDERFULLCONTENT does not work.Code: Select all
PrintWindow(hwnd, hdc, Version >= 8 ? 2 : 0)
Also PrintWindow is slower and needed only for windows that use hardware acceleration and that are not visible (lies under others).