Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

drawImage not getting the image drawn before printing!  RSS feed

 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not an applet, and I'm not displaying the image for the user, either. I've got an image (my oCanvas object is a Graphics2D) that I'm drawing by calling drawString and fillRect to put stuff on it, and then I'm writing it out to a file. I've been using this for a long time and am trying to simply modify it by calling drawImage on it. I have a local image file that I want to add to this image, and here's the code that's not working:

The class I'm in extends Component, which is why I have this in there, but I also tried it by overriding the imageUpdate method, and I've also tried it with null in there. drawImage is returning false, meaning the image is not yet loaded. I need my program to wait for that image to be drawn before going on, and I've been Googling around for a while trying to figure out a good way to do this, b/c I'm finding wading around this particular section of the API to be a bit hairy for me (being that I rarely do anything with graphics).
Thanks for any help!
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.
From the old AWT tutorial:

The MediaTracker class lets you easily download data for a group of images and find out when the images are fully loaded. Ordinarily, an image's data isn't downloaded until the image is drawn for the first time. To request that the data for a group of images be preloaded asynchronously, you can use the forms of checkID() and checkAll() that take a boolean argument, setting the argument to true. To load data synchronously (waiting for the data to arrive), use the waitForID() and waitForAll() methods. The MediaTracker methods that load data use several background threads to download the data, resulting in increased speed.
To check on the status of image loading, you can use the MediaTracker statusID() and statusAll() methods. To simply check whether any image data remains to be loaded, you can use the checkID() and checkAll() methods.

 
Brian Pipa
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the javadocs:

Try converting your .bmp image to one of the supported formats.
Brian
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Duh! Thanks so much. I was *really* tired yesterday!
:roll:

Originally posted by Brian Pipa:
From the javadocs:

Try converting your .bmp image to one of the supported formats.
Brian
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!