-
Bug
-
Resolution: Fixed
-
P3
-
1.0
-
1.0.2
-
x86
-
windows_nt
-
Not verified
Win32 only: drawing scaled double-buffering image causes exception in
sun.awt.win32.Win32Graphics.drawImage()
Steps to reproduce
Compile and run the attached code
// will need /usr/green2/sqe/kas-tests/AppletFrame.java
// package bugs;
import java.applet.Applet;
import java.awt.*;
import java.util.*;
public class ict extends Applet
{
// class variables
InterfaceComponent _component;
ViewCanvas _view;
BuildCanvas _canvas;
public ict()
{
setLayout( new BorderLayout() );
setBackground( Color.lightGray );
_component = new InterfaceComponent( Color.lightGray );
add( "South", _view = new ViewCanvas( _component, 0.5F ) );
add( "Center", _canvas = new BuildCanvas(_component) );
}
public void init()
{
resize(700, 400);
}
public void start()
{
Image image = createImage( _component._totalWidth, _component._totalHeight );
_component.init(image);
}
public void repaint()
{
Component components[] = getComponents();
for ( int i = 0; i < components.length; ++i )
components[i].repaint();
}
public static void main(String args[])
{
AppletFrame.startApplet("ict", "Image Canvas Test", args);
}
}
class InterfaceComponent
{
public Image _image;
Graphics _graphics;
public int _totalWidth;
public int _totalHeight;
public int _width = 600;
public int _height = 300;
int _inset = 50;
int _creepFactor = 1;
Color _bg;
public InterfaceComponent(Color background)
{
_bg = background;
_totalWidth = _width + ( _inset * 2 );
_totalHeight = _height + ( _inset * 2 );
}
public void init( Image image )
{
_image = image;
_graphics = _image.getGraphics();
_graphics.setColor(_bg);
_graphics.fillRect(0, 0, _totalWidth, _totalHeight);
_graphics.setColor(Color.blue);
_graphics.fillRect(_inset, _inset, _width, _height);
_graphics.setColor(Color.red);
_graphics.drawLine( 0,
_totalHeight - _creepFactor,
_totalWidth,
_totalHeight - _creepFactor );
}
public void update()
{
++_creepFactor;
_graphics.setColor(Color.red);
_graphics.drawLine(0, _totalHeight - _creepFactor, _totalWidth,
_totalHeight - _creepFactor);
// stub
System.out.println("Updating image");
}
}
class BuildCanvas extends Canvas
{
InterfaceComponent _component;
public BuildCanvas(InterfaceComponent component)
{
_component = component;
}
public Dimension preferredSize()
{
Dimension size = new Dimension( _component._totalWidth,
_component._totalHeight );
return size;
}
public Dimension minimumSize()
{
Dimension size = new Dimension( _component._totalWidth,
_component._totalHeight );
return size;
}
public void paint(Graphics g)
{
g.drawImage( _component._image, 0, 0, this );
}
/** To avoid image flicker, override update()
*/
public void update(Graphics g)
{
g.drawImage(_component._image, 0, 0, this);
}
public boolean mouseDown(Event evt, int x, int y)
{
_component.update();
getParent().repaint();
return true;
}
}
class ViewCanvas extends Canvas
{
InterfaceComponent _component;
int _width, _height;
public ViewCanvas(InterfaceComponent component, float scale)
{
_component = component;
_width = (int)( (float)_component._totalWidth * scale );
_height = (int)((float)_component._totalHeight * scale );
}
public Dimension preferredSize() {
Dimension size = new Dimension(_width, _height);
return size;
}
public Dimension minimumSize()
{
Dimension size = new Dimension(_width, _height);
return size;
}
public void paint(Graphics g)
{
g.drawImage(_component._image, 0, 0,
_width, _height, this);
}
/** To avoid flicker override update
*/
public void update(Graphics g)
{
g.drawImage(_component._image, 0, 0,
_width, _height, this);
}
}
sun.awt.win32.Win32Graphics.drawImage()
Steps to reproduce
Compile and run the attached code
// will need /usr/green2/sqe/kas-tests/AppletFrame.java
// package bugs;
import java.applet.Applet;
import java.awt.*;
import java.util.*;
public class ict extends Applet
{
// class variables
InterfaceComponent _component;
ViewCanvas _view;
BuildCanvas _canvas;
public ict()
{
setLayout( new BorderLayout() );
setBackground( Color.lightGray );
_component = new InterfaceComponent( Color.lightGray );
add( "South", _view = new ViewCanvas( _component, 0.5F ) );
add( "Center", _canvas = new BuildCanvas(_component) );
}
public void init()
{
resize(700, 400);
}
public void start()
{
Image image = createImage( _component._totalWidth, _component._totalHeight );
_component.init(image);
}
public void repaint()
{
Component components[] = getComponents();
for ( int i = 0; i < components.length; ++i )
components[i].repaint();
}
public static void main(String args[])
{
AppletFrame.startApplet("ict", "Image Canvas Test", args);
}
}
class InterfaceComponent
{
public Image _image;
Graphics _graphics;
public int _totalWidth;
public int _totalHeight;
public int _width = 600;
public int _height = 300;
int _inset = 50;
int _creepFactor = 1;
Color _bg;
public InterfaceComponent(Color background)
{
_bg = background;
_totalWidth = _width + ( _inset * 2 );
_totalHeight = _height + ( _inset * 2 );
}
public void init( Image image )
{
_image = image;
_graphics = _image.getGraphics();
_graphics.setColor(_bg);
_graphics.fillRect(0, 0, _totalWidth, _totalHeight);
_graphics.setColor(Color.blue);
_graphics.fillRect(_inset, _inset, _width, _height);
_graphics.setColor(Color.red);
_graphics.drawLine( 0,
_totalHeight - _creepFactor,
_totalWidth,
_totalHeight - _creepFactor );
}
public void update()
{
++_creepFactor;
_graphics.setColor(Color.red);
_graphics.drawLine(0, _totalHeight - _creepFactor, _totalWidth,
_totalHeight - _creepFactor);
// stub
System.out.println("Updating image");
}
}
class BuildCanvas extends Canvas
{
InterfaceComponent _component;
public BuildCanvas(InterfaceComponent component)
{
_component = component;
}
public Dimension preferredSize()
{
Dimension size = new Dimension( _component._totalWidth,
_component._totalHeight );
return size;
}
public Dimension minimumSize()
{
Dimension size = new Dimension( _component._totalWidth,
_component._totalHeight );
return size;
}
public void paint(Graphics g)
{
g.drawImage( _component._image, 0, 0, this );
}
/** To avoid image flicker, override update()
*/
public void update(Graphics g)
{
g.drawImage(_component._image, 0, 0, this);
}
public boolean mouseDown(Event evt, int x, int y)
{
_component.update();
getParent().repaint();
return true;
}
}
class ViewCanvas extends Canvas
{
InterfaceComponent _component;
int _width, _height;
public ViewCanvas(InterfaceComponent component, float scale)
{
_component = component;
_width = (int)( (float)_component._totalWidth * scale );
_height = (int)((float)_component._totalHeight * scale );
}
public Dimension preferredSize() {
Dimension size = new Dimension(_width, _height);
return size;
}
public Dimension minimumSize()
{
Dimension size = new Dimension(_width, _height);
return size;
}
public void paint(Graphics g)
{
g.drawImage(_component._image, 0, 0,
_width, _height, this);
}
/** To avoid flicker override update
*/
public void update(Graphics g)
{
g.drawImage(_component._image, 0, 0,
_width, _height, this);
}
}