Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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 2835 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?
Thanks,
roland

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
public BufferedImage LoadImage(String str)
   {
      System.out.println("loading " + str);
      BufferedImage bf = null;
      URL url = null;
        try
      {
         url = new URL(codebase, str);
      }
        catch (Exception e) {}
     
      BufferedImage image = null;
      try
      {
         image = ImageIO.read(url);
      }
      catch (IOException e)
      {
         System.out.println("error");
      }
      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.

Myomyomyo.
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.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
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

Myomyomyo.
Offline ra4king

JGO Kernel


Medals: 347
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.
 Cheesy
Offline counterp

Senior Member


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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (44 views)
2014-09-23 14:38:19

radar3301 (25 views)
2014-09-21 23:33:17

BurntPizza (62 views)
2014-09-21 02:42:18

BurntPizza (32 views)
2014-09-21 01:30:30

moogie (39 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!