-1
我有一個Java應用程序,有幾個JPanel,每個執行大量的繪畫,我得到很的性能問題。我正在使用下面的技術來試圖避免受到太多的影響,只有當面板上的某些內容發生變化時纔將JPanels內容繪製到BufferedImage上,而不是在主窗口調用重新繪製時執行此操作。當每個面板中有幾件事情發生變化時,應用程序變慢,動畫變得非常緊張。繪畫BufferedImage性能
我檢查CPU和它的只有在5%,但更新顯示非常緊張,當有幾個更新正在進行。有沒有什麼可能會影響到這一點,我只希望CPU在受到壓力時會出現緊張的問題。
public class myClass extends JPanel {
private BufferedImage bImage;
private void updateImage() {
BufferedImage temp= new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics g = temp.getGraphics();
Graphics2D g2 = (Graphics2D) g;
//Do lots and lots of drawing on g with other bufferedImages and lines and text etc
synchronized (bImage) {
bImage = temp;
}
}
public void paintComponent(Graphics g) {
synchronized (bImage) {
g.drawImage(bImage, 0, 0, this);
}
}
你使用雙緩衝? - 它可以幫助 – Toumash
對於我來說,這看起來並不像我的超級的paintComponent方法和同步。如果您創建併發布了一個[最小示例程序](http://sscce.org),則更好。 –
你多久繪一次'JPanel'?你是否在固定的時間內畫畫? – GiantTree