我想在一些纯色背景上绘制一些文本,并且在文本周围出现一些文物。有没有办法获得干净的文字?Java AWT文本产生文物
final BufferedImage image = new BufferedImage(400, 400,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = (Graphics2D) image.getGraphics();
g2d.setColor(Color.BLUE);
g2d.fillRect(0,0, image.getWidth(), image.getHeight());
Font font = new Font ("Verdana", Font.PLAIN, 40);
AffineTransform affinetransform = new AffineTransform();
FontRenderContext frc = new FontRenderContext(affinetransform, true, true);
TextLayout layout = new TextLayout("Hello World!", font, frc);
g2d.setColor(Color.WHITE);
layout.draw(g2d, 100, 100);
ImageIO.write(image, "jpg", new File("testDirtyText.jpg"));
围绕这个任何其他方面的任何建议,将不胜感激也。
谢谢!
错误,什么文物;对不起,我只看到一个带有白色文字的蓝色矩形;并没有看起来“失序”? – GhostCat
工件就在文字的边缘。这是因为JPEG压缩质量问题。 @波恩指出我正确的方向。 – undetected