• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Drawing An Image In Full-Screen

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to draw a single image in full-screen mode. I can get it to switch into full-screen and draw strings, but not images. Here's my code:



This draws a blue screen with the string "Loading iamges...". Which means taht imagesAreLoaded is never being flipped to true. I have changed my code so that loadImage () appears like this following:



That draws a blue screen, but no "Loading images..." string, which I think means that it atleast allows the program to flip the imagesAreLoaded switch.

For the sake of completion, I'll post the ScreenManager class as well.


[ February 05, 2006: Message edited by: Brandon Tom ]
 
Brandon Tom
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I forgot to mention that I'm using Java 5.0
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a flaw (in my opinion anyway) in the ImageIcon class. It does not throw an exception when the file is not found. It does not return a null ImageIcon class. It doesn't even return a null Image class from getImage(). In short, it will load a nonexistant file with a width and height of -1. That's the only way I found to detect when the file is not being loaded, or being loaded improperly.

I'd bet that's what's happening. Make sure the file is being loaded.
 
Brandon Tom
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So basically, there's two issues: the first is that ImageIcon is not finding the image and failing to report that (in a way that's meaningful to this program), and the second issue would be that the image I'm trying to load isn't where I'm saying it is... hmm...

There is still something very strange occurring. loadImages () is still exiting before it switches the imagesAreLoaded flag to true. I'm baffled as to why this occurs if not exception is being thrown.

Thanks for the insight. It has been very clarifying.
[ February 06, 2006: Message edited by: Brandon Tom ]
 
Brandon Tom
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess, in a way, having ImageIcon.getImage () return an Image object with a height and width of -1 makes some sense.

Some programs have, literally hundreds of images, most of which are insignificant to the core functionality of the program. If you had to deal with try and catching in those circumstances, it might be a big headache (although I don't think it would take too a big a brain to work around it).

Null Image objects might be not better. You might not want to have to test every insignificant image whether or not it's a real object before you try to draw it. It could bear down on the application.

By returning an actual Image object with significant markers, if the image couldn't be found, you could still draw, but it would just draw a blank. If the images was crucial to the program you could still check it.

I'm just surprised at how hard it was to learn about this. I've been to dozens of websites that actual neglect to mention this fact.

Of course if I had just checked the API...
[ February 06, 2006: Message edited by: Brandon Tom ]
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you wanted to see if ImageIcon's image loading succeeded, you could always call it getImageLoadStatus method. That being said, I prefer to use javax.imageio.ImageIO.
 
Brandon Tom
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I resolved the issue. I discovered that when I run my program from the NetBeans IDE, creating a JAR and launching it from a directory where the image files aren't. I wonder if I can configure that.

I'll still need to modify the code so that I can detect when an images isn't

Also, I should look into the ImageIO class. That's the second time someone has mentioned it. What are the advantages of ImageIO to ImageIcon?
[ February 06, 2006: Message edited by: Brandon Tom ]
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>Also, I should look into the ImageIO class. That's the second time someone
>has mentioned it. What are the advantages of ImageIO to ImageIcon?

1. ImageIO knows more image formats. It has a plug-in architecture so you can install more reader/writers. A typical additional format people are interested in is TIFF.

2. You may not be interested in it for this example, but as the name suggests, the ImageIO classes also allow you to write images.

3. ImageIO reads in an image as a java.awt.image.BufferedImage, which for a lot of uses is a more convenient API than java.awt.Image. No more MediaTrackers!

4. If you create an ImageIcon from a URL or a filename it will uses Toolkit's getImage method which caches the Image data, and often this cache gets in the way. For example, if you update a file and try to reread an image, you will get the stale cached copy instead.

5. You can do more advanced things with image files like just reading the height and width of the image, reading any stored thumbnails or reading a series of images (common in TIFF files).

6. If you want to read a quick thumbnail on the fly, you can set the subsampling and read only every fourth pixel, for example, instead of creating the larger image only to shrink it.

7.Using an IIOReadProgressListener you can animate a progress bar to show how reading is progressing in large files.

I'm sure others can add more to this list.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic