PixelSearch in opposite direction

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

PixelSearch in opposite direction

16 Aug 2017, 12:25

Hi!

Is there a simple way to find the last specified-color pixel in a region, i.e. to search from the lower corners upwards to the upper corners?

I would like to search in an 1 pixel wide region from bottom to top of the region. According to Doc the direction can be changed by coordinates (y1 > y2) only if Slow mode is used. Is there really no way to do the same with the Fast mode?

Thank you very much in advance!
Last edited by newbieforever on 21 Sep 2017, 07:43, edited 1 time in total.
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Re: PixelSearch in opposite direction

21 Sep 2017, 07:42

Is there really no solution for such a simple task?
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: PixelSearch in opposite direction

21 Sep 2017, 07:59

ImageGetColors ().ahk detects all colors of an existing image/file.
Means, an image with 1-px width, n-px height would parse a vertical line for its color values.
Search the forum for Gdip.ahk + partial + area + ...

Good luck :)
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Re: PixelSearch in opposite direction

21 Sep 2017, 08:12

@BoBo: Thank you very much.

Hm ... I have to search in a program's window, not in an image or file. I suppose there would be a way to make an image from my search area, but ... A little to complicated for me, I think ...
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: PixelSearch in opposite direction

21 Sep 2017, 09:23

Two ideas:
[Gdip_ImageSearch]
Use GDI+ to do image search? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 04#p136204

[retrieve pixels as text, 8 characters per pixel, but note, the rows of pixels are retrieved in reverse order]
Gdip: image binary data to hex string for OCR - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=35339
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
autocart
Posts: 214
Joined: 12 May 2014, 07:42

Re: PixelSearch in opposite direction

12 May 2019, 13:07

Hi there,

EDIT:
Never mind, I don't need that solution anymore at the moment.
EDIT END

I had (almost) the same desire. Came up with the code below. (Note that the search here is one dimensional, however, it should be rather easy to extend it to 2 dimensions. Parameter #4 in _get_nextPixelWithColor defines the direction - until the edge of the screen, assuming a one screen PC setup.)
Even though it is faster than the slow PixelSearch in reverse direction, it still is not fast at all.

Does anyone have an idea how to make it faster?

Many thanks in advance.
Regards, S.

Code: Select all

CoordMode, Mouse, Screen
MouseGetPos, v_out_mouse_X, v_out_mouse_Y
a_pixelFound := _get_nextPixelWithColor("0xRRGGBB", v_out_mouse_X, v_out_mouse_Y, "+x", 100)
if a_pixelFound
	MsgBox, % a_pixelFound.X ", " a_pixelFound.Y
else
	MsgBox, Not found.


_get_nextPixelWithColor(p_rgb_0xRRGGBB, p_start_X, p_start_Y, p_direction_plusMinusXY, p_stepSizePixel)
{
	CoordMode, Pixel, Screen
	v_target_X := p_start_X
	v_target_Y := p_start_Y
	v_targetOutOfScreen := 0
	v_increment_X := 0
	v_increment_Y := 0
	
	if (InStr(p_direction_plusMinusXY, "x", false))
		v_increment_X := p_stepSizePixel
	if (InStr(p_direction_plusMinusXY, "y", false))
		v_increment_Y := p_stepSizePixel
	if (SubStr(p_direction_plusMinusXY, 1, 1) = "-")
	{
		v_increment_X *= -1
		v_increment_Y *= -1
	}
	
	PixelGetColor, v_rgb_out, % v_target_X, % v_target_Y, RGB
	While ((not v_rgb_out = p_rgb_0xRRGGBB) and (not v_targetOutOfScreen))
	{
		v_target_X += v_increment_X
		v_target_Y += v_increment_Y
		
		if (v_target_X < 0 or v_target_X > A_ScreenWidth or v_target_Y < 0 or v_target_Y > A_ScreenHeight)
		{
			v_targetOutOfScreen := 1
		}
		else
		{
			PixelGetColor, v_rgb_out, % v_target_X, % v_target_Y, RGB
		}
	}

	if (p_stepSizePixel = 1)
		if v_targetOutOfScreen
			return 0
		else
			return Object("X", v_target_X, "Y", v_target_Y)
	else
		return _get_nextPixelWithColor(p_rgb_0xRRGGBB, v_target_X - v_increment_X, v_target_Y - v_increment_Y, p_direction_plusMinusXY, p_stepSizePixel // 2)
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Xtra and 342 guests