Java Image Gray Scale grayScaleImage(Image img, int percent)

Here you can find the source of grayScaleImage(Image img, int percent)

Description

Creates a gray scaled variant of the given image

License

Open Source License

Parameter

Parameter Description
img image to grayscale
percent grayscale percentage

Return

grayscaled image

Declaration

public static Image grayScaleImage(Image img, int percent) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.swing.*;
import java.awt.*;

import java.awt.image.FilteredImageSource;
import java.awt.image.ImageProducer;

public class Main {
    /**//from ww w. j  av a  2 s. c om
     * Creates a gray scaled variant of the given image
     *
     * @param img     image to grayscale
     * @param percent grayscale percentage
     * @return grayscaled image
     */
    public static Image grayScaleImage(Image img, int percent) {
        ImageProducer producer = new FilteredImageSource(img.getSource(), new GrayFilter(true, percent));
        return Toolkit.getDefaultToolkit().createImage(producer);
    }
}

Related

  1. createGrayedImage(Image i, final boolean b, final int p)
  2. isGrayscale(ImageIcon icon)
  3. makeGrayImage(Image in)