【发布时间】:2015-09-21 19:44:42
【问题描述】:
当我使用 (0,0) "Rectangle(0,0,100,100)" 的坐标作为矩形时,我得到了渐变。当我使用:
GradientPaint gp = new GradientPaint(0, 0, c1, 0, 100, c2);
Rectangle reckt = new Rectangle(0,100,100,200);
渐变消失。我做错了什么?
public void draw( Graphics g ) {
Graphics2D g2d = (Graphics2D) g;
c1 = new Color(0, 0, 255);
c2 = new Color(0, 255, 255);
GradientPaint gp = new GradientPaint(0, 0, c1, 0, 100, c2);
g2d.setPaint(gp);
Rectangle reckt = new Rectangle(0,0,100,100);
g2d.fill(reckt);
}
【问题讨论】:
-
使用 AffineTransform 并平移位置,然后简单地在 0x0 处绘制/绘制。完成后别忘了重置它
标签: java graphics awt gradient graphics2d