import javax.swing.*;
import java.awt.*;
/**
* <p>Title: 圖片的處理,</p>
* <p>Description: 將圖片放大和翻轉顯示</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Filename: ImgDemo.java</p>
* @version 1.0
*/
class ImgDemo extends JFrame {
Image image;
/**
*<br>方法說明:構造器,顯示窗體
*<br>輸入參數:
*<br>返回類型:
*/
ImgDemo(String filename) {
setTitle("drawImage Example");
try {
image = getToolkit().getImage(filename);
setIconImage(image);
} catch (Exception e) {
e.printStackTrace();
}
setSize(600, 250);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
show();
}
/**
*<br>方法說明:繪制圖像
*<br>輸入參數:
*<br>返回類型:
*/
public void paint(Graphics g) {
Insets insets = getInsets();
int x = insets.left, y = insets.top;
//獲取圖片尺寸
int w = image.getWidth(this);
int h = image.getHeight(this);
//正常顯示圖片
g.drawImage(image, x, y, this);
//縮小圖形
g.drawRect(x, y, w/4+1, h/4+1);//畫一個框
g.drawImage(image, x+1, y+1, w/4, h/4, this);
//水平翻轉
g.drawImage(image, x+w, y, x+2*w, y+h, w, 0, 0, h, this);
}
/**
*<br>方法說明:主方法,接受參數
*<br>輸入參數:
*<br>返回類型:
*/
public static void main(String[] args) {
if (args.length == 1) {
new ImgDemo(args[0]);
} else {
System.err.println("usage: java ImgDemo images-name ");
}
}
}