Results 1 to 1 of 1
  1. #1
    alanchan is offline Member
    Join Date
    Nov 2010
    Rep Power

    Default Gradient Filter problem

    I had tried to build a gradient filter for image processing,which when the filter is applied,a dark gardient will appear at the bottom right of the image, and gradually fade out at the top left corner(see the attachment pls).
    But after I run the filter, I found that nothing had applied onto the photos,
    even I changed the color of the gradient. Can anyone figure out why this happen? thx~~

    the code is like this:

    import java.awt.image.BufferedImage;
    import javax.imageio.ImageIO;
    import javax.swing.JOptionPane;
    import java.awt.Color;
    import java.awt.GradientPaint;
    import java.awt.Graphics2D;

    public class gradientFilter{
    final private static String DEFAULT_OUTFILE_NAME = "new";
    static int IMG_WIDTH, IMG_HEIGHT;
    static BufferedImage initialImg, processImg, newImg;
    private String openFile = null;

    public gradientFilter(String name){

    public BufferedImage imGradient (BufferedImage imIn,int type, int h, int w){
    BufferedImage imGradient=new BufferedImage(w,h, type);

    GradientPaint gp=new GradientPaint((float)0,(float)0,Color.WHITE,(float )w,(float)h,Color.PINK,true);
    Graphics2D g =imGradient.createGraphics();
    return imGradient;

    private void setGradient() throws{
    initialImg = File(openFile));
    int type = initialImg.getType() == 0? BufferedImage.TYPE_INT_ARGB : initialImg.getType();
    IMG_WIDTH = initialImg.getWidth();
    IMG_HEIGHT = initialImg.getHeight();
    newImg = imGradient(initialImg, type, IMG_HEIGHT, IMG_WIDTH);


    public static void main(String[] args){
    String name = JOptionPane.showInputDialog("Please enter the file you wish to load (filename.type):", args[0]);
    if (name.length()<=0)
    name = args[0];

    String newName = JOptionPane.showInputDialog("Save as:", DEFAULT_OUTFILE_NAME);
    if (newName.length()<=0)

    newName = newName+".png";

    gradientFilter opcg = new gradientFilter(name);

    ImageIO.write(newImg, "png", new File(newName));
    catch( e){
    System.out.println("ERROR: cannot save image");
    catch(NullPointerException e){
    Attached Thumbnails Attached Thumbnails Gradient Filter problem-test.jpg  
    Last edited by alanchan; 11-24-2010 at 11:58 AM.

Similar Threads

  1. Gradient of an image
    By Sapan in forum Forum Lobby
    Replies: 1
    Last Post: 04-08-2011, 03:03 PM
  2. Color gradient
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-21-2008, 08:50 PM
  3. Filename Filter problem
    By KevMeistr in forum Advanced Java
    Replies: 2
    Last Post: 06-14-2008, 02:43 AM
  4. web content filter or internet filter
    By sundarjothi in forum Advanced Java
    Replies: 3
    Last Post: 05-15-2008, 11:36 AM
  5. servlet Filter problem
    By saint_jorjo in forum New To Java
    Replies: 1
    Last Post: 03-13-2008, 01:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts