Using RenderingHints to draw text as an image

I am drawing text to a BufferedImage which will then be scrolled acros the screen as a sprite. I am rendering white text on a black background with an Arial font using RenderingHints.KEY_ANTIALIASING and RenderingHints.VALUE_ANTIALIAS_ON.

However, I’ve noticed that for any font size at or below 14 points any curved or angled portion of the character being rendered appears faded and thus the resultant strings appear very splotchy.

Is this just an unavoidable side effect of rendering white, aliased text on a black background with small point sizes or is there something I can do normalize the color transitions between the curved and straight points of the font?

I would have thought that KEY_STROKE_CONTROL set to VALUE_STROKE_NORMALIZE would have helped, but it seems to have no effect. Am I missing something else that might help? Is there a better way to render aliased fonts in Java than what I’m using?

Thanks for any insight.

Oh, I guess maybe some actual code might be useful too…

My main rendering routine is as follows…


public BufferedImage getBufferedImage()
      {
            if (mainImage != null)
            {
                  return mainImage;
            }
            Dimension dim = getCalculatedBounds();
            mainImage = new BufferedImage((int)dim.getWidth(),(int)dim.getHeight(),BufferedImage.TYPE_INT_ARGB);
            this.paintComponent(mainImage.createGraphics());
                  
            return mainImage;  
      }

protected void paintComponent(Graphics g)
      {
            Graphics2D g2d = (Graphics2D)g;
      
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
            
            Font tempFont = this.getFont();
            g2d.setFont(tempFont);
            int fontBaseline = getBaseline(); 
      
            g2d.setColor(bgColor);
             g2d.fillRect(0, 0, compWidth, compHeight);
            g2d.setColor(fgColor);
            
            int numRows = dataMatrix.size();
            for (int row=0;row<numRows;row++)
            {
                  int fontLoc = ((getRowHeight() * (row+1)) - fontBaseline);
                  paintString(g2d, row, fontLoc);
            }
            g2d.dispose();
      }