Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I'm having issues with my bejeweled bot picking up colors from my timer which is connected to a picturebox which is allowing me to select the rectangle based on the games location with the following code;
VB
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles tmrRecognizeColors.Tick
        Dim graph As Graphics
        screenshot = New System.Drawing.Bitmap(rect.Width, rect.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
        graph = Graphics.FromImage(screenshot)
        graph.CopyFromScreen(rect.X, rect.Y, 0, 0, rect.Size, CopyPixelOperation.SourceCopy)
        PictureBox1.Image = screenshot

        Dim x, y As Integer
        For x = 20 To 300 Step 40
            For y = 30 To 310 Step 40

                Dim c As Color = screenshot.GetPixel(x, y)

                If c.R > 250 And c.G < 5 And c.B < 30 Then
                    'color is red
                    Grid((((x - 20) / 40) + 1), (((y - 30) / 40) + 1)) = Color.Red
                    NumGrid((((x - 20) / 40) + 1), (((y - 30) / 40) + 1)) = 1


Then problem i'm having is that the colors are for a different game, and it's not detecting the read properly.

The actual color for red is red: 236,Green: 133, Blue: 110 but i've tried changing this and it still isn't working based on the use of either '> or <' and i've tried using for example;

VB
If c.R = "236" And c.G = "133" And c.B = "110" Then
                    'color is red
                    Grid((((x - 20) / 40) + 1), (((y - 30) / 40) + 1)) = Color.Red
                    NumGrid((((x - 20) / 40) + 1), (((y - 30) / 40) + 1)) = 1


But it isn't successful.

Any idea how i can overcome this issue?

What I have tried:

Changing the values based on the rgb color in the game i'm using.
Posted
Comments
F-ES Sitecore 17-May-17 10:58am    
try and remove the quotes, c.R=236 etc. If that doesn't work then the colour values are not what you think they are. Debug your code to find the actual values.
caf20012 17-May-17 11:07am    
For example you mean: If c.R = 236 And c.G = 133 And c.B = 30 Then
F-ES Sitecore 17-May-17 11:09am    
Yes.
caf20012 17-May-17 11:21am    
Isn't working. No colours are showing in Picolours which is a picturebox.
Ralf Meier 19-May-17 1:47am    
In your code-line you compare a value with a string - that can't be successful !!!
It must be : 'If (c.R = 236) And (c.G = 133) And (c.B = 110) Then '
Are you sure with the values ...?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900