Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Progress callback of image load

Posted on 2007-12-01
11
Medium Priority
?
274 Views
Last Modified: 2010-03-30
Hi,

I'm using java.awt.image.BufferedImage to load images from my local web server. The problem is that loading these images can take a long time and my applet just freezes. Until it's done. I'm loading them like:

        try
        {
            Buffered img = ImageIO.read(this.getClass().getResourceAsStream(("myfile.jpg")));
        }

Is there someway to load it in another thread, and get progress notifications, like every %10 or something? This way I can draw a graphic for the user of the image loading instead of just having the browser lockup until it's done.

Thanks
0
Comment
Question by:DJ_AM_Juicebox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
11 Comments
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 20389667
you can use MediaTracker

http://java.sun.com/javase/6/docs/api/java/awt/MediaTracker.html

but that won't tell how much has been loaded.

or use a listener (and load the image in a different thread)

http://java.sun.com/mailers/techtips/corejava/2007/tt0207.html#2
0
 

Author Comment

by:DJ_AM_Juicebox
ID: 20389711
Ok I'll check those out, the lsitener sounds more promising.

One thing I don't get about this process - my applet loads 6 high res images when it starts up (probably 400 x 600 pixels each). I only am displaying one of them at startup though, the others are just sitting in memory waiting to be shown. This initial load up takes like 20 seconds. What is the bottleneck here - is it that my webserver is just really slow in loading the local images? Or is the java applet trying to move the loaded images into the client's memory, so while I'm not necessarily displaying the images yet, java is already trying to transfer the images into the client browser's memory? Is that how it works?

Thanks
0
 
LVL 92

Expert Comment

by:objects
ID: 20389748
hard to say, the vm is going to take time to load initially.
plus downloading the images is going to take time, you can jar them up to improve performace as only one http request would be required.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 86

Expert Comment

by:CEHJ
ID: 20390745
Where are the images. Are they where the applet is running (the client) or are they where the applet originates (the server)?
0
 

Author Comment

by:DJ_AM_Juicebox
ID: 20391611
The images are where the applet originates (the server). So I'm assuming they are loaded into the client's memory (even though they're not yet displayed) which means they need to be downloaded by the client?
0
 
LVL 92

Expert Comment

by:objects
ID: 20392568
thats correct, which is going to take time (on top of time to load classes/jars and start vm)
0
 

Author Comment

by:DJ_AM_Juicebox
ID: 20392601
How can one figure out about how long it takes to load classes/jars? Is it significant at all? At what point does it become really slow, etc? How can you improve load time of the classes etc?

My project has about 8 class files, the largest of which is 8kb.
0
 
LVL 92

Expert Comment

by:objects
ID: 20392626
how longs a piece of string :)
Depends on the size, and the network connection.
In your case though it sounds like it would not be significant, and the loading of the vm and images would be the signioficant parts.

one way to improve loading would be to jar up classes, that way only a single http request would be needed instead of 8.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 20392665
Use a URLConnection to get the image, then you'll know how big it is, which is essential for a percentage progress bar
0
 
LVL 92

Expert Comment

by:objects
ID: 20392680
> Use a URLConnection to get the image, then you'll know how big it is, which is essential for a percentage progress bar

unnecessary and will make it sloooowwwwer
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 20392712
>>unnecessary

?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

597 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