0
每次調用paintComponent()時,Graphics2D是否會重置組合?爲什麼?下次調用paintComponent()時,Graphics2D是否會重置組合?爲什麼?
例如,
public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
System.out.println(((AlphaComposite)g2.getComposite()).getAlpha()); //printing alpha value before setting composition
g.drawImage(background,0,0,500,500,null);
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
g.setColor(Color.RED);
g.fillOval(x-100,y-100,200,200);
System.out.println(((AlphaComposite)g2.getComposite()).getAlpha()); //printing alpha value after setting composition
}
上述代碼打印以下時的paintComponent()被調用幾次...
1.0
0.5
1.0
0.5
1.0
0.5
1.0
0.5
意思的Graphics2D重置組合物之後的paintComponent(),爲什麼它必須做什麼?
這是一個JFrame或一個小程序 – imulsion