aspose file tools*
The moose likes Java in General and the fly likes Slow images in jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Slow images in jar" Watch "Slow images in jar" New topic
Author

Slow images in jar

Mich Robinson
Ranch Hand

Joined: Jun 28, 2009
Posts: 250
    
    1
I have a jar file but the program when running as an application takes some time to grab the images and display them. When the application first starts it ends up displaying the pieces in an othello game about 5 seconds before displaying the board and this looks quite poor - I was expecting it to do this instantly as it's all wrapped up in the jar. As an applet everything is instant but then it's using different code to grab the images and sounds.

Application code to grab the image:

What am I doing wrong?
Is there a way to have one bit of code that grabs images for applications and applets?
Same for sound?

Cheers


Arcade : Alien Swarm
Board : Chess - Checkers - Connect 4 - Othello
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

I don't know why it's taking 5 seconds to load an image from a jar - that is quite strange. Have you ruled out disk corruption?

Some suggestions -

a) Mitigate the problem by not displaying your pieces until after calling the routine to load the board

b) Try loading it from a regular file rather than a jar - does this make a difference?

c) Pre-load the Image when the application starts. If it takes a noticeable amount of time then, kick off the loading process in a background thread and display an intro / settings screen in the meantime.
Mich Robinson
Ranch Hand

Joined: Jun 28, 2009
Posts: 250
    
    1
Luigi Plinge wrote:I don't know why it's taking 5 seconds to load an image from a jar - that is quite strange. Have you ruled out disk corruption?
The image is fairly large (150k of a 200k jar) but I thought it would load the whole jar before doing anything else.

Luigi Plinge wrote:a) Mitigate the problem by not displaying your pieces until after calling the routine to load the board
I tried this - 10 seconds seemed safe - but this is a hell of a time to look at a blank page or a rather dull title page.

Luigi Plinge wrote:b) Try loading it from a regular file rather than a jar - does this make a difference?
It was equally slow - I moved it to a jar to try and improve things.

Luigi Plinge wrote:c) Pre-load the Image when the application starts. If it takes a noticeable amount of time then, kick off the loading process in a background thread and display an intro / settings screen in the meantime.
I might have to do this but I'd rather fix the original issue if I can.
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

Have a go using ImageIO.read(File input).

Anyways 200k shouldn't take a fraction of a second to load, assuming it's coming from a local hard disk. Probably you're doing something wrong after you've loaded it.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  16

Maybe you can post an SSCCE for us that demonstrates the problem. Make sure to include the image (or one that produces the same problem).
Mich Robinson
Ranch Hand

Joined: Jun 28, 2009
Posts: 250
    
    1
I solved the issue by using much smaller images and tilling them. It's not quite so pretty but the trade off is worth it due to having a much smaller jar (300k -> 60k) and the images load instantly (well nearly). Feel free to give it a try, it's the othello program below. Thanks for your advice.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Slow images in jar