Beruflich Dokumente
Kultur Dokumente
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
/**
*
* @author Ahmad
*/
public class MidPaper {
File imageFile,output;
JLabel j1,j2,j3,j4,j5;
String path;
String fpath;
BufferedImage result;
MidPaper () {
bp = new JPanel();
p1 = new JPanel ();
p2 = new JPanel();
p3= new JPanel();
b1= new JButton("Load Image");
b2= new JButton("Blur");
b3= new JButton("Gray");
b4= new JButton("Save");
b1.setLocation(530, 10);
b1.setSize(100, 30);
b2.setLocation(560, 330);
b2.setSize(70, 30);
b3.setLocation(560, 370);
b3.setSize(70, 30);
b4.setLocation(560, 410);
b4.setSize(70, 30);
bp.setLocation(0, 0);
bp.setSize(300, 300);
bp.setBackground(Color.yellow);
p1.setLocation(0, 330);
p1.setSize(300, 230);
p1.setBackground(Color.red);
p2.setLocation(330, 330);
p2.setSize(220, 230);
p2.setBackground(Color.black);
frame.setVisible(true);
frame.setTitle("paper ");
frame.setSize(650, 600);
frame.setResizable(true);
frame.add(bp);
frame.add(j1);
frame.add(p1);
frame.add(j2);
frame.add(p2);
frame.add(b1);
frame.add(b2);
frame.add(b3);
frame.add(b4);
bp.add(j3);
p1.add(j4);
p2.add(j5);
frame.setLayout(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(50, 50);
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
try{
j3.setBounds(0, 0, 300, 300);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}});
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
try {
// Reading the Image from the file and storing it in to a Matrix object
String file = path;
Mat src = Imgcodecs.imread(file);
Imgcodecs.imwrite("C:\\Users\\dell\\Documents\\NetBeansProjects\\practice2\\convert
ed33.jpg", dst);
fpath=
"C:\\Users\\dell\\Documents\\NetBeansProjects\\practice2\\converted32.jpg";
ImageIcon my_image = new ImageIcon(fpath);
Image pic =my_image.getImage();
Image resimg = pic.getScaledInstance(j4.getWidth() , j4.getHeight(),
Image.SCALE_SMOOTH);
ImageIcon resized= new ImageIcon(resimg);
j4.setIcon(resized);
System.out.println("Image processed");
}
catch (Exception ex){
}});
b3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
try
{
j5.setBounds(0, 0, 220, 230);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}});
b4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
try
{
File f1= new File(fpath);
BufferedImage image = ImageIO.read(imageFile);
BufferedImage result = new BufferedImage(image.getWidth(),
image.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
Graphics2D graphic = result.createGraphics();
ImageIcon my_image = new ImageIcon(result);
graphic.drawImage(image, 0,0,Color.RED,null);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}});
}
public static void main(String[] args) {
MidPaper ob = new MidPaper();
}