Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: returning color of pixel in loop

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    13
    My Mood
    Relaxed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default returning color of pixel in loop

    Hello everyone!

    Ok, here is part of my code:
                        Color c = robot.getPixelColor(663, 60);
                        Color red_Battle = new Color(231,50,42);
     
                        if(c.getRGB() == red_Battle.getRGB()){
     
                            Color end2 = robot.getPixelColor(6, 538);
                            Color zero = new Color(5,5,0);
                            while(end2.getBlue() == zero.getBlue()){
     
                                Color spd = robot.getPixelColor(72, 572);
                                Color nula = new Color(63,61,41);
     
                                if(spd.getRGB() == nula.getRGB()){
                                    r.delay(50);
                                    r.keyPress(KeyEvent.VK_F);
                                    r.delay(50);
                                    r.keyRelease(KeyEvent.VK_F);
                                    r.delay(50);
                                    r.keyPress(KeyEvent.VK_F);
                                    r.delay(50);
                                    r.keyRelease(KeyEvent.VK_F);
                                    r.delay(50);
                                    r.keyPress(KeyEvent.VK_F);
                                    r.delay(50);
                                    r.keyRelease(KeyEvent.VK_F);
                                    r.delay(800);
                                    r.keyPress(KeyEvent.VK_A);
                                    r.delay(1000);
                                    r.keyRelease(KeyEvent.VK_F);
                                    r.delay(50);
                                    r.keyRelease(KeyEvent.VK_A);
                                    r.delay(50);
                                    r.keyPress(KeyEvent.VK_R);
                                    r.delay(50);
                                    r.keyRelease(KeyEvent.VK_R);
                                    r.delay(50);
                                    r.keyPress(KeyEvent.VK_R);
                                    r.delay(50);
                                    r.keyRelease(KeyEvent.VK_R);
                                    r.delay(1000);
                                    System.out.println("Speed 0 km/h.");
                                }
                                 end2 = robot.getPixelColor(6, 538);
                             }
                        }

    First color returning in statement IF is working fine.
    Second color returning in statement While is working properly too.
    But third not - statement IF is not running when pixel on 72x752 has the same RGB value as variable 'nula' (63,61,41).

    I really can't find where is the problem


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: returning color of pixel in loop

    Try debugging your code by adding some printlns to show the values of all the variables as they are set and tested.
    For example assign the values returned by the get methods to variables and print their values before testing them in the if statement. The print out will show you the values that the program is seeing and using and should help you understand what the program is doing.

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    13
    My Mood
    Relaxed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: returning color of pixel in loop

    Thank you, it helped me. I used

    System.out.println("Value of color is "+ spd);

    and it gave me different value of color. I tried to use them and now it is working fine.

    So far I was using PrintScreen button to take a photo of my screen and then Photoshop to find out coordinates and color of exact pixel.
    Until now I didn't have a problem with that.

Similar Threads

  1. Returning to a loop after showConfirmDialog.
    By qrts in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 5th, 2011, 07:01 AM
  2. Trying to show change on Image based on pixel values
    By javaGurl in forum Algorithms & Recursion
    Replies: 1
    Last Post: September 20th, 2011, 03:49 PM
  3. text color changer based on words/ word classification by color
    By knoxy5467 in forum Java Theory & Questions
    Replies: 25
    Last Post: June 15th, 2011, 07:52 AM
  4. Setting individual sRGB pixel values on BufferedImages
    By nitrogenFingers in forum AWT / Java Swing
    Replies: 2
    Last Post: February 11th, 2011, 10:27 AM
  5. Get Pixel
    By Ophe in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 27th, 2011, 04:24 PM