Hi All,
I was wondering if anyone knew a good way to detect a change in a pixel.
i.e. I have code that uses bitblt to capture a pixel on the screen as follows:
and what ive been doing is simply putting this in a while loop and passing it the color of the pixel im looking for it to change too and waiting for it to return true.
It seems there should be a smoother/easier way that would be easier on resources ?
any thoughts/ideas would be great
also any advise on memory management/clean up techniques in vb.net would ge great (i know c# is better for this, but the app is in vb.net)
thanks
I was wondering if anyone knew a good way to detect a change in a pixel.
i.e. I have code that uses bitblt to capture a pixel on the screen as follows:
Code:
Public Function checkPixel(ByVal X As Integer, ByVal Y As Integer, ByVal col() As Color, ByVal errRange As Integer) As Boolean
Dim imgPixel As Image
Dim bmpPixel As Bitmap
Dim gr As Graphics
Dim dcDest As IntPtr, dcSource As IntPtr
Dim i As Integer, j As Integer
initialize image
imgPixel = New Bitmap(1, 1)
get handle to new image
gr = Graphics.FromImage(imgPixel)
dcDest = gr.GetHdc()
get handle to desktop
dcSource = GetWindowDC(GetDesktopWindow())
copy pixel to image
BitBlt(dcDest, 0, 0, 1, 1, dcSource, X, Y, SRCCOPY)
release handle
gr.ReleaseHdc(dcDest)
process image
bmpPixel = New Bitmap(imgPixel)
Check all colors in array
For i = 0 To UBound(col)
If isColorEqual(bmpPixel.GetPixel(0, 0), col(i), errRange) Then
bmpPixel = Nothing
System.GC.Collect()
checkPixel = True
Exit Function
End If
Next
bmpPixel = Nothing
System.GC.Collect()
checkPixel = False
End Function
and what ive been doing is simply putting this in a while loop and passing it the color of the pixel im looking for it to change too and waiting for it to return true.
It seems there should be a smoother/easier way that would be easier on resources ?
any thoughts/ideas would be great
also any advise on memory management/clean up techniques in vb.net would ge great (i know c# is better for this, but the app is in vb.net)
thanks