-
Bug
-
Resolution: Fixed
-
P4
-
6
-
mustang
-
x86
-
windows_2000
Name: nt126004 Date: 01/31/2002
FULL PRODUCT VERSION :
java version "1.4.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b91)
Java HotSpot(TM) Client VM (build 1.4.0-rc-b91, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
EXTRA RELEVANT SYSTEM CONFIGURATION :
The bug occurs also on solaris and linux
A DESCRIPTION OF THE PROBLEM :
When rendering an image to the screen using
Graphics2D.drawImage(Image, AffineTransform, ImageObserver).
If a transform with a large zoom factor is supplied,
the rendering of the image is incorrect. This can be seen
if drawing a rectangle around a pixel. the rectangle is
expected to be seen exactly around the pixel in large zoom
factor but its not. (the rectangle is accurate, the
drawImage not)
REGRESSION. Last worked in version 1.3.1
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. create a jpg image with a black pixel at 100,100
2. compile and run the attached class according to the
directions on the class coments
EXPECTED VERSUS ACTUAL BEHAVIOR :
To see the red rectangle exactly around the black pixel
when zoomed.
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package imagebug;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import javax.swing.*;
import java.util.*;
import java.awt.event.*;
import java.net.*;
/**
* This application shows a bug in the Graphics2D.drawImage
function
* The application shows an image and draws a red rectangle
on the pixel at (300,30)
* the pixel is black
* To see the bug:
* 1. run the application on jdk-1.4.0 beta3 b84
* 2. u should see a window with an image that appears to
be white
* 3. maximize the window
* 4. press the "zoom" button, u should see a black
rectangle which is the pixel at
* the specified point and a red rectangle around him
* 5. The rectangles are expected to be in synch with the
image pixel, however it
* is not!
* 6. use the slider to see the bug in other zoom factors
*/
public class ImageBugFrame extends JFrame {
URL imageUrl = getClass().getResource("image.jpg");
Image image = Toolkit.getDefaultToolkit().getImage
(imageUrl);
JPanel jPanel1 = new JPanel();
JButton btnZoomOriginal = new JButton();
JButton btnZoom = new JButton();
JPanel jPanel2 = new ImageCanvas();
Rectangle2D.Float pixelRectangle =
new
Rectangle2D.Float(0,0,1,1);
AffineTransform transform = new AffineTransform();
JSlider jSlider1 = new JSlider();
public ImageBugFrame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
btnZoomOriginal.setText("Original");
btnZoomOriginal.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
btnZoomOriginal_actionPerformed(e);
}
});
btnZoom.setText("Zoom");
btnZoom.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
btnZoom_actionPerformed(e);
}
});
jSlider1.setMinimum(300);
jSlider1.setMaximum(300000);
jSlider1.addMouseMotionListener(new
java.awt.event.MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
jSlider1_mouseDragged(e);
}
});
this.getContentPane().add(jPanel1, BorderLayout.SOUTH);
jPanel1.add(btnZoomOriginal, null);
jPanel1.add(btnZoom, null);
jPanel1.add(jSlider1, null);
this.getContentPane().add(jPanel2, BorderLayout.CENTER);
}
public static final void main(String[] args) {
JFrame frame = new ImageBugFrame();
frame.setBounds(0,0,300,300);
frame.pack();
frame.show();
}
class ImageCanvas extends JPanel {
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2d = (Graphics2D)g;
g2d.drawImage(image, transform, this);
Shape scaledRect =
transform.createTransformedShape(pixelRectangle);
g2d.setPaint(Color.red);
g2d.draw(scaledRect);
}
}
void zoom(double factor, int x, int y) {
transform.setToIdentity();
pixelRectangle.setRect(x,y, 1,1);
transform.translate(x, y);
transform.scale(factor, factor);
transform.translate(-x , -y);
repaint();
}
void btnZoom_actionPerformed(ActionEvent e) {
zoom(2000/3,300,30);
}
void btnZoomOriginal_actionPerformed(ActionEvent e) {
transform.setToIdentity();
repaint();
}
void jSlider1_mouseDragged(MouseEvent e) {
zoom(jSlider1.getValue()/300, 300,30);
}
}
---------- END SOURCE ----------
Release Regression From : 1.3.1
The above release value was the last known release where this
bug was knwon to work. Since then there has been a regression.
(Review ID: 137698)
======================================================================