Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Slow images in jar

 
Mich Robinson
Ranch Hand
Posts: 260
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Luigi Plinge
Ranch Hand
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 260
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 6083
71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 260
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic