Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight
Visual Design
Deep Zoom
Silverlight
Deep Zoom

Updated: November 2008

Deep Zoom provides the ability to zoom almost arbitrarily large images in Silverlight in a performant manner. Images can be displayed at very small and very large scale without affecting performance of the application displaying the image. The only property affecting performance is the number of pixels to be displayed on screen.

To see an example of a Web site that uses Deep Zoom, click here. You can use the mouse wheel to zoom in and out and move around the images by dragging.

This overview introduces you to Deep Zoom, including scenarios for its use and how you can utilize it in your Silverlight applications.

This topic contains the following sections.

The main scenarios for Deep Zoom center on displaying and navigating large images and/or a panorama of images. Normally, loading large images is not an optimal experience for users because of the lag required for the images to load. Deep Zoom mitigates this difficulty by loading progressively higher resolution images. This creates a "blurry to crisp" experience for users (for more information, see Inside Deep Zoom later in this topic). In addition, Deep Zoom provides functionality to allow users to change their view of an image, using spring animations giving users the impression of a smooth movement around the image(s). For example:

  • Exploration of Very Large or High Resolution Images: A classic example of this would be zooming in on parts of a large map to see different levels of detail and then, using the mouse, moving your view around the map surface. As the user moves their view, animations are used to give the user the impression that they are "moving" from one place to the other on the image. Another example would be exploring a professional photo composition made up of high-resolution pictures.

  • 3-D Photography: Take pictures of a room, one after the other, creating a collection of photos that make up a 360 degree picture of the room. Now the user can pan around the room with each photo blending into the other.

  • Advertisements: You could create a relatively low-resolution image to represent the overall theme of the ad, and then have progressively higher resolution images containing more impressions and data about the product. When the page the ad is embedded in first loads, the ad smoothly sharpens and draws the attention of the reader by loading subsequently higher resolution images. In addition, if the user's mouse enters the ad, different parts of the ad can zoom in.

Deep Zoom enables smooth loading and panning by serving up multi-resolution images and using spring animations.

Loading

Deep Zoom uses several aspects of multi-resolution images to achieve a high frame-rate and fast open experience for even very large images. On open, only a small amount of data that can be loaded very quickly is needed to show something on screen. The initial experience is to show a scaled up version of a low resolution version of the image, and blend in higher resolutions as they become available. This is the reason for the telltale blurry-to-sharp experience in Deep Zoom. It is also the reason that Deep Zoom is able to seemingly open images immediately without much wait time to load image data, regardless of the size of the image.

Cc645050.Different_res_over_time(en-us,VS.95).png

Besides initial loading, this same behavior is experienced as the user interacts with the application (for example, zooming and panning). Serving up images of varying resolutions as needed is accomplished using an image pyramid.

Image Pyramid

An image pyramid tiles an image into 256x256 tiles of JPG or PNG images (the size here is arbitrary and can be modified), and it stores lower resolution versions of the image in tiles as well. Each tile is stored in a separate file, and each level of the pyramid is stored in separate folders. The image below shows schematically how the image pyramid works. The image itself is available in full resolution at the bottom of the pyramid (see image below), and lower resolution versions down to 4x4 pixels are stored alongside the full resolution image. The images at each level of the pyramid are stored in 256x256 pixel tiles (indicated by the white lines in the images). This allows Deep Zoom to fetch only those tiles required for the current size of the image on screen, instead of downloading the entire image. For example, if you zoomed in to see only the highlighted middle part of the image, Deep Zoom only loads the highlighted tiles rather than the entire 1024x1024 image.

Cc645050.Image_pyramid(en-us,VS.95).png

Creating these pyramids by hand can be tedious, so using a tool to convert your images into an image pyramid is recommended. For example, you can use Deep Zoom Composer to do this. The file format used to access the image pyramid uses an XML schema. Again, you can generate this file format using Deep Zoom Composer, but you may want to exert more precise control over your file format by creating the XML by hand or by manually making changes to a tool generated file. To learn more about the XML schema used by the Deep Zoom file format, see Deep Zoom File Format Overview.

Cc645050.alert_note(en-us,VS.95).gifNote:

