import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
public class GetPixel {
public PixelMadness() {
ImageHolder holder = new ImageHolder();
JFrame frame = new JFrame();
JPanel panel = new JPanel();
panel.add(holder);
frame.getContentPane().add(panel);
frame.setSize(400,400);
frame.setVisible(true);
}
public static void main(String[] args) {
GetPixel getpixel = new GetPixel();
}
}
class ImageHolder extends Canvas {
ImageIcon icon = new ImageIcon( "zx2.jpg ");
Image image = icon.getImage();
int imageWidth = image.getWidth(this);
int imageHeight = image.getHeight(this);
int[] pixelArray = new int[imageWidth * imageHeight];
PixelGrabber grabber = new PixelGrabber(image,0,0,imageWidth,imageHeight,pixelArray,0,imageWidth);
public ImageHolder() {
try { grabber.grabPixels(); }
catch(InterruptedException ie){
System.out.println( "Pixel array not completed ");
return;
}
addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent me){
int mouseX = (int)me.getPoint().getX();
int mouseY =(int) me.getPoint().getY();
int pixel = pixelArray[(mouseY * imageWidth) + mouseX];
getPixel(pixel);
}
});
setSize(imageWidth,imageHeight);
}
public void paint(Graphics g){
int xCenter = (getSize().width / 2) - (imageWidth / 2);
int yCenter = (getSize().height / 2) - (imageHeight / 2);
g.drawImage(image, xCenter, yCenter, imageWidth, imageHeight, this);
}
public void getPixel(int pixel){
int alpha = (pixel > > 24)&0xff;
int red = (pixel > > 16)&0xff;
int green = (pixel > >
&0xff;
int blue = (pixel)&0xff;
System.out.println( "( "+alpha+ ", "+red+ ", "+green+ ", "+blue+ ") ");
}
}
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
public class GetRectPixel {
public GetRectPixel() {
ImageHolder holder = new ImageHolder();
JFrame frame = new JFrame();
JPanel panel = new JPanel();
panel.add(holder);
frame.getContentPane().add(panel);
frame.setSize(400,400);
frame.setVisible(true);
}
public static void main(String[] args) {
GetPixel getpixel = new GetPixel();
}
}
class ImageHolder extends Canvas{
BufferedImage bi ;
Image image;
MediaTracker mt ;
int imageWidth;
int imageHeight;
public ImageHolder() {
mt =new MediaTracker(this);
try{
image = Toolkit.getDefaultToolkit().createImage( "gigi3.jpg ");
mt.addImage(image,0);
mt.waitForAll();
imageWidth = image.getWidth(this);
imageHeight = image.getHeight(this);
}
catch(Exception e){}
bi = new BufferedImage(imageWidth,imageHeight,BufferedImage.TYPE_INT_RGB);
addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent me){
int mouseX = (int)me.getPoint().getX();
int mouseY =(int) me.getPoint().getY();
getPixel(mouseX,mouseY);
}
});
setSize(imageWidth,imageHeight);
}
public void paint(Graphics g){
int xCenter = (getSize().width / 2) - (imageWidth / 2);
int yCenter = (getSize().height / 2) - (imageHeight / 2);
g.drawImage(image, xCenter, yCenter, imageWidth, imageHeight, this);
}
public void getPixel(int x,int y){
ColorModel cm = this.getColorModel();
int rgb = cm.getRGB(x*y);
int red = (rgb> > 24)&0xff ;
int green = (rgb> > 16)&0xff ;
int blue = (rgb> >
&0xff ;
System.out.println( "( "+red+ ", "+green+ ", "+blue+ ") ");
}
}