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

java.awt.Color.brighter()/darker() methods make color opaque

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b121
    • CPU:
      generic, sparc
    • OS:
      generic, solaris
    • Verification:
      Verified

      Description

      Java SE specification states for java.awt.Color.brighter()/darker() methods:

      For instance "darker"
        "This method applies an arbitrary scale factor to each of the three RGB
         components of this Color to create a darker version of this Color."

      This means that alpha component must remain unchanged, however it is not
      the case for many Java implementations: 1.4.2, 5.0, 6.0, 7.

      The code snippet helps to reproduce the problem:
      -------------------------------------------------
      import java.awt.Color;

      public class TestColor {

          private void test(boolean direction) {
              Color color = new Color(20, 20, 20, 125);
              System.out.println(color.getAlpha());
              final int initialAlpha = color.getAlpha();
              for (int i = 0; i < 3; i++) {
                  if (direction) {
                      color = color.brighter();
                  } else {
                      color = color.darker();
                  }
                  if (color.getAlpha() != initialAlpha) {
                      System.out.println(direction ? "Color.brighter() failed: " + color.getAlpha() + " " + initialAlpha :
                                                     "Color.darker() failed: " + color.getAlpha() + " " + initialAlpha);
                  }
              }
          }

          public static void main(String argv[]) {
              new TestColor().test(true);
              new TestColor().test(false);
         }
      }
      --------------------------------------------------------------

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              dav Andrei Dmitriev (Inactive)
              Reporter:
              visaenko Vasily Isaenko (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: