I have background templates where java program must write some dynamic texts,
BufferedImage i开发者_高级运维mage = ImageIO.read(new File("background.jpg"));
Graphics g = image.createGraphics();
g.setFont(new Font("DejaVu Sans",Font.PLAIN,18));
g.drawString("Hello,World!",10,10);
When writing in such manner, I have some resolution problems around text that Java wrote.
How to write high resolution text on image by Java?
UPDATE: Here example with anti-aliasing.
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
The problem is not the drawing of the text, but the subsequent saving of the file: If you are using JPEG-compression, you will get compression artifacts, specially around sharp corners like your text.
There is no real way around this, apart from not using JPG.
精彩评论