Solved

Applet.getImage() faster alternative

Posted on 2004-10-18
21
850 Views
Last Modified: 2008-03-17
Hello,

Is there any faster method than Applet.getImage()?

I'm writing an applet that displays images like a gallery, but I find Applet.getImage() a bit slow. Each of my image is about 100k or (800x600) so I know it will take time. But it is relatively slower than the speed of a Browser.

Size of image is important for quality wise, so is there any other way? Thought about using BufferedReader to read in stream then construct the image, would this be faster?

Thanks.
0
Comment
Question by:funnyveryfunny
  • 10
  • 5
  • 3
  • +1
21 Comments
 
LVL 92

Expert Comment

by:objects
ID: 12342993
add your images to a jar and load them from there
0
 
LVL 92

Assisted Solution

by:objects
objects earned 20 total points
ID: 12343003
to load from jar use:
getImage(getClass().getResource(imagename));
0
 
LVL 4

Author Comment

by:funnyveryfunny
ID: 12343050
thanx but my Image list is growing all the time so this would not be ideal.
0
 
LVL 4

Author Comment

by:funnyveryfunny
ID: 12343054
I'm reading Javadoc on ImageInputStream and ImageIO, would this be any good?
0
 
LVL 92

Expert Comment

by:objects
ID: 12343071
i doubt they'd make any difference.
0
 
LVL 4

Author Comment

by:funnyveryfunny
ID: 12343076
ImageIO provides a read() that returns BufferedImage which is fine but does it improve on speed?
0
 
LVL 4

Author Comment

by:funnyveryfunny
ID: 12343091
oh wise one, in your experience what shall I do?

Stick with Applet.getImage() and hope that user doesn't mind.
Use filecache?
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 12343341
Hi funnyveryfunny,

I'm assuming that you're creating an image viewer applet to show pictures from an album.

I am not sure that there are any metrics available for image loading times using the various I/O sources vs. getImage(). I would recommend that you measure and see how it goes.

\t
0
 
LVL 92

Expert Comment

by:objects
ID: 12343366
> ImageIO provides a read() that returns BufferedImage which is fine but does it improve on speed?

I doubt it, its probably using thew same mechanism to perform the download.
0
 
LVL 4

Author Comment

by:funnyveryfunny
ID: 12343382
Thanx orangehead911,
I'm looking into how I can retrieve Image metric data to display in JProgress bar while its loading.
Can you shed some lights?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Author Comment

by:funnyveryfunny
ID: 12343416
looks like I have to give up on that.

Now the least I can do for the poor viewers is to indicate some progress while they sat there wondering what's going on here? So how do show image loading progress using JProgressBar.
0
 
LVL 92

Expert Comment

by:objects
ID: 12343428
> thanx but my Image list is growing all the time so this would not be ideal.

you could rebuild your jar when your image list changed.
0
 
LVL 14

Accepted Solution

by:
Tommy Braas earned 20 total points
ID: 12343436
funnyveryfunny,

If you use ImageIO you can utilize a IIOReadProgressListener. Not sure exactly how to do that (haven't needed to), but look here http://java.sun.com/j2se/1.4.2/docs/api/javax/imageio/event/IIOReadProgressListener.html

There's also an article on Java.sun on ImageIO: http://java.sun.com/j2se/1.4.2/docs/guide/imageio/spec/imageio_guideTOC.fm.html

\t
0
 
LVL 4

Author Comment

by:funnyveryfunny
ID: 12343452
thanx Objects, I gave up on the idea of "speedy gonzalez" :-(

What about image loading progress? please advice.
0
 
LVL 4

Author Comment

by:funnyveryfunny
ID: 12343457
I'll look at the links now.
Thanx.
0
 
LVL 9

Assisted Solution

by:Ovi
Ovi earned 20 total points
ID: 12357042
When you request the image from your server, the http header should return the total file length. Use a normal download procedure to read the bytes of the image and notify the progress periodically. After the image is loaded, you can buil'it from it's byte array.

A way of faster download, is to use multiple threads to get the image. Supposing your image is 100 kb long, you could have 5 threads reading the image parts from 0-19 kb, 20-39 kb, ... up to 80-99 kb.  For this to be possible you have to make sure your server supports multipart downloads. If you are interested in this technique, please review the http protocol specifications for file transfer, and as an example look at FlashGet download manager.
The output of each download thread will lead you to the solution.
0
 
LVL 4

Author Comment

by:funnyveryfunny
ID: 12360285
Thanx Ovi, at the moment I'm intending to place the applet with www.geocities.com free service but in the future this could be any where so I dont want it as a server-dependent program.

I have tested the image loading progress using IIOReadProgressListener, although the documentation is not very specific I managed to implement a console version therefore give me a bit of time before I finalise this question.

In the mean time, thank you.
0
 
LVL 9

Expert Comment

by:Ovi
ID: 12366804
... you can try anyway with the multiple threads option. Usually all servers are upgraded to use the latest http protocol ....
And if the server is not using it, you can just use a single thread model to download. If your implementation is general enough, the applet will be capable of behaving in different ways, depending on the situation.
0
 
LVL 4

Author Comment

by:funnyveryfunny
ID: 12373751
Ovi, something for the future.

I decided to use ImageIO and ImageReader methods, cut down loading time by approx half.

thank you all.
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 12377614
=-)
0
 
LVL 9

Expert Comment

by:Ovi
ID: 12378081
That's cool. Thank you :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
json example 39 130
get weblogic logged in user in java 2 57
compre toata in where clue oracle 4 55
micro services spring boot application error 3 136
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

4 Experts available now in Live!

Get 1:1 Help Now