Here you can find the source of grayScaleImage(Image img, int percent)
Parameter | Description |
---|---|
img | image to grayscale |
percent | grayscale percentage |
public static Image grayScaleImage(Image img, int percent)
//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); } }