public int getpixel (int x,int y) throws awtexception{//function returns the RGB value of the color.
Robot RB = null; The class in the Java.awt.image package can be used to crawl the screen, that is, screenshots.
RB = new Robot ();
Toolkit tk = Toolkit.getdefaulttoolkit (); Get the default toolkit
Dimension di = Tk.getscreensize (); Screen Size Specifications
Rectangle rec = new Rectangle (0,0,di.width,di.height);
BufferedImage bi = rb.createscreencapture (rec);
int pixelcolor = Bi.getrgb (x, y);
return 16777216+pixelcolor; The value of Pixelcolor is negative, after practice: The maximum color value is the actual color value.
}
Another kind
Import Java.awt.image.BufferedImage;
Import Javax.imageio.ImageIO;
Import java.io.*;
public class test{
public static void Main (String args[]) {
int[] RGB = new INT[3];
File File = new file ("A.bmp");
BufferedImage Bi=null;
try{
Bi = imageio.read (file);
}catch (Exception e) {
E.printstacktrace ();
}
int Width=bi.getwidth ();
int Height=bi.getheight ();
int Minx=bi.getminx ();
int Miny=bi.getminy ();
System.out.println ("Width=", "+width+", height= "+height+");
System.out.println ("minx=", "+minx+", miniy= "+miny+");
for (int i=minx;i<width;i++) {
for (int j=miny;jSystem.out.print (Bi.getrgb (JW, IH));
int Pixel=bi.getrgb (i, j);
Rgb[0] = (Pixel & 0xff0000) >> 16;
RGB[1] = (Pixel & 0xff00) >> 8;
RGB[2] = (pixel & 0xff);
System.out.println ("i=" +i+ ", j=" +j+ ":(" +rgb[0]+ "," +rgb[1]+ "," +rgb[2]+ ")");
}
}
}
}