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

Images with RGB (169,169,169) is changed upon AffineTransformOp

    XMLWordPrintable

    Details

    • Subcomponent:
      2d
    • OS:
      windows

      Description

      FULL PRODUCT VERSION :
      java version " 1.7.0_09 "
      Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
      Java HotSpot(TM) Client VM (build 23.5-b02, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      Color RGB(169,169,169) is converted to pink if AffineTransformOp::filter is called on an BufferedImage of type BufferedImage.TYPE_INT_ARGB.
      This behavior is only present when AffineTransformOp.TYPE_NEAREST_NEIGHBOR is used and it did not happen on JDK 6.


      REGRESSION. Last worked in version 6u31


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package ui;

      import java.awt.BorderLayout;
      import java.awt.Graphics;
      import java.awt.Graphics2D;
      import java.awt.Image;
      import java.awt.geom.AffineTransform;
      import java.awt.image.AffineTransformOp;
      import java.awt.image.BufferedImage;
      import java.io.File;

      import javax.swing.ImageIcon;
      import javax.swing.JComponent;
      import javax.swing.JFrame;

      // To run this code you must have a jpg with a filled square of color 169,169,169.

      public class JTestBufferImage extends JFrame
      {
          RenderComponent _comp = new RenderComponent();
          JTestBufferImage()
          {
              _comp.setImage(new File( " c:\\temp\\square.jpg " ));
              getContentPane().add(_comp,BorderLayout.CENTER);
              setSize(400,400);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          }
          /**
           * @param args
           */
          public static void main(String[] args)
          {
              new JTestBufferImage().setVisible(true);
          }

          class RenderComponent extends JComponent
          {

              BufferedImage _img = null;

              RenderComponent()
              {
              }

              void setImage(File fi)
              {
                  setImage(new ImageIcon(fi.getAbsolutePath()).getImage());
              }

              void setImage(Image src)
              {
                  _img = new BufferedImage(src.getWidth(null), src.getHeight(null),BufferedImage.TYPE_INT_ARGB);
                  AffineTransform transform = AffineTransform.getTranslateInstance(0, 0);
                  AffineTransformOp op = new AffineTransformOp(
                      transform,
                      AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
                  Graphics2D g2d = _img.createGraphics();
                  g2d.drawImage(src, 0, 0, null);
                  _img = op.filter(_img, null); // Color RGB 169,169,169 is modified.
                  g2d.dispose();
                  setSize(_img.getWidth(),_img.getHeight());
                  repaint();
              }

              @Override
              protected void paintComponent(Graphics g)
              {
                  if (_img!=null)
                  {
                      g.drawImage(_img, 0, 0, null);
                  }
              }

          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      AffineTransformOp.Use TYPE_BILINEAR or AffineTransformOp.TYPE_BICUBIC

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: