GetPixel() Working but slow, Any other ideas.

BrntPhish

New member
Joined
Dec 23, 2010
Messages
4
Programming Experience
1-3
Basically what i am doing is letting the user select a point on the screen(x,y)

Then i use a Loop to:
get a screenshot of this as a 1 by 1 bitmap.
load it into a picturebox
I then use getpixel on this bmp to get color
Then i check if the green value of the pixel is > 220
if it is i exit my loop
Then i perform what i need to.

The problem is that the pixel changes quickly and i am having to keep re-writing the bitmap image waiting for the change. By the the the pixel has turned green and already changed colors.
I am trying to get the mouse to click, the instant the pixel turns greens, but it has been delayed a bit.

Is there a better way to monitor a pixel on the screen was a faster "reaction time".

I read about getdibits() but since i am getting a new bitmap everytime the pixel is not green, i do not think dibits would help. Also it seemed a little complicated if i was not gonna get a performance gain.


Private Sub MonitorPixel()
Dim xAxis As Integer
Dim yAxis As Integer
Dim bmp As New Bitmap(1, 1, PixelFormat.Format32bppArgb)
Dim gr As Graphics = Graphics.FromImage(bmp)
Dim MyColor As Color = color.black 'Reset Color to non-green color

Do Until MyColor.G > 225
gr.CopyFromScreen(xAxis, yAxis, 0, 0, New Size(2, 2), CopyPixelOperation.SourceCopy)
PictureBox1.Image = bmp
MyColor = bmp.GetPixel(0, 0)
Loop
SetMousePos(xAxis, yAxis)
LeftClick()
End Sub
 
Update

Well i have since removed the un-needed picture box control, it was just there for testing. This project it basically made to monitor a "Meter" from an internet website and click when it reaches the correct position. I have tried monitoring the pixel located 20 pixels before the "correct position". Which has shown some promise, but the problem is since it continously reloads the bmp from the screen, the program reaction to the pixel changing varies with each time it runs. ie ... sometimes the meter moves faster than it does other times.
Then i used a getpixel to monitor 2 different pixels eactly 50 pixels apart 50 pixels from the "correct click" position and used a stopwatch control to see how long it takes for the meter to move 50 pixels from the first to the second pixel(Xdif). Then i used Thread.Sleep(Xdif) to make the program sleep the same amout of time before performing a click. My thinking was that if it takes 150ms for the meter to move 50pixels, then i just monitor a pixel 50px away from where i need the meter, and click (xdif) after it reaches there. The problem is that Thread.sleep(Xdif) does not always "wake up" at the same speed. Sometimes it is 70ms after it is supposed to be and sometimes it wakes 70ms quicker. Is there possibly something to use rather than Thread.sleep() that will pause for a certain number of ms??
 
Update

Well nothing seems to be working consistently. I have tried the Stopwatch and Thread.sleep(). There has to be a different way to continuously monitor the meter progress that is more effecient than getpixel() ... The meter is running inside a flash window if that makes any difference. ANY other ideas would be GREATLY appreciated.
 
Still Too Slow

Here is the code for the PixelMonitoring

VB.NET:
Private Sub btnDingforMe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDingforMe.Click
'Reset Color        
MyColor = Color.Black
'Random Nums   
Dim Xrand As Long
Dim Yrand As Long
'Set Buttons
 btnCalculate.Enabled = False
 btnDingforMe.Enabled = False
 btnEditClubs.Enabled = False
 btnEditCourses.Enabled = False
 btnEditGreenSpeeds.Enabled = False
 btnOpenLog.Enabled = False
 btnSetMark.Enabled = False
 'Get Club TIMING Adjustment since i can't monitor quick enough     
 XclickAdjust = trkDingAdjust.Value + txtDingSpeedOffset.Text
 'Set Pixel To Monitor       
 Xmark = xAxis + XclickAdjust
 'Get Random Nums before starting Loop      
 RandomNumber = RandomClass.Next(-20, -10)
 Xrand = xAxis + RandomNumber
 Yrand = yAxis + RandomNumber
 'Loop to monitor pixel Color Screenshotsize is 1x1
        Do While MyColor.G < 225
            gr.CopyFromScreen(Xmark, yAxis, 0, 0, screenshotsize, CopyPixelOperation.SourceCopy)
            MyColor = bmp.GetPixel(0, 0)
        Loop
'Move Mouse before Clicking to a Random Spot on Screen
SetMousePos(Xrand, Yrand)
 LeftClick()
'Reset Buttons
btnCalculate.Enabled = True
btnDingforMe.Enabled = True
btnEditClubs.Enabled = True
btnEditCourses.Enabled = True
btnEditGreenSpeeds.Enabled = True
btnOpenLog.Enabled = True
btnSetMark.Enabled = True
'Set Focus       
cboClub.Focus()
End Sub

If i converted this to C would it be fast enough then? If so does someone knw where i can convert the WHOLE project including the Designer, cause i am not too snappy with C, C++ or C#

Thanks
..... somebody write something, i am beating my head aginst the wall!!!!

BP
 
Last edited:
i see your trying to find green in a page is this for an triggerbot? if so i already have developed a fully functional trigger bot, soon i will be restructuring the code to create an aimbot with triggerbot version of this if you are interested please let me know.


~programming is a test of skill as in the gaming world, where they test the integrity of the players, we utilize our abilities to the best of our capacity, i happen to be able to code~
 
Back
Top