Trouble finding Color of Pixel

Hello all,
I've put together a program which, should return "Success!" if the color if a pixel is equal to the value supplied in an if statement. The values are exactly the same, retrieved from the same pixel, but still when I run the program, the program returns the "else" statement, "Failure!" Does anyone know what the issue is? I'll post all the code as it is a very short program.
import java.awt.Component;
import java.awt.Graphics;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
* This class demonstrates how to load an Image from an external file
public class Main extends Component {
    Robot robot;
    BufferedImage img;
    public void paint(Graphics g) {
        g.drawImage(img, 0, 0, null);
    public Main() {
          try {
          robot = new Robot();
        } catch (AWTException ex) {
       try {
           img = ImageIO.read(new File("/Users/george/Desktop/strawberry.jpg"));
       } catch (IOException e) {
    Color c = new Color(148, 152, 155);
    public void search(){ 
        System.out.println(c);
        if (robot.getPixelColor(20,20) == c){
            System.out.println("Success!");
        }else{
            System.out.println("Failure!  The Color is:");
            System.out.println(robot.getPixelColor(20,20));
    public static void main(String[] args) {
        JFrame f = new JFrame("Find Pixel");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Main main = new Main();
        f.add(main);
        f.setVisible(true);
        main.search();
}Thanks! Any and all input is great. Also, if you know any good jokes, please share.
--James                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Your code is very confusing. Are you trying to access a pixel of the image or of the screen?
Anyway, the line
if (robot.getPixelColor(20,20) == c){should be
if (robot.getPixelColor(20,20).equals(c)){

Similar Messages

  • How I find color of the pixel on the screen?, How I find color of the pixel on the screen?

    How I find color of the pixel on the screen?, How I find color of the pixel on the screen?

    DigitalColor Meter, in your Applications/Utilities folder.
    Regards.

  • Strange trouble with Color

    I experience strange trouble with Color I can't overcame. I try to export DPX sequences in Color ("manually") without using Final Cut. I navigate in setup room to my folder where the files are stored and after I open that folder there is nothing there at all. I tried different folders as well sometime it opens empty and I have to go back up and open folder again to be able to see the contents. But some folder are never "refresh" always opens empty , but I am 110 present sure there are files in them ( I check in Finder). This starts to happen after 10.5.2 update. I have no idea what to do with this and how to overcame that problem., please help.
    My setup is Mac pro 2x2.66Mhz , 3GB Ram, ATI Radeon X1900 video card, 2 Apple cinema displays.
    Mac OS X 10.5.2, Color 1.0.2
    Thanks!

    Let me see if I understand this...
    What you are attempting to convey is that you are trying to import .dpx files into COLOR directly and that COLOR does not recognize the files.
    My bet would be that there is an issue with the .dpx file format. It may be the way they are written, stored, named, the bit-depth... any number of issues. The fact that they don't show up is COLOR's way of telling you that there is a compatibility problem. My experience is that 10-bit and above is poorly handled at the moment, and is not supported at all by some previous versions of Quicktime and Shake, for example, under Leopard, and not even Tiger .4.11. What I started getting were perfect proxy renditions, but actual rendered material was almost pure noise, except there were shadowy remnants of the original scene.
    Consider yourself lucky that the application stopped you at this point, rather than allow the project to go forward, then corrupt after you had devoted a considerable amount of your time and energy to it, then have to go back to fix the original files and do ti all over again, or struggle with reconform, etc.
    jPo

  • Image Capture and Preview have trouble finding scanner. Photoshop no problem.

    Image Capture and Preview have trouble finding the scanner wirelessly unless it is on when the Mac starts up. Photoshop finds the scanner no problem. Any suggestions for Image Capture or Preview?
    The scanner is Canon MP620. Mac is MBP, running 10.8.2
    I have done all the uninstall, reinstall, update drivers, etc. Please don't bother suggesting that stuff.
    Thanks.

    As for the scanner - so is this new one wireless? When I hooked up my Epson All-in-One, I had to install it via USB first before I could install the wireless (per their instructions).  With Snow Leopard, I simply installed the driver and it covered and recognized both the print and scan function - not so in Lion; I had to go through hoops with the scanner part and it finally showed up as a separate unit. I thought that is silly, but - as long as it works.....  I'm trying to think of possibilities since I'm about out of ideas, so you might want to consider that (if it applies). The other troubleshooting suggestions usually include redoing the "add" function after a reboot.
    As for Image Capture, I am out of ideas. FWIW, I never use it - in my workflow, there is no need for it. Not sure if this would have an impact, but make sure that you choose Image Capture in the CDs&DVDs Preference Pane (mine is set to ignore or ask purposely):
    If that does not work, I'd suggest reinstalling the OS over the top of what you have.

  • I'm having trouble finding twisted-web

    I am running x86_64 and trying to install the twisted-web package and I am having some trouble finding it.
    I used the package search on the archlinux.org main page and I found a  match, but when I try pacman -Sy twisted-web I get "error: 'twisted-web': not found in sync db".
    I noticed that it is supposed to be in the extra repository so I checked my pacman.conf and "Extra" is properly configured (and I have installed packages from it before).
    I checked the PKGBUILD that was online and it supports x86_64, I then checked my abs directory to see if the PKGBUILD was there (under my /var/abs/extra/network directory) and I found "twisted" but no "twisted-web".
    I also searched AUR for twisted-web and came up with nothing, and I assume this is because it is already in the extra repository.
    I am new to Arch and I cannot think of anything else to do.  My only other thought is that the package page says "out-of-date" so maybe it has been removed from the extra repository or something along those lines, but that seems like a strange thing to do.
    Anyway I really like arch and I have looked at several PKGBUILD's already so if its just a matter of making a build for a new version that would be no problem for me to do (and submit it to AUR or a maintainer) I just need a little guidance.  Chances are I'm just inexperienced and missing something really obvious.
    Thanks for reading
    -pilo

    Thanks thats really helpful, what confused me was that when I searched for twisted-web from the main page then clicked -> view cvs entries -> pkgbuild -> view, the PKGBUILD there had "arch=(i686 x86_64)" so I thought I should be able to install it.
    Im realatively experienced at compiling programs and programming myself so I will take a stab at getting it to compile myself and submit a new PKGBUILD if I get it working.
    Thanks a lot for your help, im really liking arch.

  • Trouble with color on Presario, No red tones on display. Not a monitor issue.

    Am experiencing trouble with color on Presario, model no. CQ5500F. Purchased a couple of years ago, and trouble was present immediately. Am getting no red tones - red items appear black or sometimes blue. Was told by HP that it was a monitor issue, and let computer slide out of warranty. installed new monitor today and problem still exists. Is this merely a display adjustment of some kind? Or will I have to pay HP their $99 for a one time fix? Any suggestions appreciated.

    Hello UncleBob62,
    It could be the display driver that is not properly working
    1. Click on the start icon
    2. Right click on computer and go to properties
    3. Select Device Manager
    4. Expand display adapters and right click on the video card driver and uninstall
    The computer screen will go blank
    On the keyboard press the windows key the right arrow key twice and then the letter R.
    At this point your computer is going to reboot. After the reboot Windows will install generic drivers for your video card. Do you still see a lack of red tones?
    If I have helped you in any way click the Kudos button to say Thanks.
    The community works together, click Accept as Solution on the post that solves your issue for other members of the community to benefit from the solution.
    - Friendship is magical.

  • JS/CS3 hyperlinks trouble: finding a hyperlinkTextDestination

    I'm having trouble finding a hyperlinkTextDestination in a document.
    According to the reference I should be able to refer to a hyperlinkTextDestination by using:
    myDocument.hyperlinkTextDestinations.item(myLabel);
    This statement returns an invalid object.
    I also tried to iterate through the collection of hyperlinkTextDestinations to find the item with my label. Like so:
    for(i = 0; i < myDocument.hyperlinkTextDestinations.length; i++)
    if(myDocument.hyperlinkTextDestinations[i].label == myLabel)
    myDestination = myDocument.hyperlinkTextDestinations[i];
    This is not working either. I did set a label to the hyperlinkTextDestination. When this label is encountered myDocument.hyperlinkTextDestinations[i].label == myLabel evaluates to false!
    How to solve this problem?
    Grtn, Kees

    Hi KvD
    For hyperlink destination you should provide a string (i.e word or character or insertion point) not a frame. After getting the frame label you have to catch textframe's text then add any one of the above said string. May be this will help you.
    Regards
    priyan

  • I'm having trouble finding firefox sync on my desktop and to download to my ipad2 for schoolwork!

    I'm having trouble finding firefox sync on my desktop AND getting it over to my ipad2. I've been through all the support and still can't find it. Please help! I need it for my schoolwork!

        Mam129, I rely on email to stay connected with family and friends so I know how important it is to be able view them on my phone. But don’t worry because I’m here to help.
    Are you still unable to set up your email? A fix for the issue has recently been implemented. Please try setting up the email again and keep me posted if you have any issues.
    John B
    Follow us on Twitter @VZWSupport.

  • Can't find color tab in speedgrade

    Can't find color tab in speedgrade

    Working with CS6? There it is still called Monitor and you'll find it to de left. Or you can use the shortcut D (once or twice depending where you start form).

  • Please Help Get a Color from Pixel !!!!

    Is anybody know how to get a Color from pixel.
    My program is not Full Screen .
    So i think Robot.getPixelColor() don't suitable.
    Please Help me!

    Robot.getPixelColor() will work fine, but the problem you will have is getting the mouse set to the correct location and getting your application to know where it is: you can do it with win32 calls and JNI. Here are a few that I have found helpful--they are in a VB format:
    Public Const CLR_INVALID = &HFFFF 'not a valid pixel
    Public Const MOUSE_MOVED = &H1
    Public Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move
    Public Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
    Public Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
    Public Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down
    Public Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up
    Public Const REQUEST_LEFT_CLICK = &H2D 'request left click "-"
    Public Const REQUEST_RIGHT_CLICK = &H2B 'request right click "+"
    Type POINTAPI
    x As Long
    y As Long
    End Type
    Type POINTSTRUCT
    hwnd As Long
    hdc As Long
    ptAbsolute As POINTAPI
    ptOrigin As POINTAPI
    ptLocal As POINTAPI
    ptColor As Long
    sType As String
    retMessage As Boolean
    End Type
    Declare Function GetCursorPos _
    Lib "user32" (ByRef lpPoint As POINTAPI) _
    As Long
    Declare Function SetCursorPos _
    Lib "user32" (ByVal x As Long, ByVal y As Long) _
    As Long
    Declare Sub mouse_event _
    Lib "user32" (ByVal dwFlags As Long, _
    ByVal dx As Long, _
    ByVal dy As Long, _
    ByVal cButtons As Long, _
    ByVal dwExtraInfo As Long)
    Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Declare Function GetMessageExtraInfo Lib "user32" () As Long
    Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, _
    ByVal x As Long, _
    ByVal y As Long) As Long
    Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, _
    ByVal yPoint As Long) As Long
    Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
    Declare Function GetWindowOrgEx Lib "gdi32" (ByVal hdc As Long, _
    ByRef lpPoint As POINTAPI) As Long

  • I want a soundbar for my 6th generation nano but am having trouble finding a compatible device. I'd like more than a dock, ideally a soundbar with wireless subwoofer. I'll only use the soundbar for music, not TV home theater. Any suggestions?

    I want a soundbar for my 6th generation nano but am having trouble finding a compatible device. I'd like more than a dock, ideally a soundbar with wireless subwoofer. I'll only use the soundbar for music, not TV home theater. Any suggestions? Thanks.

    Google

  • I'm having trouble finding the HEALTH magazine app for my iPad.  The mag insists that it has a free app.  Help!!

    I'm having trouble finding the HEALTH magazine app for my iPad.  The mag insists that it has a free app.  Help!!

    What country are you in ? Is this the app : Health magazine ?

  • I'm having trouble finding carton hd on the app store

    I'm having trouble finding carton hd on the App Store

    Just a guess, are you looking for this:
    https://itunes.apple.com/us/app/cartoon-h.d-wallpapers/id535109714?mt=8

  • Adobe Photoshop CC, problem with color noise/pixelation on the monitor display

    After downloading Adobe Photoshop CC, my images come in with color noise/pixelation on the monitor display. I've tried checking the color space preferences, but this doesn't help. I didn't have this problem before. Is there anything else I can check? There's no problem with LR, just Photoshop.

    My performance settings are: Available RAM 10905 MB/using 7633 MG (70 percent); cache levels 4, history 20, cache tile size 1024K. However, I noticed under Graphics processer settings, it is set on Advanced Drawing Mode - perhaps this should be changed to Normal or Basic Mode? Your help is very much appreciated.

  • I have Final Cut Pro X (10.0.9) and would like to change my project settings but I am having trouble finding the 'Modify Settings button.'  Where exactly is it located?

    I have Final Cut Pro X (10.0.9) and would like to change my project settings but I am having trouble finding the 'Modify Settings button.'  Where exactly is it located?  Here is the link which gives the instructions but doesn't seem to say where the 'Modify Settings Button' is located: http://support.apple.com/kb/PH12526?viewlocale=en_US

    You have to choose – one settigf or another.
    The thing is.your HD clips will look better in an SD project than your SD clips will in an HD project.
    WIthout knowing much more about your project and the kind of content, it's really hard to be specific. But generally I'd let my project settings be guided by what fraction of my timeline will be made up of HD clips and how much SD clips. If it's 75% HD, I'd probably do an HD project…and so on,
    Good luck.
    Russ

Maybe you are looking for

  • Problem with multiple XP accounts since installing new version of iTunes/QT

    I am running XP Pro. A year or so ago, I went through the "disaster" recovery of installing the new version of iTunes (5.0) along with its nasty QT upgrade that was not ready for prime time. After much thrashing, I got my computer back to iTunes 4.9.

  • Videos not playing in photoshop organizer

    I have Premier Elements and Photoshop Elements. The videos in Pemier Elements play ok and when I click on them Windows Media Player plays them ok, but the Organizer in Photoshop says I don't have the right decompression software to display them. Has

  • Slowdown w CF 7.02 and kvoop.exe with K2Indexing

    If anyone can offer some insight on this, we are a mid size business that runs CF apps for our websites. We have recently had our servers slowed to a halt when performing functions like mailing list sending via CFmail tags and the like. What we notic

  • Z10 Version 10.1.0.418​1 not able to update anymore

    So my original Z10 has version 10.1.0.4181 and i got a replace phone with 10.1.0.273 and it will not update as it states it is up to date...... I am with rogers and i need this to be upgraded so i can transfer over my data from the previous phone.

  • JNI_CreateJavaVM and IPV6

    Hi all, I met the error on Linux. Here is the scenario: My C-code will create a JVM, it find method from a Java Class to execute. My Java Class create a DatagramSocket with ipv6 address, but it throw a exception:"Exception creating server socket: jav