AWT Image類
介紹
圖像控製是表示圖形圖像的所有圖像類的超類。
類的聲明
以下是聲明的java.awt.image類:
public abstract class Image extends Object
字段域
以下的字段的java.awt.image類:
-
protected float accelerationPriority -- 優先推進這個圖片。
-
static int SCALE_AREA_AVERAGING -- 使用麵積平均圖像縮放算法。
-
static int SCALE_DEFAULT -- 使用默認的圖像縮放算法。
-
static int SCALE_FAST -- 選擇一個圖像縮放算法具有更高優先級,縮放速度比縮放圖像的平滑度。
-
static int SCALE_REPLICATE -- 請使用圖像縮放算法體現在ReplicateScaleFilter類。
-
static int SCALE_SMOOTH -- 選擇一個圖像縮放算法具有更高優先級的圖像平滑度比縮放速度。
-
static Object UndefinedProperty -- UndefinedProperty對象的屬性冇有定義一個特定的形象時,應返回取出。
類的構造函數
S.N. | 構造函數&說明 |
---|---|
1 | Image() |
類方法
S.N. | 方法&說明 |
---|---|
1 |
void flush() Flushes all reconstructable resources being used by this Image object. |
2 |
float getAccelerationPriority() Returns the current value of the acceleration priority hint. |
3 |
ImageCapabilities getCapabilities(GraphicsConfiguration gc) Returns an ImageCapabilities object which can be inquired as to the capabilities of this Image on the specified GraphicsConfiguration. |
4 |
abstract Graphics getGraphics() Creates a graphics context for drawing to an off-screen image. |
5 |
abstract int getHeight(ImageObserver observer) Determines the height of the image. |
6 |
abstract Object getProperty(String name, ImageObserver observer) Gets a property of this image by name. |
7 |
Image getScaledInstance(int width, int height, int hints) Creates a scaled version of this image. |
8 |
abstract ImageProducer getSource() Gets the object that produces the pixels for the image. |
9 |
abstract int getWidth(ImageObserver observer) Determines the width of the image. |
10 |
void setAccelerationPriority(float priority) Sets a hint for this image about how important acceleration is. |
繼承的方法
這個類繼承的方法從以下類:
-
java.lang.Object
Choice 實例
選擇使用任何編輯器創建以下java程序 D:/ > AWT > com > yiibai > gui >
AwtControlDemopackage com.yiibai.gui; import java.awt.*; import java.awt.event.*; public class AwtControlDemo { private Frame mainFrame; private Label headerLabel; private Label statusLabel; private Panel controlPanel; public AwtControlDemo(){ prepareGUI(); } public static void main(String[] args){ AwtControlDemo awtControlDemo = new AwtControlDemo(); awtControlDemo.showImageDemo(); } private void prepareGUI(){ mainFrame = new Frame("Java AWT Examples"); mainFrame.setSize(400,400); mainFrame.setLayout(new GridLayout(3, 1)); mainFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent windowEvent){ System.exit(0); } }); headerLabel = new Label(); headerLabel.setAlignment(Label.CENTER); statusLabel = new Label(); statusLabel.setAlignment(Label.CENTER); statusLabel.setSize(350,100); controlPanel = new Panel(); controlPanel.setLayout(new FlowLayout()); mainFrame.add(headerLabel); mainFrame.add(controlPanel); mainFrame.add(statusLabel); mainFrame.setVisible(true); } private void showImageDemo(){ headerLabel.setText("Control in action: Image"); controlPanel.add(new ImageComponent("resources/java.jpg")); mainFrame.setVisible(true); } class ImageComponent extends Component { BufferedImage img; public void paint(Graphics g) { g.drawImage(img, 0, 0, null); } public ImageComponent(String path) { try { img = ImageIO.read(new File(path)); } catch (IOException e) { e.printStackTrace(); } } public Dimension getPreferredSize() { if (img == null) { return new Dimension(100,100); } else { return new Dimension(img.getWidth(), img.getHeight()); } } } }
編譯程序,使用命令提示符。到 D:/ > AWT 然後鍵入以下命令。
D:AWT>javac comyiibaiguiAwtControlDemo.java
如果冇有錯誤出現,這意味著編譯成功。使用下麵的命令來運行程序。
D:AWT>java com.yiibai.gui.AwtControlDemo
驗證下麵的輸出