Posted By:
Dmitry_Zakharov
Posted On:
Tuesday, November 26, 2002 05:09 AM
I tried to draw some image in offscreen image. Wait until image is finished drawing. And draw offscreen image on frame. I make the code below. But when I run, I see black screen. What's wrong with the code below ? import java.awt.*; import java.awt.image.*; public class Test{ static java.awt.Image img; static boolean done = false; public static void main (String[] args){ img = java.awt.Toolkit.getDefaultToolkit().getImage ("test.gif"); final BufferedImage b = new BufferedImage(400, 400, BufferedImage.TYPE_INT_RGB); final Graphics g = b.getGraphics(); ImageObserver o = new ImageObserver (){ public boolean imageUpdate (Image img, int infoflags, in
More>>
I tried to draw some image in offscreen image. Wait until image is finished drawing. And draw offscreen image on frame. I make the code below. But when I run, I see black screen. What's wrong with the code below ?
import java.awt.*;
import java.awt.image.*;
public class Test{
static java.awt.Image img;
static boolean done = false;
public static void main (String[] args){
img = java.awt.Toolkit.getDefaultToolkit().getImage ("test.gif");
final BufferedImage b = new BufferedImage(400, 400, BufferedImage.TYPE_INT_RGB);
final Graphics g = b.getGraphics();
ImageObserver o = new ImageObserver (){
public boolean imageUpdate (Image img, int infoflags, int x, int y, int w, int h){
if ((infoflags & (ERROR|ABORT|ALLBITS|FRAMEBITS)) != 0){
return !(done = true);
}
g.drawImage (Test.img, 0, 0, this);
return !(done = false);
}
};
g.drawImage(img, 0, 0, o);
try{
while (!done) Thread.sleep (100);
}catch (Throwable e){}
final Frame f = new Frame(){
public void paint (Graphics g){
g.drawImage (b, 0, 0, this);
}
};
f.setSize (100, 100);
f.setVisible (true);
}
}
<<Less