Sie sind auf Seite 1von 14

/*

* To change this license header, choose License Headers in Project Properties.


* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Praktikum1;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;

/**
*
* @author Riska
*/
public class citra1 extends javax.swing.JFrame {

/**
* Creates new form citra1
*/
BufferedImage image=null;
BufferedImage image4=null;
BufferedImage image5=null;
BufferedImage image6=null;
BufferedImage image7=null;

BufferedImage image8=null;
int width;
int height;
String scrIm = "dora.jpg";
private Object grayScale;

public citra1() {
initComponents();
}

/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jButton1 = new javax.swing.JButton();


jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jButton6 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jButton1.setText("Load");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jButton2.setText("Copy");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jButton3.setText("Flip H");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});

jButton4.setText("Grayscale");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});

jButton5.setText("Flip V");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});

jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N


jLabel1.setText("Pengolahan Citra");

jButton6.setText("Rotate 90'");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});

jButton7.setText("Rotate 180'");
jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton7ActionPerformed(evt);
}
});

jLabel4.setText("Riska Ulfia ~ 361455401070");

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());


getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()

.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 190,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(290, 290, 290))
.addGroup(layout.createSequentialGroup()
.addGap(20, 20, 20)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 371,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(42, 42, 42)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 91,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 86,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 85,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 85,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 86,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 83,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jButton7))
.addGroup(layout.createSequentialGroup()

.addGap(298, 298, 298)


.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 167,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(34, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 48,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 33,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 33,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 33,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 33,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 33,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 33,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 33,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 387,
Short.MAX_VALUE)
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 14,


javax.swing.GroupLayout.PREFERRED_SIZE))
);

pack();
}// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {


//load
File input = new File(scrIm);
try {
image = ImageIO.read(input);
} catch (IOException ex) {
Logger.getLogger(citra1.class.getName()).log(Level.SEVERE, null, ex);
}
Icon imageIcon = new ImageIcon(image);
jLabel2.setIcon(imageIcon);

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {


//flip V
File input = new File(scrIm);
try {
image6 = ImageIO.read(input);
width = image6.getWidth();
height = image6.getHeight();

BufferedImage imageFlip = new BufferedImage(width, height,


BufferedImage.TYPE_INT_RGB);

for (int i = 0; i <width; i++) {


for (int j = 0; j < height; j++) {
Color w = new Color (image6.getRGB(i, j));
imageFlip.setRGB(i, height-(1+j), w.getRGB());
}
}

ImageIcon imageIcon6;
imageIcon6 = new ImageIcon(imageFlip);
jLabel3.setIcon(imageIcon6);
} catch (IOException ex) {
Logger.getLogger(citra1.class.getName()).log(Level.SEVERE,null, ex);
}
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {


//copy
File input = new File(scrIm);
try {
image = ImageIO.read(input);
} catch (IOException ex) {
Logger.getLogger(citra1.class.getName()).log(Level.SEVERE, null, ex);
}
Icon imageIcon = new ImageIcon(image);
jLabel3.setIcon(imageIcon);

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {


//flip H
File input = new File(scrIm);

try {
image4 = ImageIO.read(input);
width = image4.getWidth();
height = image4.getHeight();

BufferedImage imageFlip = new BufferedImage(width, height,


BufferedImage.TYPE_INT_RGB);

for (int i = 0; i <width; i++) {


for (int j = 0; j < height; j++) {
Color w = new Color (image4.getRGB(i, j));
imageFlip.setRGB(width-(1+i), j, w.getRGB());
}
}

ImageIcon imageIcon4;
imageIcon4 = new ImageIcon(imageFlip);
jLabel3.setIcon(imageIcon4);
} catch (IOException ex) {
Logger.getLogger(citra1.class.getName()).log(Level.SEVERE,null, ex);
}

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {


//grayscale
File input = new File(scrIm);
try {
image8 = ImageIO.read(input);
width = image8.getWidth();
height = image8.getHeight();

BufferedImage grayScale = new BufferedImage(width, height,


BufferedImage.TYPE_INT_RGB);

for (int i = 0; i <width; i++) {


for (int j = 0; j < height; j++) {
Color w = new Color (image8.getRGB(i, j));
int red = (int)(w.getRed());
int green = (int) (w.getGreen());
int blue = (int) (w.getBlue());
int avg = (red+green+blue) /3 ;
Color newColor = new Color(avg,avg,avg);
grayScale.setRGB(i, j, newColor.getRGB());

}
}

ImageIcon imageIcon8;
imageIcon8 = new ImageIcon(grayScale);
jLabel3.setIcon(imageIcon8);
} catch (IOException ex) {
Logger.getLogger(citra1.class.getName()).log(Level.SEVERE,null, ex);
}
}

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {


//rotatae 90'
File input = new File(scrIm);
try {
image5 = ImageIO.read(input);
width = image5.getWidth();

height = image5.getHeight();

BufferedImage imageFlip = new BufferedImage(width, height,


BufferedImage.TYPE_INT_RGB);

for (int i = 0; i <width; i++) {


for (int j = 0; j < height; j++) {
Color w = new Color (image5.getRGB(i, j));
imageFlip.setRGB(height-(1+j), i, w.getRGB());
}
}

ImageIcon imageIcon5;
imageIcon5 = new ImageIcon(imageFlip);
jLabel3.setIcon(imageIcon5);
} catch (IOException ex) {
Logger.getLogger(citra1.class.getName()).log(Level.SEVERE,null, ex);
}
}

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {


//rotate 180'
File input = new File(scrIm);
try {
image7 = ImageIO.read(input);
width = image7.getWidth();
height = image7.getHeight();

BufferedImage imageFlip = new BufferedImage(width, height,


BufferedImage.TYPE_INT_RGB);

for (int i = 0; i <width; i++) {

for (int j = 0; j < height; j++) {


Color w = new Color (image7.getRGB(i, j));
imageFlip.setRGB(width-(1+i), height-(1+j), w.getRGB());
}
}

ImageIcon imageIcon7;
imageIcon7 = new ImageIcon(imageFlip);
jLabel3.setIcon(imageIcon7);
} catch (IOException ex) {
Logger.getLogger(citra1.class.getName()).log(Level.SEVERE,null, ex);
}
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}

} catch (ClassNotFoundException ex) {


java.util.logging.Logger.getLogger(citra1.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(citra1.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(citra1.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(citra1.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
}
//</editor-fold>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new citra1().setVisible(true);
}
});
}

// Variables declaration - do not modify


private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;

private javax.swing.JButton jButton7;


private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
// End of variables declaration
}

Das könnte Ihnen auch gefallen