PixelSearch

指定された色のピクセルを画面上の領域で検索します。

PixelSearch &OutputVarX, &OutputVarY, X1, Y1, X2, Y2, ColorID , Variation

パラメータ

&OutputVarX, &OutputVarY

型:VarRef

ColorIDに一致する最初のピクセルの X 座標と Y 座標を格納する出力変数への参照(一致しない場合、変数は空白にされます)。Coordinates are relative to the active window's client area unless CoordMode was used to change that.

X1, Y1

型:整数

検索する矩形の開始角のX、Y座標。Coordinates are relative to the active window's client area unless CoordMode was used to change that.

X2, Y2

型:整数

検索する矩形の終了角のX、Y座標。Coordinates are relative to the active window's client area unless CoordMode was used to change that.

ColorID

型:整数

検索するカラーIDを指定します。This is typically expressed as a hexadecimal number in Red-Green-Blue (RGB) format. 事例:0x9d6346. カラーIDは、Window Spy(トレイメニューからアクセス可能)またはPixelGetColorを使用して決定することができます。

Variation

型:整数

省略された場合、デフォルトは 0 です。Otherwise, specify a number between 0 and 255 (inclusive) to indicate the allowed number of shades of variation in either direction for the intensity of the red, green, and blue components of the color. For example, if 2 is specified and ColorID is 0x444444, any color from 0x424242 to 0x464646 will be considered a match. このパラメータは、求める色が常に全く同じ色合いでない場合に有効です。255色のバリエーションを指定した場合、すべての色が一致します。

戻り値

型:整数(ブーリアン)

この関数は、指定された領域で色が見つかった場合は 1(真)を、見つからなかった場合は 0(偽)を返します。

エラー処理

関数が検索を行うことを妨げる問題があった場合、OSErrorがスローされる。

備考

検索する領域は可視でなければなりません。言い換えれば、ウィンドウが他のウィンドウの後ろに隠れている領域を検索することは不可能です。一方、マウスカーソルの下にある画素は、通常、検出することができます。The exception to this is game cursors, which in most cases will obstruct any pixels beneath them.

Although color depths as low as 8-bit (256-color) are supported, PixelSearch performs much better in 24-bit or 32-bit color.

X1Y1で指定された座標から検索を開始し、X1からX2までの行のすべてのピクセルが一致するかどうかをチェックします。そこで一致する画素が見つからなければ、一致する画素が見つかるまで、Y2に向かって1行ずつ検索を続けます。

検索順序は、パラメータの順序に依存します。つまり、X1X2より大きい場合、X1列目から右から左へ検索を行うことになる。同様に、Y1Y2より大きい場合は、下から上に向かって検索を行うことになります。

検索する領域が大きく、高い頻度で検索を繰り返す場合、CPU時間を多く消費する可能性があります。これを緩和するために、面積を最小限に抑えます。

PixelGetColor, ImageSearch, CoordMode, MouseGetPos

Searches a region of the active window for a pixel and stores in Px and Py the X and Y coordinates of the first pixel that matches the specified color with 3 shades of variation.

if PixelSearch(&Px, &Py, 200, 200, 300, 300, 0x9d6346, 3)
    MsgBox "A color within 3 shades of variation was found at X" Px " Y" Py
else
    MsgBox "That color was not found in the specified region."