1

I am not sure if this is possible as I have been looking for a few hours and cant find what I am looking for.

What i am doing is taking a color from a game panel which is semi translucent so the color which I am taking is always subtly changing. What is need is a way to check if it is +/- 10 or so shades of my desired color.

Something like If color1 is +/-10 of 0x?

I have tried using the image search to do similar but that didn't work.

Any help would be greatly appreciated

bgmCoder
  • 6,205
  • 8
  • 58
  • 105
user2443215
  • 11
  • 1
  • 2

2 Answers2

5

In addition to Robert's answer, you can compare the colors mathematically.

First start by separating the Red, Green, and Blue values.

ToRGB(color) {
    return { "r": (color >> 16) & 0xFF, "g": (color >> 8) & 0xFF, "b": color & 0xFF }
}

Then we need a function that compares the colors. Each of thee variables holds a number representing the difference in the two color values. For example if red is 255 in c1, and 200 in c2, rdiff will be 55. We use Abs so that we don't end up with -55 when c2 has a higher value. Then we make sure the difference for each of these is less than our vary.

Compare(c1, c2, vary=20) {
    rdiff := Abs( c1.r - c2.r )
    gdiff := Abs( c1.g - c2.g )
    bdiff := Abs( c1.b - c2.b )

    return rdiff <= vary && gdiff <= vary && bdiff <= vary
}

Here's how it can be used. We take some numbers, and then compare them to each other with the default vary of 20.

light_pink := ToRGB(0xFFAAFF)
darker_pink := ToRGB(0xFAACEF)
purple := ToRGB(0xAA00FF)


MsgBox % Compare(light_pink, dark_pink) ; True
MsgBox % Compare(light_pink, purple) ; False
Petrucio
  • 5,491
  • 1
  • 34
  • 33
Brigand
  • 84,529
  • 20
  • 165
  • 173
0

I assume that your read about the limitations of PixelGetColor: Known limitations:

"A window that is partially transparent or that has one of its colors marked invisible (TransColor) typically yields colors for the window behind itself rather than its own. PixelGetColor might not produce accurate results for certain applications. If this occurs, try specifying the word Alt or Slow in the last parameter."

When using ImageSearch, you can specify the Delta of the colours. Example:

ImageSearch, FoundX, FoundY, %SearchRangeLeft%, %SearchRangeTop%, %SearchRangeRight%, %SearchRangeBottom%, *20 %ImageFile%  

Here the *20 indicates the variation in the range from 0 to 255 of my search colour. When searching for a pixel inside the image of 100,100,100 (RGB), it will match anything between 80,80,80 and 120,120,120. Hope this helps, but matching transparent colours is difficult and prone to errors. The smaller the image and search range the better (and faster)

Robert Ilbrink
  • 7,738
  • 2
  • 22
  • 32