开发者

Force Java2D Subpixel Antialiasing

开发者 https://www.devze.com 2022-12-29 13:22 出处:网络
I am using Java2D to generate images with text on them.The fonts are being horribly rendered with bad antialiasing on a Server running Ubuntu but render beautifully on an OSX and Ubuntu workstation.I

I am using Java2D to generate images with text on them. The fonts are being horribly rendered with bad antialiasing on a Server running Ubuntu but render beautifully on an OSX and Ubuntu workstation. I guess that the difference between the two Ubuntu installs is xwindows vs no xwindows? Maybe? Anyway, I guess that my rendering hints are being ignored and the java 1.6 subpixel antialiasing algorithms are not being used on the server.

My Rendering hints are below. I am optimizing for a vertically positioned display.

g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.开发者_JS百科VALUE_TEXT_ANTIALIAS_LCD_VRGB);

I'm creating the font directly from a ttf file which did improve the rendering. I don't think the font was installed on the machine so it was defaulting to something else. Now the font is correct but the antialiasing is still off. It does look better than when I turn antialiasing completely off and generate the images so I assume it is doing something but it just doesn't look as good.

and I've tried the Java property

-Dawt.useSystemAAFontSettings=lcd

but it didn't change anything.

Any suggestions? Thanks.


Did you already try something like this:

public void paintComponent(Graphics g){
  @SuppressWarnings("unchecked")
  Map<String, String> desktopHints = (Map<String, String>) Toolkit
    .getDefaultToolkit().getDesktopProperty("awt.font.desktophints");
  Graphics2D g2d = (Graphics2D) g;
  if(desktopHints != null){
    g2d.addRenderingHints(desktopHints);
  }
  g2d.drawString("text", 10, 10);
}

The Graphics object received in paintComponent() is set up with defaults that do not know anything about the desktop properties (monitor type). Querying Toolkit for the desktophints will return information from the underlying operating system about the hardware used. Compare "Filthy Rich Clients", page 59.

0

精彩评论

暂无评论...
验证码 换一张
取 消