Deep Zoom image pyramids only support the image files supported by the BitmapImage class.

Cc645050.alert_note(en-us,VS.95).gifNote:

Photosynth is a tool that uses the same format as Deep Zoom composer making it well suited for Deep Zoom applications. Photosynth was designed for creating three-dimensional, 360-degree models. For example, you could take a series of digital photos of a place you have visited, load the images into Photosynth, and Photosynth analyzes each photo for similarities which it then uses to build a model of where the photos were taken (stitches them together).

Panning and Zooming Animations

Every movement (pan or zoom) inside of Deep Zoom uses spring animations. These springs animate from an initial to final state, where the gradient relative to time decays exponentially towards 1. The spring destination value is immediately updated in response to a user zoom/pan action. When the developer changes the display viewport, the transition to fit the content into the new viewport also happens using springs to ensure smoothness and visual continuity.

This section walks through creating a very simple Deep Zoom application. The steps are as follows:

1. Create an image pyramid.

2. Add a Deep Zoom object like MultiScaleImage or MultiScaleSubImage to your application.

3. Hook up events to add interactivity (zoom and panning) to your Deep Zoom object(s).

Create an Image Pyramid

As mentioned above, the best way to create an image pyramid is to use a tool like Deep Zoom Composer. Using this tool, you can create an image pyramid out of a single image or multiple images arranged in a panorama.

Add a Deep Zoom object

Once you have a Deep Zoom pyramid, also known simply as a Deep Zoom image, you need a Deep Zoom object like MultiScaleImage to load it. You can create a MultiScaleImage in XAML as in the following example.

<MultiScaleImage x:Name="deepZoomObject" Source="source/items.dzi" />

Or you can create a MultiScaleImage in procedural code as in the following example.

C#
MultiScaleImage myDeepZoomObject = new MultiScaleImage();
myDeepZoomObject.Source = new Uri("source/items.dzi");
Dim myDeepZoomObject As MultiScaleImage = New MultiScaleImage
myDeepZoomObject.Source = New Uri("source/items.dzi")

Note that the Source property points to the Deep Zoom image you created in the first step. At this point, when the Web page opens, the image zooms onto the screen, while going from blurry to crisp resolution.

Hook up Events

At this point, the user cannot interact with the image yet. To enable interaction, you need to hook events to the MultiScaleImage and use procedural code to provide the zooming and panning functionality.

In this simple example, the MouseEnter event is used to zoom into the middle of the image when the mouse pointer moves over the image.

<MultiScaleImage x:Name="deepZoomObject" Source="source/dzc_output.xml" 
 MouseEnter="DeepZoomObject_MouseEnter" />

C#
private void DeepZoomObject_MouseEnter(object sender, MouseEventArgs e)
{

    // The ZoomAboutLogicalPoint method allows you to zoom and pan
    // in the same step. The first parameter is the zoom (3x) and the
    // third and fourth parameters are the respective x and y coordinates
    // of the logical point to zoom around.
    this.deepZoomObject.ZoomAboutLogicalPoint(3, .5, .5);
}

Visual Basic
Private Sub DeepZoomObject_MouseEnter(ByVal sender As Object, ByVal e As MouseEventArgs)
    ' The ZoomAboutLogicalPoint method allows you to zoom and pan
    ' in the same step. The first parameter is the zoom (3x) and the
    ' third and fourth parameters are the respective x and y coordinates
    ' of the logical point to zoom around.
    Me.deepZoomObject.ZoomAboutLogicalPoint(3, 0.5, 0.5)
End Sub

Run this sample

In the preceding example, the ZoomAboutLogicalPoint method is what does the zooming and panning. The first parameter is the zoom multiplier, which is incremented from the current zoom factor of the image. For example, in this example the default zoom is 1, so the value 3 means that it is zoomed in 3 times. If you were to zoom again using the same value, you would be zoomed in at 3 * 3 which is 9 times from the original size.

The second and third parameters of the ZoomAboutLogicalPoint method are the respective x and y coordinates of the logical point of where to zoom around (or where to pan to). A logical point uses normalized values (0 to 1) for x and y positions within the image. Therefore, the value 0.5,0.5 is in the middle of the image because 0.5 is in the middle of 0 and 1. If you specified a coordinate value <= 0 or >=1, the image would pan completely out of view.

