List of usage examples for java.awt.image ColorConvertOp ColorConvertOp
public ColorConvertOp(ICC_Profile[] profiles, RenderingHints hints)
From source file:org.polymap.core.data.image.ImageGrayscaleProcessor.java
protected Image grayscale(Image image) { long start = System.currentTimeMillis(); // load image data new javax.swing.ImageIcon(image).getImage(); if (!(image instanceof BufferedImage)) { BufferedImage bimage = new BufferedImage(image.getHeight(null), image.getWidth(null), BufferedImage.TYPE_4BYTE_ABGR); Graphics g = bimage.getGraphics(); g.drawImage(image, 0, 0, null);//from w w w. j a v a 2 s . co m g.dispose(); image = bimage; } // grayscale ColorConvertOp filter = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); BufferedImage grayImage = new BufferedImage(image.getHeight(null), image.getWidth(null), BufferedImage.TYPE_4BYTE_ABGR); Graphics g = grayImage.getGraphics(); filter.filter((BufferedImage) image, grayImage); g.dispose(); log.info("Gray scaling took: " + (System.currentTimeMillis() - start) + "ms"); return grayImage; }
From source file:paintbasico2d.VentanaPrincipal.java
private void EscalaGrisesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EscalaGrisesActionPerformed // TODO add your handling code here: VentanaInterna vi = (VentanaInterna) escritorio.getSelectedFrame(); if (vi != null) { vi.getLienzo().setImage(vi.getLienzo().getImage()); if (vi.getLienzo().getImage() != null) { ICC_Profile icc = ICC_Profile.getInstance(ColorSpace.CS_GRAY); ColorSpace cs = new ICC_ColorSpace(icc); ColorConvertOp conver = new ColorConvertOp(cs, null); BufferedImage imgdest = conver.filter(vi.getLienzo().getImage(), null); vi.getLienzo().setImage(imgdest); }/* w ww . ja va 2s .co m*/ } repaint(); }