<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Одновременный поиск нескольких пикселей]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=13160&amp;type=atom" />
	<updated>2023-10-27T07:00:10Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=13160</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Одновременный поиск нескольких пикселей]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=159406#p159406" />
			<content type="html"><![CDATA[<p>Извините за долгое молчание, то ездил, то болел.<br />Заменил. Теперь pixelColor всегда равен 0.</p>]]></content>
			<author>
				<name><![CDATA[Qp]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=43240</uri>
			</author>
			<updated>2023-10-27T07:00:10Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=159406#p159406</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Одновременный поиск нескольких пикселей]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=159335#p159335" />
			<content type="html"><![CDATA[<p>Попробуйте заменить 0x00CC0020 на 0x40CC0020.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2023-10-14T14:18:27Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=159335#p159335</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Одновременный поиск нескольких пикселей]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=159327#p159327" />
			<content type="html"><![CDATA[<p>Я подумал, может, в координатах напутал - устроил поиск 100*100:<br /></p><div class="codebox"><pre><code>x := 0 ; координаты области относительно экрана
y := 0
w := 600
h := 100

xPix := 1 ; координаты пикселя внутри области 0xFF00E9
yPix := 1 ; левый верхний будет xPix := 1, yPix := 1

hBitmap := HBitmapFromScreen(x, y, w, h, pBits)

while (xPix &lt; 100)
	{
	FileAppend, `nновый столбец`n, D:\AHK\bitmap\log.txt
	while (yPix &lt; 100)
		{
		pixelColor := GetPixel(pBits, w * 4, xPix, yPix)
		FileAppend, %pixelColor%`n, D:\AHK\bitmap\log.txt
		yPix++
		}
	yPix := 1
	xPix++
	}</code></pre></div><p>- нет, нету. А там, где чёрная полоса, пишет просто 0 вместо 0x000000.</p>]]></content>
			<author>
				<name><![CDATA[Qp]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=43240</uri>
			</author>
			<updated>2023-10-11T08:35:22Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=159327#p159327</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Одновременный поиск нескольких пикселей]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=159326#p159326" />
			<content type="html"><![CDATA[<p>Я по играм не спец, может, коллега <strong>Malcev</strong> что-то подскажет.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2023-10-11T08:23:18Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=159326#p159326</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Одновременный поиск нескольких пикселей]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=159325#p159325" />
			<content type="html"><![CDATA[<p>Спасибо, работает! Но есть проблема: смотрит сквозь изображение, сгенерированное аддоном к игре.<br />Используя добавление к вашему коду<br /></p><div class="codebox"><pre><code>while (yPix &lt; 82)
{
MouseMove, xPix, yPix, 20
Sleep, 50
pixelColor := GetPixel(pBits, w * 4, xPix, yPix)
FileAppend, %pixelColor%`n, D:\AHK\bitmap\log.txt
yPix++
}</code></pre></div><p>, я вижу, что скрипт проверяет цвет именно по тем координатам, что мне надо, но сиреневый квадратик (0xFF00E9) он не видит, видит то, что за ним.</p>]]></content>
			<author>
				<name><![CDATA[Qp]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=43240</uri>
			</author>
			<updated>2023-10-11T08:16:52Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=159325#p159325</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Одновременный поиск нескольких пикселей]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=159321#p159321" />
			<content type="html"><![CDATA[<p>Попробуйте так:<br /></p><div class="codebox"><pre><code>x := 100 ; координаты области относительно экрана
y := 100
w := 500
h := 500

xPix := 20 ; координаты пикселя внутри области
yPix := 20 ; левый верхний будет xPix := 1, yPix := 1

hBitmap := HBitmapFromScreen(x, y, w, h, pBits)
MsgBox, % pixelColor := GetPixel(pBits, w * 4, xPix, yPix)

HBitmapFromScreen(X, Y, W, H, ByRef pBits := &quot;&quot;) {
   hDC := DllCall(&quot;GetDC&quot;, &quot;Ptr&quot;, 0, &quot;Ptr&quot;)
   hBM := CreateDIBSection(W, -H, pBits)
   hMDC := DllCall(&quot;CreateCompatibleDC&quot;, &quot;Ptr&quot;, hDC, &quot;Ptr&quot;)
   hObj := DllCall(&quot;SelectObject&quot;, &quot;Ptr&quot;, hMDC, &quot;Ptr&quot;, hBM, &quot;Ptr&quot;)
   DllCall(&quot;BitBlt&quot;, &quot;Ptr&quot;, hMDC, &quot;Int&quot;, 0, &quot;Int&quot;, 0, &quot;Int&quot;, W, &quot;Int&quot;, H
                   , &quot;Ptr&quot;, hDC, &quot;Int&quot;, X, &quot;Int&quot;, Y, &quot;UInt&quot;, SRCCOPY := 0x00CC0020)
   DllCall(&quot;SelectObject&quot;, &quot;Ptr&quot;, hMDC, &quot;Ptr&quot;, hObj, &quot;Ptr&quot;)
   DllCall(&quot;DeleteDC&quot;, &quot;Ptr&quot;, hMDC)
   DllCall(&quot;ReleaseDC&quot;, &quot;Ptr&quot;, 0, &quot;Ptr&quot;, hDC)
   Return hBM
}

CreateDIBSection(w, h, ByRef ppvBits := 0, bpp := 32) {
   hDC := DllCall(&quot;GetDC&quot;, &quot;Ptr&quot;, 0, &quot;Ptr&quot;)
   VarSetCapacity(BITMAPINFO, 40, 0)
   NumPut(40 , BITMAPINFO,  0)
   NumPut( w , BITMAPINFO,  4)
   NumPut( h , BITMAPINFO,  8)
   NumPut( 1 , BITMAPINFO, 12)
   NumPut(bpp, BITMAPINFO, 14)
   hBM := DllCall(&quot;CreateDIBSection&quot;, &quot;Ptr&quot;, hDC, &quot;Ptr&quot;, &amp;BITMAPINFO, &quot;UInt&quot;, 0, &quot;PtrP&quot;, ppvBits, &quot;Ptr&quot;, 0, &quot;UInt&quot;, 0, &quot;Ptr&quot;)
   DllCall(&quot;ReleaseDC&quot;, &quot;Ptr&quot;, 0, &quot;Ptr&quot;, hDC)
   return hBM
}

GetPixel(pBits, stride, x, y) {
   ; или NumGet(pBits + (x - 1) * 4 + stride * (y - 1), &quot;UInt&quot;) &amp; 0xFFFFFF если не нужно форматировать
   Return Format(&quot;{:#x}&quot;, NumGet(pBits + (x - 1) * 4 + stride * (y - 1), &quot;UInt&quot;) &amp; 0xFFFFFF)
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2023-10-10T13:41:07Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=159321#p159321</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Одновременный поиск нескольких пикселей]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=159320#p159320" />
			<content type="html"><![CDATA[<p>Да.</p>]]></content>
			<author>
				<name><![CDATA[Qp]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=43240</uri>
			</author>
			<updated>2023-10-10T12:24:58Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=159320#p159320</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Одновременный поиск нескольких пикселей]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=159319#p159319" />
			<content type="html"><![CDATA[<p>Вам нужно на одном и том же скриншоте разные пиксели получать?</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2023-10-10T09:44:29Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=159319#p159319</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Одновременный поиск нескольких пикселей]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=159318#p159318" />
			<content type="html"><![CDATA[<p>По моим замерам один PixelGetColor занимает 15-16 мс. И когда их число уверенно движется к сотне, это становится проблемой. Не разгуляешься.<br />Жаль, ладно, будем искать.</p>]]></content>
			<author>
				<name><![CDATA[Qp]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=43240</uri>
			</author>
			<updated>2023-10-10T09:13:05Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=159318#p159318</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Одновременный поиск нескольких пикселей]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=159317#p159317" />
			<content type="html"><![CDATA[<p>Этот код не приспособлен для получения цвета по координатам. Может, просто использовать <a href="https://www.autohotkey.com/docs/v1/lib/PixelGetColor.htm">PixelGetColor</a>?</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2023-10-10T08:44:32Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=159317#p159317</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Одновременный поиск нескольких пикселей]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=159316#p159316" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Если нужно много раз искать цвет на одном скриншоте, попробуйте такое:</p></blockquote></div><p>Здравствуйте! У меня задача похожая, и, думаю, bitmap - это именно то, что мне нужно, но есть пара нюансов:<br />- мне нужно получать цвет по определённым координатам;<br />- пока что я смотрю на это всё как баран на новые ворота. Понимание &quot;это класс, а это объект, а dll - это что-то системное&quot; не сильно мне помогает. Вас не затруднит снабдить код комментариями?</p>]]></content>
			<author>
				<name><![CDATA[Qp]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=43240</uri>
			</author>
			<updated>2023-10-10T04:04:26Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=159316#p159316</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Одновременный поиск нескольких пикселей]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=152755#p152755" />
			<content type="html"><![CDATA[<p>Если нужно много раз искать цвет на одном скриншоте, попробуйте такое:<br /></p><div class="codebox"><pre><code>color1 := 0x123456
color2 := 0xabcdef

FastPixel := new FastPixelSearch(0, 0, A_ScreenWidth, A_ScreenHeight)
res1 := FastPixel.Search(color1)
res2 := FastPixel.Search(color2)

if !res1
   MsgBox, Color %color1% not found
else
   MsgBox, % &quot;x: &quot; . res1.x . &quot;`ny: &quot; . res1.y

if !res2
   MsgBox, Color %color2% not found
else
   MsgBox, % &quot;x: &quot; . res2.x . &quot;`ny: &quot; . res2.y

class FastPixelSearch
{
   __New(x, y, w, h) {
      this.hBM := this.Api.HBitmapFromScreen(x, y, w, h, pvBits)
      this.pvBits := pvBits
      this.w := w
      this.size := w*h
   }
   
   Search(colorRGB) {
      static bin := 0
      (!bin &amp;&amp; bin := this.Api.GetBin())
      (!(colorRGB &gt;&gt; 24) &amp;&amp; colorRGB |= 0xFF000000)
      byte := DllCall(bin, &quot;ptr&quot;, this.pvBits, &quot;UInt&quot;, this.size, &quot;UInt&quot;, colorRGB, &quot;Int&quot;)
      if (byte == this.pvBits + this.size * 4)
         Return false
      offset := (byte - this.pvBits)//4
      Return {x: mod(offset, this.w), y: offset//this.w}
   }
   
   class Api
   {
      GetBin() {
         static PAGE_EXECUTE_READWRITE := 0x40, CRYPT_STRING_BASE64 := 0x1
         ; C source code - https://godbolt.org/z/oYx39nr5s
         code := A_PtrSize = 8 ? &quot;idJIjQSRSDnBcw9EOQF1BInI6wZIg8EE6+zD&quot;
                               : &quot;VYnli1UIi0UMi00QjQSCOcJzDTkKdQSJ0OsFg8IE6+9dww==&quot;
         size := StrLen( RTrim(code, &quot;=&quot;) )*3//4
         bin := DllCall(&quot;GlobalAlloc&quot;, &quot;UInt&quot;, 0, &quot;Ptr&quot;, size, &quot;Ptr&quot;)
         DllCall(&quot;VirtualProtect&quot;, &quot;Ptr&quot;, bin, &quot;Ptr&quot;, size, &quot;UInt&quot;, PAGE_EXECUTE_READWRITE, &quot;UIntP&quot;, old:=0)
         DllCall(&quot;crypt32\CryptStringToBinary&quot;, &quot;Str&quot;, code, &quot;UInt&quot;, 0, &quot;UInt&quot;, CRYPT_STRING_BASE64
                                              , &quot;Ptr&quot;, bin, &quot;UIntP&quot;, size, &quot;Ptr&quot;, 0, &quot;Ptr&quot;, 0)
         Return bin
      }
      
      HBitmapFromScreen(X, Y, W, H, ByRef pvBits) {
         static rop := (SRCCOPY := 0x00CC0020) | (CAPTUREBLT := 0x40000000)
         hDC := DllCall(&quot;GetDC&quot;, &quot;Ptr&quot;, 0, &quot;Ptr&quot;)
         hBM := this.CreateDIBSection(W, H, hDC, pvBits)
         hMDC := DllCall(&quot;CreateCompatibleDC&quot;, &quot;Ptr&quot;, hDC, &quot;Ptr&quot;)
         hObj := DllCall(&quot;SelectObject&quot;, &quot;Ptr&quot;, hMDC, &quot;Ptr&quot;, hBM, &quot;Ptr&quot;)
         DllCall(&quot;BitBlt&quot;, &quot;Ptr&quot;, hMDC, &quot;Int&quot;, 0, &quot;Int&quot;, 0, &quot;Int&quot;, W, &quot;Int&quot;, H
                         , &quot;Ptr&quot;, hDC, &quot;Int&quot;, X, &quot;Int&quot;, Y, &quot;UInt&quot;, rop)
         DllCall(&quot;SelectObject&quot;, &quot;Ptr&quot;, hMDC, &quot;Ptr&quot;, hObj, &quot;Ptr&quot;)
         DllCall(&quot;DeleteDC&quot;, &quot;Ptr&quot;, hMDC)
         DllCall(&quot;ReleaseDC&quot;, &quot;Ptr&quot;, 0, &quot;Ptr&quot;, hDC)
         Return hBM
      }

      CreateDIBSection(w, h, hDC, ByRef pvBits) {
         VarSetCapacity(BITMAPINFO, 40, 0)
         NumPut(40, BITMAPINFO,  0)
         NumPut( w, BITMAPINFO,  4)
         NumPut(-h, BITMAPINFO,  8)
         NumPut( 1, BITMAPINFO, 12)
         NumPut(32, BITMAPINFO, 14)
         hBM := DllCall(&quot;CreateDIBSection&quot;, &quot;Ptr&quot;, hDC, &quot;Ptr&quot;, &amp;BITMAPINFO, &quot;UInt&quot;, 0
                                          , &quot;PtrP&quot;, pvBits, &quot;Ptr&quot;, 0, &quot;UInt&quot;, 0, &quot;Ptr&quot;)
         return hBM
      }
   }
   
   __Delete() {
      DllCall(&quot;DeleteObject&quot;, &quot;Ptr&quot;, this.hBM)
   }
}</code></pre></div><p>Скриншот здесь берётся один раз, когда выполняется строка:<br /></p><div class="codebox"><pre><code>FastPixel := new FastPixelSearch(0, 0, A_ScreenWidth, A_ScreenHeight)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2022-04-12T18:40:59Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=152755#p152755</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Одновременный поиск нескольких пикселей]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=152754#p152754" />
			<content type="html"><![CDATA[<p>Или сформулирую точнее:<br />как выполнить несколько (в моём случае 25) <em>PixelSearch</em> по одному скриншоту?<br />или иным способом снизить время выполнения нескольких <em>PixelSearch</em> до приемлемых (десятки миллисекунд) величин?</p><p>или, если вы ТОЧНО знаете, что в АНК это невозможно, дайте мне знать, пожалуйста.</p><p>Заодно - то же самое для <em>PixelGetColor</em>.</p>]]></content>
			<author>
				<name><![CDATA[isxodnik]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=41364</uri>
			</author>
			<updated>2022-04-12T03:37:28Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=152754#p152754</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Одновременный поиск нескольких пикселей]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=152708#p152708" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>stealzy пишет:</cite><blockquote><p>Есть функции для замены PixelSearch, которые будут работать в три раза (в данном случае) быстрее. Поищите на форуме, если интересно.</p></blockquote></div><p>Искал <em>PixelSearch одновремен*</em>, не нашёл. По каким словам?</p>]]></content>
			<author>
				<name><![CDATA[isxodnik]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=41364</uri>
			</author>
			<updated>2022-04-06T02:07:39Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=152708#p152708</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Одновременный поиск нескольких пикселей]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=120752#p120752" />
			<content type="html"><![CDATA[<p><strong>stealzy</strong> извините, речь идёт о GDI+ (GDIP)?</p><p><strong>ypppu</strong> спасибо я понял и исправил &quot;это недоразумение&quot;, но при вводе даже второй &quot;переменной&quot; код начинает работать некорректно, я не говорю уже о 3-ей и 4-ой... При попытке найти 2-ой совершенно другой цвет, мышь начинает кликать на все возможные цвета, в чем может быть проблема?</p><p>Приблизительный код: (новый)</p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><div class="codebox"><pre><code>#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.




#Persistent
SetBatchLines, -1  
SetTimer, S1, 0
Pause

*~XButton2::
Loop
	{
S1:
MouseGetPos, xpos, ypos
zX1:=xpos-5,zX2:=xpos+5,zY1:=ypos-5,zY2:=ypos+5
PixelSearch, VarX_1, VarY_1, zX1, zY1, zX2, zY2, 0x000001, 4, Fast RGB
PixelSearch, VarX_2, VarY_2, zX1, zY1, zX2, zY2, 0x000002, 2, Fast RGB

if !ErrorLevel
{
;Sleep, 10
;MouseMove, VarX, VarY
;moveAmount := (moveAmount = 2) ? 3 : 0
;mouseXY(moveAmount,1000)
MouseClick ,, ;	VarX_1, VarY_1,, 0
MouseClick ,, ;	VarX_2, VarY_2,, 0
SetTimer, S1, Off
SetTimer, S2, -50
}
	If !GetKeyState(&quot;XButton2&quot;, &quot;P&quot;)
		         Break
   }
Return
mouseXY(VarX,VarY)
{
DllCall(&quot;mouse_event&quot;,int,1,int,x,int,y,uint,0,uint,0)
}

End::ExitApp 

S2:
SetTimer, S1, On 
Return</code></pre></div></div></div>]]></content>
			<author>
				<name><![CDATA[romzes96]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=38749</uri>
			</author>
			<updated>2017-11-04T09:43:24Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=120752#p120752</id>
		</entry>
</feed>
