Hey coders out there, I am in need of a little help today! I am trying to find a program and or create one I guess (If I know how) that will allow me to record continously an application window of a program running on my computer and check to see if a color shows up in the designated region I have selected for that current program.
I guess this is how I want it to run:
1: Select region of a program that is open and set it
2: that region is monitored by my application and constantly checks to see if a certain ‘color’ RBG comes up
3: If that color I have selected happens to pop up on that screen then it plays a sound from a folder on the computer through my speakers
I want the program to monitor a certain portion of an application running behind all my other windows really rather than it monitoring a single pixel on my screen.
Please note that the program running in the background will not be changing in window size nor will it move if that makes it any easier. The spot im recording will stay within the same pixel box if that makes sense…
Essentially, you’d like a program that monitors a portion of your screen and if a certain color (as in a single pixel) appears anywhere in that monitored portion, than the program will play some predetermined sound, yes?
I’m just trying to make sure I understand what you’d like.
Ahh, but will the specific program that it’s monitoring be the top most window? Or is that specific program going to be behind other windows occasionally?
That’ll let you take a screenshot of a given window - even if it’s minimized (use Google to figure out how to call it).
If you go that route, you’ll have to call the function in a loop and risk missing some color changes (the ones that happen in-between the screenshot calls). If you need something near real-time, you’ll have to do some low-level hooking into the GDI library to detect when a window redraws itself. But even then you won’t be able to detect every change.
The time just needs to be within a second or two so real time checking isnt a problem… I guess ill have to research more haha… How would i call to check for a color in a specific region of a printwindow picture then?
So I’m guessing my coding process should look like this somewhat
1: use printwindow to capture window
2: Check the captured window to see if my color is being projected in the region
3: a: if yes, play sound
b: if no, repeat loop
That’s about all you have to do. You just have to find the region in the returned bitmap that you’re monitoring. The returned image should be an array of RGB color values (not 100% sure of this).
So I was able to get it to work up to a certain point. Now ill need a little guidance again as google couldn’t help.
I have the image in a picturebox (exactly what I wanted) when I load my program… Sadly, I want to be able to find a specific color inside that picturebox but I cannot figure out a way to do that.
I currently have been messing around with this:
'Picture is on the picturebox. Now we need to FIND the specific color we are looking for......
Dim bmp As New Bitmap(PictureBox1.Image)
Dim b(bmp.Width * bmp.Height - 1) As Integer
Dim bd As BitmapData = bmp.LockBits(New Rectangle(Point.Empty, bmp.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb)
Marshal.Copy(bd.Scan0, b, 0, b.Length)
bmp.UnlockBits(bd)
'This is where we check each pixel to see if it's yellow.
Dim x As Integer = -1, y As Integer = -1
For i As Integer = 0 To b.Length - 1
If b(i) = Color.Yellow.ToArgb Then
x = i Mod bmp.Width
y = i \ bmp.Width
Exit For
End If
Next
bmp.Dispose()
'Display the results.
If x > -1 Then
MessageBox.Show("Found the yellow.")
Else
MessageBox.Show("No yellow found.")
End If
Notice how it’s searching for a specific COLOR as in Color.Yellow… I either need it to search for an RGB or a hexadecimal color, not a generic one. How would I go about doing this? Ive been looking all over and cannot find any ways to fix this.