Wednesday, March 3, 2010

Calculating when a MultiScaleImage has reached 1:1 scale of the original image.

For a project I am working on I'm using a Silverlight MultiScaleImage to display an exceptionally large tiled image. As part of this I wanted to enforce a maximum zoom when the image was displayed at 1:1 scale. After some Googling I wasn't able to find any immediate solutions so I had to tackle it myself.

The solution I came up with in the end was fairly simple. I already had the original image width in pixels, so all I had to do was to compare that against MultiScaleImage.ActualWidth divided by MultiScaleImage.ViewportWidth before zooming.


if(_msi.ActualWidth / _msi.ViewportWidth > OriginalImageWidth)

Note: I'm still pretty new to the MultiScaleImage so if there's a better way feel free to comment.