Mon May 06, 2013 11:16 pm
package imageviewer;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ConvolveOp;
import java.awt.image.Kernel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class CustomFilter extends JFrame{
/** Creates a new instance of CustomFilter */
public CustomFilter(BufferedImage buffImage) {
setTitle("Custom Filter");
setSize(400,200);
setLocation(250,250);
Orginal=buffImage;
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
myPanel.setLayout(new GridLayout(5,5));
for(int i=0;i<5;i++)
for(int j=0;j<5;j++) {
myfilds[i][j]=new JTextField("0.08",5);
myPanel.add(myfilds[i][j]);
}
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int count=0;
float foa;
for(int i=0;i<5;i++)
for(int j=0;j<5;j++) {
customfil[count] =Float.parseFloat(myfilds[i][j].getText());
count++;
}
int w =Orginal.getWidth();
int h = Orginal.getHeight();
biop = new ConvolveOp(new Kernel(dim[0][0],dim[0][1],customfil));
BufferedImage bi = new BufferedImage(w,h,Orginal.TYPE_INT_RGB);
biop.filter(Orginal,bi);
new ShowFrame(bi,"Custom Filter");
}
});
Cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
cp.add(myPanel);
cp.add(ok);
cp.add(Cancel);
}
private JTextField [][] myfilds=new JTextField[5][5];
private JPanel myPanel=new JPanel();
private JButton ok=new JButton("OK");
private JButton Cancel=new JButton("Cancel");
private float[] customfil = new float[25];
private BufferedImageOp biop;
private BufferedImage Orginal;
private int dim[][] = {{5,5}};
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.