Example usage for java.awt.image ColorConvertOp ColorConvertOp

List of usage examples for java.awt.image ColorConvertOp ColorConvertOp

Introduction

In this page you can find the example usage for java.awt.image ColorConvertOp ColorConvertOp.

Prototype

public ColorConvertOp(ICC_Profile[] profiles, RenderingHints hints) 

Source Link

Document

Constructs a new ColorConvertOp from an array of ICC_Profiles.

Usage

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();
}