import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import javax.swing.JFrame;
public class Main extends Canvas {
public Main() {
setBackground(Color.white);
}
public void paint(Graphics g) {
try {
Graphics2D g2D;
g2D = (Graphics2D) g;
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
String fileName = "a.jpg";
Image img = getToolkit().getImage(fileName);
g2D.drawImage(img, new AffineTransform(), this);
AffineTransform aTran = new AffineTransform();
aTran.translate(200.0f, 0.0f);
g2D.transform(aTran);
AffineTransform imageSpaceTran = new AffineTransform();
imageSpaceTran.setToShear(0.1f, 0.1f);
// draw the sheared image
g2D.drawImage(img, imageSpaceTran, this);
// move the image over
aTran.translate(50.0f, 0.0f);
g2D.transform(aTran);
imageSpaceTran.scale(1.5f, 1.5f);
// draw the enlarged image
g2D.drawImage(img, imageSpaceTran, this);
} catch (Exception e) {
}
}
public static void main(String s[]) {
JFrame frame1 = new JFrame("2D Images ");
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.getContentPane().add("Center", new Main());
frame1.pack();
frame1.setSize(new Dimension(750, 370));
frame1.setVisible(true);
}
}
|