Silverlight Beta 2 Update Flash vs Silverlight: JavaScript Sample 1
Oct 23

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

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
	}
}

Shares and Enjoy~

Did you like this post?

Subscribe here:  

9 Responses to “Flash vs Silverlight: Loading External Image”

  1. unruledboy Says:

    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)

  2. Herberth Madrigal Says:

    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

  3. Nolz Says:

    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!

  4. rolf Says:

    too much cheap sharpening artifacts for silverlight, image looks better in flash… i vote flash then.

  5. Sphinx Says:

    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!

  6. haha Says:

    haha taaaaiiiiiizz de laid serieux ya trop rien ki marche

  7. tali Says:

    wats with the kid!!!

  8. NewsPeeps Says:

    Flash vs Silverlight: Loading External Image…

    Thank you for submitting this cool story - Trackback from NewsPeeps…

  9. brandon Says:

    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.

Leave a Reply