我在用缓冲图像画一个图。使用eclipse2020-03和java1.8,它运行得很好,看起来很棒。使用openjdk15升级到eclipse2020-12,看起来很糟糕。发生了什么变化?如何更正此代码?很抱歉,我不能发布太多的类,这是一个相当大的应用程序。如果有关系的话,我在画一个jpanel。
如果我使用mainplot(g2),它看起来很棒,但是如果我在那条线下使用缓冲区来绘制,它就很糟糕了。
谢谢你对我的帮助。
@Override public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
Dimension d = getSize();
BufferedImage bi = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB);
Graphics2D big = bi.createGraphics();
mainPlot(g2); // Looks great with this in, but if use below instead, looks very bad.
// mainPlot(big);
// g2.drawImage(bi, 0, 0, null); // get image drawn in thread and draw on plot
// big.dispose();
}
简化的mainplot():
private void mainPlot(Graphics2D g) {
Graphics2D g2 = (Graphics2D)g;
// adjustPlot(); // Adjust the plots scales based on data/settings
super.paintComponent(g2);
String[] splitData = null; // holds string split into pieces
boolean success = false;
AffineTransform transform = g2.getTransform(); // save current transform values
g2.setColor(Color.black);
g2.setStroke(new BasicStroke(2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); // set width of stroke
String rgb = props.getProperty(CFG.colorBack.toString()); // set backcolor of plot
thisControl.setBackground(process.getColor(rgb));
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
for (int j=100;j < 300;j+=10)
g2.drawLine(10, j, 500, j);
Font font = new Font("SanSerif", Font.BOLD, 50);
g2.setFont(font);
g2.drawString("test", 300, 50);
}
未缓冲和缓冲的图像:[1]:https://i.stack.imgur.com/ksa8w.png [2]: https://i.stack.imgur.com/tvlo8.png
我觉得这是一个大小不匹配的问题,但不知道是什么问题。
暂无答案!
目前还没有任何答案,快来回答吧!