- Write the code in your IDE.
- You can download the jar here.
- The jar requires JRE 7, which can be downloaded here
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class jar {
public static void main(String[] args) throws IOException {
final
JFrame welcome = new JFrame("OMEGA");
String opt[] = {
"Original",
"Dot-pattern",
"Negative",
"Pixelate",
"High-Contrast",
"Semi-Contrast",
"Black-&-White",
"Vertical",
"Horizontal",
"Resize",
"Flip",
"Skew",
"Erratic"
};
final
JComboBox < ?>select = new JComboBox <
Object > (opt);
JTextField addoff = new JTextField("Enter image address");
JTextField options = new JTextField(" Choose edit option");
JButton ok = new JButton("OK");
final
JTextField add = new JTextField();
JButton br = new JButton("Browse");
br.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
JFileChooser browse = new JFileChooser("c:\\");
if (browse.showOpenDialog(welcome) == JFileChooser.APPROVE_OPTION) {
add.setText(browse.getSelectedFile().getPath());
}
}
});
add.setLocation(140,
10);
add.setSize(110,
20);
options.setEditable(false);
options.setSize(120,
20);
options.setLocation(10,
40);
addoff.setEditable(false);
addoff.setSize(120,
20);
addoff.setLocation(10,
10);
select.setSelectedIndex(0);
select.setSize(200,
20);
select.setLocation(140,
40);
ok.setSize(80,
20);
ok.setLocation(260,
70);
br.setLocation(260,
10);
br.setSize(80,
20);
welcome.setSize(365,
139);
welcome.setLayout(null);
welcome.setResizable(false);
welcome.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width/2-welcome.getSize().width/2,Toolkit.getDefaultToolkit().getScreenSize().height/2-welcome.getSize().height/2);
welcome.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
welcome.add(options);
welcome.add(add);
welcome.add(select);
welcome.add(addoff);
welcome.add(ok);
welcome.add(br);
JOptionPane.showMessageDialog(welcome, "Welcome to OMEGA: The last
word in image processing", "Welcome", JOptionPane.PLAIN_MESSAGE);
welcome.setVisible(true);
ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
loop: {
Image xyz = null;
if (add.getText().equals("")) {
JOptionPane.showMessageDialog(welcome, "Please enter a file
address", "Warning", JOptionPane.WARNING_MESSAGE);
break loop;
}
if (new File(add.getText()).isFile() == false) {
JOptionPane.showMessageDialog(welcome, "Your file doesn't exist.
Please check your filname and try again.", "Warning", JOptionPane.WARNING_MESSAGE);
break loop;
}
try {
if (ImageIO.read(new File(add.getText())) == null) {
JOptionPane.showMessageDialog(welcome, "Your file is not compatible
with system. Only .JPG, .PNG, \n.BMP and .GIF files can be edited. Please use
another file.", "Warning", JOptionPane.WARNING_MESSAGE);
break loop;
}
} catch(IOException e1) {
// TODO
Auto-generated catch block
e1.printStackTrace();
}
try {
xyz = ImageIO.read(new File(add.getText()));
if (xyz.getHeight(null) * xyz.getWidth(null) > 15000) {
int result = JOptionPane.showConfirmDialog(welcome, "Your image size is too large
for Omega to edit.\n Do you want Omega to resize it before editing?", "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (result == JOptionPane.YES_OPTION) {
double nw = Math.ceil(Math.sqrt(xyz.getWidth(null) * 15000 / xyz.getHeight(null)));
double nh = nw * xyz.getHeight(null) / xyz.getWidth(null);
double wid = (nw / xyz.getWidth(null));
double ht = (nh / xyz.getHeight(null));
BufferedImage
image = null;
image = new BufferedImage((int) Math.ceil(nw), (int) Math.ceil(nh), BufferedImage.TYPE_INT_ARGB);
Graphics2D
graphics2D = image.createGraphics();
try {
for (int i = 0; i < (xyz.getHeight(null) * ht); i++) {
for (int j = 0; j < (xyz.getWidth(null) * wid); j++) {
int abc = ((BufferedImage) xyz).getRGB((int)(Math.ceil(j / wid)), (int)(Math.ceil(i / ht)));
graphics2D.setPaint(new Color(abc));
graphics2D.fillRect(j, i, j + 1, i + 1);
}
}
}
catch (Exception e) {
// TODO: handle
exception
}
graphics2D.dispose();
ImageIO.write(image, "png", new File("Omega~Resize~Ouptut.png"));
xyz = ImageIO.read(new File("Omega~Resize~Ouptut.png"));
}
else if (result == JOptionPane.NO_OPTION) {
add.setText("");
break loop;
}
else {
break loop;
}
}
} catch(IOException e1) {
// TODO
Auto-generated catch block
e1.printStackTrace();
}
new File("Omega~Resize~Ouptut.png").deleteOnExit();
final JFrame frm = new JFrame();
frm.setSize(xyz.getWidth(null) +
25, xyz.getHeight(null) + 50);
frm.setAlwaysOnTop(true);
frm.setLayout(null);
frm.setResizable(false);
int choice = 0;
add.setEditable(false);
choice = select.getSelectedIndex();
//Original t
if (choice == 0) {
frm.setTitle("Original");
for (int i = 0; i < xyz.getHeight(null); i++) {
for (int j = 0; j < xyz.getWidth(null); j++) {
JTextArea
x = new JTextArea();
x.setEditable(false);
x.setVisible(true);
x.setLocation(j + 5, i + 5);
x.setSize(1, 1);
int abc = ((BufferedImage) xyz).getRGB(j, i);
x.setBackground(new Color(abc));
frm.add(x);
}
}
frm.setVisible(true);
}
//Dot t
if (choice == 1) {
int pix = Integer.parseInt(JOptionPane.showInputDialog("Enter dot value"));
frm.setTitle("Dot");
for (int i = 0; i < xyz.getHeight(null) / pix; i++) {
for (int j = 0; j < xyz.getWidth(null) / pix; j++) {
JTextArea
x = new JTextArea();
x.setEditable(false);
x.setVisible(true);
x.setLocation(j * pix + 5, i * pix + 5);
x.setSize(1, 1);
int abc = ((BufferedImage) xyz).getRGB(j * pix, i * pix);
x.setBackground(new Color(abc));
frm.add(x);
}
}
frm.setVisible(true);
}
//Negatify t
if (choice == 2) {
frm.setTitle("Negatify");
for (int i = 0; i < xyz.getHeight(null); i++) {
for (int j = 0; j < xyz.getWidth(null); j++) {
JTextArea
x = new JTextArea();
x.setEditable(false);
x.setVisible(true);
x.setLocation(j + 5, i + 5);
x.setSize(1, 1);
int abc = -((BufferedImage) xyz).getRGB(j, i);
x.setBackground(new Color(abc));
frm.add(x);
}
}
frm.setVisible(true);
}
//Pixelate t
if (choice == 3) {
int pix = Integer.parseInt(JOptionPane.showInputDialog("Enter pixel value"));
frm.setTitle("Pixelate");
for (int i = 0; i < xyz.getHeight(null) / pix; i++) {
for (int j = 0; j < xyz.getWidth(null) / pix; j++) {
JTextArea
x = new JTextArea();
x.setEditable(false);
x.setVisible(true);
x.setLocation(j * pix + 5, i * pix + 5);
x.setSize(pix, pix);
int abc = ((BufferedImage) xyz).getRGB(j * pix, i * pix);
x.setBackground(new Color(abc));
frm.add(x);
}
}
frm.setVisible(true);
}
//High-contrast t
if (choice == 4) {
final JFrame high = new JFrame("High-contrast options");
JTextField ask = new JTextField("Choose contrast mode");
String array[] = {
"Mode 1",
"Mode 2",
"Mode 3"
};
final JComboBox < ?>opt = new
JComboBox < Object > (array);
JButton acc = new JButton("OK");
ask.setLocation(10, 10);
ask.setSize(140, 20);
ask.setEditable(false);
opt.setLocation(160, 10);
opt.setSize(80, 20);
acc.setLocation(170, 40);
acc.setSize(70, 20);
final Image xy = xyz;
acc.addActionListener(new ActionListener() {@Override
public void actionPerformed(ActionEvent arg0) {
int cont = opt.getSelectedIndex();
frm.setTitle("High-contrast:
Mode " + cont + 1);
for (int i = 0; i < xy.getHeight(null); i++) {
for (int j = 0; j < xy.getWidth(null); j++) {
int abc = ((BufferedImage) xy).getRGB(j, i);
if (cont == 0) {
abc = (new Color(abc)).getBlue();
}
if (cont == 1) {
abc = (new Color(abc)).getGreen();
}
if (cont == 2) {
abc = (new Color(abc)).getRed();
}
if (abc > 127.5) {
continue;
}
JTextArea
x = new JTextArea();
x.setEditable(false);
x.setVisible(true);
x.setLocation(j + 5, i + 5);
x.setSize(1, 1);
if (abc < 127.5) {
x.setBackground(Color.black);
}
frm.add(x);
}
}
high.setVisible(false);
frm.setVisible(true);
}
});
high.add(ask);
high.add(opt);
high.add(acc);
high.setLayout(null);
high.setSize(270, 109);
high.setResizable(false);
high.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width/2-high.getSize().width/2,Toolkit.getDefaultToolkit().getScreenSize().height/2-high.getSize().height/2);
high.setVisible(true);
}
//Semi-contrast t
if (choice == 5) {
final JFrame high = new JFrame("Semi-contrast options");
JTextField ask = new JTextField("Choose contrast mode");
String array[] = {
"Mode 1",
"Mode 2",
"Mode 3"
};
final JComboBox < ?>opt = new
JComboBox < Object > (array);
JButton acc = new JButton("OK");
ask.setLocation(10, 10);
ask.setSize(140, 20);
ask.setEditable(false);
opt.setLocation(160, 10);
opt.setSize(80, 20);
acc.setLocation(170, 40);
acc.setSize(70, 20);
final Image xy = xyz;
acc.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
int cont = opt.getSelectedIndex();
frm.setTitle("Semi-contrast:
Mode " + cont + 1);
for (int i = 0; i < xy.getHeight(null); i++) {
for (int j = 0; j < xy.getWidth(null); j++) {
int abc = ((BufferedImage) xy).getRGB(j, i);
if (cont == 0) {
abc = (new Color(abc)).getBlue();
}
if (cont == 1) {
abc = (new Color(abc)).getGreen();
}
if (cont == 2) {
abc = (new Color(abc)).getRed();
}
if (abc >= 150) {
continue;
}
JTextArea
x = new JTextArea();
x.setEditable(false);
x.setVisible(true);
x.setLocation(j + 5, i + 5);
x.setSize(1, 1);
if (abc < 75) {
x.setBackground(Color.black);
}
if (abc >= 75 & abc < 150) {
x.setBackground(Color.gray);
}
frm.add(x);
}
}
high.setVisible(false);
frm.setVisible(true);
}
});
high.add(ask);
high.add(opt);
high.add(acc);
high.setLayout(null);
high.setSize(270, 109);
high.setResizable(false);
high.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width/2-high.getSize().width/2,Toolkit.getDefaultToolkit().getScreenSize().height/2-high.getSize().height/2);
high.setVisible(true);
}
//Black-&-White t
if (choice == 6) {
final JFrame high = new JFrame("Black-&-White options");
JTextField ask = new JTextField("Choose B/W mode");
String array[] = {
"Mode 1",
"Mode 2",
"Mode 3"
};
final JComboBox < ?>opt = new
JComboBox < Object > (array);
JButton acc = new JButton("OK");
ask.setLocation(10, 10);
ask.setSize(140, 20);
ask.setEditable(false);
opt.setLocation(160, 10);
opt.setSize(80, 20);
acc.setLocation(170, 40);
acc.setSize(70, 20);
final Image xy = xyz;
acc.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
int cont = opt.getSelectedIndex();
frm.setTitle("Black-&-White:
Mode " + cont + 1);
for (int i = 0; i < xy.getHeight(null); i++) {
for (int j = 0; j < xy.getWidth(null); j++) {
int abc = ((BufferedImage) xy).getRGB(j, i);
if (cont == 0) {
abc = (new Color(abc)).getBlue();
}
if (cont == 1) {
abc = (new Color(abc)).getGreen();
}
if (cont == 2) {
abc = (new Color(abc)).getRed();
}
if (abc >= 180) {
continue;
}
JTextArea
x = new JTextArea();
x.setEditable(false);
x.setVisible(true);
x.setLocation(j + 5, i + 5);
x.setSize(1, 1);
x.setBackground(new Color((new
Color(abc)).getBlue(),(new Color(abc)).getBlue(),(new Color(abc)).getBlue()));
if (abc < 45) {
x.setBackground(Color.black);
}
if (abc >= 45 & abc < 90) {
x.setBackground(new Color(64, 64, 64));
}
if (abc >= 90 & abc < 135) {
x.setBackground(Color.gray);
}
if (abc >= 135 & abc < 180) {
x.setBackground(new Color(184, 184, 184));
}
frm.add(x);
}
}
high.setVisible(false);
frm.setVisible(true);
}
});
high.add(ask);
high.add(opt);
high.add(acc);
high.setLayout(null);
high.setSize(270, 109);
high.setResizable(false);
high.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width/2-high.getSize().width/2,Toolkit.getDefaultToolkit().getScreenSize().height/2-high.getSize().height/2);
high.setVisible(true);
}
//Vertical t
if (choice == 7) {
int pix = Integer.parseInt(JOptionPane.showInputDialog("Enter vertical value"));
frm.setTitle("Vertical");
for (int i = 0; i < xyz.getHeight(null) / pix; i++) {
for (int j = 0; j < xyz.getWidth(null) / pix; j++) {
JTextArea
x = new JTextArea();
x.setEditable(false);
x.setVisible(true);
x.setLocation(j * pix + 5, i * pix + 5);
x.setSize(1, pix);
int abc = ((BufferedImage) xyz).getRGB(j * pix, i * pix);
x.setBackground(new Color(abc));
frm.add(x);
}
}
frm.setVisible(true);
}
//Horizontal t
if (choice == 8) {
int pix = Integer.parseInt(JOptionPane.showInputDialog("Enter horizontal value"));
frm.setTitle("Horizontal");
for (int i = 0; i < xyz.getHeight(null) / pix; i++) {
for (int j = 0; j < xyz.getWidth(null) / pix; j++) {
JTextArea
x = new JTextArea();
x.setEditable(false);
x.setVisible(true);
x.setLocation(j * pix + 5, i * pix + 5);
x.setSize(pix, 1);
int abc = ((BufferedImage) xyz).getRGB(j * pix, i * pix);
x.setBackground(new Color(abc));
frm.add(x);
}
}
frm.setVisible(true);
}
//Resize t
if (choice == 9) {
final JFrame res = new JFrame("Resize options");
JTextField alpha = new JTextField("Enter new height percentage");
JTextField beta = new JTextField("Enter new width percentage");
final JTextField in1 = new
JTextField();
final JTextField in2 = new
JTextField();
JButton get = new JButton("OK");
res.setLayout(null);
res.setResizable(false);
alpha.setLocation(10, 10);
alpha.setSize(165, 20);
alpha.setEditable(false);
beta.setLocation(10, 40);
beta.setSize(165, 20);
beta.setEditable(false);
in1.setLocation(185, 10);
in1.setSize(100, 20);
in2.setLocation(185, 40);
in2.setSize(100, 20);
get.setLocation(210, 70);
get.setSize(75, 20);
final Image xy = xyz;
get.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
double ht = Double.parseDouble(in1.getText()) / 100;
double wid = Double.parseDouble(in2.getText()) / 100;
frm.setSize((int) Math.ceil(xy.getWidth(null) * wid) + 25, (int) Math.ceil(xy.getHeight(null) * ht) + 50);
frm.setTitle("H:
" + ht * 100 + "% W: " + wid * 100 + "%");
for (int i = 0; i < (xy.getHeight(null)); i++) {
for (int j = 0; j < (xy.getWidth(null)); j++) {
JTextArea
x = new JTextArea();
x.setEditable(false);
x.setVisible(true);
x.setLocation((int) Math.ceil(j * wid) + 5, (int) Math.ceil(i * ht)+5);
x.setSize((int) Math.ceil(wid), (int) Math.ceil(ht));
int abc = ((BufferedImage) xy).getRGB(j, i);
x.setBackground(new Color(abc));
frm.add(x);
}
}
res.setVisible(false);
frm.setVisible(true);
}
});
res.add(alpha);
res.add(beta);
res.add(in1);
res.add(in2);
res.add(get);
res.setSize(313, 142);
res.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width/2-res.getSize().width/2,Toolkit.getDefaultToolkit().getScreenSize().height/2-res.getSize().height/2);
res.setVisible(true);
}
//Flip t
if (choice == 10) {
final JFrame high = new JFrame("Flip options");
JTextField ask = new JTextField("Choose flip mode");
String array[] = {
"Horizontal",
"Vertical",
"Both"
};
final JComboBox < ?>opt = new
JComboBox < Object > (array);
JButton acc = new JButton("OK");
ask.setLocation(10, 10);
ask.setSize(140, 20);
ask.setEditable(false);
opt.setLocation(160, 10);
opt.setSize(80, 20);
acc.setLocation(170, 40);
acc.setSize(70, 20);
final Image xy = xyz;
acc.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
int num = opt.getSelectedIndex();
frm.setTitle("Flip");
for (int i = 0; i < xy.getHeight(null); i++) {
for (int j = 0; j < xy.getWidth(null); j++) {
JTextArea
x = new JTextArea();
x.setEditable(false);
x.setVisible(true);
if (num == 0) {
x.setLocation(xy.getWidth(null) + 4
- j, i + 5);
}
if (num == 1) {
x.setLocation(j + 5, xy.getHeight(null) + 4 - i);
}
if (num == 2) {
x.setLocation(xy.getWidth(null) + 4
- j, xy.getHeight(null) + 4
- i);
}
x.setSize(1, 1);
int abc = ((BufferedImage) xy).getRGB(j, i);
x.setBackground(new Color(abc));
frm.add(x);
}
}
high.setVisible(false);
frm.setVisible(true);
}
});
high.add(ask);
high.add(opt);
high.add(acc);
high.setLayout(null);
high.setSize(270, 109);
high.setResizable(false);
high.setLocation(599, 307);
high.setVisible(true);
}
//Skew t
if (choice == 11) {
final JFrame res = new JFrame("Skew options");
JTextField alpha = new JTextField("Enter integer skew amount");
JTextField beta = new JTextField(" Enter
skew mode");
final JTextField in1 = new
JTextField();
String arr[] = {
"Horizontal(Top-Right)",
"Horizontal(Bottom-Right)",
"Vertical(Right-Bottom)",
"Vertical(Right-Top)"
};
final JComboBox < ?>in2 = new
JComboBox < Object > (arr);
JButton get = new JButton("OK");
res.setLayout(null);
res.setResizable(false);
alpha.setLocation(10, 10);
alpha.setSize(165, 20);
alpha.setEditable(false);
beta.setLocation(10, 40);
beta.setSize(165, 20);
beta.setEditable(false);
in1.setLocation(185, 10);
in1.setSize(150, 20);
in2.setLocation(185, 40);
in2.setSize(150, 20);
get.setLocation(260, 70);
get.setSize(75, 20);
final Image xy = xyz;
get.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
frm.setResizable(true);
frm.setSize(Toolkit.getDefaultToolkit().getScreenSize());
int val = Integer.parseInt(in1.getText());
int sel = in2.getSelectedIndex();
if (sel == 0) {
frm.setTitle("H: T-R
" + val);
}
if (sel == 1) {
frm.setTitle("H: B-R
" + val);
}
if (sel == 2) {
frm.setTitle("V: R-B
" + val);
}
if (sel == 3) {
frm.setTitle("V: R-T
" + val);
}
for (int i = 0; i < xy.getHeight(null); i++) {
for (int j = 0; j < xy.getWidth(null); j++) {
JTextArea
x = new JTextArea();
x.setEditable(false);
x.setVisible(true);
if (sel == 0) {
x.setLocation(5 + j + (xy.getHeight(null) - 1 - i) * val / 45, 5 + i); // H T-R
}
if (sel == 1) {
x.setLocation(5 + j + i * val / 45, 5 + i); // H B-R
}
if (sel == 2) {
x.setLocation(5 + j, 5 + i + j * val / 45); // V R-B
}
if (sel == 3) {
x.setLocation(5 + j, 5 + i + (xy.getWidth(null) - 1 - j) * val / 45); // V R-T
}
x.setSize(1, 1);
int abc = ((BufferedImage) xy).getRGB(j, i);
x.setBackground(new Color(abc));
frm.add(x);
}
}
res.setVisible(false);
frm.setVisible(true);
}
});
res.add(alpha);
res.add(beta);
res.add(in1);
res.add(in2);
res.add(get);
res.setSize(361, 142);
res.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width/2-res.getSize().width/2,Toolkit.getDefaultToolkit().getScreenSize().height/2-res.getSize().height/2);
res.setVisible(true);
}
//Erratic t
if (choice == 12) {
frm.setTitle("Erratic");
double e = Double.parseDouble(JOptionPane.showInputDialog("Enter value of erraticity"));
for (int i = 0; i < xyz.getHeight(null); i++) {
for (int j = 0; j < xyz.getWidth(null); j++) {
JTextArea
x = new JTextArea();
x.setEditable(false);
x.setVisible(true);
x.setLocation(j + 5, i + 5);
x.setSize((int) Math.ceil(Math.random() * e), (int) Math.ceil(Math.random() * e));
int abc = ((BufferedImage) xyz).getRGB(j, i);
x.setBackground(new Color(abc));
frm.add(x);
}
}
frm.setVisible(true);
}
add.setEditable(true);
}
}
});
}
}
- Execute the program