Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2004

Tip: Looking for answers? Try searching our database.

help: lost bufferedimage content

Thread view: 
andrzej semeniuk - 23 Jan 2004 04:11 GMT
hi there,

i create a bufferedimage object, paint onto it, then redisplay it
periodically.  this works fine for a while; after moving the frame to
the background, then back to front etc, i totally lose the contents of
the buffer: all pixels are lost replaced with a white fill (component
background color).  now, i don't mind that this happens sometimes as
long as there would be a way to determine that the contents is lost,
in which case i would simply repaint the buffer.  however, i am using
bufferedimage, not volatileimage, and i don't know of a way to check
that the image has lost its content.

on the other hand i tried using volatileimage, with either
ImageCapabilities(true) and ImageCapabilities(false), but in this case
the drawn contents is not displayed even once; what's more, every time
i check contentsLost() it returns true, and yet the contents is not
displayed after painting into it.

i'm using1.4.1_02-b06 on windows xp, graphics card is nvidia geforce4
4200 go with 64mb of video memory.

here's the code for creating the buffered and volatile images:

     GraphicsEnvironment Ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
     GraphicsDevice Gd = Ge.getDefaultScreenDevice();
     GraphicsConfiguration Gc = Gd.getDefaultConfiguration();

//      __local.image = new java.awt.image.BufferedImage(
//          G.getClipRect().width,
//          G.getClipRect().height,
//          java.awt.image.BufferedImage.TYPE_INT_ARGB
//          );
//      __local.image = Gc.createCompatibleImage(
//          G.getClipRect().width,
//          G.getClipRect().height,
//          Transparency.TRANSLUCENT
//          );
       __local.image = Gc.createCompatibleVolatileImage(
           G.getClipRect().width,
           G.getClipRect().height,
           new ImageCapabilities(true)
           );

any ideas?
thanks
Chris Smith - 23 Jan 2004 14:55 GMT
> i create a bufferedimage object, paint onto it, then redisplay it
> periodically.  this works fine for a while; after moving the frame to
> the background, then back to front etc, i totally lose the contents of
> the buffer: all pixels are lost replaced with a white fill (component
> background color).

In your BufferedImage?  Are you sure of this?  This sounds suspiciously
like broken component painting code.  Perhaps your BufferedImage is
fine, but you just need to repaint it to the component.

> on the other hand i tried using volatileimage, with either
> ImageCapabilities(true) and ImageCapabilities(false), but in this case
> the drawn contents is not displayed even once; what's more, every time
> i check contentsLost() it returns true, and yet the contents is not
> displayed after painting into it.

If contentsLost is returning true, then you wouldn't expect to have the
contents displayed.  Did you get that backwards?

Nevertheless, I suspect you've got a more fundamental problem than using
a VolatileImage.  Let's solve the simpler BufferedImage problem first,
then work out VolatileImage if you need it.

Signature

www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

andrzej semeniuk - 23 Jan 2004 22:24 GMT
> > i create a bufferedimage object, paint onto it, then redisplay it
> > periodically.  this works fine for a while; after moving the frame to
[quoted text clipped - 5 lines]
> like broken component painting code.  Perhaps your BufferedImage is
> fine, but you just need to repaint it to the component.

yes, i'm sure it is bufferedimage.  i draw the image into the graphics
object i obtain in the paint method of a jcomponent.  the jcomponent
is embedded in a jpanel that is contained inside a jframe.  the jpanel
contains only this component, and spans the area of the frame.  in my
jcomponent paint method i draw the image first into the jcomponent's
graphics object, then i perform some custom drawing on that graphics
object based on some recent events (ie. mouse move).  basically, this
works fine for a while.  then if i change the order of the frame (move
it back, then front), the underlying image is not drawn, but the
mouse-move graphics is.  my guess would be that somehow the
bufferedimage memory had to be relinquished to the system.  although
annoying, that is still ok as long as i have some way to realize that
the image is lost and i should recreate it, but as far as i know
bufferedimage does not provide methods for this, volatileimage does?
i'm not interested in using volatileimage really, unless it would
solve my problem.

> > on the other hand i tried using volatileimage, with either
> > ImageCapabilities(true) and ImageCapabilities(false), but in this case
[quoted text clipped - 4 lines]
> If contentsLost is returning true, then you wouldn't expect to have the
> contents displayed.  Did you get that backwards?

in my paint() method i check whether contentsLost() is true.  if it
is, i redraw into the image, then draw the image into the jcomponent
graphics, but the image graphics is not displayed.

> Nevertheless, I suspect you've got a more fundamental problem than using
> a VolatileImage.  Let's solve the simpler BufferedImage problem first,
> then work out VolatileImage if you need it.

sure, that sounds good to me.
Chris Smith - 24 Jan 2004 02:14 GMT
> > > i create a bufferedimage object, paint onto it, then redisplay it
> > > periodically.  this works fine for a while; after moving the frame to
[quoted text clipped - 7 lines]
>
> yes, i'm sure it is bufferedimage.

Okay.

> my guess would be that somehow the
> bufferedimage memory had to be relinquished to the system.

No, that's not the case.  If you were to run out of memory using
BufferedImage, then your application would fail with an
OutOfMemoryException.  Under no circumstances would the system just
throw away the contents of that image without telling you.

> i draw the image into the graphics
> object i obtain in the paint method of a jcomponent.  the jcomponent
[quoted text clipped - 6 lines]
> it back, then front), the underlying image is not drawn, but the
> mouse-move graphics is.

This sounds *so* much like a broken paint that I'd like to see the
contents of that paint method.  Can you post it?

I also wonder if you're unintentionally creating a new BufferedImage
somewhere; that would cause you to lose the contents but it wouldn't
show up until the next repaint.  That sounds like your symptoms, right?

Signature

www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

andrzej semeniuk - 24 Jan 2004 13:34 GMT
chris, you were absolutely right, the problem was in my code,
bufferedimage works fine.  thanks very much for your help.

> > > > i create a bufferedimage object, paint onto it, then redisplay it
> > > > periodically.  this works fine for a while; after moving the frame to
[quoted text clipped - 35 lines]
> somewhere; that would cause you to lose the contents but it wouldn't
> show up until the next repaint.  That sounds like your symptoms, right?

that's a natural assumption.  in my case i was not updating a flag
that indicated to construct and redraw the buffered image when it
should.  stupid mistake, but that's why it's also the worst to debug.
Andrew Thompson - 23 Jan 2004 23:14 GMT
...
| here's the code for creating the buffered and volatile images:
<snip code 'snippet'>

Quoting Chris Smith..
"In your BufferedImage?  Are you sure of this?
This sounds suspiciously like broken component
painting code. "

| any ideas?

http://www.physci.org/codes/sscce.jsp
Much more effective than a code snippet..

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.