示例#1
0
 private static ImageIcon makeGrayImageIcon1(Image img) {
   BufferedImage source =
       new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
   Graphics g = source.createGraphics();
   g.drawImage(img, 0, 0, null);
   g.dispose();
   ColorConvertOp colorConvert =
       new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
   BufferedImage destination = colorConvert.filter(source, null);
   return new ImageIcon(destination);
 }
示例#2
0
  private BufferedImage convert(BufferedImage image, int imageType) {
    if (image.getType() == imageType) {
      return image;
    }

    int w = image.getWidth();
    int h = image.getHeight();
    BufferedImage newImg = new BufferedImage(w, h, imageType);
    ColorSpace srcSpace = image.getColorModel().getColorSpace();
    ColorSpace newSpace = newImg.getColorModel().getColorSpace();
    ColorConvertOp convert = new ColorConvertOp(srcSpace, newSpace, null);
    convert.filter(image, newImg);
    return newImg;
  }