How can I inherit the system's anti-alias setting for painting text to off-screen images like swing does?

前端 未结 4 1430
迷失自我
迷失自我 2021-02-14 00:39

When I run my swing GUI applications under Java 6, they automatically use my configured sub-pixel anti-alias settings for all fonts. The result is much improved over standard A

4条回答
  •  花落未央
    2021-02-14 01:36

    Wait, are you running this code on a Windows JVM? I thought ClearType was a Microsoft technology that Swing inherits through some native code (ie, not available on Linux or other non Microsoft platforms).

    I once wrote a servlet that generated JPGs with anti aliased fonts that ran on Debian, and this was the code I used

    Font font = new Font("Komix", Font.PLAIN, 8);
    Graphics2D g2;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    FontRenderContext  frc = g2.getFontRenderContext();
    g2.setFont(font);
    g2.setPaint(Color.black);
    g2.drawString(sMessage, xOffset, yOffset);
    

    Offhand I can't recall if any of this code relies on Swing (I imported javax.swing and the servlet is about 300 lines long, so I may have thought I needed it for something else), a quick check on Google looks like this is squarely in the AWT space. Hope that helps.

提交回复
热议问题