Details
-
Bug
-
Resolution: Fixed
-
P3
-
8, 11, 15, 16
-
b07
-
x86_64
-
windows_10
Description
ADDITIONAL SYSTEM INFORMATION :
Microsoft Windows [Version 10.0.18363.1474]
java version "16" 2021-03-16
Java(TM) SE Runtime Environment (build 16+36-2231)
Java HotSpot(TM) 64-Bit Server VM (build 16+36-2231, mixed mode, sharing)
A DESCRIPTION OF THE PROBLEM :
In the produced image file, the red path looks good and the blue path looks weird. The difference between the two is that the blue path has double lineTo() calls. The effect is somehow related to the miter limit setting. I doubt that this is the correct behavior. I tried the same path with SVG and didn't get such an effect.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run the attached code
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
two identical paths in different colors
ACTUAL -
blue path is different and jagged
---------- BEGIN SOURCE ----------
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class JaggedLines
{
public static void main(String[] args) throws IOException
{
BufferedImage bim = new BufferedImage(500, 500, BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D) bim.getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setBackground(Color.white);
g.clearRect(0, 0, bim.getWidth(), bim.getHeight());
GeneralPath path;
AffineTransform at = g.getTransform();
g.setColor(Color.red);
g.transform(AffineTransform.getTranslateInstance(0, -1400));
g.transform(AffineTransform.getScaleInstance(10, 10));
path = new GeneralPath();
path.moveTo(24.954517, 159);
path.lineTo(21.097446, 157.5);
path.lineTo(17.61364, 162);
path.lineTo(13.756569, 163.5);
path.lineTo(11.890244, 160.5);
g.draw(path);
g.setTransform(at);
g.setColor(Color.blue);
path = new GeneralPath();
g.transform(AffineTransform.getTranslateInstance(0, -1300));
g.transform(AffineTransform.getScaleInstance(10, 10));
path.moveTo(24.954517, 159);
path.lineTo(21.097446, 157.5);
path.lineTo(21.097446, 157.5); // this repeats the previous one
path.lineTo(17.61364, 162);
path.lineTo(17.61364, 162); // this repeats the previous one
path.lineTo(13.756569, 163.5);
path.lineTo(13.756569, 163.5); // this repeats the previous one
path.lineTo(11.890244, 160.5);
g.draw(path);
g.dispose();
ImageIO.write(bim, "png", new File("huhu.png"));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
remembering whether the last path operation was a lineTo, and then comparing its coordinate, and ignoring it if it's the same. Checking the position with getCurrentPoint() isn't enough because in some cases, a moveTo and lineTo to the same position is used to produce a dot.
FREQUENCY : always
Microsoft Windows [Version 10.0.18363.1474]
java version "16" 2021-03-16
Java(TM) SE Runtime Environment (build 16+36-2231)
Java HotSpot(TM) 64-Bit Server VM (build 16+36-2231, mixed mode, sharing)
A DESCRIPTION OF THE PROBLEM :
In the produced image file, the red path looks good and the blue path looks weird. The difference between the two is that the blue path has double lineTo() calls. The effect is somehow related to the miter limit setting. I doubt that this is the correct behavior. I tried the same path with SVG and didn't get such an effect.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run the attached code
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
two identical paths in different colors
ACTUAL -
blue path is different and jagged
---------- BEGIN SOURCE ----------
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class JaggedLines
{
public static void main(String[] args) throws IOException
{
BufferedImage bim = new BufferedImage(500, 500, BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D) bim.getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setBackground(Color.white);
g.clearRect(0, 0, bim.getWidth(), bim.getHeight());
GeneralPath path;
AffineTransform at = g.getTransform();
g.setColor(Color.red);
g.transform(AffineTransform.getTranslateInstance(0, -1400));
g.transform(AffineTransform.getScaleInstance(10, 10));
path = new GeneralPath();
path.moveTo(24.954517, 159);
path.lineTo(21.097446, 157.5);
path.lineTo(17.61364, 162);
path.lineTo(13.756569, 163.5);
path.lineTo(11.890244, 160.5);
g.draw(path);
g.setTransform(at);
g.setColor(Color.blue);
path = new GeneralPath();
g.transform(AffineTransform.getTranslateInstance(0, -1300));
g.transform(AffineTransform.getScaleInstance(10, 10));
path.moveTo(24.954517, 159);
path.lineTo(21.097446, 157.5);
path.lineTo(21.097446, 157.5); // this repeats the previous one
path.lineTo(17.61364, 162);
path.lineTo(17.61364, 162); // this repeats the previous one
path.lineTo(13.756569, 163.5);
path.lineTo(13.756569, 163.5); // this repeats the previous one
path.lineTo(11.890244, 160.5);
g.draw(path);
g.dispose();
ImageIO.write(bim, "png", new File("huhu.png"));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
remembering whether the last path operation was a lineTo, and then comparing its coordinate, and ignoring it if it's the same. Checking the position with getCurrentPoint() isn't enough because in some cases, a moveTo and lineTo to the same position is used to produce a dot.
FREQUENCY : always