Click here to Skip to main content
15,894,539 members
Articles / Desktop Programming / WPF

Deep Zoom for WPF

Rate me:
Please Sign up or sign in to vote.
4.97/5 (54 votes)
24 Nov 2010Ms-PL13 min read 385.3K   9.1K   100  
An implementation of MultiScaleImage (Deep Zoom) for WPF, compatible with Deep Zoom Composer and Zoom.it.
using System.ComponentModel;
using System.Windows.Media;

namespace DeepZoom
{
    /// <summary>
    /// Represents a tile that displays an image in the screen.
    /// </summary>
    internal class VisualTile : INotifyPropertyChanged
    {
        private ImageSource _source;

        public VisualTile(Tile tile, MultiScaleTileSource tileSource)
        {
            ZIndex = tile.Level;
            Scale = 1 / tileSource.ScaleAtLevel(tile.Level);
            var position = tileSource.GetTilePosition(tile.Column, tile.Row);
            Left = position.X * Scale;
            Top = position.Y * Scale;
        }

        public VisualTile(Tile tile, MultiScaleTileSource tileSource, ImageSource source)
            : this(tile, tileSource)
        {
            Source = source;
        }

        public int ZIndex { get; private set; }

        public double Left { get; private set; }

        public double Top { get; private set; }

        public double Scale { get; private set; }

        public ImageSource Source
        {
            get { return _source; }
            internal set
            {
                _source = value;
                RaisePropertyChanged("Source");
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;
        protected void RaisePropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(name));
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Virtual Dreams
Brazil Brazil
Hi! I'm Roberto. I'm a Brazilian Engineering student at the University of São Paulo and the Ecole Centrale de Lille (France).

I've participated in the Imagine Cup competition and went to the world finals every year from 2005 to 2009. I also won the 1st place award in 2006, in India, for the Interface Design invitational, in 2007 in Korea, for the Embedded Development invitational, and in 2009 in Egypt for the Windows Mobile Award.

Currently I keep a blog (in English and Portuguese) at http://virtualdreams.com.br/blog/ and a weekly webcast about WPF and Silverlight (in Portuguese) at http://www.xamlcast.net.

Comments and Discussions