Total members 11786 |It is currently Sat Jul 20, 2019 4:57 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





use of Affine Transform in java
Code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.geom.AffineTransform;

public class AffineTransformExample extends JFrame {
 ShowLabel label;
  JComboBox shearX, shearY;
  String[] shear = { "0.00", "0.25", "0.50", "0.75", "1.00" };

  public AffineTransformExample() {
    super("Affine Transform Example");
    Container container = getContentPane();
    label = new ShowLabel();
    container.add(label);

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(2, 4, 5, 5));
    
    shearX 
= new JComboBox(shear);
    shearX.setSelectedItem("0.00");
    panel.add(new JLabel("Shear X:"));
    panel.add(shearX);
    shearX.addActionListener(new ComboBoxListener());
   
    shearY 
= new JComboBox(shear);
    shearY.setSelectedItem("0.00");
    panel.add(new JLabel("Shear Y:"));
    panel.add(shearY);
    shearY.addActionListener(new ComboBoxListener());
    container.add(BorderLayout.NORTH, panel);
    setSize(350,300);
    setVisible(true);
  }
    public static void main(String arg[]) {
    new AffineTransformExample();
  }
    class ComboBoxListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
      JComboBox box = (JComboBox) e.getSource();
        if (box == shearX) {
        label.shearx = Double.parseDouble((String) box.getSelectedItem());
        label.value(true);
        label.filter();
        label.repaint();
      } else if (box == shearY) {
        label.sheary = Double.parseDouble((String) box.getSelectedItem());
        label.value(true);
        label.filter();
        label.repaint();
      }
    }
  }
}
class ShowLabel extends JLabel {
  Image image;
  BufferedImage bufferedImage1, bufferedImage2;
  BufferedImage bufferedImage;
  Graphics2D g2d;
  AffineTransform affineTransform;
  double shearx = 1.0, sheary = 1.0;

  ShowLabel() {
    image = Toolkit.getDefaultToolkit().getImage("image4.jpg");
    MediaTracker mediaTracker = new MediaTracker(this);
    mediaTracker.addImage(image, 1);
    try {
      mediaTracker.waitForAll();
    } catch (Exception e) {}
    createImages();
    affineTransform = new AffineTransform();
  }
    public void createImages() {
    bufferedImage1 = new BufferedImage(image.getWidth(this), image
        
.getHeight(this), BufferedImage.TYPE_INT_RGB);
    g2d = bufferedImage1.createGraphics();
    g2d.drawImage(image, 0, 0, this);
    bufferedImage = bufferedImage1;
    bufferedImage2 = new BufferedImage(image.getWidth(this), image
        
.getHeight(this), BufferedImage.TYPE_INT_RGB);
  }
    public void value(boolean scale, boolean shear) {
      if (shear) {
      affineTransform.setToShear(shearx, sheary);
      shear = true;
    }
  }
    public void filter() {
    AffineTransformOp affineTransformOp = new AffineTransformOp
          
(affineTransform, null);
    Graphics2D G2D = bufferedImage2.createGraphics();
    G2D.clearRect(0, 0, bufferedImage2.getWidth(this), bufferedImage2.
           getHeight(this));
    affineTransformOp.filter(bufferedImage1, bufferedImage2);
    bufferedImage = bufferedImage2;
  }
    public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2D = (Graphics2D) g;
    g2D.drawImage(bufferedImage, 0, 0, this);
  } 





Attachments:
File comment: Affine Transform in java
affineTransform.gif
affineTransform.gif [ 14.67 KiB | Viewed 6102 times ]
Author:
Mastermind
User avatar Posts: 2707
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : use of Affine Transform
 Transform Rotate Filter     -  
 Compute FFT (Fourier Transform) in ITK for a 2d image     -  
 force letters to be lowercase text-transform     -  
 Encryption and Decryption encryption Affine cipher code     -  



Topic Tags

Java AWT






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
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