Incremental display of Images in a application....???

D

David

Hi

I've run into a bit of a perplexing problem.

I'm using JDK 1.3, and would like to stay with it
if I can for a while, until I at least understand some
things a bit better before moving on.

I would like to be able to load an Image into a JPanel
'incrementally' in a Java application (as opposed to an
applet). I would like to see the picture start at the top
and as it's loaded, display itself bit by bit, like you'd
expect to see when loading a large jpg from a slow
Internet connection in a browser.

I've reduced the code to this, which is basically a
tutorial-like version of simplified image loading.

// TestPanel is an inner class in a
// 'JFrame extended' test routine

private class TestPanel extends JPanel{

public Image localImage;

public TestPanel(){
this.setOpaque(true); // .....thought this might help
this.setDoubleBuffered(false); // ....same
}

public void setLocalImage(String path){
localImage = tk.createImage(path);
}

protected void paintComponent(Graphics g) {
if (this.localImage != null){
g.drawImage(localImage, 0, 0, this);
} else{
g.drawString("Missing Picture", 200, 100);
}
}

// ......next I over-rode
public boolean imageUpdate(Image img,
int infoflags,
int x,
int y,
int width,
int height){
if ((infoflags & ImageObserver.ALLBITS) != 0){
this.repaint();
return false;
} else if ((infoflags & ImageObserver.SOMEBITS) != 0){
//this.repaint(); //....tried this...it didn't help.
//return true;
} else {
}

return true;
}

The above code works okay, and the picture is eventually
drawn as expected, but it is never refreshed during loading,
and waits until it is completely finished loading before being
instantly drawn at the end (right after ALLBITS is detected).
All the documentation says drawImage(....) draws as much
of the picture as is currently available, but it isn't so..... at
least not in my app...??
There must be a secret or something.....
Including a repaint() when SOMEBITS is detected does
nothing but slow things down alot.

I've tried allot of different things, too many to list, but nothing
seems to work.

Is there any way to get it to draw 'incrementally' as it's
loading???

Thanks if you can help!
David Otte
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top