this code should recognize the blue point in an image. I have run
one, which alter the color of pixels and draw it again, but this one
is kidding me for 2 weeks.
Would U PLZ help me?
import java.awt.*;
import javax.swing.*;
import java.awt.image.*;
public class DefineBlue extends JApplet
{
private Image img;
public void paint(Graphics g){
super.paint(g);
MediaTracker mt=new MediaTracker(this);
img=getImage(getCodeBase(),"X.bmp");
try{
mt.waitForID(0);
}
catch(InterruptedException e)
{
}
int w=img.getWidth(this);
int h=img.getHeight(this);
int np=w*h;
int pix[]=new int[np];
PixelGrabber pg= new PixelGrabber
(img,0,0,w,h,pix,0,w);
try{
pg.getPixels();
}
catch(InterruptedException e)
{
}
g.drawString(" X",50,0);
g.drawString(" Y",100,0);
ColorModel cm= ColorModel.getRGBdefault();
for(int i=0;i<np;i++)
{
int r=cm.getRed(pix[i]);
int gr=cm.getGreen(pix[i]);
int b=cm.getBlue(pix[i]);
if((r==0) && (gr==0) && (b!=0)){
int Y=(np/w)+1;
int X=np%w;
g.drawString(""+X,50,50+20*i+10);
g.drawString(""+Y,100,50+20*i+10);
}
}
}
}