Jim,

I figured out my problem.  It had nothing to do with MemoryImageSource.

It was all my own dumb mistake.  I've been almost entirely programming
in Swing for the last 5 years.  Swing does all the buffering.

I started a little applet project in AWT just to get a small, light, fast
applet. It turns out that Component.update() either has changed or what
I was doing before never had a problem with update().

update() clears the drawing area -- in this case a Canvas -- to the background
color and then calls paint().  One must over ride update() to stop the
flickering and tearing.  I just override update in MyCanvas to a stub.

update()
{
       return;
}

Either I knew this once and forgot or it's changed since the last time
I made my own custom component from Canvas.  It was all me.

And I pretty much am relying on BufferStrategy now so no offscreen drawing
what so ever.  It works flawlessly now.

Thanks for responding....

Ken

Jim Graham wrote:
When you set the animated attribute to true on a MIS it will never be
"complete" so drawImage will never return true.

The return value of drawImage should probably be ignored for 99.999999%
of code - it doesn't tell you anything that you really need to know. All
it is telling you is if all of the image data has been completely loaded
from the source, but your ImageObserver will be notified when new data
is available so there isn't much you need to do with the return value
other than its informative (novelty?) value.  In particular, if you
immediately reissue the drawImage call it will paint exactly the same
thing it painted the previous time until new data arrives (which isn't
likely to happen if you are wasting all of the CPU time repainting
something that hasn't changed yet).

With respect to the change in behavior in 1.4 vs. 1.5, I'm not sure what
might be causing that without a standalone test case.  The only odd
thing I see is that you are double buffering things - dumping pixels
into canvasImage with newPixels and then immediately transferring them
to buffer with drawImage and later the pixels get dumped from buffer to
the screen with the drawImage in the paint method - why not just use the
drawImage to the screen directly?

            ...jim

Ken Warner wrote:

I'm haveing a strange problem -- I've used MemoryImageSource before with
great success.  But now, doing the same thing I've done before in Java
1.4
I'm getting flickering on newPixels() in Java 1.5...

That is, when I send new pixels to my MemoryImageSource mis and
repaint() the image flickers badly.  Didn't do this in 1.4.

The odd thing is that --

while((status = bg.drawImage(canvasImage,0,0,thisW, thisH,this)) ==
false);

never breaks because bg.drawImage never returns true.  Do I have to
use a MediaTracker
or something???

Here's what I'm doing -- I've tried it using BufferStrategy and get
the same flicker

  //this is an AWT Canvas
  private Image canvasImage = null;
  private Image buffer = null;
  private Graphics2D bg = null;
  private MemoryImageSource mis = null;
  private ColorModel cm = null;
  init()
  {
      thisW = this.getWidth();
      thisH = this.getHeight();
      mis = new MemoryImageSource(thisW,thisH,pixels,0,thisW);
      mis.setAnimated(true);
      mis.setFullBufferUpdates(true);
      canvasImage = this.createImage(mis);
      buffer = this.createImage(thisW, thisH);
      bg = (Graphics2D)buffer.getGraphics();
   }

  public void paint(Graphics g)
  {
      g.drawImage(buffer,0,0,thisW, thisH,this);
  }
     public void newPixels(int [] newPixels)
  {
      mis.newPixels(newPixels, ColorModel.getRGBdefault(),0, thisW);
      boolean status = false;
      //while((status = bg.drawImage(canvasImage,0,0,thisW,
thisH,this)) == false);
      bg.drawImage(canvasImage,0,0,thisW, thisH,this);
      this.repaint();
  }

===========================================================================

To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
of the message "signoff JAVA2D-INTEREST".  For general help, send
email to
[EMAIL PROTECTED] and include in the body of the message "help".




===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to