Imagesearch shades of variation for a very small icon Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
redrum
Posts: 83
Joined: 25 Jan 2015, 22:57

Re: Imagesearch shades of variation for a very small icon

Post by redrum » 16 Apr 2024, 12:11

Seven0528 wrote:
16 Apr 2024, 07:02
 ImagePut tends to receive frequent updates,
but there's a tendency for the version information in the code comments not to be updated properly.
With AutoHotkey, there are several folders that can be used as Lib, so I speculate that there might be a script in one of those folders with higher priority.

Here, there are 8736 lines, 380805 characters, and not a single line of code included with #Include.
Would you like to test it out? (I've attached the license terms to the code.)
GetQuantowerKeybdBtnToggleState
Tutorial.1_GetQuantowerKeybdBtnToggleState-1.0.1-ahk2.ahk
It works!
Works flawlessly when using mouse to toggle button on/off.
state 0.png
(2.68 KiB) Downloaded 72 times
state 1.png
(2.45 KiB) Downloaded 72 times
Then I tried using app's hotkey (user defined in app, not an AHK workaround) to toggle button on/off. And at first I got -1 whether on/off, but after a few iterations, this is also correctly showing either state 1 for on or 0 for off.

redrum
Posts: 83
Joined: 25 Jan 2015, 22:57

Re: Imagesearch shades of variation for a very small icon

Post by redrum » 16 Apr 2024, 13:14

Seven0528 wrote:
16 Apr 2024, 07:02
 ImagePut tends to receive frequent updates,
but there's a tendency for the version information in the code comments not to be updated properly.
Ah, I see. I went and got the latest code from the 'master': https://github.com/iseahound/ImagePut/blob/master/ImagePut.ahk

And to your point, that was last updated 4 days ago, while the code comments show:

Code: Select all

; Date:      2023-03-02
; Version:   1.10
So I replaced ImagePut.ahk in \Lib with the latest, and voila, your earlier code works as expected. :D

User avatar
Seven0528
Posts: 347
Joined: 23 Jan 2023, 04:52
Location: South Korea
Contact:

Re: Imagesearch shades of variation for a very small icon

Post by Seven0528 » 16 Apr 2024, 13:48

 @redrum
Finally! I'm glad I could help you :)
  • English is not my native language. Please forgive any awkward expressions.
  • 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.

redrum
Posts: 83
Joined: 25 Jan 2015, 22:57

Re: Imagesearch shades of variation for a very small icon

Post by redrum » 16 Apr 2024, 14:59

Seven0528 wrote:
16 Apr 2024, 13:48
 @redrum
Finally! I'm glad I could help you :)
Thank you so much for the help!

In the following code you provided, is there a good (or even possible) place to either (1) subdivide the original window or image, or (2) specify search area?

Code: Select all

    winGetPos(&winX, &winY, &winW, &winH, hWnd)
    ;------------------
    hbm:=CreateDIBSection(winW, winH), hdc:=CreateCompatibleDC(), obm:=SelectObject(hdc, hbm)
	PrintWindow(hwnd, hdc)
	pHaystack:=Gdip_CreateBitmapFromHBITMAP(hbm)
	SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
    bufHaystack:=ImagePutBuffer(pHaystack)
    ;------------------
    state:=-1 ;  Unknown
    variation:=5 ;  I thought a little variation wouldn't be necessary, but it is needed. I'm not sure why.
    loop 1    {
        if (xys:=bufHaystack.ImageSearchAll(bufNeedleOff,variation))    {
            if (xys.length)    {
                state:=0 ;  Off
                break
            }
        }
        if (xys:=bufHaystack.ImageSearchAll(bufNeedleOn,variation))    {
            if (xys.length)    {
               state:=1 ;  On
               break
            }
        }
    }
I have two trading charts stacked together (these are 1 window as far as Windows is concerned, so both charts are part of `hWnd` and the subsequent `bufHaystack`. So your code is essentially searching to see if the toggle button for the upper chart is on/off. I'd like to be able to check the lower chart as well.

I use one hotkey to make the upper chart active, and a separate hotkey to make the lower chart active (either hotkey makes the entire window active as far as Windows is concerned, but the charts are activated separately as far as Quantower is concerned, meaning if I use 1st hotkey to active upper chart, QT built-in trading hotkeys will impact only upper chart. So what I'd like to do is create a script that activates upper chart, then checks if toggle button for upper chart is enabled (if so, do nothing) or disabled (if so, enable). So I only need to search upper half of image generated downstream of `hWnd`. When I activate lower chart, I want to search lower half of image.

That's why I'm wondering if somewhere downstream of `hWnd`, the image can be subdivided.
2 charts stacked screenshot.png
(195.86 KiB) Downloaded 57 times

User avatar
Seven0528
Posts: 347
Joined: 23 Jan 2023, 04:52
Location: South Korea
Contact:

Re: Imagesearch shades of variation for a very small icon

Post by Seven0528 » 16 Apr 2024, 22:28

 If I could obtain coordinates from ImagePut, it would make things easier, but unfortunately, I'm getting strange coordinates on my computer.
If necessary, you could crop the captured image from the hWnd using GDI+, and perform image searching.
If you search online, you'll likely find examples of cropping pBitmap using the Gdip library.
You could try searching yourself, or perhaps post a separate question specifically about that part.

This is a personal matter, but I'm also active in the AHK community in Korea.
Lately, I've been answering multiple questions simultaneously, which has made it difficult for me to focus on my own tasks.
I'd like to concentrate on my work for the next few days.
I'll try to think more about your issue when I have time later. I'm sorry I couldn't be more helpful.
  • English is not my native language. Please forgive any awkward expressions.
  • 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.

redrum
Posts: 83
Joined: 25 Jan 2015, 22:57

Re: Imagesearch shades of variation for a very small icon

Post by redrum » 17 Apr 2024, 00:03

Seven0528 wrote:
16 Apr 2024, 22:28
 If I could obtain coordinates from ImagePut, it would make things easier, but unfortunately, I'm getting strange coordinates on my computer.
If necessary, you could crop the captured image from the hWnd using GDI+, and perform image searching.
If you search online, you'll likely find examples of cropping pBitmap using the Gdip library.
You could try searching yourself, or perhaps post a separate question specifically about that part.

This is a personal matter, but I'm also active in the AHK community in Korea.
Lately, I've been answering multiple questions simultaneously, which has made it difficult for me to focus on my own tasks.
I'd like to concentrate on my work for the next few days.
I'll try to think more about your issue when I have time later. I'm sorry I couldn't be more helpful.
@Seven0528 absolutely no worries. Thank you for being so generous with your time.

And thanks for pointing me in the direction of cropping bitmap using Gdip.

Code: Select all

    ; subdividing bufHaystack
    originalWidth := 1261
    halfHeight := 795  ; half of the bitmap's height

    ; Clone the top half of the bitmap
    pTopHalf := Gdip_CloneBitmapArea(pHaystack, 0, 0, originalWidth, halfHeight)

    ; Clone the bottom half of the bitmap
    pBottomHalf := Gdip_CloneBitmapArea(pHaystack, 0, halfHeight, originalWidth, halfHeight)

    ; convert to image buffers 
    bufTopHalf := ImagePutBuffer(pTopHalf)
    bufBottomHalf := ImagePutBuffer(pBottomHalf)
Some kinks to work out, as visualizing the bitmaps reveals they are not as expected. But I'm on the right track I think. And if I can't figure it out, I'll start a new thread since that would be a different topic. Marking this thread's issue as solved. Thanks again @Seven0528 . :D

Post Reply

Return to “Ask for Help (v2)”