Results 1 to 5 of 5

Thread: How to get the colour of a screen pixel in java?

  1. #1
    Join Date
    Nov 2009
    Posts
    57

    How to get the colour of a screen pixel in java?

    Hello to all,
    I am last year B.Sc.I.T. student. In our last lecture our sir asked one question like How to get the color of a screen pixel in java? None of use able to give right answer. Can anyone tell me how to get the color of a screen pixel using java program? Please help me.
    Thank you.
    Last edited by Linoo; 03-02-2010 at 06:50 PM.

  2. #2
    Join Date
    Nov 2005
    Posts
    1,323

    Re: How to get the colour of a screen pixel in java?

    The following program shows how to get the color of a pixel in the screen. It is very simple program. You have to just use Robot.getPixelColor() method to do this. You have to just provide two variable to it for doing this. Just try to understand it.



    Code:
    package in.java.example.awt;
    
    import java.awt.Color;
    import java.awt.Robot;
    import java.awt.AWTException;
    
    public class ColorPickerEg {
        public static void main(String[] args) {
            try {
                Robot robos = new Robot();
    
                
                Color color = robos.getPixelColor(30, 30);
    
                
                System.out.println("Yellow   = " + color.getYellow());
                System.out.println("Green = " + color.getGreen());
                System.out.println("Red  = " + color.getRed());
    
            } catch (AWTException e) {
                e.printStackTrace();
            }
        }
    }

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: How to get the colour of a screen pixel in java?

    You have to use following code in your project to get the colour of a screen pixel. You have to use jsp code to do this. You have to first assign string text of javascripts to string and then you have to use this code in your project.


    Code:
    <script types="texts/javascripts">
    
    if (screens.colorDepths<=8) 
     documents.bodys.styles.backgrounds="#040FF00" 
    else
     documents.bodys.styless.background="#E7F8E564D" s
    
    </script>

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: How to get the colour of a screen pixel in java?

    It is very easy process to get the colour of a screen pixel using java program. You have to just use following program in your project to do this. In following program I have use pixelEG class to define robot class. After this I have assign different color to it. Just try to understand each line.


    Code:
    import java.awt.Color;
    import java.awt.Robot;
    
    public class pixelEG {
      public static void main(String[] args) throws Exception{
        Robot robows = new Robot();
    
        Color color = robot.getPixelColor(20, 20);
    
        System.out.println("evergreen   = " + color.getRed());
        System.out.println("Greenmasala = " + color.getGreen());
        System.out.println("Bluewine  = " + color.getBlue());
      }
    }

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to get the colour of a screen pixel in java?

    Hey as per my information I don't think javascript/vbscript have such type of feature. You are not able to get the color of a screen pixel using java program. Such type of feature is only available in C/C++. In this case try to write code in c language or c++ language to get the color of a screen pixel.
    I hope my suggestion will help you.

Similar Threads

  1. Replies: 5
    Last Post: 26-11-2011, 02:28 PM
  2. Dead pixel on LED screen
    By Iason in forum Monitor & Video Cards
    Replies: 7
    Last Post: 17-05-2011, 10:05 PM
  3. how to change white background screen to other colour?
    By abhi123tri in forum Customize Desktop
    Replies: 3
    Last Post: 12-06-2010, 07:21 PM
  4. Fix A Stuck Pixel On Your Screen
    By ChrisUlrich in forum Tips & Tweaks
    Replies: 2
    Last Post: 12-03-2009, 09:11 AM
  5. Defective pixel on a flat screen
    By jesse in forum Tips & Tweaks
    Replies: 2
    Last Post: 26-12-2008, 01:18 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,522,328.73932 seconds with 17 queries