目标:
-DeepZoom基本知识
-DeepZoomComposer工具
-MultiScaleImage控件
一.DeepZoom基本知识
-源于遥感影像的金字塔显示方式
-提供了与高分辨率图像进行交互的能力
-可以快速缩放图像而不影响应用的性能
-加载或平移图像时可以光滑过渡
-spring animations
应用
-高分辨率、极大图像的浏览;3D合成图像;广告。
分类
-Single Collection
二.DeepZoom Composer
-制件DeepZoom图片工具,http://www.microsoft.com/downloads/en/details.aspx?familyid=457b17b7-52bf-4bda-87a3-fa8a4673f8bf
三.MultiScaleImage控件
-打开、放大和平移多分辨率图片
-快速任意缩放展示大图形、高分辨率图像的应用程序
属性:
-Source – Web Uri
-UserSprings – springs animations
-ViewportOrigin - CenterPoint
-ViewportWidth – ZoomLevel
事件:
-ImageFailed
-ImageOpenFailed
-ImageOpenSucceeded
使用
<MultiScaleImage x:Name="msi" Width="474" Height="652" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="6,0,0,0" Source="dzc_output.xml"/>
Demo:
public partial class MainPage : PhoneApplicationPage
{
private double zoom = 1;
private bool isMoving = false;
private bool isDown = false;
private Point lastMouseDownPos = new Point();
private Point lastMousePos = new Point();
private Point lastMouseViewPort = new Point();
// Constructor
public MainPage()
{
InitializeComponent();
}
private void MultiScaleImage_ImageOpenSucceeded(object sender, RoutedEventArgs e)
{
msi.ViewportOrigin = new Point(0,0);
msi.ViewportWidth = 1;
}
private void PhoneApplicationPage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
lastMouseDownPos = e.GetPosition(msi);
lastMouseViewPort = msi.ViewportOrigin;
isDown = true;
msi.CaptureMouse();
}
private void PhoneApplicationPage_MouseMove(object sender, MouseEventArgs e)
{
lastMousePos = e.GetPosition(msi);
if(isDown && !isMoving)
{
isMoving = true;
double w =msi.ViewportWidth;
Point p = new Point(msi.ViewportOrigin.X,msi.ViewportOrigin.Y);
msi.UseSprings =false;
msi.ViewportOrigin = new Point(p.X,p.Y);
msi.ViewportWidth = w;
zoom = 1/w;
msi.UseSprings = true;
}
if(isMoving)
{
Point point = lastMouseViewPort;
point.X = (lastMouseDownPos.X - lastMousePos.X)/msi.ActualWidth*msi.ViewportWidth;
point.Y = (lastMouseDownPos.Y -lastMousePos.Y)/msi.ActualWidth*msi.ViewportWidth;
msi.ViewportOrigin = point;
}
}
private void PhoneApplicationPage_MouseLeave(object sender, MouseEventArgs e)
{
if (isMoving)
{
bool isShift = (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift;
double newzoom = zoom;
if (isShift)
newzoom /= 2;
else
newzoom *= 2;
Zoom(newzoom, msi.ElementToLogicalPoint(this.lastMousePos));
}
isMoving = false;
isDown = false;
msi.ReleaseMouseCapture();
}
private void Zoom(double zoomnew, Point p)
{
if (zoomnew < 0.5)
{
zoomnew = 0.5;
}
msi.ZoomAboutLogicalPoint(zoomnew / zoom, p.X, p.Y);
zoom = zoomnew;
}
private void PhoneApplicationPage_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
}
/// <summary>
/// 放大
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ApplicationBarIconButton_Click(object sender, EventArgs e)
{
msi.ZoomAboutLogicalPoint(1.5, 0, 0);
}
/// <summary>
/// 还原
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
{
this.msi.ViewportWidth = 1;
this.msi.ViewportOrigin = new Point(0,0);
}
private void ApplicationBarMenuItem_Click(object sender, EventArgs e)
{
Zoom(zoom*1.3,msi.ElementToLogicalPoint(new Point(.5*msi.ActualWidth,.5*msi.ActualHeight)));
}
}
{
private double zoom = 1;
private bool isMoving = false;
private bool isDown = false;
private Point lastMouseDownPos = new Point();
private Point lastMousePos = new Point();
private Point lastMouseViewPort = new Point();
// Constructor
public MainPage()
{
InitializeComponent();
}
private void MultiScaleImage_ImageOpenSucceeded(object sender, RoutedEventArgs e)
{
msi.ViewportOrigin = new Point(0,0);
msi.ViewportWidth = 1;
}
private void PhoneApplicationPage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
lastMouseDownPos = e.GetPosition(msi);
lastMouseViewPort = msi.ViewportOrigin;
isDown = true;
msi.CaptureMouse();
}
private void PhoneApplicationPage_MouseMove(object sender, MouseEventArgs e)
{
lastMousePos = e.GetPosition(msi);
if(isDown && !isMoving)
{
isMoving = true;
double w =msi.ViewportWidth;
Point p = new Point(msi.ViewportOrigin.X,msi.ViewportOrigin.Y);
msi.UseSprings =false;
msi.ViewportOrigin = new Point(p.X,p.Y);
msi.ViewportWidth = w;
zoom = 1/w;
msi.UseSprings = true;
}
if(isMoving)
{
Point point = lastMouseViewPort;
point.X = (lastMouseDownPos.X - lastMousePos.X)/msi.ActualWidth*msi.ViewportWidth;
point.Y = (lastMouseDownPos.Y -lastMousePos.Y)/msi.ActualWidth*msi.ViewportWidth;
msi.ViewportOrigin = point;
}
}
private void PhoneApplicationPage_MouseLeave(object sender, MouseEventArgs e)
{
if (isMoving)
{
bool isShift = (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift;
double newzoom = zoom;
if (isShift)
newzoom /= 2;
else
newzoom *= 2;
Zoom(newzoom, msi.ElementToLogicalPoint(this.lastMousePos));
}
isMoving = false;
isDown = false;
msi.ReleaseMouseCapture();
}
private void Zoom(double zoomnew, Point p)
{
if (zoomnew < 0.5)
{
zoomnew = 0.5;
}
msi.ZoomAboutLogicalPoint(zoomnew / zoom, p.X, p.Y);
zoom = zoomnew;
}
private void PhoneApplicationPage_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
}
/// <summary>
/// 放大
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ApplicationBarIconButton_Click(object sender, EventArgs e)
{
msi.ZoomAboutLogicalPoint(1.5, 0, 0);
}
/// <summary>
/// 还原
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
{
this.msi.ViewportWidth = 1;
this.msi.ViewportOrigin = new Point(0,0);
}
private void ApplicationBarMenuItem_Click(object sender, EventArgs e)
{
Zoom(zoom*1.3,msi.ElementToLogicalPoint(new Point(.5*msi.ActualWidth,.5*msi.ActualHeight)));
}
}