Graphics2D 是否会在每次调用 paintComponent() 时重置构图?为什么?
例如,
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() 之后重置了合成,为什么必须这样做?