[5120] in java-interest
MediaTracker bug??
daemon@ATHENA.MIT.EDU (Christopher Helck)
Mon Jan 29 18:12:55 1996
Date: Mon, 29 Jan 1996 16:27:06 -0500
From: chris@telesph.com (Christopher Helck)
To: java-interest@java.sun.com
I'm having a problem with some images that are loaded with MediaTracker, when
I draw them with different sizes they are sometimes messed up. For example
suppose I have an image that is 40 pixels tall and 30 pixels wide, if I load
it with MediaTracker and display it as a 40x40 square I get garbage, displaying
it with other sizes (30x30) seems ok.
I have an example (with source) under http://www.walrus.com/~chelck. I see this
problem under Windows 95 and Solaris. (Note: under my home page I incorrectly
state that the problem occurs with the square's dimension is width x width --
I meant height x height).
I had researched this problem some time ago and worked around it, it's come
back to haunt me. Any help would be appreciated. Here's the source:
import java.lang.*;
import java.awt.*;
import java.applet.Applet;
public class MTBug extends Applet {
public void init() {
setLayout(new BorderLayout());
add("Center", new ImageCanvas(this));
show();
}
}
class ImageCanvas extends Canvas {
Applet applet;
Image image;
MediaTracker tracker;
int w;
int h;
ImageCanvas(Applet applet) {
this.applet = applet;
/*
* Change the next line to load your own gif image
*/
image = applet.getImage(applet.getDocumentBase(), "T1.gif");
tracker = new MediaTracker(this);
tracker.addImage(image, 0);
/*
* Wait for the image to load, we never see an exception!
*/
try {
tracker.waitForID(0);
} catch (InterruptedException e) {
System.out.println("Caught an exception");
return;
}
w = image.getWidth(this);
h = image.getHeight(this);
}
public void paint(Graphics g) {
if ((tracker.statusID(0, true) & MediaTracker.COMPLETE) != 0) {
g.drawImage(image, 0, 0, w, h, this); // Ok
g.drawImage(image, 50, 50, w, w, this); // Ok
g.drawImage(image, 100, 100, h, h, this); // Not ok
g.drawImage(image, 150, 150, h, w, this); // Ok
}
}
}
Thanks.
chris@telesph.com
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com