Results 1 to 1 of 1
Thread: Gradient Filter problem
- 11-24-2010, 08:50 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 1
- Rep Power
- 0
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 java.io.File;
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){
openFile=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();
g.drawImage(imIn,0,0,w,h,null);
g.setPaint(gp);
g.dispose();
return imGradient;
}
private void setGradient() throws java.io.IOException{
initialImg = ImageIO.read(new 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){
try{
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 = DEFAULT_OUTFILE_NAME;
newName = newName+".png";
gradientFilter opcg = new gradientFilter(name);
opcg.setGradient();
ImageIO.write(newImg, "png", new File(newName));
}
catch(java.io.IOException e){
System.out.println("ERROR: cannot save image");
}
catch(NullPointerException e){
}
}
}Last edited by alanchan; 11-24-2010 at 10:58 AM.
Similar Threads
-
Gradient of an image
By Sapan in forum Forum LobbyReplies: 1Last Post: 04-08-2011, 03:03 PM -
Color gradient
By Java Tip in forum java.awtReplies: 0Last Post: 06-21-2008, 08:50 PM -
Filename Filter problem
By KevMeistr in forum Advanced JavaReplies: 2Last Post: 06-14-2008, 02:43 AM -
web content filter or internet filter
By sundarjothi in forum Advanced JavaReplies: 3Last Post: 05-15-2008, 11:36 AM -
servlet Filter problem
By saint_jorjo in forum New To JavaReplies: 1Last Post: 03-13-2008, 12:05 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks