Duplicate :
|
Name: jk109818 Date: 12/17/2002 FULL PRODUCT VERSION : java version "1.4.1_01" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01) Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode) FULL OPERATING SYSTEM VERSION :RedHat 8.0 (glibc-2.2.93-5, kernel 2.4.18-18.8.0, Red Hat Linux release 8.0 (Psyche)) A DESCRIPTION OF THE PROBLEM : When creating an image using Component.createImage(int x, int y), and then drawing said image to Graphics2D object after calling Graphics2D.rotate(double theta, double x, double y), the colors red, green, and black no longer appear. The color blue remains constant. This problem also appears when using a BufferedImage of the following types: TYPE_INT_BGR, TYPE_USHORT_555_RGB, and TYPE_USHORT_565_RGB. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : 1. Create an Image using Component.createImage(int width, int height). 2. Call Graphics2D.rotate(double theta, double x, double y) on a Graphics object that will render to the screen. 3. Call Graphics2D.drawImage(Image img, int x, int y, ImageObserver observer) passing the created image. EXPECTED VERSUS ACTUAL BEHAVIOR : I expect to see the image rotated display all color correctly. Instead, blue, red, and black seem to be missing. REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import javax.swing.*; public class RotateTest extends JPanel implements ActionListener { private Image mImage; private Timer mTimer; private double mRotate = 0d; public RotateTest() { } public void startTest() { mImage = createImage(100, 100); Graphics g = mImage.getGraphics(); g.setColor(Color.red); g.fillRect(0, 0, 50, 50); g.setColor(Color.blue); g.fillRect(50, 0, 50, 50); g.setColor(Color.green); g.fillRect(0, 50, 50, 50); g.setColor(Color.black); g.fillRect(50, 50, 50, 50); mTimer = new Timer(50, this); mTimer.start(); } public static void main(String args[]) { RotateTest test = new RotateTest(); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(test); frame.setSize(200, 200); frame.setVisible(true); test.startTest(); } public void paintComponent(Graphics g) { int width = getWidth(); int height = getHeight(); Graphics2D g2d = (Graphics2D)g; g2d.setPaint(Color.white); g2d.fillRect(0, 0, width, height); if (mImage != null) { g2d.rotate(mRotate, width/2, height/2); g2d.drawImage(mImage, width/4, height/4, this); } } public void actionPerformed(ActionEvent e) { if (e.getSource() == mTimer) { if ((mRotate += Math.PI/16) >= (Math.PI*2)) { mRotate = 0; } repaint(); } } } ---------- END SOURCE ---------- CUSTOMER WORKAROUND : Instead of using Component.createImage(int width, int height), create new images using a BufferedImage constructor, such as: mImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); Note, passing TYPE_INT_BGR, TYPE_USHORT_555_RGB, and TYPE_USHORT_565_RGB as the final argument in the BufferedImage will continue to create the bug. Release Regression From : 1.3.1_06 The above release value was the last known release where this bug was known to work. Since then there has been a regression. (Review ID: 167279) ======================================================================