2013-02-16 62 views

回答

0

這是解決你如何能做到這

boolean pf=false,qf=false,rf=false,sf=false,tf=false; 
    BitmapFactory.Options bitmapFatoryOptions=new BitmapFactory.Options(); 
    bitmapFatoryOptions.inPreferredConfig=Bitmap.Config.RGB_565; 
    bmp =BitmapFactory.decodeResource(getResources(), R.drawable.test4,bitmapFatoryOptions); 
    bmp = bmp.copy(bmp.getConfig(), true); 
    int thresh = 150; 
    for(int i=0;i<bmp.getWidth();i++){ 
     for(int j=0;j<bmp.getHeight();j++){ 
      int pixel = bmp.getPixel(i, j); 
      int red = Color.green(pixel); 
      int green = Color.red(pixel); 
      int blue = Color.blue(pixel); 
      if(red<thresh&&green<thresh&&blue<thresh){ 
       if((oldj>=j||p.x==0)&&!pf){ 
        p.x=i; 
        p.y=j; 

       } 
       else{ 
        pf=true; 
        //Toast.makeText(getApplicationContext(), "told="+oldj, Toast.LENGTH_SHORT).show(); 

       if(pf&&!qf&&(oldj<=j||q.x==0)){ 
        q.x=i; 
        q.y=j; 
        //Toast.makeText(getApplicationContext(), "old="+oldj, Toast.LENGTH_SHORT).show(); 
       } 
       else{ 
        qf=true; 
        if(!rf&&(oldj>=j||r.x==0)){ 
         r.x=i; 
         r.y=j; 
        } 
        else{ 
         rf=true; 
         if(!sf&&(oldj<=j||s.x==0)){ 
          s.x=i; 
          s.y=j; 
         } 
         else{ 
          sf=true; 
          if(!tf&&(oldj>=j||t.x==0)){ 
           t.x=i; 
           t.y=j; 
          } 
          else{ 
           tf=true; 
          } 
         } 
        } 
       } 
       } 
       oldj=j; 
       oldi=i; 
       break; 
      } 
     } 
    } 
    paint(p,bmp); 
    paint(q,bmp); 
    paint(r,bmp); 
    paint(s,bmp); 
    paint(t,bmp); 

}