The area of the image the user views at any given time is called the viewport area. The following illustration shows what the viewport area looks like conceptually.

Cc645050.DeepZoom_ViewPort(en-us,VS.95).png

Below is the complete code for this simple "mouse-over/mouse-off" zoom. This code includes a MouseLeave event so that when the mouse pointer leaves the image, it zooms and pans back to its original perspective.

<MultiScaleImage x:Name="deepZoomObject" Source="source/dzc_output.xml" 
 MouseEnter="DeepZoomObject_MouseEnter"
 MouseLeave="DeepZoomObject_MouseLeave"/>

C#
private void DeepZoomObject_MouseEnter(object sender, MouseEventArgs e)
{

    // The ZoomAboutLogicalPoint method allows you to zoom and pan
    // in the same step. The first parameter is the zoom (3x) and the
    // third and fourth parameters are the respective x and y coordinates
    // of the logical point to zoom around.
    this.deepZoomObject.ZoomAboutLogicalPoint(3, .5, .5);
}

private void DeepZoomObject_MouseLeave(object sender, MouseEventArgs e)
{
    double zoom = 1;
    zoom = zoom / 3;
    // This time the zoom is reversed (1/3) although the pan 
    // remains the same - zoom back out from the middle.
    this.deepZoomObject.ZoomAboutLogicalPoint(zoom, .5, .5);
}

Visual Basic
Private Sub DeepZoomObject_MouseEnter(ByVal sender As Object, ByVal e As MouseEventArgs)
    ' The ZoomAboutLogicalPoint method allows you to zoom and pan
    ' in the same step. The first parameter is the zoom (3x) and the
    ' third and fourth parameters are the respective x and y coordinates
    ' of the logical point to zoom around.
    Me.deepZoomObject.ZoomAboutLogicalPoint(3, 0.5, 0.5)
End Sub

Private Sub DeepZoomObject_MouseLeave(ByVal sender As Object, ByVal e As MouseEventArgs)
    Dim zoom As Double = 1
    zoom = (zoom / 3)
    ' This time the zoom is reversed (1/3) although the pan 
    ' remains the same - zoom back out from the middle.
    Me.deepZoomObject.ZoomAboutLogicalPoint(zoom, 0.5, 0.5)
End Sub

Run this sample

For a simple sample that shows basic functionality including panning (by dragging with your mouse) and zooming (using the mouse wheel or clicking), use the following links:

If you want to work with a set of individual multi-resolution images, for example, programmatically move individual multi-resolution images around the screen or filter your images, you will want to use a collection of images rather than a single high-resolution image. There are two basic things you need to do to do this:

  1. Export your images as a collection rather than as a single image. You can do this in Deep Zoom Composer. Just make sure to select the "Create Collection" check box when you export your composition. Images within the collection you export are called "sub images" and each one has its own image pyramid.

  2. Access the sub images in the MultiScaleImage (individual MultiScaleSubImage objects) by using the SubImages property. The following example shows how to get a list of sub images in a MultiScaleSubImage.

    C#
    private List<MultiScaleSubImage> RandomizedListOfImages()
    {
      List<MultiScaleSubImage> imageList = new List<MultiScaleSubImage>();
      Random ranNum = new Random();
    
      // Store List of sub images.
      foreach (MultiScaleSubImage subImage in myMultiScaleImage.SubImages)
      {
        imageList.Add(subImage);
      }
    
      return imageList;
    }
    Private Function RandomizedListOfImages() As List
      Dim imageList As List = New List
      Dim ranNum As Random = New Random
      ' Store List of sub images.
      For Each subImage As MultiScaleSubImage In myMultiScaleImage.SubImages
        imageList.Add(subImage)
      Next
      Return imageList
    End Function
    
    

The following sample allows you to rearrange images in a grid pattern by manipulating all the MultiScaleSubImage objects in the collection. Click the Randomize Images button to see the effect:

Date

History

Reason

November 2008

Added Visual Basic versions of code snippets.

Content bug fix.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker