0

How can detect if a picture contains a specific RGB integer color (NOT regular RGB value) in vb.net? I found this code online that lets you detect if a specific color is present in a picture using a regular RGB value, and it works fine.

ColorInBitmap("c:\test.jpg", Color.FromArgb(109, 109, 109))

I want to not have to use a standard RGB value but instead use a RGB integer (like 111041888 for blue) without having to use standard rgb values.

I want to use this code in determining if a picture contains a range of colors (like from 177 to 18687 [dark red to orange]. Is there any way I can do this?

BLINKOR
  • 31
  • 1
  • 9
  • 2
    You will need the standard RGB, but you can use [ColorTranslator.ToWin32](https://learn.microsoft.com/en-us/dotnet/api/system.drawing.colortranslator.towin32?view=netframework-4.8) to convert it to an integer value. – LarsTech Jan 13 '20 at 23:37
  • Will that still let me be able to detect a color within a specific color range? (like from 177 to 18687)? – BLINKOR Jan 13 '20 at 23:42
  • 1
    Yes, you can use the FromWin32 to pass an integer to get the color, use that value in your code. – LarsTech Jan 13 '20 at 23:47
  • See the notes here: [Analyze colors of an Image](https://stackoverflow.com/a/59102380/7444103), they may come in handy. You can get the current Color as an Int32 value with `dim rgb32 as integer = red Or (green << 8) Or (blue << 16)` (same as `ColorTranslator.ToWin32()`, but one less function call per iteration) . – Jimi Jan 14 '20 at 00:18
  • You have just to translate the RGB integer into RGB values or wise versa, if you want to use the existing function. Otherwise you can write the function by yourown and multithread it on top of it. – Horitsu Jan 14 '20 at 05:16
  • The problem is that I want to be able to detect a range of colors, not a single one. (Like all colors between red to green). Do I have to manually translate each value? – BLINKOR Jan 14 '20 at 05:35
  • If you want to detect colours, you probably need to use the HSL model instead of RGB. Note 1: [Does the .Net Color struct use an HSB or HSL colour space?](https://stackoverflow.com/a/24733512/1115360). Note 2: hues of 359 and 1 are as close together as hues of 1 and 3. – Andrew Morton Jan 14 '20 at 09:45

0 Answers0