Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8015070

Antialiased text on translucent backgrounds gets bright artifacts

XMLWordPrintable

    • 2d
    • b118

      FULL PRODUCT VERSION :
      Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
      Java HotSpot(TM) Server VM (build 23.21-b01, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux xxxx 2.6.31-23-generic-pae #75-Ubuntu SMP Fri Mar 18 19:14:10 UTC 2011 i686 GNU/Linux

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      I've seen this same problem on Windows 7 as well. Also, the artifacts can be triggered with Java 1.6 if the background image has just the right band ordering, and maybe sample model.

      A DESCRIPTION OF THE PROBLEM :
      Text drawn on translucent backgrounds with Java 7 with anti-aliasing turned on get artifacts in the anti-aliased pixels. These pixels are brighter than they should be.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a buffered image with transparency, fill it with a color that's translucent, turn on text anti aliasing, then draw text with an opaque color.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      All sample values in the resulting image should have values in the range between the background color and the text color, inclusive.
      ACTUAL -
      The anti-aliased pixels around the edges of the text are brighter than they should be. For example, with a background color RGB (153, 153, 153) and a text color (255, 136, 0), the defective pixels have values like (255, 255, 239). Orange text on a gray background shouldn't have white edges!

      Depending on the colors used for background and text, the problem can be hard to detect.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package bugtester;

      import java.awt.Color;
      import java.awt.Font;
      import java.awt.Graphics2D;
      import java.awt.RenderingHints;
      import java.awt.image.BufferedImage;
      import java.io.File;
      import java.io.IOException;

      import javax.imageio.ImageIO;

      public class AwtAntiAliasingBugRunner {

      public static void main(String[] args) throws IOException {

      BufferedImage bufferedImage = new BufferedImage(200, 100, BufferedImage.TYPE_4BYTE_ABGR);

      Graphics2D graphics = (Graphics2D) bufferedImage.getGraphics();

      graphics.setColor(new Color(153, 153, 153, 127));
      graphics.fillRect(0, 0, 100, 100);

      graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

      Font font = new Font( " Verdana " , Font.PLAIN, 55);

      graphics.setFont(font);

      graphics.setColor(new Color(255, 136, 0));
      graphics.drawString( " Save " , 20, 60);

      graphics.dispose();

      ImageIO.write(bufferedImage, " png " , new File( " artifacts.png " ));
      }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      No known workaround. Although the impact of this bug is not severe right now, this may prevent us from migrating our software from Java 6 to Java 7.

            pnarayanan Prahalad Kumar Narayanan (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: