Exemplo n.º 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);
 }
Exemplo n.º 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;
  }
Exemplo n.º 3
0
 /**
  * Simple method to use if one wants to change the current color scheme to e.g grayscale,
  * black/white and so on
  *
  * @param source source image object
  * @param colorSpaceType color space type. see java.awt.color.ColorSpace.<TYPES>
  * @param <T> type
  * @return BufferedImage
  * @throws IOException _
  * @throws NullPointerException _
  */
 public static <T> BufferedImage convertColorScheme(final T source, final Integer colorSpaceType)
     throws IOException, NullPointerException {
   if (verifyNotNull(source, colorSpaceType)) {
     BufferedImage sourceImage;
     sourceImage = convertToBufferedImage(source);
     BufferedImage target =
         new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), sourceImage.getType());
     if (verifyNotNull(sourceImage)) {
       ColorSpace colorSpace = ColorSpace.getInstance(colorSpaceType);
       ColorConvertOp converter = new ColorConvertOp(colorSpace, null);
       target = converter.filter(sourceImage, target);
       if (verifyNotNull(target)) {
         return target;
       }
       throw new NullPointerException("Unable to create target image. Result was null");
     }
   }
   throw new NullPointerException(E_OBJECT_WAS_NULL);
 }