-
Bug
-
Resolution: Not an Issue
-
P3
-
6
-
None
-
generic
-
generic
During experimenting with advanced painting technigues in Swing
I noticed that I get unexpected results for rotation transformation
(see the test case below)
Most of the Swing components are painted with help of
Graphics.drawRect(int,int,int,int) and Graphics.fillRect(int,int,int,int) methods,
and that methods seem to have a bug with rotation transformation,
because Graphics.drawRect(Rectange) and Graphics.fillRect(Rectangle) works fine
I think this bug is really worth fixing for Mustang,
because it is highly visible when you applying tranformation on Swing components
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
public class TransformTest {
public static void main(String[] args) throws Exception {
BufferedImage i = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = (Graphics2D) i.getGraphics();
g2.translate(5, 5);
paint(g2);
g2.translate(20, 0);
g2.rotate(Math.PI / 2);
paint(g2);
File file = new File("MyTest.png");
file.createNewFile();
ImageIO.write(i, "png", file);
}
public static void paint(Graphics2D g2) {
int width = 5, height = 5;
g2.setColor(Color.BLUE);
g2.fillRect(0, 0, width, height);
g2.setColor(Color.RED);
g2.drawRect(0, 0, width - 1, height - 1);
}
// This variant works ok
/*
public static void paint(Graphics2D g2) {
int width = 5, height = 5;
Rectangle rect = new Rectangle(0, 0, width - 1, height - 1);
g2.setColor(Color.BLUE);
g2.fill(rect);
g2.setColor(Color.RED);
g2.draw(rect);
}
*/
}
I noticed that I get unexpected results for rotation transformation
(see the test case below)
Most of the Swing components are painted with help of
Graphics.drawRect(int,int,int,int) and Graphics.fillRect(int,int,int,int) methods,
and that methods seem to have a bug with rotation transformation,
because Graphics.drawRect(Rectange) and Graphics.fillRect(Rectangle) works fine
I think this bug is really worth fixing for Mustang,
because it is highly visible when you applying tranformation on Swing components
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
public class TransformTest {
public static void main(String[] args) throws Exception {
BufferedImage i = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = (Graphics2D) i.getGraphics();
g2.translate(5, 5);
paint(g2);
g2.translate(20, 0);
g2.rotate(Math.PI / 2);
paint(g2);
File file = new File("MyTest.png");
file.createNewFile();
ImageIO.write(i, "png", file);
}
public static void paint(Graphics2D g2) {
int width = 5, height = 5;
g2.setColor(Color.BLUE);
g2.fillRect(0, 0, width, height);
g2.setColor(Color.RED);
g2.drawRect(0, 0, width - 1, height - 1);
}
// This variant works ok
/*
public static void paint(Graphics2D g2) {
int width = 5, height = 5;
Rectangle rect = new Rectangle(0, 0, width - 1, height - 1);
g2.setColor(Color.BLUE);
g2.fill(rect);
g2.setColor(Color.RED);
g2.draw(rect);
}
*/
}