I'm working with drawImage of a JPanel Component. It has a very odd behaviour. It should require an Image as the first argument: for example, drawImage(img,0,0,null). Everything works fine when img is, for example, a BufferedImage created with createImage or ImageIO.read. The problems come when I use some MyImage class that extends Image. No way to get the image drawn. For example, I tried:
class MyImage extends Image {
private Image img;
public MyImage() {
try {img=}
catch (IOException e)

}
public void flush() {img.flush();}
public Graphics getGraphics() {return img.getGraphics();}
public int getHeight(ImageObserver observer) {return img.getHeight(observer);}
public Object getProperty(String name, ImageObserver observer) {return img.getProperty(name,observer);}
public Image getScaledInstance(int width, int height, int hints) {return img.getScaledInstance(width,height,hints);}
public ImageProducer getSource() {return img.getSource();}
public int getWidth(ImageObserver observer) {return img.getWidth(observer);}
}
An image created with i=new MyImage() should behave exactly like the Image img defined inside the class. Instead, no image is displayed!
I made many other tests. A way to get a working MyImage is to extend BufferedImage; I draw on i=new MyImage() by using getGraphics(). This image can be drawn by drawImage. So I tried to modify the methods defined in Image, in order to detect how drawImage works. It was really a surprise! After calling drawImage, only getHeight and getWidth are called, with null as argument. This notwithstanding, the image can be drawn correctly!!!
Now, I ask if someone has been able to write a class that extends Image and can be displayed by drawImage. It is evident that the Image methods are not enough. But what are the requirements to get a working Image object?
Thank you for the help!
Doriano Brogioli