This is a simple example demonstrating how to load an external image (not embed). It will also detect the downloading progress and illustrate it with the progress bar.
The source file size of Flash is much larger than Silverlight. It’s because I used many components in this application which result in a increase in file size.
Comparison
Flash implementation: 40 minutes (Implemented First)
Silverlight implementation: 40 minutes
What’s the difference?
- Loading Image: Loader [AS3] vs BitmapImage[C#]
Source codes
Loading External Image [Flash 9, AS3] (391.7 KiB, 2,528 hits)
Loading External Image [Silverlight 2, C#] (25.4 KiB, 3,126 hits)
Flash
Silverlight
Loading Image: Loader [AS3] vs BitmapImage[C#]
The approach in detecting image loading progress in Flash is different to that of Silverlight. The image has to be loaded completely before you can add the image to stage.
// AS3
var urlRequest : URLRequest = new URLRequest(URL);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, on_complete);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, on_progress);
loader.load(urlRequest);
private function on_complete(e : Event):void{
// bitmap image
var bitmap: Bitmap = loaderInfo.content as Bitmap;
}
private function on_progress(e:ProgressEvent):void{
// e.bytesLoaded
// e.bytesTotal
}
While in C#, you have to add the image to the stage for triggering the loading process. It seems that the you can’t detect the file size if you use BitmapImage to download the image.
// C# BitmapImage bitmapImage = new BitmapImage(); bitmapImage.DownloadProgress += new EventHandler(bitmapImage_DownloadProgress); bitmapImage.UriSource = new Uri(URL, UriKind.Absolute); Image newImage = new Image() { Source = _bitmapImage }; void bitmapImage_DownloadProgress(object sender, DownloadProgressEventArgs e) { int progress = e.Progress; // 0 = 100 if (e.Progress == 100) { // finish } }

October 23rd, 2008 at 10:08 am
I think sl is hiding the detail, since it can tell the progress, it definitely knows the size and current downloaded size, not simply not telling you(exposing it)
January 6th, 2009 at 7:15 am
Hi,
I haven’t checked the code, but I only want to point out that browser usually caches the images. So , if you run first SL app, and after that you run FL app. The second application will load faster.
On the other hand if you clear your cache, then your download speed might depend if any host between your computer and the source has cached the image, and also the ‘normal’ networking concepts (current bandwidth, the selected route, blah blah blah… )
Regards,
Herberth
February 10th, 2009 at 10:03 pm
You need to increas the FPS on the Flash-application to make the comparison more correct. this Flash-application is set to 12 FPS, who would set it to that?
I like this concept, but you need to make the exampels more correct!
February 23rd, 2009 at 10:13 pm
too much cheap sharpening artifacts for silverlight, image looks better in flash… i vote flash then.
May 1st, 2009 at 1:00 am
Browser caching makes it hard to compare loading speed in the two examples. Silverlight seem to do a poor resampling job though - what rolf calls “cheap sharpening artifacts” is really not image sharpening but lack of real downsampling. I vote flash!
May 19th, 2009 at 12:59 am
haha taaaaiiiiiizz de laid serieux ya trop rien ki marche
June 24th, 2009 at 2:50 am
wats with the kid!!!
August 8th, 2009 at 6:33 pm
Flash vs Silverlight: Loading External Image…
Thank you for submitting this cool story - Trackback from NewsPeeps…
October 29th, 2009 at 4:45 pm
I have implemented the Silverlight version in my site, but the progress (whether it is text or through a progress bar) is not fluid at all. The progress just jumps around until it is done. For example it will show: 10%, 24%, 76%, 22%, 100%, 58%, etc. Any ideas why this is happening? I am using the example code exactly as it is shown.