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

Drawing a 45° line with transparent color produces line double the thickness

    XMLWordPrintable

    Details

    • Subcomponent:
      2d
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10

      A DESCRIPTION OF THE PROBLEM :
      Using the Graphics2D class function drawLine to draw a line angled at 45° in the upward direction (x1 < x2 and y1 > y2), while using a color with an alpha value different than full opacity (alpha < 255) yields a line with double the thickness then when either using a fully opaque color or when drawing a line in the downward direction (x1 < x2 and y1 < y2) angled at 45° while using a color with arbitrary opacity (alpha <= 255).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached code and look at the output file named "transparent.png".

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The pixels to which the line is drawn in the "transparent.png" output file should be the same ones that are drawn in the "opaque.ong" output file.
      ACTUAL -
      The line drawn in the "transparent.png" output file has double the width than the one drawn in the "opaque.png" output file.

      ---------- BEGIN SOURCE ----------
      package main.app;

      import javax.imageio.ImageIO;
      import java.awt.*;
      import java.awt.image.BufferedImage;
      import java.io.File;
      import java.io.IOException;

      public class Program {
          public static void main(String[] args) throws IOException {
              BufferedImage transparentImage = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB);
              Graphics2D transparentGraphics = transparentImage.createGraphics();

              transparentGraphics.setBackground(Color.WHITE);
              transparentGraphics.fillRect(0, 0, transparentImage.getWidth(), transparentImage.getHeight());

              transparentGraphics.setPaint(new Color(0, 0, 0, 128));
              transparentGraphics.drawLine(0, 49, 49, 0);

              transparentGraphics.dispose();
              ImageIO.write(transparentImage, "png", new File("transparent.png"));

              BufferedImage opaqueImage = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB);
              Graphics2D opaqueGraphics = opaqueImage.createGraphics();

              opaqueGraphics.setBackground(Color.WHITE);
              opaqueGraphics.fillRect(0, 0, opaqueImage.getWidth(), opaqueImage.getHeight());

              opaqueGraphics.setPaint(new Color(0, 0, 0, 255));
              opaqueGraphics.drawLine(0, 49, 49, 0);

              opaqueGraphics.dispose();
              ImageIO.write(opaqueImage, "png", new File("opaque.png"));
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

        1. opaque1.png
          opaque1.png
          8 kB
        2. Program.java
          1 kB
        3. transparent1.png
          transparent1.png
          8 kB

          Activity

            People

            Assignee:
            azvegint Alexander Zvegintsev
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: