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

前端 未结 4 1429
迷失自我
迷失自我 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:41

    I found there were a few factors going on here.

    First, the image needs to be created from the underlying AWT component, and it must be created without transparency:

    cfg.createCompatibleImage(wid,hgt);
    

    instead of

    cfg.createCompatibleImage(wid,hgt,Transparency.TRANSLUCENT);
    

    Second, for some inexplicable reason, the primary AA setting, KEY_ANTIALIASING, must be off to use LCD subpixel AA.

    Lastly, and most importantly, the desktop font rendering hints are easily retrieved using:

    java.awt.Toolkit.getDesktopProperty("awt.font.desktophints")
    

    Update 2010-01-05

    Retesting in Java 6.26, it seems like the problem with needing to set general AA off to render text AA has finally been resolved (way to go Oracle... after Sun was just a few years decade too late).

提交回复
热议问题