哪一種創(chuàng)建圖像的方法好一些?
1. Image image = java.awt.Toolkit.getDefaultToolkit.getImage(java.lang.String / java.net.URL);
使用這個方法,馬上返回,而圖像的加載是在后臺進(jìn)行,即,并不能馬上得到圖像的數(shù)據(jù)
2. Image image = new ImageIcon(fileName / url).getImage();
直到圖像加載完后,才向下繼續(xù)運行
java.awt.Image
|__java.awt.image.BufferedImage
Graphics g = bufferedImage.getGraphics();
在g上畫圖
protected void javax.swing.JComponent.paintComponent(java.awt.Graphics g) {
super.paintComponent(g); // 保證實現(xiàn)雙緩沖
Graphics2D g2d = (Graphics2D)g2d;
}
如在另一個線程中加載圖像數(shù)據(jù),然后調(diào)用panel.repaint(),使新加載的圖像顯示出來
不要去重寫paint方法與repaint