public BufferedImage changeGrey() {   
       PixelGrabber pg = new PixelGrabber(image.getSource(), 0, 0, iw, ih, pixels, 0, iw);   
       try {   
           pg.grabPixels();   
       } catch (InterruptedException e) {   
           e.printStackTrace();   
       }   
  
       // 设定二值化的域值，默认值为100   
       int grey = 100;   
       // 对图像进行二值化处理，Alpha值保持不变   
       ColorModel cm = ColorModel.getRGBdefault();   
  
       for (int i = 0; i < iw * ih; i++) {   
           int red, green, blue;   
           int alpha = cm.getAlpha(pixels[i]);   
           if (cm.getRed(pixels[i]) > grey) {   
              red = 255;   
           } else {   
              red = 0;   
           }   
  
           if (cm.getGreen(pixels[i]) > grey) {   
              green = 255;   
           } else {   
              green = 0;   
           }   
  
           if (cm.getBlue(pixels[i]) > grey) {   
              blue = 255;   
           } else {   
              blue = 0;   
           }   
  
           pixels[i] = alpha << 24 | red << 16 | green << 8 | blue;   
       }   
  
       // 将数组中的象素产生一个图像   
       return ImageIOHelper.imageProducerToBufferedImage(new MemoryImageSource(iw, ih, pixels, 0, iw));   
    }