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

drawImage misses background's alpha channel

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 8u60
    • client-libs
    • 2d
    • b114
    • x86_64
    • linux

      FULL PRODUCT VERSION :
      java version "1.8.0_60"
      Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
      Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux 3.13.0-63-generic #103-Ubuntu SMP Fri Aug 14 21:42:59 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      Alpha channel of background is missing when drawing scaled image through Graphics2D#drawImage(Image, int, int, int, int, Color, ImageObserver) and Graphics2D#drawImage(Image, int, int, int, int, int, int, int, int, Color, ImageObserver).
      When image is unscaled, alpha channel is used as normal.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached simple test case. The left image is unscaled and background is correct. The right image is scaled and alpha channel is lost.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Scaled image with semitransparent background just like the left one's.
      ACTUAL -
      Scaled image with opaque background.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.image.*;

      import javax.swing.*;

      public class Test {
      public static void main(String[] args) {
      JFrame frame = new JFrame("test");
      frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
      JPanel content = new JPanel() {
      @Override
      public void paint(Graphics g) {
      Image img = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB);
      Graphics2D imgGraphics = (Graphics2D) img.getGraphics();
      imgGraphics.setColor(Color.blue);
      imgGraphics.fillRect(10, 10, 30, 30);
      imgGraphics.dispose();
      g.setColor(Color.pink);
      g.fillRect(0, 0, 100, 50);
      g.drawImage(img, 0, 0, new Color(0, 255, 255, 128), null);
      g.drawImage(img, 55, 5, 40, 40, new Color(0, 255, 255, 128), null);
      }
      };
      frame.getContentPane().add(content);
      frame.setSize(100, 50);
      frame.setVisible(true);
      }
      }
      ---------- END SOURCE ----------

            jdv Jayathirth D V
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: