Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (804)
Games in Android Showcase (237)
games submitted by our members
Games in WIP (867)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  ImageIO speed problem  (Read 8280 times)
0 Members and 1 Guest are viewing this topic.
Offline roland
« Posted 2011-08-01 09:23:19 »

Hi, I'm having a really strange problem. I'm making an applet that loads about 20 small images(32x32 or 64x64) with ImageIO.
This works fine in eclipse (the applet takes about 0.3 seconds to load the images), but when I export it to a jar and run it on my website, the applet takes 30 seconds to load just the images.
The total size of all the images is 160kb. I am on broadband and can download at 1.2mb/s and my webhost isn't that slow either.
Can anyone help me with this?

public BufferedImage LoadImage(String str)
      System.out.println("loading " + str);
      BufferedImage bf = null;
      URL url = null;
         url = new URL(codebase, str);
        catch (Exception e) {}
      BufferedImage image = null;
         image =;
      catch (IOException e)
      if (image == null)
         return null;
      bf = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
      bf.getGraphics().drawImage(image, 0, 0,bf.getWidth(),bf.getHeight(), null);
      return bf;

Offline theagentd
« Reply #1 - Posted 2011-08-01 11:04:41 »

Try to open the Java console. You'll see that the whole JAR is downloaded every time you load a picture.

Offline roland
« Reply #2 - Posted 2011-08-01 19:32:55 »

Thanks for the reply, theagentd.

That is indeed a problem if it does! I am looking at my java console and it doesn't say that. Do I need to change a setting?
Also I am not loading the image as a resource inside that applet, but from a file on my website.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline philfrei
« Reply #3 - Posted 2011-08-01 21:57:26 »

I'm not clear how the Java console would help here. If the code doesn't throw an exception or print a message to the console, then there wouldn't be much to see, afaik. But there may be tools that I am unaware of, as I only learned how to even get the console to show just a couple weeks ago!

However, each time you load from a file, you are incurring the time needed to bring that data over the internet, which is much slower than loading a "resource" that is part of the jar file. When you include the images as resources, they are brought over along with the rest of the applet, and loading is direct (all occuring on the client) rather than via streaming.

music and music apps:
Offline theagentd
« Reply #4 - Posted 2011-08-01 22:07:11 »

The problem I had was that I was loading images from a single JAR file, but somehow the caching didn't work and the JAR was downloaded every time I loaded an image. I found this out by first checking the network traffic (which showed about (Jar file size) x (number of images)). I could see in the Java console that the caching didn't work by starting the applet and quickly opening the console and increasing the trace level (just press 5 or something). It the screamed out "loading resource blah blah, cache post not found" over and over again. I never managed to get it working as it should but I suspect a bad HTTP server program was the culprit. Let's hope it's something else.  Wink

Offline ra4king

JGO Kernel

Medals: 508
Projects: 3
Exp: 5 years

I'm the King!

« Reply #5 - Posted 2011-08-01 22:30:39 »

Try including the resources inside the jar. That is the fastest way since only 1 file has to ever be downloaded: the jar file.

Offline Eli Delventhal

JGO Kernel

Medals: 42
Projects: 11
Exp: 10 years

Game Engineer

« Reply #6 - Posted 2011-08-02 00:28:43 »

You can also zip it on the server and then unzip the file and get the resources from there.

Still, 30 seconds seems a bit long. I'd profile how much of that time is the actual loading from the internets, and how much is ImageIO reading it. To do that you'd need to save the data locally first.

See my work:
OTC Software
Offline roland
« Reply #7 - Posted 2011-08-02 07:18:25 »

Thanks everyone for the replies!  Smiley
Sticking the images in the jar did the trick! now the applet takes about 5 seconds to load but ImageIO loads the images just as fast as offline.
Offline counterp

Senior Devvie

Medals: 11

« Reply #8 - Posted 2011-08-03 03:22:16 »

If permissions isn't a problem, the best solution is to store all media locally on the client. (A one time download)
Pages: [1]
  ignore  |  Print  

Riven (397 views)
2019-09-04 15:33:17

hadezbladez (5280 views)
2018-11-16 13:46:03

hadezbladez (2204 views)
2018-11-16 13:41:33

hadezbladez (5544 views)
2018-11-16 13:35:35

hadezbladez (1150 views)
2018-11-16 13:32:03

EgonOlsen (4585 views)
2018-06-10 19:43:48

EgonOlsen (5462 views)
2018-06-10 19:43:44

EgonOlsen (3119 views)
2018-06-10 19:43:20

DesertCoockie (4016 views)
2018-05-13 18:23:11

nelsongames (4708 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!