JavaFX - Loading Images
JavaFX provides many features which can be utilized while loading large images. Image has an attribute backgroundLoading which can be set to true, so that image loads in a background thread without freezing the UI. A placeholder image (thumbnail) can be shown using placeholder attribute. The approximate percentage of image's loading that has been completed can be determined from progress attribute.
Now lets see how to use these attributes. In below code we have set backgroundLoading to true and specified placeholder image.
// Load specified image in background thread
var imageView = ImageView {
image: Image {
url: "<image url>"
backgroundLoading: true
placeholder: Image {
url: "<thumbnail url>"
}
}
}
Now we can directly get the progress of image loading using imageView.image.progress or we can bind this value to another attribute as shown below
// Bind to Image.progress and print the progress
var progress = bind imageView.image.progress on replace {
println("progress {progress}");
}
The same progress attribute can be bound to actual progress bar. In this sample we are binding this progress to width of a Rectangle. So that the width of rectangle is proportional to the progress of image loading as shown below.
Rectangle {
x: 11
y: (sceneHeight - 9)
// Change width of rectangle proportional to image progress
width: bind ((sceneWidth - 20) * progress)/100.0
height: 3
arcWidth: 5
arcHeight: 5
fill: Color.RED
}
Source:



this is great. But I find image take more time than normal loading. In my case, I feel it is taking more than 30-40 percent of more time.
What your ideas on this ?
Posted by Vaibhav Choudhary on April 11, 2009 at 03:10 PM IST #
@Vaibhav I tried loading http://farm4.static.flickr.com/3077/2365118433_ccb790041d_o_d.jpg [800X600] image using Browser and JavaFX. It was taking almost same time. Can you compare?
Posted by Rakesh Menon on April 11, 2009 at 03:21 PM IST #
Hi i created flash like demo please check this out
http://farrukh.hostrator.com/
Posted by Farrukh obaid on April 13, 2009 at 02:31 AM IST #
@Farrukh This looks cool! Would you like to add a post to http://jfxstudio.wordpress.com/ ?
Posted by Rakesh Menon on April 13, 2009 at 08:48 AM IST #