create Grayed Image - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Create

Description

create Grayed Image

Demo Code

/**/*from  w  ww.  j a va  2  s .  c  o  m*/
 * Copyright 1998-2008, CHISEL Group, University of Victoria, Victoria, BC, Canada.
 * All rights reserved.
 */
//package com.java2s;

import java.awt.Image;
import java.awt.Toolkit;

import java.awt.image.FilteredImageSource;
import java.awt.image.ImageFilter;

import java.awt.image.ImageProducer;

import javax.swing.GrayFilter;

public class Main {
    public static Image createGrayedImage(Image i, final boolean b,
            final int p) {
        ImageFilter filter = new GrayFilter(b, p);
        ImageProducer prod = new FilteredImageSource(i.getSource(), filter);
        Image grayImage = Toolkit.getDefaultToolkit().createImage(prod);
        return grayImage;
    }
}

Related Tutorials